在命令行下,我知道使用echo $?给我退出代码。在gdb中,我使用“r”来运行程序并且程序终止,那么gdb如何获得此退出代码? gdb里面的所有命令?
谢谢!
答案 0 :(得分:4)
当程序退出时,gdb将便捷变量int main() {
return 23;
}
设置为退出代码。
所以给出:
(gdb) run
Starting program: /tmp/q
[Inferior 1 (process 3677) exited with code 027]
(gdb) print $_exitcode
$1 = 23
在gdb中运行它,我得到:
{{1}}
答案 1 :(得分:1)
它只是在程序终止时在调试会话结束时打印退出代码。或者为exited normally
退出代码打印0
。请参阅此测试程序的测试调试会话:
#include <stdlib.h>
int main(int argc, char *argv[]) {
return atoi(argv[1]);
}
调试会话:
[ksemenov@NB824RIH ~]$ gdb -q ./a.out
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) r 0
Starting program: /home/ksemenov/a.out 0
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.23.1-10.fc24.x86_64
[Inferior 1 (process 19162) exited normally]
(gdb) r 1
Starting program: /home/ksemenov/a.out 1
[Inferior 1 (process 19166) exited with code 01]
(gdb) r 6
Starting program: /home/ksemenov/a.out 6
[Inferior 1 (process 19167) exited with code 06]
(gdb)