gdb使用整理
coredump 配置使用
kernel
[Config Kernel settings] -> [General setup] -> [Configure standard kernel features(except users)] -> [Enable ELF core dumps],打开该选项编译后在image目录下多一个 vmlinuz.img.align文件
ulimit -c unlimited 设置coredump文件大小为unlimited
ulimit -s unlimited(option)设置线程栈大小
echo “/usr/conf/core_%e_%p_%t” > /proc/sys/kernel/core_pattern 设置core文件生成目录,一般可设置为SD卡目录
gdb 查看内存内容
参考: https://blog.csdn.net/chun_1959/article/details/45867167
gdb coredump 原理
参考: https://blog.csdn.net/u014403008/article/details/54666438
GDB: Listing all mapped memory regions for a crashed process
(gdb) help info proc
Show /proc process information about any running process.
Specify any process id, or use the program being debugged by default.
Specify any of the following keywords for detailed info:
mappings – list of mapped memory regions.
stat – list a bunch of random process info.
status – list a different bunch of random process info.
all – list all available /proc info.
gdb dump memory region
dump binary memory result.bin 0x200000000 0x20000c350
gdb share library command
Forces GDB to load symbols for the specified shared libraries or all loaded shared libraries.
sharedlibrary
sharedlibrary [Library Name]
sharedlibrary [Regular Expression]
share [...]
f GDB does not automatically load debugging symbols for your library when debugging with gdbserver, please check the search path using the set solib-search-path command.
(gdb) set auto-solib-add off
(gdb) break main
Breakpoint 1 at 0x80484ed: file main.cpp, line 7.
(gdb) run
Starting program: /home/testuser/libtest/testApp
Breakpoint 1, main () at main.cpp:7
7 printf("In main()\n");
(gdb) info sources
Source files for which symbols have been read in:
/home/testuser/libtest/main.cpp
Source files for which symbols will be read in on demand:
(gdb) info sharedlibrary
From To Syms Read Shared Object Library
0xb7fde820 0xb7ff6b9f No /lib/ld-linux.so.2
0xb7fd83a0 0xb7fd84c8 No /home/testuser/libtest/libTest.so
0xb7e30f10 0xb7f655cc No /lib/i386-linux-gnu/libc.so.6
(gdb) sharedlibrary libTest
Reading symbols from /home/testuser/libtest/libTest.so...done.
Loaded symbols for /home/testuser/libtest/libTest.so
(gdb) info sources
Source files for which symbols have been read in:
/home/testuser/libtest/main.cpp
Source files for which symbols will be read in on demand:
/home/testuser/libtest/lib.cpp
(gdb) break lib.cpp:5
Breakpoint 2 at 0xb7fd846e: file lib.cpp, line 5.
(gdb) continue
Continuing.
In main()
Breakpoint 2, func () at lib.cpp:5
5 printf("In func()\n");