[英]How is gdb stack trace readability of release code influenced on x64?
I am working on a project, where the request "we want more information in release build stack traces" came up.我正在处理一个项目,其中出现了“我们需要发布构建堆栈跟踪中的更多信息”的请求。
With "stack trace" I mean basically the output of taa bt
in gdb
, which I suppose to be equivalent to the output of gstack for a running process.对于“堆栈跟踪”,我的意思基本上是gdb
of taa bt
的输出,我认为它相当于正在运行的进程的 gstack 输出。 If this is true would be one of my questions.如果这是真的,这将是我的问题之一。
My main problem is that availability of stack traces is rather erratic (sometimes you have them, sometimes you don't) and documentation could be more detailed (eg gdb
documentation states that " -fomit-frame-pointer
makes debugging impossible on some machines.", without any clear information about x86_64)我的主要问题是堆栈跟踪的可用性相当不稳定(有时您拥有它们,有时您没有)并且文档可能更详细(例如, gdb
文档指出“ -fomit-frame-pointer
使得在某些机器上无法进行调试。 ”,没有任何关于 x86_64 的明确信息)
Also, when examining a running program with gstack
, I get a quite perfect stack traces.此外,当使用gstack
检查正在运行的程序时,我得到了一个非常完美的堆栈跟踪。 I am unsure, though, if this is exactly what I would get from a core dump with gdb
(which would mean that all cases where I get less information, the stack has been really corrupted).但是,我不确定这是否正是我从gdb
的核心转储中得到的(这意味着在我获得的信息较少的所有情况下,堆栈确实已损坏)。
Currently, the code is compiled with -O2
.目前,代码是用-O2
编译的。 I have seen one stack trace lately, where our own program code's stack frames did not have any function parameter values, but the first (inner) frames, where our code already called a third party library, provided these values.我最近看到一个堆栈跟踪,其中我们自己的程序代码的堆栈帧没有任何函数参数值,但第一个(内部)帧,我们的代码已经调用了第三方库,提供了这些值。 Here, I am not sure if this is a sign that the first party library had better gcc debugging options set, or if these information is just lost at some point iterating down the stack trace.在这里,我不确定这是否表明第一方库设置了更好的 gcc 调试选项,或者这些信息是否只是在迭代堆栈跟踪的某个时刻丢失了。
I guess my questions are:我想我的问题是:
gstack
of a running program正在运行的程序的gstack
输出taa bt
将 gdb 附加到正在运行的程序,执行taa bt
gcore
on a running program, opening core with gdb
, then taa bt
在正在运行的程序上调用gcore
,用gdb
打开核心,然后taa bt
gdb
程序中止,系统写入核心文件,用gdb
打开All considerations made under the assumption that the program binary exists for the core dump, and source code is not available.所有考虑都假设程序二进制文件存在于核心转储,并且源代码不可用。
With "quality of a stack trace" i mean 3 criteria:对于“堆栈跟踪的质量”,我的意思是 3 个标准:
Which compiler options influence the stack trace quality on x86_64哪些编译器选项会影响 x86_64 上的堆栈跟踪质量
The -fomit-frame-pointer
is the default on x86_64
, and does not cause stack traces to be unusable. -fomit-frame-pointer
是x86_64
上的默认值,不会导致堆栈跟踪不可用。
GDB relies on unwind descriptors, and you could strip these with either strip
or -fno-unwind-tables
(this is ill -advised). GDB 依赖于展开描述符,您可以使用strip
或-fno-unwind-tables
剥离它们(这是不明智的)。
are stack traces from these origins identical:来自这些来源的堆栈跟踪是否相同:
- output of gstack of a running program - 正在运行的程序的 gstack 输出
Last I looked, gstack
was a trivial shell script that invoked gdb
, so yes.最后我看, gstack
是一个调用gdb
的简单shell脚本,所以是的。
- attached gdb to a running program, executed "taa bt"将 gdb 附加到正在运行的程序,执行“taa bt”
Yes.是的。
- called gcore on a running program, opening core with gdb, then "taa bt"在正在运行的程序上调用 gcore,用 gdb 打开核心,然后“taa bt”
Yes, provided the core
is opened with GDB on the same system where gcore
was run.是的,前提是在运行gcore
的同一系统上使用 GDB 打开core
。
- program aborted and core file written by system, opened with gdb程序中止,系统写入核心文件,用gdb打开
Same as above.和上面一样。
If you are trying to open core
on a different system from the one where it was produced, and the binary uses dynamic libraries, you need to set sysroot
appropriately.如果您尝试在与生成core
的系统不同的系统上打开core
,并且二进制文件使用动态库,则需要适当set sysroot
。 See this question and answer.看到这个问题和答案。
Note that there are a few reasons stack may look corrupt or unavailable in GDB:请注意,堆栈在 GDB 中可能看起来已损坏或不可用的几个原因:
-fno-unwind-tables
or strip
ing mentioned above -fno-unwind-tables
或上面提到的strip
.cfi
directives从程序集编译的代码,并且缺少正确的.cfi
指令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.