GDB Debugging: How to Debug a C/C++ program

Sdílet
Vložit
  • čas přidán 22. 07. 2024
  • What is the GNU GDB debugger?
    This video explains what is the GDB debugger and how to debug a C / C++ program inside the Linux terminal.
    A debugger is a program that allows you to pause and resume the execution of your code and makes it easier for programmers to find bugs in their code.
    We will execute the GDB tool step by step to explain the most popular commands to add breakpoints, watch variables, and pause/resume the execution of C and C++ code.
    GDB is a powerful debugger that allows us to work with C and C++ code from inside the operating system terminal. Mastering GDB will help you evolve as a programmer and open doors to optimize your code and find potential errors.
    We will work with a very basic C sample code, where one of the functions is returning the wrong value as a result. With GDB we can break the execution, watch the value of the variables, and continue to inspect our code line by line.
    For complete and comprehensive courses, including ones on the Linux operating system and other C and C++ development tools, visit:
    pikuma.com
    SUBSCRIBE to learn more about computer science topics:
    / @pikuma
    Follow me on Twitter:
    / pikumalondon
  • Jak na to + styl

Komentáře • 52

  • @kenwallace6493
    @kenwallace6493 Před 2 lety +9

    Still best GBD tutorial to date. 10/21

  • @abhis-world
    @abhis-world Před 4 lety +11

    You are indeed a great tutor! Thanks for coming up with this in the most precise way possible

  • @niazahsan1337
    @niazahsan1337 Před 3 lety +3

    Wonderful! Loved the simplicity

  • @samdavepollard
    @samdavepollard Před rokem

    never used gdb but would like to get into it
    this was a perfect introduction
    many thanks for sharing your knowledge

  • @upthinker2336
    @upthinker2336 Před 3 lety +1

    Great tutorial, thank you for this!

  • @subbirrahman1289
    @subbirrahman1289 Před 25 dny +1

    great tutorial. Thank you so much man

  • @awesomeicemanpheasan
    @awesomeicemanpheasan Před 3 lety +2

    Great help. Thanks!

  • @TL-fe9si
    @TL-fe9si Před 2 lety

    Thank you very much! This is really helpful!!

  • @starc0w
    @starc0w Před rokem +1

    Thank you so much Gustavo!

  • @AshishKumar-tg6zh
    @AshishKumar-tg6zh Před 4 lety +2

    I want more free videos on Linux and Game development.
    I watched all your CZcams videos.
    And I also enrolled for your Fundamentals of game development. And I am learning and enjoying it.
    Thanks for all of your great tutorials.
    And I want a SDL c++ course that teaches in-depth knowledge of game development like memory management, handling pointers, physics engine, optimization and many more cool stuff that the c++ made for.
    Again thank you very much 😊

    • @pikuma
      @pikuma  Před 4 lety +1

      Thank you so much. I'm recordng new videos and courses as we speak. OpenGL and Game physics are the next ones. :)

    • @AshishKumar-tg6zh
      @AshishKumar-tg6zh Před 4 lety +1

      @@pikuma You are my greatest teacher. That is what i wanted. I am rely excited for the new course.
      If I make any game I will definitely going to add your name.
      And If I will make some money I am going to support you.
      Thanks you very much. I will waiting for your next course on Game Development.

    • @AshishKumar-tg6zh
      @AshishKumar-tg6zh Před 4 lety +1

      I finished your Fundamental of 2D game engine.
      Wow! That is my best course in my life. I learned a lot that I can't learn from CZcams videos. You shown me the power of Linux, C++ from terminal, vim the best code editor which taught me how to write code without mouse and most important fundamentals of 2D game Engine.
      Now I am going to make a level editor from C++ SDL.
      And I am also going to take Raycasting but I don't want to learn other languages like JavaScript.
      Why don't you use c++ and lua.
      Sorry for bad English.

    • @pikuma
      @pikuma  Před 4 lety +1

      @@AshishKumar-tg6zh This is incredibly inspiring. Thank you so much for the support. :)

  • @muudus_tv
    @muudus_tv Před 3 lety +1

    Wow this is the best video i got, i always love the classic retro way of doing stuffs. Where can i find all the debugging keyboard cmd for GDB along with good explanation of same.

  • @mrbbayat
    @mrbbayat Před 3 lety +1

    Fantastic.

  • @ajobe15
    @ajobe15 Před 4 lety +8

    Great tutorial! I would love to see a more in-depth debugging tutorial, though. For example, what would you do if there was a segmentation fault? Learning to debug C++ on Linux is frustrating when you are so used to Visual Studio.

    • @pikuma
      @pikuma  Před 3 lety +2

      True. I do believe Visual Studio is the best C++ IDE out there. Such a great piece of software...

  • @akshaykuralkar8848
    @akshaykuralkar8848 Před 3 lety

    Thank you its very help me

  • @universocpp
    @universocpp Před 2 lety +2

    Valeu, Gustavo!!

  • @AnnatarTheMaia
    @AnnatarTheMaia Před rokem +3

    Show them core file debugging and conditional watches. Also, executables should always be compiled with -g -gcc-record-switches -g3, which will make the executable significantly larger but doesn't impact execution speed since the runtime linker knows to ignore the debugging slots of the ELF file. For 0.2 ms longer that it takes to start, it's worth having the source code and the symbols embedded in the executable in case a core dump happens and debugging is required, but the source code and symbol information isn't available separately. And yes there is a practice on GNU/Linux to separate the debugging information out of such generated executable, but it relies on GNU objdump utility which isn't guaranteed to be present on other UNIX operating systems, and usually requires figuring out which additional package contains the said debugging information, so it is by no means a good practice. Therefore it is better to have the source code and the debugging information embedded in the executable. Always.

  • @futuza
    @futuza Před 2 lety

    Anyway you could cover gdb for large projects? Eg: How would you go about using it with something like a game with hundreds or thousands of source files. How to easily set a break point somewhere in middle of all that to find the part of the program you need to actually step through without having to go through thousands of lines first?

  • @mohamadfawaz4146
    @mohamadfawaz4146 Před 2 lety

    Big Man !

  • @muudus_tv
    @muudus_tv Před 3 lety

    Do you prefer to debug large code the same way ?

  • @myelinsheathxd
    @myelinsheathxd Před 2 lety

    How I can catch an errors inside a code by third party software?
    My main idea is to create game engine and catch errors of the editor and runtime code errors using GDB..

  • @welawela105
    @welawela105 Před rokem

    hello good presentation of gdb but from my side "layout next" is not recognized as a command...
    I'm on windows system and using native "gdb.exe" program provided with my MinGW/bin repertory.

    • @matsmcmats
      @matsmcmats Před rokem

      maybe you can use it from within mingw instead?

  • @juliocgfreitas
    @juliocgfreitas Před 3 lety +1

    Ótima explicação. Vi que é brasileiro. Massa. Vou adquirir o curso de LUA em breve e ver se melhoro meus códigos em C. Tem previsão de migrar seus outros cursos pra Udemy? Grande abraço.

    • @pikuma
      @pikuma  Před 3 lety +1

      Grande Julio. Os cursos novos vão ser publicados no meu site pikuma.com. Na Udemy só vou manter os que já fpram publicados lá. Abração!

  • @niranjanamurthy4168
    @niranjanamurthy4168 Před 4 lety +1

    good

  • @SlideRSB
    @SlideRSB Před 2 lety +1

    While I do appreciate the lesson on debugging with GDB, I saw the flaw in logic immediately without the need to use a debugger in this case.

    • @pikuma
      @pikuma  Před 2 lety +1

      Ha! True.
      But one day you'll have a SegFault and then it will all make sense. 🙂
      Or you can just use a proper IDE as well, even better.

    • @SlideRSB
      @SlideRSB Před 2 lety +1

      @@pikuma It already makes sense as I currently do have code that SegFaults. Now to apply the methods you've demonstrated...

  • @albertnormandy5753
    @albertnormandy5753 Před 2 lety

    When I use "layout next" I get my code but in assembly language. I not sure why this is.

    • @pikuma
      @pikuma  Před 2 lety

      Did you use -g to compile and keep the symbols? I think I mentioned that in the video.

    • @albertnormandy5753
      @albertnormandy5753 Před 2 lety +2

      @@pikuma I was indeed using the g flag but it still gave me asm. I found out that I had to type "layout src" to have my c code appear

  • @danyalkucuktas9763
    @danyalkucuktas9763 Před rokem

    How you install gdb on the Mac with the M1 chip

    • @pikuma
      @pikuma  Před rokem +1

      Apple uses lldb instead of gdb. They are very similar.

  • @kpritam4529
    @kpritam4529 Před 3 lety +2

    How you make the vim editor so colourful 😅😅

    • @pikuma
      @pikuma  Před 3 lety +1

      Hi Pritam. It's a simple theme called Monokai. :)

  • @malickdiop28
    @malickdiop28 Před rokem

    👍🏾👍🏾👍🏾

  • @torto20
    @torto20 Před 4 lety +3

    Estou fazendo o curso de raycasting javascript. Muito bom depois quero fazer os demais. Voce e brasileiro?

    • @pikuma
      @pikuma  Před 4 lety +2

      Opa Heitor, sim! Sou do RS mas moro em Londres há uns bons anos. De onde tu é?

    • @torto20
      @torto20 Před 4 lety

      @@pikuma legal! Sou de são paulo. Nao tenho um ingles muito bom mas estou conseguindo entender as aulas. Voce tem cursos em portugues relacionado a programacao de jogos?

    • @pikuma
      @pikuma  Před 4 lety

      @@torto20 O pessoal me diz que as legendas automáticas mais atrapalham do que ajudam. Eu vou gerar legendas manualmente em Pt-BR em todos os cursos em alguns meses.

    • @torto20
      @torto20 Před 4 lety

      @@pikuma legal!!

  • @Vnifit
    @Vnifit Před 3 lety +3

    1:03 you have a variable C E L E R Y