如何使用GDB在MPSoC单板上调试应用层软件

编译PetaLinux时,使能GDB。单板上就会有GDB。zcu106的VCU TRD 2018.2 已经包含GDB.

带调试信息编译软件,比如添加-g, 或者-g3开关。对于zcu106的ctrl-sw,在encoder_defs.mk里修改CFLAGS, 添加-g3,得到
CFLAGS+=-Wall -Wextra -g3

编译PetaLinux时,上板运行。

执行GDB后,使用file命令设置应用程序,使用set args命令设置应用程序的参数。

使用step命令单步运行应用程序,使用run命令运行应用程序。

使用info stack可以查看调用关系。

其它命令可以查看gdb帮助。

有时应用层软件已经崩溃。可以使用core文件来启动调试。缺省情况下,即使软件已经崩溃,也不会产生core文件,这时需要使用ulimit -c unlimited使系统产生core文件。

下面是调试记录。

root@zcu106_vcu_trd:/run# gdb
GNU gdb (GDB) 8.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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 "aarch64-xilinx-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word".

(gdb) file ctrlsw_encoder
Reading symbols from ctrlsw_encoder...done.

(gdb) set args -cfg hevc_1080p_cpb100_br1m_nofill_autoqp.cfg

(gdb) pwd
Working directory /run.

(gdb) run
Starting program: /usr/bin/ctrlsw_encoder -cfg hevc_1080p_cpb100_br1m_nofill_autoqp.cfg
warning: File "/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
add-auto-load-safe-path /lib/libthread_db-1.0.so
line to your configuration file "/home/root/.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "/home/root/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
ctrl-sw-v183-2019-0130
Function: exe_encoder/main.cpp-main() Compilation time: Mar 12 2019-21:33:54
My own configuration items is invalid.

Program received signal SIGSEGV, Segmentation fault.
0x0000007fbf367550 in strlen () from /lib/libc.so.6
(gdb) info stack
#0 0x0000007fbf367550 in strlen () from /lib/libc.so.6
#1 0x0000007fbf333b58 in vfprintf () from /lib/libc.so.6
#2 0x0000007fbf339728 in printf () from /lib/libc.so.6
#3 0x000000000040f958 in ParseCommandLine (argc=0, argc@entry=3, argv=0x6c69666f72702d2d, argv@entry=0x7ffffffb88, cfg=...) at exe_encoder/main.cpp:521
#4 0x0000000000410938 in SafeMain (argc=argc@entry=3, argv=argv@entry=0x7ffffffb88) at exe_encoder/main.cpp:923
#5 0x0000000000407540 in main (argc=3, argv=0x7ffffffb88) at exe_encoder/main.cpp:1123
(gdb) quit
A debugging session is active.

Inferior 1 [process 2496] will be killed.

Quit anyway? (y or n) y

root@zcu106_vcu_trd:/run# ctrlsw_encoder -cfg hevc_1080p_cpb100_br1m_nofill_autoqp.cfg
ctrl-sw-v183-2019-0130
Function: exe_encoder/main.cpp-main() Compilation time: Mar 12 2019-21:33:54
My own configuration items is invalid.
Segmentation fault

root@zcu106_vcu_trd:/run# ll
total 180
drwxr-xr-x 2 messagebus messagebus 60 Mar 13 01:20 dbus
-rw-r--r-- 1 root root 5 Mar 13 01:20 dropbear.pid
-rw-r--r-- 1 root root 16 Mar 13 01:20 ifstate
-rw-r--r-- 1 root root 5 Mar 13 01:20 inetd.pid
-rw-r--r-- 1 root root 5 Mar 13 01:20 klogd.pid
lrwxrwxrwx 1 root root 16 Mar 13 01:20 ld.so.cache -> /etc/ld.so.cache
drwxrwxrwt 3 root root 60 Mar 13 01:20 lock
-rw-r--r-- 1 root root 5 Mar 13 01:20 messagebus.pid
drwxr-xr-x 2 root root 60 Mar 13 01:20 mount
-rw-r--r-- 1 root root 88 Mar 13 01:20 resolv.conf
drwxr-xr-x 2 root root 40 Mar 13 01:20 sepermit
-rw-r--r-- 1 root root 5 Mar 13 01:20 syslogd.pid
drwxr-xr-x 6 root root 140 Mar 13 01:21 udev
-rw-r--r-- 1 root root 5 Mar 13 01:20 udhcpc.eth0.pid
-rw-rw-r-- 1 root root 2800 Mar 13 01:21 utmp
-rwxr-xr-x 1 root root 7387 Mar 13 01:22 hevc_1080p_cpb100_br1m_nofill_autoqp.cfg

