主返回后的分段错误 [英] segmentation fault after main returns

查看:22
本文介绍了主返回后的分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 上的 c 语言中有一个很长的程序,在 main 返回后给我带来了分段错误.这是一个很长的程序,所以我不能发布它.那么你能帮我看看什么会导致这样的错误吗?

I have a long program in c over Linux, that gives me segmentation fault after main returns. Its a long program, so I cant post it. So can you help me what can make such error?

谢谢.

哇,这些答案来得真快.谢谢你们.我想我解决了,我忘了 malloc 一个字符串并将其用作缓冲区.现在我已经分配了它,它不会向我发出分段错误的信号.

Wow, Those answers came really fast. Thank you all. I think i worked it out, i forgot to malloc a string and used it as buffer. Now that I've malloced it, it does not signal me with a segmentation fault.

再次感谢大家.

推荐答案

猜想:你可能不小心损坏了 main 中的堆栈,所以它丢失了返回地址.你那里有一个字符串缓冲区可能会溢出吗?

Guess: you might be accidentally corrupting the stack in main so it's lost the return address. Do you have a string buffer there that you could be overrunning?

如果没有,你应该尝试:

If not, you should try:

  • 在 valgrind 下运行程序
  • 使用 gdb 调试程序以捕获崩溃并查看您当时所处的位置;您还可以调试转储的核心文件

如果您的发行版有 glibc-debug 软件包,安装它们可能会有所帮助,因为此时您将使用 glibc 代码.

It might help to install glibc-debug packages if your distro has them since you'll be in glibc code at that point.

这篇关于主返回后的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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