GDB抱怨缺少raise.c

问题描述 投票:10回答:1

每次gdb捕获异常时,我都会收到一个恼人的错误。我运行了以下示例程序

#include <stdexcept>

int main() {
  throw std::invalid_argument("");
  return 0;
}

运行gdb的结果是

terminate called after throwing an instance of 'std::invalid_argument'
  what():  

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

这并不是那么糟糕,因为我得到了我需要的信息,它只是在困扰我......

有谁知道如何解决这个问题?

c++ exception gdb
1个回答
9
投票

要在Ubuntu上对C库进行完整的源代码调试,您需要:

1)安装libc6的debuginfo版本。

它可能已经安装,但如果不是,请运行sudo apt install libc6-dbg

2)下载与已安装的C库版本对应的源代码。

首先,在任何地方创建一个目录 - 我将在这里使用/opt/src。然后执行以下操作:

sudo apt install dpkg-dev
cd /opt/src
apt source libc6
find $PWD -maxdepth 1 -type d -name 'glibc*'

记住这个名字 - 它会像/opt/src/glibc-2.23

现在,运行gdb,运行程序直到它停止,并在gdb提示符下执行以下操作:

(gdb) info source
Current source file is ../sysdeps/unix/sysv/linux/raise.c
Compilation directory is /build/glibc-KM3i_a/glibc-2.23/signal

因此,gdb期望源代码位于与我们放置它的位置不同的目录中。有两种方法可以解决这个问题:

a)移动或使用符号链接,以便源代码(或似乎是)在/build/glibc-KM3i_a/glibc-2.23中。

b)告诉gdb如何替换正确的源目录路径名:

  (gdb) set substitute-path /build/glibc-KM3i_a/glibc-2.23 /opt/src/glibc-2.23

现在,回到你的框架,gdb应该显示源代码行:

(gdb) frame 1
#1 0xb7e2fea9 in __GI_raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:54
         return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
© www.soinside.com 2019 - 2024. All rights reserved.