使用gdb检测sh中的分段错误? [英] Using gdb to detect segmentation fault in sh?

查看:182
本文介绍了使用gdb检测sh中的分段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用科学linux。在目录user / project / Build中,在我运行'make'编译和链接所有的cpp文件后,我没有问题。但是,当我去了目录user / run / run.sh,它运行用户/项目/ Build / bin / project中的项目二进制,我得到一个分割错误错误。在目录user / run中,我在命令提示符下输入'gdb',并获得消息***没有指定目标,没有找到makefile。停止。

I am using scientific linux. In the directory user/project/Build, after I ran 'make' to compile and link all the cpp files,I had no problems. But then, when I went to directory user/run/run.sh, which runs the project binary in user/project/Build/bin/project, I get a segmentation fault error. In the directory user/run, I enter 'gdb' in the command prompt and get the message "*** No targets specified and no makefile found. Stop."

我应该做什么来检测分段错误?

What am I supposed to do to detect the segmentation fault?

推荐答案

p>首先,您必须使用调试符号支持构建项目。对于 gcc ,这是使用 -g 选项完成的。然后你的程序的可执行文件运行 gdb 。例如:

First of all you have to build your project with debug symbols support. For gcc this is accomplished using the -g option. Then your run the gdb with the executable of your program. For example:

gdb ./a.out

将出现 gdb 命令提示符。为了启动你的程序,你应该执行命令 run 。如果你的程序需要一些命令行参数,你也可以指定它们。例如 run -d firstarg -l secondarg 等。

The gdb command promt appears. In order to start your program, you should execute the command run. If your program needs some command line arguments, you specify them too. E.g run -d firstarg -l secondarg etc.

当程序接收到分段错误时, gdb 提示命令
bt full

When your program receives a segmentation fault, just execute to the gdb prompt the command bt full

这将给你的程序的回溯,变量状态和segfault收到的源代码行。

This will give you the backtrace of your program, the variable states and the source code line where the segfault received.

这篇关于使用gdb检测sh中的分段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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