[lug] Linux threads programming

rm at fabula.de rm at fabula.de
Mon Jan 13 07:04:50 MST 2003


On Mon, Jan 13, 2003 at 02:34:03PM +0100, Carlos Hernandez wrote:
> Hello,
> 
> 
> rm at fabula.de wrote:
> 
> > Just for my understanding: are you trying to implement some
> > sort of thread-local dump/undump by saving the C-callstack?
> 
> Yes it is.

Tricky, to say the least, but you probably know that allready :-)

> >
> > Hmm, if so, how do you intend to deal with absolute addresses stored
> > on the stack? If your stack holds addresses from _within_ the stack
> > (like local pointers that get passed down in function calls) these
> > pointers will be dangling after undumping.
> >
> >  Ralf Mattes
> 
> This is our first atempt to roll back single threads, at the moment were
> thinking in an ideal program : no
> pointers, etc. However, dealing with pointers maybe requires instrumenting
> malloc calls.

That won't be enough, i'm affraid (but: IANATG - i'm not a thread guru).
Consider the following code:

/* -- file: sample.c --*/

#include <stdlib.h>
#include <stdio.h>

void bar (char *foo)
{
  printf( "My current stack starts at %p and i'll return to %p\n",
          __builtin_frame_address(0),
          __builtin_return_address(0));
}

int main (int argc, char **argv)
{

 char *blub = malloc(10);

 bar(blub);

 exit(0);
}

if you run:

 bash-2.05a$ gcc -g -o sample sample.c 
 bash-2.05a$ ./sample 
 My current stack starts at 0xbffffc9c and i'll return to 0x80484a4
 bash-2.05a$ 

If you save the stack from within bar() it'll contain a return address
that would need tobe relocated during undump (ok, not for this small example
since 'main()' won't move, but most likely your stack has a deeper nesting
and some frames will return to addresses _within_ the dumped stack ...
Dumping a whole program is tricky enough (relocation of shared libraries etc.)
but dumping individual parts/threads sound like an awfull mess to me.
What exactly are you trying to do, if i might ask?

 Ralf Mattes


> Carlos
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug



More information about the LUG mailing list