Re: accessing each pthread's context



That's an illusion. ... backtrace ... doesn't work in ... read() ...

I'm just beginning to understand that issue. There's backtrace
code written for OS X PPC that gets around that issue by
creating a fake frame when the thread is doing a system call.
The code walks up the stack looking for a system call instruction
("sc" in ppc), and then builds a fake frame with a link register
pointing to the previous (valid) frame. I imagine something similar
could be done on x86. Here's their code:
http://developer.apple.com/samplecode/MoreIsBetter/listing41.html

Newer glibc's have backtrace_symbols() which will translate PC
values to symbol names for you.

Yea, I've used it, but its easier to bypass backtrace_symbols when you
use libcwd to demangle the symbol name. Also backtrace_symbols doesn't
do a very good job of figuring out the arguments to a function on the
stack ... by using the frame pointer you can print out the top eight
or so args on the stack when the function is called and later
reconstruct the arguments to the function.

cheers,
brendan

.