GDB from NetBeans 7.1 on OSX Leopard not stopping at breakpoints in library projects

911 Views Asked by At

This is my first question in StackOverflow since I joined some weeks ago and I wish someone could shed some light to this issue that drives me nuts! I've already searched thru the web, but I cannot find a successful solution to this problem.

I'm having some trouble with debugging with Netbeans 7.1 on Mac OSX 10.5.8 (Leopard) using GNU GDB. My problem is that I can't easily debug my own static or dynamic libraries from a test application because the debugger doesn't stop at breakpoints set in the source code of that libraries. However I've noticed that I can "step into" the library functions and, once I'm in them, breakpoints in those functions do fire!

My testbench consists on 2 simple projects: "mylib" (a C static library) and "mylib-test" (a C application). 'mylib' simply contains a header and a c file that define the function:

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

On the other hand, the mylib-test source simply uses that function:

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

Both projects compile and execute successfully. For your convenience, below I put down the output of compiling/linking both projects:

Output of compiling 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

Output of compiling mylib-test:

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 

By examining the Debugger Console, I've noticed that breakpoints placed in the library's source code are marked as "PENDING" when I load the application on the debugger (see line starting by 12^done, field 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-test\n"
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-MacOSX\n"
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"}

It seems that GDB is not loading the symbols of the library, yet it is actually linked statically (I mean, there are no dynamic libraries to load)!! However, if I step into function sum from the main() function, and then place the breakpoint, then it is successfully resolved:

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"}

I hope I've given enough information... Does anybody have an idea of what's going on? Thank you in advance!

Further info:

GCC version: 686-apple-darwin9-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5577)

GDB version: GNU gdb 6.3.50-20050815 (Apple version gdb-967)

Netbeans version: 7.1 (Build 201112071828)

////////////// EDIT //////////////////////////////////////////////////

So far I thought the problem was GDB, but today I've noticed it is not true: I've been able to debug the application directly using GDB from the command line, i.e., I could set breakpoints to my sum function and the debugger successfully stopped at them without the need to step into the function. So, I'm sure I'm having some issue with how NetBeans starts/initializes GDB. I've also noticed that NetBeans is trying to get features from GDB without success. From the debugger console:

~"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 are\nwelcome
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"
2

There are 2 best solutions below

3
On

I have no answer for this issue but I have some clues that could help finding solution.

I belive it's not NetBeans' fault. It's something with gdb. Probably it has to be compiled with some special configuration flag(s).

I was using gdb 7.4 (downloaded while ago with MinGW) with NetBeans 7.0-7.2 and Eclipse Juno on Windows 7 and everything was working as expected - gdb was stopping when entering breakpoints in my libraries (static or dynamic).

Lately I wanted to migrate to gdb compiled with Python support to get pretty-printing of complex STL structure in Eclipse. So I've downloaded latest gdb 7.5 sources and I've compiled it with "--with-python" flag:

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

Pretty pretting works. Not even on Eclipse but with NetBeans as well (you only need to point to .gdbinit file in Project's Debug settings). The problem is my own compiled version of gdb has no ability to stop on breakpoints in my libraries (on NetBeans 7.2 and Eclipse Juno).

My conclusion is that gdb should be compiled with some flag(s) to get this ability. Or maybe it would be just sufficient to run it with some flag(s). I would also be grateful for help with this issue.

I'm attaching some possible useful informations:

Screenshots with correct stack trace on gdb 7.4

Screenshots with incorrect stack trace on gdb 7.5

Correct gdb:

C:\MinGW\bin>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:\MinGW\bin>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"

Incorrect gdb:

C:\MinGW\bin>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:\MinGW\bin>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"
1
On

I've checked at my work if absence of libexpat is causing gdb problem you described. And it seem that this is the case :) Try to compile and install expat first and then compile gdb from soruces. Be sure to have:

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

in your logs (somewhere after "make" command. not after "./configure").

To compile gdb I used gcc 4.6.2 from MinGW under Windows 7 and gdb-7.5 sources. I also added two additional configure flags but for sure they aren't necessery:

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