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 | jiangly | 3898 |
2 | tourist | 3840 |
3 | orzdevinwang | 3706 |
4 | ksun48 | 3691 |
5 | jqdai0815 | 3682 |
6 | ecnerwala | 3525 |
7 | gamegame | 3477 |
8 | Benq | 3468 |
9 | Ormlis | 3381 |
10 | maroonrk | 3379 |
# | User | Contrib. |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | Dominater069 | 161 |
4 | Um_nik | 159 |
4 | atcoder_official | 159 |
6 | djm03178 | 157 |
7 | adamant | 153 |
8 | luogu_official | 150 |
9 | awoo | 149 |
10 | TheScrasse | 146 |
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