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 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
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
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-r
quickly find and paste a previous commandp /t x
prints binary representation of variablex
command
+p x
+end
. Now it will printx
every time you hit the breakpoint.up
a few times (this goes up the call stack until you are at the error location).b if x > 10
thanks really much, that is so helpful