| 1 | = Debug Tools = |
| 2 | Most times debugging without a debugger is really hard. In complex programms printing text and values of variables to the console is not an option for debugging anymore. Being able to handle a debugger like GDB oder DDD makes (coders) life much easier. |
| 3 | |
| 4 | == GDB == |
| 5 | GDB is the standard (console based) unix debugger. |
| 6 | === Basic usage === |
| 7 | To simply run the program and wait for a segfault follow the below instructions. |
| 8 | 1. Go to the binary directory (bin) and run '''gdb orxonox''' |
| 9 | 2. Type '''run''' |
| 10 | 3. Wait for the segfault to occur ... |
| 11 | * If you want to display the back trace ( list of function calls ) just type '''bt'''. |
| 12 | * You can change the context (function to debug) by typing '''up''' and '''down'''. |
| 13 | * If you want to display the value of a variable make sure you are in the right context (by using up and down) and type '''print varname''' |
| 14 | * If you have an object pointer and you don't know the exact type of the class (e.g. pointer to WorldEntity which is actually a !SpaceShip) you can type '''x/wa addressOfObject''' and gdb will tell you what class type the object located in ''addressOfObject'' has by considering the vtables |
| 15 | === Setting Breakpoints === |
| 16 | You can set breakpoints for |
| 17 | - functions: '''break namespace::ClassName::functionName''' (e.g. ''break orxonox::SpaceShip::fire'') |
| 18 | - codelines: '''break fileName.cc::''lineNr''''' (e.g. ''break !SpaceShip.cc:367'') |
| 19 | If the program hasn't yet been run in gdb, it will not have loaded all our libraries (e.g. libcore.so, libnetwork.so) and thus will not be able to set the breakpoint immediately, but ask you whether it should set it at run time. Make sure you entered the address/function correctly and type ''yes''. |
| 20 | * To delete a breakpoint you can either use '''delete''' or '''clear'''. Type '''help''' / '''help ''gdb-function''''' for more information. |
| 21 | === Setting Watchpoints === |
| 22 | Sometimes it's usefull to know when the value of a variable changes. |
| 23 | 1. To make use of this feature set a breakpoint somewhere you can access the variable from (watchpoints for static variables can be set without doing this). |
| 24 | 2. Run the program and wait for the breakpoint to get triggered |
| 25 | 3. Type '''watch ''varname''''' |
| 26 | == DDD == |
| 27 | DDD is a simple graphical debugger based on GDB. |