i used to use visual studio in debugging, but now i switched to linux and of course i need to learn to debug with gdb, may someone share his experience with me
i used to use visual studio in debugging, but now i switched to linux and of course i need to learn to debug with gdb, may someone share his experience with me
| # | User | Rating |
|---|---|---|
| 1 | ecnerwala | 3844 |
| 2 | Benq | 3792 |
| 3 | tourist | 3719 |
| 4 | VivaciousAubergine | 3647 |
| 5 | jiangly | 3616 |
| 6 | ksun48 | 3595 |
| 7 | Kevin114514 | 3491 |
| 8 | strapple | 3486 |
| 9 | Um_nik | 3376 |
| 10 | turmax | 3371 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 141 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
| Name |
|---|



The terminal interface of gdb is often cumbersome to use directly. It is recommended to use a windows-based GUI such as the linux version of the Code::Blocks IDE freeware that runs gdb internally for debugging, but is much more user-friendly.
GDB, by default, only prints one line of code at a time. This makes it very difficult to understand current state and context of the code. Printing more lines (
l) is helpful, but also quite annoying. You can enable the TUI mode (tui enable, orC-x a), which opens a window with the current code, and highlights the current line.To debug, it's handy to pass the input via from a text file:
start <input_text_file.Then use the common commands to debug: print a variable
p x, create a breakpointb, continue to the next breakpointc, go to next linen, step to next executed lines, jump once to lineu 123, finish a function and print return valuefin, show the call stack withbt, ...Notice, each one of these commands has dozens of options and different usages. E.g. you can make a breakpoint in the current line
b, by specifying a line numberb 123, by a function nameb my_function, ... Just glance over the documentation of gdb, so that you know what is possible.Some random tricks:
C-rquickly find and paste a previous commandp /t xprints binary representation of variablexcommand+p x+end. Now it will printxevery time you hit the breakpoint.upa few times (this goes up the call stack until you are at the error location).b if x > 10thanks really much, that is so helpful