Once the SDK is installed, you can run the application to be debugged on the target, in this case wvdial, using gdbserver.
- Launch gdbserver with the application to run as argument:
# gdbserver localhost:1234 /usr/bin/wvdial -c Process /usr/bin/wvdial created; pid = 549 Listening on port 1234
The gdbserver is launched listening on localhost on a random 1234 port and is waiting for a connection from the remote GDB.
- In the host, you can now set up the environment using the recently installed SDK:
$ cd /opt/poky/2.4/
$ source environment-setup-cortexa9hf-neon-poky-linux-gnueabi
- You can then launch the cross GDB, passing to it the absolute path to the debug version of the application to debug, which is located in a .debug directory on the sysroot:
$ ${GDB} /opt/poky/2.4/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/bin/.debug/wvdial Reading symbols from /opt/poky/2.4/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/bin/.debug/wvdial...done.
- Next, configure GDB to consider all files as trusted so that it auto loads whatever it needs:
(gdb) set auto-load safe-path /
- Also, as you know, wvdial will generate a SIGILL signal that will interrupt our debugging session, so let's instruct GDB not to stop when that signal is seen:
(gdb) handle SIGILL nostop
- You can then connect to the remote target on the 1234 port with the following:
(gdb) target remote <target_ip>:1234 Remote debugging using 192.168.1.105:1234 warning: Unable to find dynamic linker breakpoint function. GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code. 0x76fcea80 in ?? ()
- The first thing to do is to set the sysroot so that GDB is able to find dynamically loaded libraries:
(gdb) set sysroot /opt/poky/2.4/sysroots/cortexa9hf-neon-poky-linux-gnueabi/
- Type c to continue with the program's execution. You will see wvdial continuing on the target:
--> WvDial: Internet dialer version 1.61 --> Warning: section [Dialer Defaults] does not exist in wvdial.conf. --> Initializing modem. --> Sending: ATZ
- You will then see GDB intercepting a SIGILL signal on the host:
Program received signal SIGILL, Illegal instruction.
- We will now send the SIGSEGV signal to the application from a different shell with the following:
$ kill -SEGV <wvdial-pid> Program received signal SIGSEGV, Segmentation fault. 0x76b45c7c in __GI___select (nfds=1, readfds=0x7effe008, writefds=0x7effe088, exceptfds=0x7effe108, timeout=0x7effdfd8) at /usr/src/debug/glibc/2.26- r0/git/sysdeps/unix/sysv/linux/select.c:41 41 /usr/src/debug/glibc/2.26-r0/git/sysdeps/unix/sysv/linux/select.c: No such file or directory.
- You can now ask to see a backtrace:
(gdb) bt #0 0x76b45c7c in __GI___select (nfds=1, readfds=0x7effe008, writefds=0x7effe088, exceptfds=0x7effe108, timeout=0x7effdfd8) at /usr/src/debug/glibc/2.26- r0/git/sysdeps/unix/sysv/linux/select.c:41 #1 0x76db5cd8 in WvStream::_do_select(IWvStream::SelectInfo&) () from /opt/poky/2.4/sysroots/cortexa9hf-neon-poky-linux- gnueabi/usr/lib/libwvbase.so.4.6 #2 0x76db5ea4 in WvStream::_select(long, bool, bool, bool, bool) () from /opt/poky/2.4/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/lib/libwvbase.so.4.6 #3 0x000191bc in WvStream::select (isex=false, writable=false, readable=true, msec_timeout=1, this=<optimized out>) at /usr/include/wvstreams/wvstream.h:417 #4 WvDialer::wait_for_modem (this=this@entry=0x7effeca0, strs=0x0, strs@entry=0x76df6c00 <WvFastString::nullbuf>, timeout=1, timeout@entry=5000, neednewline=neednewline@entry=true, verbose=verbose@entry=true) at /usr/src/debug/wvdial/1.61-r0/wvdial-1.61/wvdialer.cc:1357 #5 0x00019b60 in WvDialer::init_modem (this=this@entry=0x7effeca0) at /usr/src/debug/wvdial/1.61-r0/wvdial-1.61/wvdialer.cc:768 #6 0x0001c9c0 in WvDialer::WvDialer (this=0x7effeca0, _cfg=..., _sect_list=<optimized out>, _chat_mode=<optimized out>) at /usr/src/debug/wvdial/1.61-r0/wvdial-1.61/wvdialer.cc:119 #7 0x00014d74 in main (argc=<optimized out>, argv=<optimized out>) ---Type <return> to continue, or q <return> to quit---