GDB
This topic provides details on using the open-source GDB tool on a host PC to debug a sandboxed app on a target device. This type of remote debugging is useful where resources are limited like embedded apps. The sample code in this topic has an app named hw with one executable hw_exe and a few processes created in the same executable (hw_proc1, hw_proc2, etc.).
These are the high-level steps to use GDB with a sandboxed app.
On the target device:
- Run the sandboxed app without the process that's being debugged.
- Make
gdbserveravailable in the sanboxed app. - Run the sandboxed app with
gdbserverwith the process being debugged. - Remove
gdbfrom the sandboxed app after you're finished debugging.
On the host PC:
- Launch
gdbserveron the host PC. - Remote connect to the target and run regular
gdbcommands.
See Configure IP Address if you need to setup your host/target communications.
Sample Code
The following simple app sample code is used in this topic's examples.
hw.adef
start: manualexecutables:{hw_exe = ( hw )}processes:{run:{hw_proc1 = ( hw_exe )hw_proc2 = ( hw_exe )hw_proc3 = ( hw_exe )hw_proc4 = ( hw_exe )}}
See Create Apps for more info.
.cdef
hw/Component.cdef
sources:{hello.c}cflags:{-g}
See cflags for more info on cflags.
hello.c
hw/hello.c
#include "legato.h"{LE_INFO("HELLO WORLD.");}
See Create Apps for more info.
Run without Process
To use GDB, you start the sandboxed app excluding the process being debugged.
On the target, run the app excluding the process being debugged, hw_proc3:
app start hw --norun=hw_proc3
Make GDB Available
On the target, make gdbserver available in the sandboxed /bin directory:
gdbCfg hw
Run with Process
On the target, start gdbserver with arguments specified after -- (two dashes):
app runProc hw --exe=/bin/gdbserver -- localhost:2000 /bin/hw_exe
It will return this:
Process /bin/hw_exe created; pid = 9783
Listening on port 2000
Launch GDB on Host
You need to complete these steps on the host PC:
- Launch
gdbon the host PC. - Remote connect to the target and run regular
gdbcommands.
You need to run the commands from the directory where the hw app was made.
In this example, we're running the gdb tool (arm-poky-linux-gnueabi-gdb) located in our target's toolchain path (/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi for wp85). Use the findtoolchain command on the host PC to determine your toolchain path. The path _build_hw/wp85/app/hw/staging/read-only/bin/hw_exe is relative to the app directory; this build directory is generated when an app is made.
~/LegatoApps/hw$ /opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb _build_hw/wp85/app/hw/staging/read-only/bin/hw_exe
Remote Connect
After GDB is launched, use the target remote command to connect to the target:
(gdb) target remote 192.168.2.2:2000
Remote debugging from host 192.168.2.3 will display on the target.
- Note
- You can now run any of the standard
gdbdebugging commands onhw_exe.
Remove GDB from Sandbox
Once you've finished debugging, remove gdbserver from the sandbox /bin directory:
gdbCfg hw --reset
Refer to the many available open source resources if you need help using gdb.
Copyright (C) Sierra Wireless Inc. Use of this work is subject to license.
