We will be using gdbserver to remote debug our applications.
> sudo apt-get install gdbserver
Mount image
From build directory
> sudo ./mount-image run run/rpi-basic-image-raspberrypi.rpi-sdimg.20170719
> cp <path>/gdbserver run/partition_2/usr/bin
> chmod +x run/partition_2/usr/bin/gdbserver
Now sign and burn the image to an SD Card and start up your pi.
Assuming the binary is built using cMake withe debug enabled, it will contain symbol information.
To compile the code by hand you will need to specify the -ggdb flag to enable debugging.
> gcc rdTest.c -o rdTest -ggdb
On target machine
> sudo gdbserver localhost:2345 --attach pid
or
> sudo gdbserver localhost:2345 <executable>
For CLion, add a GDB Remote Debug Configuration:
Parameter | Description | Example |
---|---|---|
Name | A name | rdsTest |
GDB | Gnu Debugger | /opt/toolchain/gcc/gcc-4.8-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gdb |
Target | Specify the remote address | 10.10.10.5:2345 |
Symbol File | Specify the local compiled binary | /home/test/projects/yas/tools/remoteDebugTest/src/rdTest |
Hopefully by this point you can connect to the remote gdbserver.
If you get the following error "error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory"
> sudo apt-get install lib32ncurses5
Verify that the binary has symbol information by issuign the following command:
> nm <binary>
0000000000601058 B __bss_start
0000000000601068 b completed.6973
0000000000601048 D __data_start
0000000000601048 W data_start
0000000000400590 t deregister_tm_clones
...
0000000000601058 D __TMC_END__
U usleep@@GLIBC_2.2.5
Using the following source ( lbs5/working/John/remoteDebug/arm/remoteDebugTest/src/rdTest.c )
rdTest.c
1 |
|
To check if your gdb is working locally you can issue some commands on the target
> gdb rdTest
(gdb) break 24
(gdb) run
Starting program: /usr/bin/rdTest
.................................
Breakpoint 1, main (argc=1, argv=0xbefffdb4)
at /home/test/projects/yas/tools/remoteDebugTest/src/rdTest.c:24
24 /home/test/projects/yas/tools/remoteDebugTest/src/rdTest.c: No such file or directory.
(gdb) print i
$1 = 33