简体   繁体   English

从addr2line获取完整路径

[英]Getting a full path from addr2line

I'm trying to automate some debugging tasks. 我正在尝试自动化一些调试任务。 In certain cases, I print the value of $ra [this is a MIPS machine] and parts of the stack as hex addresses. 在某些情况下,我打印$ra [这是一台MIPS机器]的值,并将堆栈的一部分打印为十六进制地址。 During debugging, I use addr2line to convert them into file:line pairs. 在调试期间,我使用addr2line将它们转换为file:line对。

I'd like to automate this procedure. 我想使这个过程自动化。

The problem is that addr2line returns a filename that equivelent to the value of __FILE__ at compilation time; 问题在于addr2line返回的文件名在编译时等于__FILE__的值; ie, the name of the file as passed to the compiler. 即,传递给编译器的文件名。 This is usually foo.c , sometimes src/foo.c . 通常是foo.c ,有时是src/foo.c As my project has several hundred directories in total, this may not be enough to uniquely identify the file (there may be 1/foo.c , 2/foo.c , etc). 由于我的项目总共有数百个目录,因此这可能不足以唯一地标识文件(可能有1/foo.c2/foo.c等)。 Even if it was deterministic, it seems rather inefficient to start running find in my screen for each argument [I suppose I could build a hash table and save them, but I'd like to keep this as a straightforward bash script] 即使是确定性的,开始在屏幕上为每个参数运行find似乎效率很低[我想我可以构建一个哈希表并保存它们,但我想将其保留为简单的bash脚本]

GDB seems to get the right file. GDB似乎得到了正确的文件。 If I look at the actual source file with debugging symbols, I can also see that right after the filename there appears to be the full path to the __FILE__ [ie, if __FILE__ is src/foo.c , and it's really in /home/me/projects/something/comp1/src/foo.c , I will see /home/me/projects/something/comp1 in the file. 如果我用调试符号查看实际的源文件,我还可以看到文件名之后似乎是__FILE__的完整路径[即,如果__FILE__src/foo.c ,并且它确实在/home/me/projects/something/comp1/src/foo.c ,我将在文件中看到/home/me/projects/something/comp1 How can I get this progmatically? 我该如何通过编程获得此信息?

Thanks. 谢谢。

This is very surprising behavior. 这是非常令人惊讶的行为。 I'm unable to reproduce it in: 我无法在以下位置复制它:

  • Linux with gcc 4.1.2 and addr2line 2.17.50.0.6 具有gcc 4.1.2和addr2line 2.17.50.0.6的Linux

  • Cygwin with gcc 4.3.4 and gcc 3.4.4 and addr2line 2.20.51.20100410 Cygwin与gcc 4.3.4和gcc 3.4.4以及addr2line 2.20.51.20100410

addr2line should rely on the debug information stored in the executable. addr2line应该依赖于可执行文件中存储的调试信息。 And the debug information should contain absolute paths (regardless of what source path was given to the compiler) in order to avoid any ambiguities when using a debugger. 并且调试信息应包含绝对路径(无论给编译器提供了什么源路径),以避免在使用调试器时出现任何歧义。 Everywhere I try it, addr2line always shows an absolute path. 在任何尝试的地方,addr2line始终显示绝对路径。

Assuming you are using make for your build system, one option, albeit a probably painful one, would be to change your makefiles to use a non-recursive strategy (something you really ought to be doing anyway). 假设您在构建系统中使用make,虽然可能很痛苦,但一个选择是将您的makefile更改为使用非递归策略(无论如何,您确实应该这样做)。 With such a system, only a single instance of make is running, from a single working directory (usually the top-level of your source tree). 在这样的系统中,仅在单个工作目录(通常是源树的顶层)中运行make的单个实例。 Therefore all invocations of the compiler specify the full path to the source file (relative to the root of the source tree). 因此,编译器的所有调用都指定了源文件的完整路径(相对于源树的根目录)。 This would solve your problem if, in fact, addr2line always shows the filenames as they were specified to the compiler. 实际上,如果addr2line始终显示文件名,则可以解决问题。 Not the best solution, but one that would work. 不是最好的解决方案,但可行的。 And as a side benefit, you'd get all the advantages of non-recursive make. 作为附带好处,您将获得非递归make的所有优点。

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

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