Debugging Metamod:Source on Linux
From AlliedModders Wiki
To debug your Metamod:Source plugin on Linux, you should have gdb (Gnu DeBugger) and g++ 3.4.
- Compile your plugin with -O0 -g -ggdb3. This will ensure your plugin has debug symbols compiled in. You should not be using high optimization flags or stripping symbols (-s).
- In your shell (for bash), type:
- In your directory that contains srcds_run, type:
- Note: this assumes that your processor is i686. There is also srcds_amd and srcds_i486 -- run the one that is best described by your CPU.
- In GDB, type your startup command line prepended by "run", like so:
run -game cstrike +map de_dust +ip 127.0.0.1 +maxplayers 16
- Once your server crashes, you can use bt to see a backtrace. To jump to a particular frame of the backtrace, you can use frame <n>.
- To break into the debugger, use CTRL+C.
- To continue after breaking, use cont.
- To print an expression, use print <expr>. You can print address contents, C expressions, previous expression results, and variable contents if the names are available in the frame.
- For disassembling..
- Use set disas intel for proper Intel assembly output.
- Use display/i $pc to see the current eip and its disassembly.
- Note - you only need to do this once, as GDB will show it constantly.
- Use disas <addr|expr> to disassemble an address or expression.
- Use info all to see the CPU register layout.
- Use step and next for stepping into and over lines of code (also s and n).
- Use stepi and nexti for stepping into and over individual instructions (also si and ni).