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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
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