root@zcu106_vcu_trd:/run# ulimit -c
0
root@zcu106_vcu_trd:/run# ulimit -c 16384

root@zcu106_vcu_trd:/run# ulimit -c unlimited
root@zcu106_vcu_trd:/run# ulimit -c
unlimited

root@zcu106_vcu_trd:/run# ctrlsw_encoder -cfg hevc_1080p_cpb100_br1m_nofill_autoqp.cfg
ctrl-sw-v183-2019-0130
Function: exe_encoder/main.cpp-main() Compilation time: Mar 12 2019-21:33:54
My own configuration items is invalid.
Segmentation fault (core dumped)

root@zcu106_vcu_trd:/run# ll
total 524
-rw------- 1 root root 643072 Mar 13 01:35 core
drwxr-xr-x 2 messagebus messagebus 60 Mar 13 01:20 dbus
-rw-r--r-- 1 root root 5 Mar 13 01:20 dropbear.pid
-rw-r--r-- 1 root root 16 Mar 13 01:20 ifstate
-rw-r--r-- 1 root root 5 Mar 13 01:20 inetd.pid
-rw-r--r-- 1 root root 5 Mar 13 01:20 klogd.pid
lrwxrwxrwx 1 root root 16 Mar 13 01:20 ld.so.cache -> /etc/ld.so.cache
drwxrwxrwt 3 root root 60 Mar 13 01:20 lock
-rw-r--r-- 1 root root 5 Mar 13 01:20 messagebus.pid
drwxr-xr-x 2 root root 60 Mar 13 01:20 mount
-rw-r--r-- 1 root root 88 Mar 13 01:20 resolv.conf
drwxr-xr-x 2 root root 40 Mar 13 01:20 sepermit
-rw-r--r-- 1 root root 5 Mar 13 01:20 syslogd.pid
drwxr-xr-x 6 root root 140 Mar 13 01:21 udev
-rw-r--r-- 1 root root 5 Mar 13 01:20 udhcpc.eth0.pid
-rw-rw-r-- 1 root root 2800 Mar 13 01:21 utmp
-rwxr-xr-x 1 root root 7387 Mar 13 01:22 hevc_1080p_cpb100_br1m_nofill_autoqp.cfg

root@zcu106_vcu_trd:/run# gdb
GNU gdb (GDB) 8.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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 "aarch64-xilinx-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word".

(gdb) file ctrlsw_encoder
Reading symbols from ctrlsw_encoder...done.

(gdb) set args -cfg hevc_1080p_cpb100_br1m_nofill_autoqp.cfg

(gdb) core core

[New LWP 2501]
warning: File "/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
add-auto-load-safe-path /lib/libthread_db-1.0.so
line to your configuration file "/home/root/.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "/home/root/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: File "/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
Core was generated by `ctrlsw_encoder -cfg xt802_hevc_1080p_cpb100_br1m_nofill_autoqp_yuv0129_f8000_ne'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000007fb686f550 in strlen () from /lib/libc.so.6

(gdb) info stack
#0 0x0000007fb686f550 in strlen () from /lib/libc.so.6
#1 0x0000007fb683bb58 in vfprintf () from /lib/libc.so.6
#2 0x0000007fb6841728 in printf () from /lib/libc.so.6
#3 0x000000000040f958 in ParseCommandLine (argc=0, argc@entry=3, argv=0x6c69666f72702d2d, argv@entry=0x7fce79e0f8, cfg=...) at exe_encoder/main.cpp:521
#4 0x0000000000410938 in SafeMain (argc=argc@entry=3, argv=argv@entry=0x7fce79e0f8) at exe_encoder/main.cpp:923
#5 0x0000000000407540 in main (argc=3, argv=0x7fce79e0f8) at exe_encoder/main.cpp:1123

(gdb) info local
No symbol table info available.

(gdb) info line
No line number information available.

(gdb) info watchpoints
No watchpoints.

(gdb) info source
No current source file.
(gdb)

文章来源: 赛灵思中文社区论坛

最新文章

最新文章