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
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 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
Название |
---|
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