Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Making use of backtrace?

Name: Anonymous 2010-09-01 6:00

Incoming wall of text.

I want to be able to make use of the backtrace function in order to ease debugging when my application crashes for a user. I found an implementation which seems to work on MinGW, so on the target platforms I can pretty much use SEH or signals to catch a crash, get a backtrace and do something with it (I also realize that sometimes, I won't be able to do anything good in the handler due to the state of the application. I'm willing to take that risk.)

The problem is, I don't know where to begin. I of course need the debugging information to be on a server of sorts, but I'm not even sure what I should do to get this information. How do I generate it? I know gdb can determine what line of code an address is, and I'm guessing gdb is using embedded debug info - but I can't find any reasonable sources of information for the format or how I could do this without the information embedded (although I have a feeling i could just extract and strip, it sounds redundant to me.) I'm also not sure how, using signals, I would get the backtrace, since I'm pretty sure signal handlers get a different thread. (But hell if I know. I've never actually done one.)

I saw Google Breakpad, but this is an awful solution. I checked everything out from source and it seems it doesn't really work on Windows without hacking around, and definitely not with MinGW. It might be useful for reference, but i don't think it is actually helpful in my case. Too many dependencies, not enough docs, no MinGW support... not worth it.

Any advice? I'm new here, but I'm hoping unlike /g/ people here actually know their stuff. I'm primarily concerned with MinGW right now, since I bet this will be much simpler under Linux and etc.

Name: Anonymous 2010-09-01 8:38

>>6
Sorry for the delayed response.

Well, my 'test' was to write a small application, compile it with debugging symbols (-g) then split the debugging symbols and try using it with gdb.

Basically: It wasn't the application that's interesting, even hello world would've done it.


Here's what I did (copied off of an rxvt window)

----------
xxxx@BIGBOX ~
$ gcc -g main.cpp -o main

xxxx@BIGBOX ~
$ objcopy --only-keep-debug main.exe main.debug

xxxx@BIGBOX ~
$ strip --strip-debug --strip-unneeded main.exe

xxxx@BIGBOX ~
$ objcopy --add-gnu-debuglink=main.debug main.exe

----------
At this point I have two artifacts, main.exe and main.debug. At this point, main.exe contains no debugging symbols.

Now lets see if it works.
----------
xxxx@BIGBOX ~
$ gdb main.exe
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>;...
Reading symbols from C:\msys\1.0\home\xxxx/main.exe...(no debugging symbols found)...done.
(gdb) symbol-file main.debug
Reading symbols from C:\msys\1.0\home\xxxx/main.debug...done.
(gdb) break main
Breakpoint 1 at 0x401379: file main.cpp, line 11.
(gdb) run
Starting program: C:\msys\1.0\home\xxxx/main.exe
[New Thread 83828.0x15990]

Breakpoint 1, main (argc=1, argv=0x331778) at main.cpp:11
11              puts("Test.");
(gdb) quit
A debugging session is active.

        Inferior 1 [process 83828] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]
------
Not very interesting just yet. However, if I combine this method of getting my debugging symbols and some google breakpad code, I might be able to get a useful result. Some googling shows that you can use google breakpad code to create a dump which can be used with symbols to create a backtrace with MinGW. All it takes is for me to get off my lazy ass and make use of it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List