在GDB中执行SegFault之后继续调试吗? [英] Continue debugging after SegFault in GDB?

查看:85
本文介绍了在GDB中执行SegFault之后继续调试吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GDB调试大型程序,并且程序中存在SegFault. 不必重新运行程序,是否可以切换到先前的堆栈框架并从那里继续执行?

I am debugging a huge program using GDB and there is a SegFault in my program. Instead of re-running the program, is it possible to switch to a previous stack frame and continue execution from there?

推荐答案

至少在Unix和Linux系统上,您可以使用gdb的 return 命令从中返回值当前帧,然后继续执行程序.

On Unix and Linux systems, at least, you can use gdb's handle command to tell gdb to stop the program when a signal is received (with the stop keyword) and not to pass the signal to the program (with the nopass keyword). When the program stops, you can use the return command to return a value from the current frame, then continue the program.

$ gdb -q segvtest
Reading symbols from segvtest...done.
(gdb) list 1,99999
1       #include <stdio.h>
2
3       int a()
4       {
5               int *p = 0;
6               return *p;
7       }
8
9       int main()
10      {
11              int i = a();
12              printf("a() returned %d\n", i);
13      }
(gdb) handle SIGSEGV stop nopass
Signal        Stop      Print   Pass to program Description
SIGSEGV       Yes       Yes     No              Segmentation fault
(gdb) run
Starting program: /home/mp/segvtest

Program received signal SIGSEGV, Segmentation fault.
0x00000000080006c0 in a () at segvtest.c:6
6               return *p;
(gdb) return 12345
Make a return now? (y or n) y
#0  0x00000000080006d6 in main () at segvtest.c:11
11              int i = a();
(gdb) c
Continuing.
a() returned 12345
[Inferior 1 (process 74) exited normally]
(gdb)

这篇关于在GDB中执行SegFault之后继续调试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