简体   繁体   English

如何在 gdb 中为匿名命名空间设置断点?

[英]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.我正在 gdb 中调试,我想使用函数名在函数中设置断点。 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?我还尝试使用 filename : linenum 放置断点,但是如果文件已经加载,这通常会起作用,否则它会说“找不到源文件”在将来的共享库加载时设置断点挂起? (y or [n]) n (y 或 [n]) n

So, the workaround is that once the debugger is inside the same file, I can set breakpoint using filename : line number因此,解决方法是,一旦调试器位于同一个文件中,我就可以使用 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?相关的stackoverflow 问题: 如何在Visual Studio 中的匿名命名空间内按函数名称设置断点?

But this does not solve the problem over here.但这并不能解决这里的问题。

As per some post in stackoverflow,根据stackoverflow中的一些帖子,

  1. I tried using ::function_name() but this does not work.我尝试使用 ::function_name() 但这不起作用。
  2. anonymous namespace::function_name()匿名命名空间::function_name()

namespace { int function_name(int a, int b) { return a+b;命名空间 { int function_name(int a, int b) { return a+b; } } } }

"No source file found" /root/workspace/ProtocolInterface.cpp. “未找到源文件”/root/workspace/ProtocolInterface.cpp。 Make breakpoint pending on future shared library load?在未来的共享库加载时使断点挂起? (y or [n]) y (y 或 [n]) y

Even if the breakpoint pending, it does not break at the mentioned function.即使断点挂起,它也不会在提到的函数处中断。

I think anonymous namespace must be in parentheses.我认为匿名命名空间必须在括号中。

(gdb) b (anonymous namespace)::function_name (gdb) b (匿名命名空间)::function_name

It did worked for me, please give a try.它确实对我有用,请试一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM