№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 | 150 |
Название |
---|
This is one of the questions where I really want to see the ratings of the respondents.
Can you please comment what is your opinion and why? Orz
I use a mix of both. IMO a debugger (I use gdb) is very convenient. But sometimes you want to get a good overview of everything the program does, then print statements are better.
The only thing I use in debugger (
gdb
in my case) isbacktrace
command, which shows the stack trace on where my code has crashed. The rest of debugging is done via numerous asserts to verify the invariants,#define _GLIBCXX_DEBUG
to catch out-of-range access and other things like that, and, of course, debugcout
's.Sounds great, can you please show me a code so I can learn to use this gdb properly. Thanks for sharing your experience.
What code are you talking about? I just do
Then I type
run
, and if my code crashes, I typebacktrace
(you can also typebt
as a shortcut) to see the stack trace. You can also see all the local variables for all the functions in the stack withbacktrace full
command.I use this define too along with some sanitizers (undefined and address). And I just use print statements for all debugging purposes which is basically done by the debug template I took from benq's template and modified it a bit.
The only situation I would like use debuger over printf is when my code get segmentation fault. In that case, one run of gdb and I know which line cause this problem. Super convenient.
You can also compile with
-g -fsanitize=address
and it will print line and column of the crashCurrently I use gdb from within VSCode. I also use a debug macro that I wrote. It has pretty colors!