debugging with gdb - victronenergy/venus GitHub Wiki
Note: available since Venus OS v3.70
First make sure opkg is setup correctly. There after install the compiler, libc-dbg and gdb.
opkg install libc-dbg packagegroup-core-buildessential gdb
#include <stdio.h>
int main() {
int n;
for (n = 0; n < 10; n++)
printf("hello %d\n", n);
return 0;
}
and compile it with gcc -g hello.c -o hello
. Mind the -g for debugging.
Note that after start
the symbols for the shared libraries should also be loaded.
root@ekrano:~# gdb hello
GNU gdb (GDB) 14.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-ve-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hello...
(gdb) start
Temporary breakpoint 1 at 0x10434: file hello.c, line 5.
Starting program: /data/home/root/hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
Temporary breakpoint 1, main () at hello.c:5
5 for (n = 0; n < 10; n++)
(gdb) info sharedlibrary
From To Syms Read Shared Object Library
0xb6fd8a00 0xb6ff789c Yes /lib/ld-linux-armhf.so.3
0xb6e88ec0 0xb6fa30c0 Yes /lib/libc.so.6
Not going to repeat the gdb help here, just search the internet, but some useful commands are list
/ step
/ stepi
/ next
/ nexti
/ break
/ run
/ backtrace
and info registers
. e.g.:
(gdb) list
27 __printf (const char *format, ...)
28 {
29 va_list arg;
30 int done;
31
32 va_start (arg, format);
33 done = __vfprintf_internal (stdout, format, arg, 0);
34 va_end (arg);
35
36 return done;
Instead of using list
etc, tui mode can be entered with layout next
or start gdb with -tui. One Key binding is important ctrl
+ x
followed by o
to move focus back to the control window.
