一、文件系统添加GDB支持 Link to heading
1、主要添加gdb、python、glib-2.0、thread_db等支持。
/lib目录 Link to heading
1root@ubuntu:~/SourceCode/imx8/0-yocto/DownloadToolUUU_V2.0/file/rootfs_gdb/lib# ls -la
2total 48
3drwxr-xr-x 3 root root 4096 4月 20 16:14 .
4drwxr-xr-x 4 root root 4096 4月 20 16:13 ..
5drwxr-xr-x 2 root root 4096 8月 9 2021 .debug
6-rwxr-xr-x 1 root root 35336 8月 9 2021 libthread_db-1.0.so
7lrwxrwxrwx 1 root root 19 8月 9 2021 libthread_db.so.1 -> libthread_db-1.0.so
/usr/lib目录 Link to heading
1root@ubuntu:~/SourceCode/imx8/0-yocto/DownloadToolUUU_V2.0/file/rootfs_gdb/usr/lib# ls -la
2total 3020
3drwxr-xr-x 3 root root 4096 4月 20 16:16 .
4drwxr-xr-x 5 root root 4096 4月 20 15:02 ..
5lrwxrwxrwx 1 root root 20 8月 9 2021 libpython3.7m.so -> libpython3.7m.so.1.0
6-rwxr-xr-x 1 root root 3063528 8月 9 2021 libpython3.7m.so.1.0
7-rwxr-xr-x 1 root root 5808 8月 9 2021 libpython3.so
8lrwxrwxrwx 1 root root 27 8月 9 2021 libthread_db.so -> ../../lib/libthread_db.so.1
9drwxr-xr-x 34 root root 12288 8月 9 2021 python3.7
/usr/bin目录 Link to heading
1root@ubuntu:~/SourceCode/imx8/0-yocto/DownloadToolUUU_V2.0/file/rootfs_gdb/usr/bin# ls -la
2total 7900
3drwxr-xr-x 2 root root 4096 4月 15 13:51 .
4drwxr-xr-x 5 root root 4096 4月 20 15:02 ..
5-rwxr-xr-x 1 root root 8057536 4月 15 12:00 gdb
6lrwxrwxrwx 1 root root 9 8月 9 2021 python3 -> python3.7
7-rwxr-xr-x 1 root root 6032 8月 9 2021 python3.7
8lrwxrwxrwx 1 root root 17 8月 9 2021 python3.7-config -> python3.7m-config
9-rwxr-xr-x 1 root root 6032 8月 9 2021 python3.7m
10-rwxr-xr-x 1 root root 1916 8月 9 2021 python3.7m-config-lib
11lrwxrwxrwx 1 root root 16 8月 9 2021 python3-config -> python3.7-config
/usr/share目录 Link to heading
1root@ubuntu:~/SourceCode/imx8/0-yocto/DownloadToolUUU_V2.0/file/rootfs_gdb/usr/share# ls -la
2total 16
3drwxr-xr-x 4 root root 4096 4月 20 16:56 .
4drwxr-xr-x 5 root root 4096 4月 20 15:02 ..
5drwxr-xr-x 6 root root 4096 8月 9 2021 gdb
6drwxr-xr-x 6 root root 4096 8月 9 2021 glib-2.0
2、coredump文件配置相关
/etc目录 Link to heading
1-rw-r--r-- 1 roo root 2398 4月 26 14:54 etc/sysctl.conf // 文件格式配置
2-rw-r--r-- 1 root root 1925 4月 25 12:11 etc/security/limits.conf // 文件大小配置
/lib/systemd/system目录 Link to heading
1-rw-r--r-- 1 root root 693 8月 9 2021 lib/systemd/system/systemd-sysctl.service
其中**
systemd-sysctl.service
**服务主要执行以下配置文件:**
etc/sysctl.conf
**文件**
/usr/lib/sysctl.d
**目录下conf文件
二、GDB运行过程中遇到的错误 Link to heading
1、关于optimized out问题 Link to heading
根据网络上的说法,调试期间如果一个变量的值显示<optimized out>,那么就表明编译器将该变量进行了优化,导致其值不可见。
解决方法: 设置编译优化选项,禁止相关的优化。可以尝试的方式为:
-g -O0
2、关于python 错误 Link to heading
1Python Exception <class 'NameError'> Installation error: gdb.execute_unwinders function is missing:
不影响调试功能,但是总是有这种错误打印信息,影响调试感受;
解决办法: 文件系统中缺少文件导致,将“/usr/share/gdb”文件夹添加到文件系统中;
3、关于gdb thread错误 Link to heading
(1)libthread_db错误 Link to heading
1warning: File "/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
2To enable execution of this file add
3 add-auto-load-safe-path /lib/libthread_db-1.0.so
4line to your configuration file "/home/root/.gdbinit".
5To completely disable this security protection add
6 set auto-load safe-path /
7line to your configuration file "/home/root/.gdbinit".
8For more information about this security protection see the
9"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
10 info "(gdb)Auto-loading safe path"
11
12warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
13
14warning: File "/lib/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
15
16warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
170x0000ffffb908c084 in poll () from /lib/libc.so.6
解决方法:
文件系统中缺少文件导致,将“/lib/.debug”文件夹添加到文件系统中;
(2)glib_gdb错误 Link to heading
1Traceback (most recent call last):
2 File "/usr/share/gdb/auto-load/usr/lib/libglib-2.0.so.0.6000.7-gdb.py", line 9, in <module>
3 from glib_gdb import register
4ModuleNotFoundError: No module named 'glib_gdb'
解决方法:
文件系统中缺少文件导致,将“/usr/share/glib-2.0”文件夹添加到文件系统中;
正常运行gdb thread的调试信息:
1root@baolong:~/gdb_test# ps
2 PID TTY TIME CMD
3 231 ttyLP0 00:00:00 autologin
4 241 ttyLP0 00:00:00 login
5 243 ttyLP0 00:00:00 sh
6 265 ttyLP0 00:00:02 calwin.out
7 272 ttyLP0 00:00:00 ps
8root@baolong:~/gdb_test# gdb -q -p 265
9Attaching to process 265[ 222.563353]
10[ 222.563353] /******************* max9286_dev_read return 0x00 *********************/
11[ 222.563353]
12
13[New LWP 266]
14[New LWP 267]
15[New LWP 268]
16[New LWP 269]
17[New LWP 270]
18[Thread debugging using libthread_db enabled]
19Using host libthread_db library "/lib/libthread_db.so.1".
20ioctl () at ../sysdeps/unix/sysv/linux/aarch64/ioctl.S:26
2126 ../sysdeps/unix/sysv/linux/aarch64/ioctl.S: No such file or directory.
22(gdb) list
2321 in ../sysdeps/unix/sysv/linux/aarch64/ioctl.S
24(gdb)
“No such file or directory”的错误可以不用处理;
一般第一次调用该文件时都会报此错误,第二次执行就正常了。