Re: accessing each pthread's context
- From: "bcreane" <bcreane@xxxxxxxxx>
- Date: 21 May 2006 16:16:53 -0700
You can send a thread a signal and make the signal handlermake 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 - cjhThe 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());
}
}
.
- Follow-Ups:
- Re: accessing each pthread's context
- From: Paul Pluzhnikov
- Re: accessing each pthread's context
- From: davids
- Re: accessing each pthread's context
- References:
- accessing each pthread's context
- From: bcreane
- Re: accessing each pthread's context
- From: davids
- Re: accessing each pthread's context
- From: Clifford Heath
- accessing each pthread's context
- Prev by Date: Re: accessing each pthread's context
- Next by Date: Re: accessing each pthread's context
- Previous by thread: Re: accessing each pthread's context
- Next by thread: Re: accessing each pthread's context
- Index(es):
Relevant Pages
|