Some Relief in Debugging Boost Functions

F11 Hell

F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11 F11. Finally!!

That’s the pain of debugging a boost::function in Visual Studio.

Consider the following code:

class CTest { public: void func(int i) {return 0;} }
boost::function f = boost::bind(&CTest::func, &t, _1);
f(1);

To step into the target function f, it requires 30 F11 keystrokes. Since our product uses (or overuses) boost::function, debugging can be a nightmare.

Counter the Counter Arguments

Before I get too far, let’s answer some counter arguments.

1. Who presses F11 30 times? I know exactly what to step over, so I perform combination of F10 and F11 to navigate my way through.

Answer: The exact F10/F11 combination is tricky. There are countless times that I over-pressed F10, skipped over the crucial functions.

2. There isn’t that much code to step through.

Answer: If I have to step into 5 boost functions, that’s 30 *5 = 150 F11’s. If I debug this code 30 times a day, that’s 150 * 30 = 4500 keystrokes.

Just admit it. Debugging boost::function with Visual Studio sucks.

Some Relief

In Visual Studio, there is a hidden feature that allows you to step over certain functions. Basically, it is a bunch of regular expressions that the debugger looks into. If the function signature matches the specified string, the debugger can either step into or step over the matched function.

So I spent some time crafting some regular expression to relief the pain of boost functions. It will bring down the number of F11 from 30 to 16. It’s not a complete solution, but it does help tremendously.

Add the following four keys to [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\NativeDE\StepOver]

boost_function_step_into = boost\:\:_bi\:\:list[0-9]\<boost\:\:_bi\:\:value.*=StepInto
boost_function_list_no_step_into = boost\:\:_bi\:\:list[0-9].*
boost_function_function_base_no_step_into = boost\:\:function_base\:\:.*
boost_function_unwrapper_no_step_into = boost\:\:_bi\:\:unwrapper.*

More Information

I have tested this on Boost library version 1.36, 1.37 and 1.39.

The .reg file that automatically updates your Visual Studio 9.0 path can be downloaded here.

For older Visual Studio, this trick also work. Click here for the registry location.

Leave a comment