11 ms·
I recently was troubleshooting a crash that backtraced through the boost::sml library [0]. The crash didn't actually have anything to do with the library, but i
by ddulaney 4y ago
I recently was troubleshooting a crash that backtraced through the boost::sml library [0]. The crash didn't actually have anything to do with the library, but it was used as the core event loop.
The backtrace -- as in, just the output from running `bt` in GDB -- was over a thousand wrapped lines long. There were ~5 stack frames that took up over a hundred lines of console each to print just the function name. That product's debug builds recently hit the 2GB line, which is enough that old versions of binutils complain.
I don't know what the solution is. There's some really neat stuff you can do with template metaprogramming, and in stripped release builds it compiles down extremely tiny. Plus the code is very clean to read. But it does feel like there isn't any kind of central vision for the C++ debugging experience, and bad interactions between highly-complex modern C++ libraries, the compiler, and the debugger are probably only going to get worse unless somebody (the ISO committee? vendors? every single library author individually?) thinks really hard about debugging support.
[0]: https://github.com/boost-ext/sml https://github.com/boost-ext/sml
- jcranmer 4y agoconstexpr evaluation helps a lot with that, since you can get a lot of the Turing-complete nature without having to go crazy with nested templates to get what you need.
- Blackthorn 4y agoThis is a big problem with gdb/dwarf and c++. It just does not work anywhere near as well as C does. You don't even need template metaprogramming to get a horrible experience. Just imagine using std::transform and wanting to step. You obviously want to step through your lambda that you pass it. You don't want to step through the over 9000 lines of whatever the fuck libstdc++ is doing to make std::transform work. In most cases you can't even set a breakpoint in your lambda because breakpoints are set by line number, so you'll hit the break in the transform. Leaving you needing to reformat your source code and recompile just to set a reasonable breakpoint. This particular problem could be solved if the debugger let you say "skip through some namespace (like std) but stop if it calls something else" but c++ debugging has all sorts of nonsense like this. Honestly I've just stopped using debuggers with c++ over a decade ago. It's just not worth fighting with it. I think the people that need to think about debugging ergonomics isn't the standard committee or the library authors. It's the authors of whoever is writing the next debugger. Gdb is great for C but it really doesn't map to C++ well at all.
- ddulaney 4y agoMy solution in this case was to convince my company to buy CLion, which works reasonably well and which I believe is backed by LLDB.
- mark_undoio 4y agoGDB has the "skip" command to help with this but it has limitations. It stops you stepping into namespaces you don't want to see but doesn't do anything when you step out into them. It also doesn't handle when code you don't want to see calls back into code you do - and, yes, I've recommended formatting lambdas to allow breakpoints before. I believe DWARF does support columnar information these days so it actually should be possible to solve the one line lambda given code in GDB. For looking at any data in C++ it's also very important to have GDB's pretty printers set up (and, likely, write some of your own). https://sourceware.org/gdb/onlinedocs/gdb/Pretty_002dPrinter-Introduction.html https://sourceware.org/gdb/onlinedocs/gdb/Pretty_002dPrinter... https://undo.io/resources/gdb-watchpoint/here-quick-way-pretty-print-structures-gdb/ https://undo.io/resources/gdb-watchpoint/here-quick-way-pret... (this one is from my boss)
- Joker_vD 4y agoVisual Studio debugger supported "Just My Code" since always for .NET applications and I believe they recently added something to this effect for C/C++ as well, although not nearly as flawless, of course.
- stonemetal12 4y agoThey should make a way for typedefs to trickle down to debug symbols. It would make error messages better reflect the code and offer a solution to template type bloat in debug symbols.
- yjftsjthsd-h 4y ago> over a hundred lines of console each to print just the function name At what point is it better to just rename everything to use the sha256 of the "real" name? It's obviously only for machine use anyways, so it's not like one more layer of indirection would hurt.
- ddulaney 4y agoHeh, you’re not wrong. It was handy to see the outer couple of layers of template expansion, though, so I could know at least which library it came from. I’d be very interested in some way to adjust the displayed format to be different from the “real” type name (which is of course different from the machine-readable mangled name). It might be better to put that functionality in the debugging tool.