4 ms·
Took me some time to get familiar with it but GDB is well documented and fulfills its duty. It looks ancient but it is powerful. Do not underestimate the power
by ho_schi 5y ago
Took me some time to get familiar with it but GDB is well documented and fulfills its duty. It looks ancient but it is powerful.
Do not underestimate the power of the print command! And the advanced stuff like revers-debugging, multi-threading (all-stop mode - which is the default - and the non-stop mode), binary manipulation (yep, it is possible), and remote debugging. Nowadays accompanied by stuff like debuginfod. What still need to try is the TUI modes because I assume it will improve my personal experience once I find a way of using it.
I've ended up writing all stuff useful for me onto paper, later a markdown and I can recommend everyone doing similar. GDB's learning curve is not like VIM (which is either a wall or a rocket - both looking similar on paper) but it is going upwards.
Today's highlight is "Why do I've to set up all my breakpoints again? You need to save them like an IDE":
https://sourceware.org/gdb/onlinedocs/gdb/Save-Breakpoints.html https://sourceware.org/gdb/onlinedocs/gdb/Save-Breakpoints.h...
- dotancohen 5y ago> I've ended up writing all stuff useful for me onto paper, later a markdown Would you like to share? :)
- pif 5y ago> It looks ancient but it is powerful It is powerful because it is ancient.
- nyanpasu64 5y ago> Do not underestimate the power of the print command! Still waiting for it to print the contents of a QList or QString, or pull actual data in cases where I see <optimized out>.
- gnud 5y agoAs I understand it, you can plug in the qt pretty printers from https://invent.kde.org/kdevelop/kdevelop/-/tree/master/plugins/gdb/printers https://invent.kde.org/kdevelop/kdevelop/-/tree/master/plugi...
- nyanpasu64 5y agoHow do I use these pretty printers outside of KDevelop? When I source that file from my global .gdbinit, I get the classic Python relative import error: ModuleNotFoundError: No module named 'qt' Changing KDevelop's gdbinit to `from .qt import register_qt_printers` results in: ImportError: attempted relative import with no known parent package The problem is that sourcing KDevelop's gdbinit doesn't let Python import packages relative to that file. Is there an alternative way to do this?
- gnud 5y agoI've never actually used these, I just knew they existed. I found them via DuckDuckGo, in the github repository of qBittorrent. They have a step-by-step guide for using them, without mentioning kdevelop: https://github.com/qbittorrent/qBittorrent/wiki/Setup-GDB-with-Qt-pretty-printers https://github.com/qbittorrent/qBittorrent/wiki/Setup-GDB-wi...
- mark_undoio 5y agoThe best solution I'm aware of for <optimized out> is to choose your preferred flavour of time travel debug and then step backwards until the variable comes back into scope. This will do the trick, so long as the compiler hasn't completely elided a value. It feels like there's scope for the DWARF debug info to make optimised variables debuggable normally but that's probably a pretty hairy problem.
- mark_undoio 5y agoOn a similar note - add `set history save on` to your `~/.gdbinit` and retain command history between runs of GDB (just like with your shell). https://sourceware.org/gdb/onlinedocs/gdb/Command-History.html https://sourceware.org/gdb/onlinedocs/gdb/Command-History.ht...
- kmarc 5y agoto my surprise, vim has built-in support (:help termdebug) for gdb. It's not as chiselled as some GUI debuggers but still usable and makes it (visually) easier to debug in terminal. Accidently I also moved my mouse cursor over a variable while stopped at a breakpoint, in a terminal, over ssh, and there is a hovering balloon popping up with the current state of that variable. Mind blown.