6

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.

Manoj Patil
  • 155
  • 8
Dipanjan
  • 181
  • 3
  • 12

1 Answers1

9

I think anonymous namespace must be in parentheses.

(gdb) b (anonymous namespace)::function_name

It worked for me, please give it a try.

OMGtechy
  • 7,935
  • 8
  • 48
  • 83
Manoj Patil
  • 155
  • 8