How do I set a breakpoint on a function whose name contains spaces or other special characters?


If you use one of the command line debuggers based on the Debugger Engine, you can set a breakpoint on a function whose name contains spaces or other special characters by quoting the symbol name. The trick here is that you do not quote the entire string; you quote only the symbol name.

0:001> bu @!"CSimpleArray<wchar_t *>::CSimpleArray<wchar_t *>"

Note that the quotation marks do not go around the @! part. They go only around the symbol. (Otherwise, the debugger thinks you are setting a breakpoint action.)

Another trick for setting breakpoints is using tab autocompletion for symbols. If you type bp contoso!*Widget* and then hit Tab repeatedly, you will cycle through all the matches. (It takes a few seconds to build the list of matches, so be patient the first time you hit Tab.)

Personally, I use the x command to print out all the matches, and then cherry-pick the one I want.

0:001> x contoso!*Widget*
00af114c contoso!CreateWidget
009fe863 contoso!DestroyWidget
00a2e161 contoso!MakeWidgetReadOnly
00a93168 ...

0:001> bp 00a2e161     set breakpoint on MakeWidgetReadOnly
Comments (3)
  1. Also works for non-command-line debuggers based on the debugger engine (e.g., WinDBG), of course.

  2. Mark says:

    Raymond's method also has the advantage that it works reliably for symbols with duplicate names.

    Maurits: Windbg has a command line ;)

  3. Joker_vD says:

    What if a symbol name contains a quote? For that matter, what characters are allowed in symbol names? I'd assume the null character is not allowed, what else?

Comments are closed.

Skip to main content