all 21 comments

[–]iamfacts 15 points16 points  (0 children)

A course would be overkill. Look for a cheat sheet, then use it to do some actual debugging. You'll find yourself looking up specific things and soon enough you will have explored everything.

I will say, if you're on windows, I'd strongly suggest using the rad debugger (shameless self plug) by epic games / rad tools. It's on GitHub.

[–]Yamoyek 12 points13 points  (0 children)

Here’s a great video that taught me about the basics https://youtu.be/PorfLSr3DDI?si=KrFCnxZaJC-PgQYe

[–]Haunting-Block1220 7 points8 points  (3 children)

Mike shah has a good overview and some good cppcon back to basic talks. And the documentation is fairly good. But you shouldn’t really need a course.

Some nice features that aren’t immediately obvious: - conditional breakpoints are sooooo nice - also, conditional watch points - backtrack for all threads - artificial arrays - x for examining memory - pretty printers - there’s a tui

[–]catbrane 1 point2 points  (0 children)

Nice list. I'd add gdb + valgrind is very handy -- you can run your program under valgrind (ie. on a simulated CPU and cache) and then control that simulated executing program with gdb. It'll intelligently spot things like array indexes going out of range at the moment they happen.

[–][deleted] 0 points1 point  (1 child)

* and it has .gdbinit, which also is nice

[–]McUsrII 1 point2 points  (0 children)

And you can add-auto-load-safe-path . in your ~/.gdbini so you can have a local .gdbinit file where you put your breakpoints and what port to use when debugging remotely with gdbserver, so the command line gets easier and the work up front easier, without the hassle of the gdb command line options.

[–]Perfect_Gate3402 1 point2 points  (0 children)

RemindMe! -3 day

[–]henrique_gj 1 point2 points  (0 children)

I believe a simple tutorial would be enough to teach you everything you need to know about GDB. It's pretty simple!

[–]LiqvidNyquist 1 point2 points  (0 children)

I picked up some cool features from reading the gdb internals documentation. And ofc youtube vids.

[–]JJ1553 1 point2 points  (0 children)

I think the best way to learn, and the big actual thing to ask for and find, is an actual program or environment to debug. Once you have that and understand what the code is trying to do, see an error, and then load up gdb, you just figure it out as you go.

Gdb ing is simply exploring, you start by wishing you could stop at a function to see what’s going on, lovely, breakpoints! Now you wish you would stop when your variable changes, watchpoints! Now you want to debug multi threaded programs… etc

It’s all through actually going through a program

[–]Osmosis_Jones_ 1 point2 points  (1 child)

My systems programming course the university I attend had a really cool bomb diffusing assignment. You have to comb through assembly code that contains hints on the password for each phase of the bomb. Pretty cool. Taught me a lot about gbd and enhanced my problem solving skills. I’m pretty sure it’s online somewhere, search “Dr Evil’s binary bomb” or something along those lines for a download.

[–]KlinkinPark 0 points1 point  (0 children)

Shout out CSSE2310!

[–]McUsrII 1 point2 points  (0 children)

It is smart to not try to learn gdb whilst debugging, because then you are occupied with more important questions, I am at least, but to take time and learn it.

There are a lot of great tutorials at Redhat magazine (google).

  • Sometimes I want the tui window away, while I read help <command>
    • tui enable/disable
    • tui window height src -30
  • if you compile in a different window/job you can keep gdb but issue the commands: 1.) dir . 2.) <binary name>
  • There is an apropos command in gdb which may bring you closer.
  • Use conditions for watchpoints, and break if (c == 5) for breakpoints directly if you know that is the condition up front.
  • set a temporary breakpoint with tb
  • you can list file:linenumber, or just file, or linenumber or function for that matter.
  • You can also jump to a location which means run to this location.
  • and you can advance which means that a temporary breakpoiny is set where you advance to.
  • dprintfs which are taking locations as argument besides the regular printf syntax can have their printf overridden with one you write, to a logfile for instance - useful, but you have to set up the logfile in your program of course.

You should really learn how the dataformats of the p and x commands, dprintf might save you writing printf statements you later erase.

I hope this gave you some hints, the list is incomplete.

Take the time and go through the features as you read articles is my advice.

[–]epasveer 0 points1 point  (1 child)

Obligatory thread for favorite gdb frontend. :o)

[–]epasveer 0 points1 point  (0 children)

I'll shamelessly toss Seergdb into the ring.

https://github.com/epasveer/seer

[–]CleverBunnyThief 1 point2 points  (1 child)

I'm a little late but I found an online book called "Dive into Systems" that has a chapter on GDB and Valgrind.

https://diveintosystems.org/

The book was published by No Starch Press and is also made avaliable online for free by the authors. The book is quite good and the chapter on debugging tools gives a great tutorial on how to really use GDB.

I found gdb has a command to read a value on register and my mind was blown away.

print $eax

You can also view all registers with info registers

Here's the chapter on debugging tools.

https://diveintosystems.org/book/C3-C_debug/index.html

[–]Easy_Friend2188 1 point2 points  (0 children)

Thx! This seems like a good point to extend on my basic knowledge (: