Debugging Metamod:Source on Linux

From AlliedModders Wiki
Revision as of 23:54, 5 October 2007 by BAILOPAN (talk | contribs) (Debugging SourceMM on Linux moved to Debugging Metamod:Source on Linux)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

To debug your Metamod:Source plugin on Linux, you should have gdb (Gnu DeBugger) and g++ 3.4.

Steps

  1. 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).
  2. In your shell (for bash), type:
    export LD_LIBRARY_PATH=".:bin:$LD_LIBRARY_PATH"
  3. In your directory that contains srcds_run, type:
    gdb srcds_i686
    • 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.
  4. 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
  5. 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>.

Notes

  • 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).