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

preview_player
Показать описание
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:

SUBSCRIBE to learn more about computer science topics:

Follow me on Twitter:
Рекомендации по теме
Комментарии
Автор

Still best GBD tutorial to date. 10/21

kenwallace
Автор

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

abhis-world
Автор

I want more free videos on Linux and Game development.
I watched all your YouTube 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 😊

AshishKumar-tgzh
Автор

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.

ajobe
Автор

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

samdavepollard
Автор

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.

AnnatarTheMaia
Автор

Trying to learn to debug 16 bit Assembly programs. The very few GDB tutorials assume you are working in C or C++. Would appreciate any info on how to debug an Assembly program. Got GDB working but can't figure out how to display the program code if it's not an .exe

dillingerlee
Автор

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.

muudus_tv
Автор

Thank you very much! This is really helpful!!

TL-fesi
Автор

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.

SlideRSB
Автор

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?

futuza
Автор

I need to type "list" to show the source code, otherwise it shows the asm

articleenthusiast
Автор

Ó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.

juliocgfreitas
Автор

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.

welawela
Автор

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..

myelinsheathxd
Автор

How you make the vim editor so colourful 😅😅

kpritam
Автор

Do you prefer to debug large code the same way ?

muudus_tv
Автор

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

torto
Автор

How you install gdb on the Mac with the M1 chip

danyalkucuktas
Автор

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

albertnormandy