Skip to content
Philipp M. Scholl edited this page Jan 17, 2014 · 2 revisions

Jennic provides a gdbstubs based serial-line debugger for its modules. While its functionality is quite limited it's still useful when wondering what went wrong in your program. It does support compiled-in breakpoints, catching processor exceptions, analyzing memory and the call-tree. However setting new breakpoints during execution and analyzing stack variables is buggy.

Printf logging is also supported through gdb, and we will show what can be done with the debugger on this example:

void printi(int i) {
  if (i=42) {
    printf("number is 42\n");
  }
}

So this code should print the number if it equals 42. You might have spotted the problem already, but let's use gdb to see why printi() prints "number is 42" regardless of its arguments value. To do so we'll insert a breakpoint inside the if statements body:

#include 

void printi(int i) {
  if (i=42) {
    HAL_BREAKPOINT();
    printf("number is 2\n");
  }
}

After that we need to compile the program with debugging support enabled, i.e. clean the project and call make with a DEBUG parameter:

 $ make DEBUG=true my-program.jndevkit.hex

After uploading the hex file to the jennic module, it will startup the gdbstubs support and the module will wait until a debugger connects through Uart0. There is a gdb scripts that connects your host gdb to the jennic board. So in order to start your debugging session call:

 $ ba-elf-gdb -x cpu/jennic/gdbUSB0.gdb my-program

Connecting to the board will take some time, so be patient and do not forget to reset the board after programming.

Below you can see an example debugging session of our program:


GNU gdb 6.6
Copyright (C) 2006 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 "--host=i686-pc-linux-gnu --target=ba-elf".
(gdb) p i
$1 = 42
(gdb) c
number is 42

As you can see our compiled-in breakpoint has been hit and gdb has been instructed to print the value of i. And that's where you should spot the problem, the if expression is using the assignment operator instead of checking for equality with ==.

After printing the value of i we instructs gdb to continue running the program. This will print the message "number is 42". This message will only be printed on the gdb channel, so keep in mind that if your program is not compiled with debugging support all printf output will end up in nirvana.

Happy Coding!

Clone this wiki locally