Platanito_Frito's blog

By Platanito_Frito, history, 3 years ago, In English

Hi Codeforces!

Does this only happens to me?

What are your thoughts about using a debugger?

  • It's best to use it, I use it!
  • I feel more comfortable debugging manually
  • I think it's worst for competitive programming
To the voters:

Thanks for reading and remember always to use dark theme editors :)

  • Vote: I like it
  • +33
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +36 Vote: I do not like it

This is one of the questions where I really want to see the ratings of the respondents.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you please comment what is your opinion and why? Orz

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +21 Vote: I do not like it

      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.

      • »
        »
        »
        »
        3 years ago, # ^ |
        Rev. 6   Vote: I like it 0 Vote: I do not like it

        A friend of mine told my about this trick/debugger.h thing and it's really useful.

        Here's the application of it:

        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:

        Code
    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      The only thing I use in debugger (gdb in my case) is backtrace 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, debug cout's.

      • »
        »
        »
        »
        3 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Sounds great, can you please show me a code so I can learn to use this gdb properly. Thanks for sharing your experience.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it +4 Vote: I do not like it

          show me a code so I can learn to use this gdb properly

          What code are you talking about? I just do

          $ gdb ./my_program
          

          Then I type run, and if my code crashes, I type backtrace (you can also type bt as a shortcut) to see the stack trace. You can also see all the local variables for all the functions in the stack with backtrace full command.

      • »
        »
        »
        »
        3 years ago, # ^ |
        Rev. 2   Vote: I like it +5 Vote: I do not like it

        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.

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    You can also compile with -g -fsanitize=address and it will print line and column of the crash

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Currently I use gdb from within VSCode. I also use a debug macro that I wrote. It has pretty colors!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Platanito_Frito (previous revision, new revision, compare).