用于核心转储分析的 Gdb 脚本

问题描述 投票:0回答:2

我有一个用于 c/c++ 应用程序的核心转储。我是编程新手,所以这个问题可能听起来很愚蠢。有什么方法可以编写脚本来使用 gdb 来分析核心转储吗?

c++ gdb coredump
2个回答
3
投票

是的,只需编写您想要的脚本即可。例如:

gdb \
   -ex "set pagination 0" \
   -ex "thread apply all bt" \
   -batch ${EXECUTABLE_FILE} ${CORE_FILE}

0
投票

使用 -x 选项如下

$ cat gdb.cmds
set confirm off
set height 0
cd /homes/syrajendra
file dump
core dump.core
set solib-search-path "/lib"
bt
printf "\n"
quit

$ gdb -x gdb.cmds
. . .
[Thread debugging using libthread_db enabled]
Core was generated by `dump'.
Program terminated with signal SIGABRT, Aborted.
#0  0x000000080149f6ca in thr_kill () from /lib/libc.so.7
#0  0x000000080149f6ca in thr_kill () from /lib/libc.so.7
#1  0x0000000801574149 in abort () from /lib/libc.so.7
#2  0x0000000801556011 in __assert () from /lib/libc.so.7
#3  0x000000000040130a in fun2 (num=100) at ./dump.cpp:10
#4  0x0000000000401343 in fun1 (num=100) at ./dump.cpp:20
#5  0x000000000040137e in main () at ./dump.cpp:27

© www.soinside.com 2019 - 2024. All rights reserved.