-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging
Some boards provide a JTAG interface, which makes it feasible to perform live debugging via gdb. These platforms usually provide an additional target in the Makefile system called debug
, so that simply calling make debug
should start a debugging session. Sometime this starts only a remote target to be used with gdb as explained, for example, here for the IoT-LAB_M3.
If you have a RIOT application which uses the shell for interactive input, and still want to use the gdb debugger to step through something caused by that interaction, you can do so using the program
parameter. Let's go through this step by step, using the default
app that can be found in RIOT/examples/default
:
In terminal window #1, compile and start your RIOT application.
make
sudo ./bin/native/default.elf tap0
In terminal window #2,
use pgrep
to find out the PID of your RIOT app.
pgrep default
> 2987
Then, instruct gdb to attach to that program
gdb program 2987
(If you are positive that there is only one instance of your app running, you can also run gdb program $(pgrep default)
instead.)
Now, you can set your breakpoints in gdb as usual. If you're done with your preparation, type
continue
into your gdb window.
Switching back to terminal window #1, you can now use you RIOT app as usual. (Until a breakpoint is hit, then you'll have to type continue into gdb again to “un-freeze” the app)
On other platforms, such as the MSB-A2, or when you don't have physical access to the JTAG interface, there's no other possibility to debug your code than using printf-debugging. In order to help you with that RIOT provides the macros DEBUG
and DEBUGF
that can be enabled on a per file basis, by adding something like this at the beginning of the file:
#define ENABLE_DEBUG (1)
#include "debug.h"
You will find this pattern already in several RIOT files. When ENABLE_DEBUG
is set to a positive value, DEBUG
is a simple replacement for printf()
, while DEBUGF
adds the information about the file and line number to the beginning of the output. When building with DEVELHELP
the macros additionally check if the stack size of the currently running thread is big enough to call printf
.
If ENABLE_DEBUG
is set to zero, the macros are ignored.
Please note: As written, this kind of debugging works intentionally only per file. You have to define ENABLE_DEBUG
in every file you want to debug.
RIOT - The friendly Operating System for the Internet of Things
Homepage | [GitHub] (https://github.com/RIOT-OS/) | Developers Mailing List | Users Mailing List | Twitter @RIOT_OS
- Family: ARM
- Board: Airfy Beacon
- Board: Arduino Due
- Board: CC2538DK
- Board: HikoB Fox
- Board: IoT LAB M3
- Board: LimiFrog-v1
- Board: mbed_lpc1768
- Board: MSB-IoT
- Board: MSBA2
- Board: Nucleo-L1
- Board: Nucleo-F334
- Board: Nucleo-F303
- Board: Nucleo-F091
- Board: Mulle
- Board: OpenMote
- Board: PCA1000x (nRF51822 Development Kit)
- Board: Phytec phyWAVE-KW22
- Board: RFduino
- Board: Samr21 xpro
- Board: Spark Core
- Board: STM32F0discovery
- Board: STM32F3discovery
- Board: STM32F4discovery
- Board: UDOO
- Board: yunjia-nrf51822
- Family: ATmega
- Board: Arduino Mega2560
- Family: MSP430
- Board: MSB-430H
- Board: TelosB
- Board: WSN430
- Board: Zolertia Z1
- Board: eZ430-Chronos
- Family: native
- Board: native
- Family: x86
- Board: Intel Galileo