'How to set a breakpoint in gdb for an anonymous namespace?

In my code base, there are some callbacks functions which are defined in anonymous namespace. I am debugging in gdb and I want to set breakpoint in the function using function name. I also tried putting breakpoint by using filename : linenum , but that will generally work if the file is already loaded or else it will say "No source file found" Make breakpoint pending on future shared library load? (y or [n]) n

So, the workaround is that once the debugger is inside the same file, I can set breakpoint using filename : line number

But is there any other way to set breakpoints inside anonymous namespace ?

Related stackoverflow questions : How to set breakpoint by function name inside anonymous namespace in Visual Studio?

But this does not solve the problem over here.

As per some post in stackoverflow,

  1. I tried using ::function_name() but this does not work.
  2. anonymous namespace::function_name()

namespace { int function_name(int a, int b) { return a+b; } }

"No source file found" /root/workspace/ProtocolInterface.cpp. Make breakpoint pending on future shared library load? (y or [n]) y

Even if the breakpoint pending, it does not break at the mentioned function.



Solution 1:[1]

I think anonymous namespace must be in parentheses.

(gdb) b (anonymous namespace)::function_name

It worked for me, please give it a try.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 OMGtechy