来自OSX Leopard上的NetBeans 7.1的c-GDB在库项目中不在断点处停止



这是我几周前加入StackOverflow后在这里提出的第一个问题,我希望有人能澄清这个让我抓狂的问题!我已经在网上搜索过了,但我找不到这个问题的成功解决方案。

我在使用GNU GDB在Mac OSX 10.5.8(Leopard)上调试Netbeans 7.1时遇到了一些问题。我的问题是,我无法从测试应用程序轻松调试我自己的静态或动态库,因为调试器不会在库的源代码中设置的断点处停止。然而,我注意到我可以"踏入"库函数,一旦我进入它们,这些函数中的断点就会启动!

我的测试台由两个简单的项目组成:"mylib"(C静态库)和"mylib测试"(C应用程序)mylib只包含一个头和一个定义函数的c文件:

int sum(int a, int b) {
    return a+b;
}

另一方面,mylib测试源仅使用该函数:

int main(int argc, char** argv) {
    printf("Result=%dn", sum(111, 222));
    return (EXIT_SUCCESS);
}

两个项目都成功编译并执行。为了方便起见,下面我列出了编译/链接两个项目的输出:

编译mylib的输出

gcc    -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/m.o.d -o build/Debug/GNU-MacOSX/m.o m.c
mkdir -p dist/Debug/GNU-MacOSX
rm -f dist/Debug/GNU-MacOSX/libmylib.a
ar -rv dist/Debug/GNU-MacOSX/libmylib.a build/Debug/GNU-MacOSX/m.o 
ar: creating archive dist/Debug/GNU-MacOSX/libmylib.a
a - build/Debug/GNU-MacOSX/m.o
ranlib dist/Debug/GNU-MacOSX/libmylib.a

编译mylib测试的输出

gcc    -c -g -I../mylib -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.c
mkdir -p dist/Debug/GNU-MacOSX
gcc     -o dist/Debug/GNU-MacOSX/mylib-test build/Debug/GNU-MacOSX/main.o ../mylib/dist/Debug/GNU-MacOSX/libmylib.a 

通过检查调试器控制台,我注意到当我在调试器上加载应用程序时,放置在库源代码中的断点被标记为"PENDING"(请参阅以12^done开头的行,字段addr):

11-break-insert -f "/Users/claudi/dev/mylib-test/main.c:16"
12-break-insert -f "/Users/claudi/dev/mylib/m.c:5"
7^done,line="7",file="main.c",fullname="/Users/claudi/dev/mylib-test/main.c",time={wallclock="0.00065",user="0.00032",system="0.00029",start="1345544547.505531",end="1345544547.506184"}
(gdb) 
13-break-insert -t main
&"cd /Users/claudi/dev/mylib-testn"
8^done
(gdb)
9^done,time={wallclock="0.00002",user="0.00002",system="0.00000",start="1345544547.530991",end="1345544547.531013"}
(gdb) 
&"set environment DYLD_LIBRARY_PATH=../mylib/dist/Debug/GNU-MacOSXn"
10^done
(gdb) 
11^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00001fb3",func="main",file="main.c",line="16",shlib="/Users/claudi/dev/mylib-test/dist/Debug/GNU-MacOSX/mylib-test",times="0"},time={wallclock="0.00058",user="0.00030",system="0.00029",start="1345544547.532421",end="1345544547.533003"}
(gdb) 
12^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="/Users/claudi/dev/mylib/m.c:5",times="0"},time={wallclock="0.00040",user="0.00018",system="0.00022",start="1345544547.533140",end="1345544547.533542"}
(gdb) 
13^done,bkpt={number="3",type="breakpoint",disp="del",enabled="y",addr="0x00001fb3",func="main",file="main.c",line="16",shlib="/Users/claudi/dev/mylib-test/dist/Debug/GNU-MacOSX/mylib-test",times="0"},time={wallclock="0.00017",user="0.00016",system="0.00001",start="1345544547.552190",end="1345544547.552362"}

GDB似乎没有加载库的符号,但它实际上是静态链接的(我的意思是,没有动态库可加载)!!然而,如果我从main()函数进入函数sum,然后放置断点,则它被成功解决:

