Hi folks,
I've been using libunwind in an x86_64 Linux environment to do stack walking on ptraced processes with great success. However, that's only when the tracee is single threaded. When the tracee is multi-threaded, I rewrote my tracer program to be multi-threaded using pthread, so that I have a tracer thread for each tracee thread. Each tracer thread has its own libunwind "context", i.e., each thread creates its own libunwind variables as follow:
as = unw_create_addr_space(&_UPT_accessors, 0);
ui = _UPT_create(child);
unw_init_remote(&c, as, ui);
Subsequently, each tracer thread makes unw_step(&c) calls to walk the stack frames of its corresponding tracee thread.