Subj : Re: pthreads (linux) questions To : comp.programming.threads From : Christian Parpart Date : Sun Aug 21 2005 12:31 pm jacob navia wrote: > Joe Seigh wrote: > > > Threads don't have pids any more. What non standard non portable >> thing are you trying to do? >> > > I want to print the stack of an application when it crashes. no need for all you did before. The following works in pthread environments: #include #include // in case you're using c++ #include void getCallTrace(int skipFrames /* = 0 */) { void *trace[1024]; int traceCount = backtrace(trace, 1024); for (int i = skipFrames; i < traceCount; ++i) { char *sname = NULL; Dl_info info; if (dladdr(stack[i], &info) != 0) { #if __cplusplus char *buf = NULL; int len = 0; int status = 0; sname = abi::__cxa_demangle(info.dli_sname, buf, &len, &status); #else sname = info.dli_sname; #endif } fprintf(stderr, "[%02d] @%08X %s\n", i, trace[i], sname); } } this is considered PSEUDO-code, as I just wrote it on-the-fly. A working code (C++) is at [1]. > Apparently there is no documentation isn't it? I recomment you in having a look at the info-pages of backtrace(), and the man-pages of dladdr(); > Again: > Under 32 bits I used those symbols in the pthread library > to get info about the running threads. > I would attach to each thread in turn, and using ptrace I would read > their descriptors, what allowed me to print the state of each > thread at the moment of the crash. > > How do I do that under 64 bits? never played around with ptrace(), but maybe my above snippet will help you anyway. Regards, Christian Parpart. [1] http://swl.trapni-akane.org/browser/trunk/Core/src/System/Diagnostics/TStackFrame.unix.cpp .