Блог пользователя Platanito_Frito

Автор Platanito_Frito, история, 2 года назад, По-английски

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 :)

  • Проголосовать: нравится
  • +33
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится +36 Проголосовать: не нравится

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

  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится +21 Проголосовать: не нравится

      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.

      • »
        »
        »
        »
        2 года назад, # ^ |
        Rev. 6   Проголосовать: нравится 0 Проголосовать: не нравится

        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
    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      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.

      • »
        »
        »
        »
        2 года назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

        • »
          »
          »
          »
          »
          2 года назад, # ^ |
            Проголосовать: нравится +4 Проголосовать: не нравится

          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.

      • »
        »
        »
        »
        2 года назад, # ^ |
        Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

        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.

»
2 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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.

  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

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

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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