GDB 以乱序方式跳到错误的行

2022-01-20 00:00:00 redhat g++ gdb c++ c++11

应用设置:我有使用以下 3rd 方库的 C++11 应用程序:

Application Setup : I've C++11 application consuming the following 3rd party libraries :

  • 提升 1.51.0
  • cppnetlib 0.9.4
  • jsoncpp 0.5.0

应用程序代码依赖于几个内部共享对象,它们都是由我的团队开发的(针对这些共享对象执行经典的链接时间,不使用dlopen等)

The application code relies on several in-house shared objects, all of them developed by my team (classical link time against those shared objects is carried out, no usage of dlopen etc.)

我使用的是 GCC 4.6.2,使用 GDB 7.4 和 7.6 时出现问题.

I'm using GCC 4.6.2 and the issue appears when using GDB 7.4 and 7.6.

操作系统 - Red Hat Linux 7.0 (Guinness) x86-64

OS - Red Hat Linux release 7.0 (Guinness) x86-64

问题在共享对象代码中打断点并发出 gdb next 命令时,有时 GDB 会在没有任何合理原因的情况下向后跳转到某些行(尤其是在抛出异常之后,对于那些异常有合适的 catch 块)

The issue While hitting breakpoints within the shared objects code, and issuing gdb next command, sometimes GDB jumps backward to certain lines w/o any plausible reason (especially after exceptions are thrown, for those exceptions there suitable catch blocks)

类似的问题在关闭任何 GCC 优化"这一行中得到了解答,但我的 GCC CL 显然没有使用任何优化并要求提供调试信息,请注意 -O0 &-g 开关:

Similar issues in the web are answered in something along the lines 'turn off any GCC optimization) but my GCC CL clearly doesn't use any optimization and asked to have debug information, pls note the -O0 & -g switches :

COLLECT_GCC_OPTIONS= '-D' '_DEBUG' '-O0' '-g' '-Wall' '-fmessage-length=0' '-v' '-fPIC' '-D' 'BOOST_ALL_DYN_LINK' '-D' 'BOOST_PARAMETER_MAX_ARITY=15' '-D' '_GLIBCXX_USE_NANOSLEEP' '-Wno-deprecated' '-std=c++0x' '-fvisibility=hidden' '-c' '-MMD' '-MP' '-MF' 'Debug_x64/AgentRegisterer.d' '-MT' 'Debug_x64/AgentRegisterer.d' '-MT' 'Debug_x64/AgentRegisterer.o' '-o' 'Debug_x64/AgentRegisterer.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'

还请注意,根据 Linux DSO 最知名的方法,我们隐藏了符号,只有我们想公开的类被公开(也许这是相关的???)

Please also note as per Linux DSO best known methods, we have hidden visibility of symbols, only classes we would like to expose are being exposed (maybe this is related ???)

root 中导致此问题的后续步骤应该是什么?

What should be the next steps in root causing this issue ?

推荐答案

这类问题通常是 GIGO ―― gdb 只是按照编译器指示的方式行事.因此,它通常是编译器错误而不是 gdb 错误.即使使用 -O0 编译,我也看到过这种情况.想到的例子是,某些版本的 g++ 在发出对变量析构函数的调用时发出了变量声明的位置.这会导致在其他直线代码中出现这种奇怪的跳跃行为.

This sort of problem is usually GIGO -- gdb is just acting in the way that the compiler has instructed it to act. So, it's typically a compiler bug rather than a gdb bug. I've seen this happen even with -O0 compilations. The example that comes to mind is that some versions of g++ emitted the location of a variable's declaration when emitting a call to the variable's destructor. This lead to this odd jumping behavior in otherwise straight-line code.

相关文章