|
From: Arun D. <ar...@mc...> - 2005-08-11 19:20:14
|
Greetings...
Does Valgrind have any constraints in memory debugging programs making use of makecontext/swapcontext/setcontext system calls? Towards this post is a small program using makecontext/swapcontext, which (deliberately) leaks memory. Valgrind is able to nicely point out the memory leaks in main(), but not in the functions called in non-main/swap'd context(s) - or so it seems to me.
If valgrind has constraints, what can I possibly attempt to be able to use Valgrind successfully for such programs using setcontext/swapcontext?
If it is relevant: Valgrind version 2.4.0, Linux kernel 2.4.18, GLIBC 2.3.2.
Best regards,
-Arun.
Valgrind executed as: valgrind --show-reachable=yes --leak-check=full --leak-resolution=high --log-file=vg.out --tool=memcheck sample
Program: sample.c:
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
#define STKSZ 8192
static ucontext_t uc[3];
static int switches = 0;
void a(int i) {
if(--i > 0) { a(i); }
malloc(512);
}
void d(int i) { malloc(i); }
void c(int i) { d(i); }
void b(int i) { c(i); }
static void f (int n) {
int m = 0;
unsigned int fa;
while (1) {
if (++switches == 5) {
return;
}
malloc(256);
a(4);
swapcontext (&uc[n], &uc[3 - n]);
}
}
int main (void) {
char s1[STKSZ], *st1;
char s2[STKSZ], *st2;
int i, div;
st1 = (char *)malloc(STKSZ);
st2 = (char *)malloc(STKSZ);
if((getcontext(&uc[1]) < 0) || (getcontext(&uc[2]) < 0)) {
perror("getcontext");
exit(1);
}
uc[1].uc_link = &uc[0];
uc[1].uc_stack.ss_sp = &st1[0];
uc[1].uc_stack.ss_size = STKSZ;
makecontext (&uc[1], (void (*) (void)) f, 1, 1);
uc[2].uc_link = &uc[0];
uc[2].uc_stack.ss_sp = &st2[0];
uc[2].uc_stack.ss_size = STKSZ;
makecontext (&uc[2], (void (*) (void)) f, 1, 2);
swapcontext(&uc[0], &uc[1]);
return 0;
}
|
|
From: Robert W. <rj...@du...> - 2005-08-11 20:01:15
|
> Does Valgrind have any constraints in memory debugging programs making > use of makecontext/swapcontext/setcontext system calls? We have it working, but you have to tell Valgrind about the stack for each thread. There's an example in memcheck/tests/stack_changes.c that should demonstrate what you need to do. This functionality is in 2.4.1 and 3.0.0 - earlier versions don't handle this. Regards, Robert. --=20 Robert Walsh Amalgamated Durables, Inc. - "We don't make the things you buy." Email: rj...@du... |