AlexTheo
AlexTheo

Reputation: 4184

gdbserver program crashes before main on freebsd

Trying to debug an app running on freebsd using gdb - gdbserver. Somehow if I do a local debugging (using gdb on bsd) everything is going well however using the gdbserver (I run gdb and gdbserver on the same bsd machine) seems to fail in the initialization process before main.

my workflow is:

echo "int main(int argc, char** argv){return 0;}">main.cpp
clang++ -ggdb main.cpp

gdbserver localhost:2222 ./a.out

Same machine or different doesn't matter:

gdb
file a.out
target remote localhost:2222
break main
continue -> here everything is crashing (not gdbserver but app).

Thank you in advance :)

The output of my console is:
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd".
(gdb) file a.out
Reading symbols from a.out...done.
(gdb) target remote localhost:2222
Remote debugging using localhost:2222
0x0000000800602110 in ?? ()
(gdb) break main
Breakpoint 1 at 0x400770: file main.cpp, line 1.  
(gdb) continue 
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) 

Some additional information:

(gdb) backtrace 
#0  0x0000000000000000 in ?? ()
#1  0x0000000200000000 in ?? ()
#2  0x0000000000400200 in ?? ()
#3  0x0000000000400510 in ?? ()
#4  0x00007fffffffeba0 in ?? ()
#5  0x00007fffffffeba8 in ?? ()
#6  0x00007fffffffebc0 in ?? ()
#7  0x000000000040023c in crt_noinit_tag ()
#8  0x000000080061e000 in ?? ()
#9  0x0000000000400248 in crt_noinit_tag ()
#10 0x00007fffffffedd8 in ?? ()
#11 0x00007fffffffebd0 in ?? ()
#12 0x0000000000000000 in ?? ()

(gdb) info sharedlibrary 
From                To                  Syms Read   Shared Object Library
0x00000008008599c0  0x00000008008b2f58  Yes         /usr/lib/libc++.so.1
0x0000000800ae4a20  0x0000000800af0a78  Yes         /lib/libcxxrt.so.1
0x0000000800cfdcf0  0x0000000800d158a8  Yes         /lib/libm.so.5
0x0000000800f5b780  0x00000008010673a8  Yes         /lib/libc.so.7
0x00000008012cc150  0x00000008012d58e8  Yes         /lib/libgcc_s.so.1
0x0000000800602110  0x0000000800615639  Yes         /libexec/ld-elf.so.1

This issue is reproducible using FreeBSD 10.1 and the described steps.

Upvotes: 1

Views: 557

Answers (1)

AlexTheo
AlexTheo

Reputation: 4184

For those who are looking to solve this problem:

Had a conversation with a maintainer of gdb in FreeBSD. The result is that in FreeBSD there is no gdbserver which can be used alone. Instead there is a remote debug server called ds2 which can be used instead. Unfortunately ds2 is not available in FreeBSD 10.1 but it is working well in the newer versions of FreeBSD. Tested it with gdb and it is working!!!.

Upvotes: 2

Related Questions