Debugging with GDB
felix-knorr.net
felix-knorr.net
I don't envy the maintainers' jobs, and I just gripe from the sidelines, but starting from scratch it's too bad it's such an intimidating experience, because it really is a great tool. And I say this as someone who has used MSVC's debugger (which I've often seen applauded as the best) for some decades, and I still prefer GDB now that I'm past the significant initial learning curve.
Still writing lots of .gdbinit scripts though.
Just set a timer to call back to the main thread every 100ms or so. When you get to the point in an application where you want to make changes, put a breakpoint in that callback. When it pauses, pop open the expression editor and start changing the UI. Make some views, adjust some values, etc.
When you want to see the results, hit "continue"; it'll release the main thread for about 100ms (more than enough time to re-layout and render), then you'll be back in the debugger for another round of changes. You can hack up a full, polished-looking and often working UI in a couple minutes, and then just print the whole tree to get a snapshot your work.
That same strategy works in basically any language with GDB support, in many, many UI frameworks, if the connection is sophisticated enough to call functions.
How does the adult version of GDB show threads and parallel stacks and shader debugging?
Or better yet, how do adults do hot code reload on GDB?
Couldn't tell you about shaders. Haven't needed hot code reload.
So a more powerful debugger that offers stuff beyond what you are aware of in computing, while GDB hasn't be able to do so in 40 years, is a toy.
GDB also has many good plugins - pwndbg has tons of features and UI improvements over stock GDB.
https://sourceware.org/gdb/onlinedocs/gdb/Set-Watchpoints.ht...
This anti-pattern is a bit of a red flag for me though:
bash -c "$(curl -fsSL http://gef.blah.cat/sh)"You are downloading and running their python script anyway. Why do you trust their software but not their install script?
The fact that it is hosted on http is suboptimal, but it does redirect to an https github page in this case
It is not as bad as:
curl something | sh
Where you can detect on the server side that the download goes into a pipe (due to buffering) and serve different versions of the file depending on if you are downloading it or executing it directly, but it is still bad practice.Updating a package in a OS distribution repository requires that it is signed, and spread to all the mirrors (it is unlikely that an attacker controls all of them). This makes it more likely to be discovered and hard to do targeted attacks without leaving a trace.
If it does happen that you are compromised using:
bash -c "$(curl -fsSL http://gef.blah.cat/sh)"
How will you find out afterwards, that this is what happened?I run local mirrors of everything I use (with snapshots after updating the mirror), so I at least have a history of the software that I ran to do forensics on. I could not do that if I ran scripts directly from the Internet into a shell.
For example: Something suddenly trying to connect to the Internet (or doing DNS lookups) from one of my segregated systems might prompt me to investigate. Even if you are not so "paranoid" as many would call it (I would call it being diligent), you still get the benefit of others being "paranoid".
So making sure (via packages, mirrors and signatures) that we all get the same "version" of software is important for security.
Beyond that, I have recently learned how to write custom pretty printers for GDB. This saves a lot of screen space. I should probably update [2] soon with those new techniques.
GDB is powerful, useful, and after getting my start in IDE debuggers, including Visual Studio, I struggle whenever I have to go back.
[1]: https://github.com/cyrus-and/gdb-dashboard
[2]: https://gavinhoward.com/2020/12/my-development-environment-a...
In the reverse engineering space there's some folks that use gef. but maybe that's because linux folks dont have olydbg?
would love to see a livestream of someone using gdb in the context of real world engineering. SHOW me the productivity wins here. every article and conference talk about gdb is just handwavey hypotheticals about what you could do, but in practice I just see people moving through basic debugging incredibly slowly
Also even if you use GDB in IDE, you still may need to fall back to the embedded GDB console as e.g. some classes are missing pretty printers or the IDE UI does not allow you to investigate navigate things properly. For example when you have a structure field that is void* and is casted to one or another type depending on the context, it is much easier to use the console to investigate it.
What are you comparing this to? A person skilled with an IDE?
As a general rule i have found it almost impossible to 'change' someones mind, you can influence an undecided person, but changing someones mind is generally a waste of time.
Unless you have financial incentive to do this, you're going to be running this at a loss, let the 'fixed mind' party take the hit of being wrong.
It describes how to configure GDB with the GEF, PEDA and PWNDBG plugins.
(I've only really used gdb-peda, would be great to get some time to learn the others)
(Time-travelling debuggers are OK, too, I guess)
I can also attach the debug session to an issue in order for others or future me to understand what was happening then. In a purely GUI-driven debugger, I can copy&paste a stack trace of the final point, but the history is lost.
https://sourceware.org/gdb/onlinedocs/gdb/Logging-Output.htm...
Maybe that is what OP means by a transcript.
There is so much a modern IDE debugging session is capable of.
VSCode for sure does this.
Now picture XEmacs and Emacs, running gdb as subprocess, with a little pointed finger showing the current line and a stop sign for breakpoints.
The lower buffer shows the usual gdb repl and output.
I always felt the drive towards mouse-driven tools in the PARC world (InterLisp/SmallTalk/CedarMesa) was actually a regression because of the loss of history ("how the hell did I get here?")
I compile with -gdwarf-4 -g3 to include macro definitions in the binary. That way you can use macros at the gdb prompt. I can't imagine life without those :)
`C-x a` to toggle it on
`C-l` to re-draw screen when stdout gets spit out and messes up TUI
`C-p/n` for scrolling gdb history
`up/down` for scrolling code
But agreed, TUI mode is handy (:
Recently I had to debug some bootloader code in QEMU, which provides a remote GDB port. I tried every GDB GUI and they all either (A) assumed that I would provide source code to the target code (it's a binary blob bootloader, which I don't have code for) or (B) flat out didn't work. I ended up using TUI mode, which has it's own problems (messes up my terminal when I disconnect/reconnect the GDB port)
Isn't CLion a "GUI tool for GDB"?
I have little hope for the state of Linux debugging in the future if people really think the current situation with GDB and its frontends is good or even acceptable.
Can it be powerful? Probably. But the dev experience looks terrible.
Dev experience is fixable in many ways, but wholesale lack of capability is not.
MSVC was (is) by far much better overall (I only pull it out now a days to analyze crash dumps though). Heck in vscode you can't really see variables in C++ or examine memory, or set memory change break points, but really 90% of developing doesn't require any of that, so vscode just keeps growing in use.
I do love me some GDB though, when I'm developing on *nix anyway.
Such as? I'm genuinely curious here. I know of a bunch of things that VS can't do on Windows that requires resorting to windbg (which is a terrible experience compared to VS's debugger), but what are the things you look for in a debugger that it can't do at all? Are we talking user land debugging or kernel?
When I set a breakpoint, I can make it conditional on an expression run against program data, and have it run a series of debugger commands at each stop, and then maybe continue.
Scrolling back through the transcript to see how values have changed at each stop, and running expressions on e.g. differences between such values.
All simple things.
Maybe I am spoiled but I cannot bear the nagging about code-signing it yourself
There is a gap where GDB changed terminal interaction protocol and (on Debian) left cgdb behind, so I had to build my own copy of cgdb from source. Otherwise, smooth sailing.