21-break-insert -f "/Users/claudi/dev/mylib/m.c:5"
21^done,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00001fea",func="sum",file="m.c",line="5",shlib="/Users/claudi/dev/mylib-test/dist/Debug/GNU-MacOSX/mylib-test",times="0"},time={wallclock="0.00099",user="0.00039",system="0.00060",start="1345544947.877096",end="1345544947.878088"}

我希望我已经提供了足够的信息。。。有人知道发生了什么事吗?提前谢谢!

进一步信息:

GCC版本:686-apple-darwin9-GCC-4.2.1(GCC)4.2.1(apple股份有限公司版本5577)

GDB版本:GNU GDB 6.3.50-20050815(苹果版本GDB-967)

Netbeans版本:7.1(Build 201112071828)

//////////////编辑

到目前为止,我认为问题是GDB,但今天我注意到这不是真的:我已经能够从命令行直接使用GDB调试应用程序,也就是说,我可以为我的sum函数设置断点,调试器成功地停止了这些断点,而无需进入该函数。所以,我确信我对NetBeans如何启动/初始化GDB有一些问题。我还注意到,NetBeans试图从GDB获得功能,但没有成功。从调试器控制台:

~"GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)n"
~"Copyright 2004 Free Software Foundation, Inc.n"
~"GDB is free software, covered by the GNU General Public License, and you arenwelcome
to change it and/or distribute copies of it under certain conditions.nType "show 
copying" to see the conditions.nThere is absolutely no warranty for GDB.  Type "show 
warranty" for details.n"
~"This GDB was configured as "i386-apple-darwin"."
~"n"
(gdb) 
2-list-features
3-gdb-set print repeat 0
4-gdb-set backtrace limit 1024
5-gdb-set print elements 0
6-file-exec-and-symbols  "/Users/claudi/dev/mylib-test/dist/Debug/GNU-MacOSX/mylib-test"
2^error,msg="Undefined MI command: list-features"

我对这个问题没有答案,但我有一些线索可以帮助找到解决方案。

我相信这不是NetBeans的错。这与gdb有关。可能必须使用一些特殊的配置标志对其进行编译。

我在Windows7上使用gdb 7.4(不久前与MinGW一起下载)、NetBeans 7.0-7.2和Eclipse Juno,一切都如预期的那样工作——在我的库中输入断点(静态或动态)时,gdb停止了。

最近,我想迁移到使用Python支持编译的gdb,以便在Eclipse中漂亮地打印复杂的STL结构。所以我下载了最新的gdb 7.5源代码,并用"--with python"标志进行了编译:

./configure --with-python
make && make install

漂亮的椒盐工作。甚至在Eclipse上也没有,但在NetBeans上也没有(您只需要在Project的Debug设置中指向.gdbinit文件)。问题是我自己编译的gdb版本无法在库中的断点上停止(在NetBeans 7.2和Eclipse Juno上)。

我的结论是,gdb应该使用一些标志进行编译,以获得这种能力。或者,用一些标志运行它就足够了。我也将感谢在这个问题上提供的帮助。

我附上一些可能有用的信息:

gdb 7.4 上具有正确堆栈跟踪的屏幕截图

gdb 7.5 上错误堆栈跟踪的屏幕截图

正确的gdb:

C:MinGWbin>gdb  --version
GNU gdb (GDB) 7.4
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
C:MinGWbin>gdbserver --version
GNU gdbserver (GDB) 7.4
Copyright (C) 2012 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "i686-pc-mingw32"

gdb:不正确

C:MinGWbin>gdb --version
GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
C:MinGWbin>gdbserver --version
GNU gdbserver (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "i686-pc-mingw32"

我在工作中检查了libexpat的缺失是否导致了您描述的gdb问题。情况似乎是这样的:)首先尝试编译并安装expat,然后从soruces编译gdb。一定要有:

checking for libexpat... yes
checking how to link with libexpat... <some_path>/libexpat.a

在您的日志中(在"make"命令之后的某个位置。而不是在"./configure"之后)。

为了编译gdb,我在Windows7和gdb-7.5源代码下使用了MinGW的gcc 4.6.2。我还添加了两个额外的配置标志,但可以肯定的是,它们不是必需的:

./configure --with-python --without-auto-load-safe-path 

最新更新