Sunday, February 01, 2009

Stepping Over STL Code



When debugging C++ code written using the Standard Template Library (STL) it is not unusual to find yourself stepping through STL code. Most of the time, this is not very useful: The STL implementation typically comes bundled with the C++ compiler, and it has been thoroughly tested by the vendor; it is unlikely that the bug you are after is caused by the STL.

So when a statement such as myVector.push_back(x) is encountered while tracing with the debugger, you normally want to step over it, not into it. Most debuggers offer a "step over" and a "step into" function. So you would chose "step over".

But how about this? You want to debug a routine named my_func(size_t containerSize) and want to step into the body of my_func when this statement is hit: my_func(myVector.size()). If you select "step into", the debugger will first take you into the guts of STL's vector<T>::size() implementation before stepping into my_func.

The ZeroBUGS debugger allows you to avoid such annoyances. Once inside size(), you can right click, and select to "Always step over..." that function, all functions in that file, or all files in the same directory. The debugger will remember your option, and you don't have to see the guts of size(), or any other vector function, or any other STL function, respectively.

The functionality can be used not just with the STL but any code. If you later change your mind, the "Manage" menu allows you to remove functions, files or directories from the step-into blacklist.

3 comments:

Unknown said...

Sweet,

Does this feature work with the startup runtime/GC for dmd? If it does you may have a new customer...I would love to break at _Dmain and step over all the initialization code to the first loc in main(). Also, does ZeroBugs work with ldc? (I assume so since it is DWARF output).

Thanks,
K.Wilson

Cristache said...

Hi K,

What you want to do for D is to set ZERO_D_SUPPORT to true in your environment (see http://www.zero-bugs.com/2.0/manual_environ.html), and also ZERO_START_MAIN (or set "Always stop at main" in the UI).

To your other question: the behavior of stepping over select functions is language independent so it should work for D.

I have not tested LDC, I played with GCC LLVM a while ago and as I remember it work OK. I still have to check out LDC though.

MrTact said...

If only there were a Windows version...