eclipse调试模式下的GDB无法找到stdlib / rand.c

时间:2014-11-17 01:54:25

标签: c++ c eclipse debugging gdb

我正在尝试将gdb与ubuntu上的eclipse cdt一起运行,以开始调试一些简单的程序。所以我按照我认为必要的步骤来运行它:

1。创建可执行项目

2。编译

3. 运行

4. :创建文件.gdbinit并将其放在主项目文件夹中

5. 设置部分调试器configurationenter image description here enter image description here

5. 我还试图找到一个.gdbinit文件,看起来像这样:

set schedule-multiple

dir ~/gcc_build/4.7.2/build/gcc
dir ~/gcc_build/4.7.2/gcc
dir ~/gcc_build/4.7.2/gcc/cp
dir ~/gcc_build/4.7.2/gcc/lto
source ~/gcc_build/4.7.2/build/gcc/gdbinit.in

但即使在做了以下事情之后,我在电脑里也找不到类似的东西:

# find / -name .gdbinit

所以,我的文件.gdbinit最终得到了简单的内容 - 是的只有:

set new-console on

然后我点击了Apply and Debug:

enter image description here

gdb按预期开始正常运行。我按下按钮"翻过/ F6"并且调试器逐步跳过代码。直到它到达命令rand()并且gdb挂起并显示消息:

Can't find a source file at "/build/buildd/eglibc-2.19/stdlib/rand.c" 
Locate the file or edit the source lookup path to include its location.

enter image description here

因此,我也试图找到rand.c来更新此路径以包含其位置:

# find / -name rand.c
# find / -name stdlib

来自GDB的错误消息抱怨rand.c丢失,然后我试着继续踩...从那时起重启调试后步进模式被禁用:

enter image description here

是否发生此问题是因为我的文件.gdbinit的某些设置丢失了?或者一些GDB如何无法从c99的stdlib中找到rand.c?当我编译并运行程序时,它运行得很好。只有当我尝试启动调试器时才会发生GDB崩溃。

更新:运行commands后,我遇到了丢失的rand.c问题:

# apt-get install libc6-dbg
# apt-get source libc6

但现在出现了另一个错误:

Can't find a source file at "/build/buildd/eglibc-2.19/csu/libc-start.c" 
Locate the file or edit the source lookup path to include its location.

我是否还要为gdb安装该库?

所有建议都受到高度赞赏。

2 个答案:

答案 0 :(得分:3)

从我在你的描述中看到的...看你发布的第4和第5张图片,你做了所有必要的步骤。

但是,在我看来,您的GDB附加到多个项目。这意味着除非你真的需要,我强烈建议你选择你当前没有调试的所有项目,并从调试器模式中删除它们。所以,我的建议是,在你完成了迄今为止所做的所有步骤之后,继续:

Debug Configurations > C/C++ Applications: (drop down it)

...然后点击你没有编译的每个项目,用鼠标右键选择“删除” - 但不要担心,它不会删除你的项目,只会删除你的调试项模式。

然后重启日食。当您再次尝试在调试器模式下运行时,所有内容都将比以前运行得更顺畅。

答案 1 :(得分:0)

步骤1:

转到https://www.gnu.org/software/libc/下载glibc。

步骤2:

在本地解压缩,每当eclipse提示"无法找到... xxx.c"时,只需将文件加载到eclipse中。它会起作用。