|
From: Arun D. <ar...@mc...> - 2005-08-11 23:17:54
|
Robert,
Thank you for the quick response!
I tried using VALGRIND_STACK_REGISTER/DEREGISTER in the sample code
(am listing it below), and am now using version "3.0.0" of Valgrind. However, I
still don't see the leaked memory on the alternate stacks/contexts being
properly detected by Valgrind, and the leak from the main stack continues to
be detected properly.
I suppose, if this new feature in Valgrind was tested, I am missing something.
Could you provide any insight into this?
Best regards,
-Arun.
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
#include "valgrind.h"
#define STACK_SIZE 4096
struct ucontext ctx1, ctx2, oldc;
int count;
void d(void) { malloc(1234); }
void c(void) { d(); }
void b(void) { c(); }
void a(void) { b(); }
void hello(struct ucontext *newc)
{
printf("hello, world: %d\n", count);
if (count++ == 2)
newc = &oldc;
a();
setcontext(newc);
}
int init_context(struct ucontext *uc)
{
void *stack;
int ret;
if (getcontext(uc) == -1) {
perror("getcontext");
exit(1);
}
if ((stack = malloc(STACK_SIZE)) == NULL) {
perror("malloc");
exit(1);
}
ret = VALGRIND_STACK_REGISTER(stack, stack + STACK_SIZE);
uc->uc_link = NULL;
uc->uc_stack.ss_sp = stack;
uc->uc_stack.ss_size = STACK_SIZE;
uc->uc_stack.ss_flags = 0;
return ret;
}
int main(int argc, char **argv)
{
int c1 = init_context(&ctx1);
int c2 = init_context(&ctx2);
makecontext(&ctx1, (void (*)()) hello, 2, &ctx2);
makecontext(&ctx2, (void (*)()) hello, 2, &ctx1);
a();
swapcontext(&oldc, &ctx1);
VALGRIND_STACK_DEREGISTER(c1);
free(ctx1.uc_stack.ss_sp);
VALGRIND_STACK_DEREGISTER(c2);
free(ctx2.uc_stack.ss_sp);
a();
return 0;
}
From: Robert Walsh <rjwalsh@du...>
Re: Programs using makecontext/swapcontext ...
2005-08-11 16:01
> 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.
--
Robert Walsh
Amalgamated Durables, Inc. - "We don"t make the things you buy."
Email: rjwalsh@du...
-----Original Message-----
From: Arun Dharankar <ar...@mc...>
Sent: Aug 11, 2005 3:19 PM
To: val...@li...
Subject: Programs using makecontext/swapcontext ...
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.
|
|
From: Robert W. <rj...@du...> - 2005-08-12 00:42:09
|
> I suppose, if this new feature in Valgrind was tested, I am missing something. > Could you provide any insight into this? Hmm. At this stage, I would suggest trying to concoct a small test case that exhibits the same behavior that file a bug report. You should be getting leaks, for sure. Regards, Robert. |