# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
Name |
---|
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.
A friend of mine told my about this trick/debugger.h thing and it's really useful.
Click here to check the file
Then you only need to put the file in: C:\mingw-w64\mingw64\lib\gcc\mingw32\5.1.0\include\c++\debug
And writing at the top of your code:
ifdef __LOCAL #include <debug/debugger.h>
endif
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.That's great, thank you so much.
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!
Auto comment: topic has been updated by Platanito_Frito (previous revision, new revision, compare).