6

I have the following code:

namespace
{
    void Foo()
    {
    }
}

namespace Bar
{
    void Foo()
    {
    }
}

int main()
{
    Foo();
    Bar::Foo();

    return 0;
}

I want to put breakpoint on Foo() inside anonymous namespace by name (Ctrl+B key binding). I can do it for function inside named namespace Bar with no problem by name Bar::Foo. I tried anonymous namespace::Foo for anonymous namespace but VS fails to parse this name, i guess because of whitespace character in name. Also I tried to put different quotation marks but with no luck. Is it possible at all to put this breakpoint?

ks1322
  • 33,961
  • 14
  • 109
  • 164
  • Dunno, but you can try to define a type inside the function and output its name using `typeid(T).name` (you need to include `` header), and possibly there you'll see how the function is meant to be referred to. – Cheers and hth. - Alf Sep 12 '11 at 13:07
  • In gdb, the command to set a breakpoint is: b (anonymous namespace)::xxClass::xxFunction(xxType&..). I don't known whether it works in VisualStudio. – hailinzeng Dec 31 '16 at 07:16

2 Answers2

3

I encountered a similar problem a long time ago (Debugging data in 'anynomous namespaces' (C++)). I wanted to look at the value of a data member in an unnamed namespace, but I couldn't get this done.

Finally, somebody pointed me to http://msdn.microsoft.com/en-us/library/0888kc6a%28VS.80%29.aspx. Maybe you can get the decorated function name and put a breakpoint on that.

Community
  • 1
  • 1
Patrick
  • 23,217
  • 12
  • 67
  • 130
  • Yes, this helped. I've got decorated function name using `dumpbin.exe /symbols breakpoits.obj` [http://msdn.microsoft.com/en-us/library/b842y285(v=vs.80).aspx](http://msdn.microsoft.com/en-us/library/b842y285(v=vs.80).aspx) and put breakpoint on it. Looks like there is no other way to it in VS. – ks1322 Sep 12 '11 at 13:48
0

It looks like Visual Studio can't set breakpoint by function name inside anonymous namespace. Even WinDbg can't do this.

If you have sources you can set breakpoint by line.

Sergey Podobry
  • 7,101
  • 1
  • 41
  • 51