PDA

View Full Version : backtrace and unwind with c++



TheRonin
11th July 2007, 08:41
I'm trying to create a framework for producing a stacktrace when an exception gets thrown in c++ (gcc 3.3)

I've found that glibc (the GNU C library) has something called backtrace and am wondering how it compares to gcc's unwind facility. Using _Unwind_Backtrace i can traverse the stack and get a bunch of instruction pointers, but no more context than that. I was hoping to be able to get file name and line number...maybe even method and class name.

Also, i've found some example code that uses _Unwind_Backtrace but that also checks if the gcc version is >=3.4...so i'm also wondering if there's any difference in unwind's behavior between gcc 3.3 and 3.4?

This is a very specific and niched question and i'm not really expecting a wealth of response...i don't really know where else to turn. :confused:

thanks in advance!

jpn
11th July 2007, 08:45
Not sure if this helps anyhow but have you noticed src/corelib/kernel/qcrashhandler?

TheRonin
11th July 2007, 09:16
Not sure if this helps anyhow but have you noticed src/corelib/kernel/qcrashhandler?

no, no i have not...i'll look into it :)

TheRonin
11th July 2007, 09:59
Having had a quick look at the code it looks like it starts a debugger and writes the output to a file. I'm wondering if this is done while the process is still 'active' in the sense that it can continue execution after the debuginfo has been saved, or if this is done right before termination?

TheRonin
11th July 2007, 16:27
Having looked more closely at it i'll go ahead and reply to myself: Yes, the process is still 'active' since we're only opening a pipe to a forked process. This solution is not really what i had hoped for (a bit too quick and dirty) but gets the job done...sort of.