gdb is pretty simple, in order to get a stack trace from a FSO crash, do the following in a terminal:
1)
install subversion and
checkout a current copy of the code
2) install gdb
sudo apt-get install gdb
sudo yum install gdb
3) setup your mod & settings using wxLauncher - in addition to your normal settings you must have:
- a smaller-than-your-entire-monitor resolution (Basic Settings)
- "run in a window" (Advanced Settings -> Dev Tool)
- "don't grab mouse/keyboard in a window" (Advanced Settings -> Dev Tool)
If you don't set these three options, then you'll find that you can't leave the FSO window in order to use the debugger.
4) Run the debug version of FSO (if you don't already have it, pass "--enable-debug" as a parameter to
autogen.sh and then
compile it)
gdb fs2_open_3.6.15_DEBUG
5) gdb has it's own prompt. Run FSO with this obvious command

run
6) Switch to your FSO window and do whatever is necessary to reproduce the crash
7) When the crash has occurred, switch back to your terminal and enter this at the gdb prompt:
backtrace
8) copy this output and post it where an SCP member can see it
9) Exit FSO by running this at the gdb prompt:
quit
The procedure above is probably all you need. However, if you're interested, here's some more info:
BacktracesA backtrace (MSVC calls it a stack trace) displays all the function calls that the program has passed through to get to its current position. Here's an example:
(gdb) backtrace
#0 wing_name_lookup (name=0x1993500 "Gamma", ignore_count=1) at ship/ship.cpp:11316
#1 0x00000000005d7dc4 in post_process_mission () at mission/missionparse.cpp:5317
#2 0x00000000005d7b37 in parse_mission (pm=0xfb8120, flags=0) at mission/missionparse.cpp:5270
#3 0x00000000005d8be9 in parse_main (mission_name=0x7fffffffded0 "respawn_crash.fs2", flags=0) at mission/missionparse.cpp:5642
#4 0x00000000005bfd9f in mission_load (filename_ext=0xbfb9c0 "respawn_crash") at mission/missionload.cpp:107
#5 0x000000000040c465 in game_start_mission () at freespace2/freespace.cpp:1450
#6 0x0000000000415e4f in game_enter_state (old_state=20, new_state=52) at freespace2/freespace.cpp:5974
#7 0x00000000004b90fc in gameseq_set_state (new_state=52, override=0) at gamesequence/gamesequence.cpp:282
#8 0x0000000000414ccd in game_process_event (current_state=20, event=1) at freespace2/freespace.cpp:5145
#9 0x00000000004b95f2 in gameseq_process_events () at gamesequence/gamesequence.cpp:397
#10 0x0000000000417605 in game_main (cmdline=0x227edd0 "") at freespace2/freespace.cpp:7092
#11 0x00000000004177da in main (argc=1, argv=0x7fffffffe308) at freespace2/freespace.cpp:7226
(gdb)
The backtrace shows all the function names and the values of variables passed to those functions, e.g. on line 6 above (game_enter_state), you can see that variable old_state was 20, and variable new_state was 52.
Viewing variablesYou can view the current value of variables using the gdb print command e.g.
print Ship_info[0].name
This can also be used to display nearly any C/C++ expression.
BreakpointsBreakpoints are a way of stopping FSO from running at a certain point in the code. Set one by entering the following at the gdb prompt:
break freespace2/freespace.cpp:1758
The format is directory/filename:line-number (obviously the source code you're getting the file & line number from must match the executable your running, otherwise this information may not match)
Debugging with an FSO release executableIn the rare occasion when you cannot reproduce the crash in FSO debug you can also get a backtrace from the release version. Use the same procedure as above, but keep in mind these caveats:
1) you must recompile the executable with the gcc -g option set (i.e. CXXFLAGS=-g make)
2) debugging may not be 100% reliable because the release version uses various compiler optimistaions (i.e. gcc -O2)
To workaround both these issues, compile like this and run gdb with the resulting executable:
make distclean && CXXFLAGS='-g -O0' sh autogen.sh && V=1 make
(The V=1 is not strictly neccessary, but it does show you if the CXXFLAGS were picked up correctly)
Debugging with a GUIThe command line is all well and good, but sometimes a GUI really helps and
ddd is what I've used (the package name should be "ddd" to install with apt-get or yum). It's very similar to gdb (and in fact, runs gdb underneath) but you get two obvious extras, a window to display variables/data at all times, and an interactive display of the source code (where, among other things, you can set break points via right-clicking on the appropriate line of code).
e: updated & expanded debugging details