namespaces - 在 gdb (llvm) 中中断命名空间函数

标签 namespaces gdb llvm

我正在尝试单步执行 llvm 的 opt 程序(用于作业),讲师建议在 runOnFunction 处设置一个断点。我在其中一个文件中看到了这个:

bool InstCombiner::runOnFunction(Function &F) { /* (Code removed for SO) */ }

但是gdb好像没有找到runOnFunction断点。我想到问题可能是 namespace ?我试过了,但 gdb 从未中断,它只是创建了 fooOpt.s 文件:

(gdb) b runOnFunction
Function "runOnFunction" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (runOnFunction) pending.
(gdb) r -S -instcombine -debug -o ~/Desktop/fooOpt.s ~/Desktop/foo.s

我在 Mac 上,所以我没有 objdumpotool 产生了 560 万行代码,作为 runOnFunction 的起点从它开始涉水似乎不合理在那里不止一次出现。

最佳答案

Gdb 有几个内置命令来查找此类函数的名称。首先是 info functions,它可以与可选的 regexp 参数一起使用来 grep 所有可用的函数,https://sourceware.org/gdb/current/onlinedocs/gdb/Symbols.html

info functions regexp

Print the names and data types of all defined functions whose names contain a match for regular expression regexp. Thus, ‘info fun step’ finds all functions whose names include step; ‘info fun ^step’ finds those whose names start with step. If a function name contains characters that conflict with the regular expression language (e.g. ‘operator*()’), they may be quoted with a backslash.

因此,您可以尝试 info functions runOnFunction 来获取名称。有时在执行 break 命令时在名称周围添加引号会很有用。

另一种方法是使用rbreak 命令代替break (b)。 rbreak 将在函数名称中进行正则表达式搜索,并且可以定义几个断点:https://sourceware.org/gdb/current/onlinedocs/gdb/Set-Breaks.html#Set-Breaks

rbreak regex

Set breakpoints on all functions matching the regular expression regex. This command sets an unconditional breakpoint on all matches, printing a list of all breakpoints it set. ...

The syntax of the regular expression is the standard one used with tools like grep. Note that this is different from the syntax used by shells, so for instance foo* matches all functions that include an fo followed by zero or more os. There is an implicit .* leading and trailing the regular expression you supply, so to match only functions that begin with foo, use ^foo.

(甚至 rbreak file:regex 将搜索限制为单个源文件)

PS:如果需要,您可以使用 set print demangle onoff ( https://sourceware.org/gdb/current/onlinedocs/gdb/Debugging-C-Plus-Plus.html#Debugging-C-Plus-Plus ) 打开或关闭 C++ 函数名称 demangling .关闭 demangling 后,将函数名称复制到 break 命令会更容易。

关于namespaces - 在 gdb (llvm) 中中断命名空间函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22827005/

相关文章:

xml - XSL 转换中命名空间的错误结果

c++ - rand() 为什么以及如何存在于 cstdlib 的全局和 std 命名空间中?

GDB 问题 BFD : reopening/tmp/. 。 : 没有这样的文件或目录

c++ - 在 gdb 中,我可以调用一些类函数,但其​​他的 "cannot be resolved"。为什么?

macos - 将 openmp (llvm) 与 sourceCpp 一起使用时找不到 math.h

c# - 如何在 C# 中调用特定命名空间的函数

c++ - boost 测试 : How to automatically attach debugger (GDB)?

clang - 使用 clang 优化 channel /标志进行编译

objective-c - self.iVar 是否需要 ARC 的强大属性?

xml - javax.xml.bind.UnmarshalException