Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 745
Dipanjan Avatar asked Aug 01 '19 10:08

Dipanjan


1 Answers

I think anonymous namespace must be in parentheses.

(gdb) b (anonymous namespace)::function_name

It worked for me, please give it a try.

like image 79
Manoj Patil Avatar answered Sep 24 '22 00:09

Manoj Patil