Re: accessing each pthread's context



You can send a thread a signal and make the signal handler
make a stack dump on Linux.

You're right about a signal thread being one way to get the
backtrace (see below) ... but relying on signals to be picked
up by the right thread when the program is in a hosed state
... and then do a backtrace and communicate the results
to the assertion log ... doesn't seem likely to work very
often:-)

Don't know about anyone else, but I'd like to see that - cjh
The stack trace is easy on Linux ... in a running thread. The
backtrace glibc call does it for you using the gcc builtin functions
I mentioned earlier.

void
ExceptionTracer::DumpCurThreadStack()
{
void* rtnAddrs[kStackDepth];
size_t nSize = backtrace(rtnAddrs, kStackDepth);
std::string demangledStr;

for (int i = 0; i < nSize - 2; i++)
{
Dl_info info;
demangledStr.erase();

if (dladdr(rtnAddrs[i], &info) == 0)
{
demangledStr = "ExceptionTrace::DumpCurThreadStack dladdr
failed: ";
demangledStr += dlerror();
}
else
libcwd::demangle_symbol(info.dli_sname, demangledStr);

printf("\t%s\n", demangledStr.c_str());
}
}

.



Relevant Pages

  • Re: backtrace and line numbers
    ... milkyway wrote: ... > I found this thread on the use of backtrace to get a stack dump. ... Brussel 1160 Bruxelles ...
    (comp.os.linux.development.apps)
  • Re: backtrace and line numbers
    ... milkyway wrote: ... > I found this thread on the use of backtrace to get a stack dump. ... Brussel 1160 Bruxelles ...
    (comp.os.linux.development.system)
  • How to display back trace automatically after seg fault?
    ... How can I make FreeBSD to display automatically the backtrace of an executable after a segmentation fault (the same way Linux does it)? ...
    (freebsd-questions)
  • ppc64 2.6.6 crash
    ... single 1.8GHz G5 that is triggered by kudzu.A photo of the backtrace is ... Lead Developer, Yellow Dog Linux. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Locking assertion failure.
    ... whenever I try to start MATLAB 2006a under ... Linux, ... Here's the complete backtrace: ... JRE does not support 24 bit screen depth? ...
    (comp.soft-sys.matlab)