识别导致内存错误的变量 [英] Identify variable causing memory error

查看:224
本文介绍了识别导致内存错误的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我现在遇到了一个奇怪的错误,并找到一些很好的方向,以确定问题。



基本上我看到的是一个段故障。症状如下:


  1. 只有在程序处于释放模式而不是调试模式时才会发生。

  2. 它显示为一个segfault,GDB告诉我它在 _list_release / _free()

    程序接收信号SIGSEGV ,分段错误。



    0xb0328af8在/ usr / qnx650 / target / qnx6 / x86 / lib的_list_release /libc.so.3



    (gdb)bt



    0 0xb0328af8在_list_release()从/usr/qnx650/target/qnx6/x86/lib/libc.so.3



    1 0xb032a464在__free()从/usr/qnx650/target/qnx6/x86/lib/libc.so.3,/code >



    2 0xb0329f7d in free()from /usr/qnx650/target/qnx6/x86/lib/libc.so.3


  3. 我可以在函数结束之前打印所有局部变量,因此它不是双重自由。

上次发生这种情况是一个内存错误,适合所有这些问题。恼火这个时候我找不到问题。



我想要做的是:


  1. 额外有用:如何在调试模式下强制此错误,那么GDB将更有帮助。

  2. 什么是跟踪什么小bug是导致问题的最好方法。 注意:我无法使用valgrind,它不能在我正在使用的操作系统(QNX)上工作

任何帮助将是伟大的。

解决方案


它显示为一个segfault,GDB告诉我它在_list_release / _free / free()


一般来说, code>是堆损坏的迹象(双重释放,写空闲内存,释放未分配(例如堆栈或全局)内存或堆缓冲区溢出)。


我没有使用任何动态记忆


>是。事实上,你通过其他库间接地这样做是无关紧要的。


我可以在函数结束之前打印所有局部变量,


很多评论者已经说过,你的结论并不是这样:你可以访问免费的内存


如何在Debug模式下强制这个错误,那么GDB会更有帮助





  • 您可以使用'-O2 -g'信息已启用)。

  • GDB可能不会更有帮助--GDB在调试堆损坏方面没有用。




    • 什么是跟踪什么小bug的最好方法


      您有以下选择:




      • 将您的代码移植到一个平台,您可以使用 Valgrind AddressSanitizer

      • 使用许多调试malloc实现(dmalloc,mpatrol等)之一。 QNX有一个

      • 仔细阅读代码,确保不要向可能的malloc缓冲区写入更多的数据。


      So I have run into a weird error a few times now and im looking for some good directions as to identify the problem.

      Basically what I am seeing is a seg-fault. The symptoms are as follows:

      1. It occurs only when the program is in release mode, not in debug.
      2. It appears as a segfault and GDB tells me that it is in _list_release/_free()/free() at the end of a function.

        Program received signal SIGSEGV, Segmentation fault.

        0xb0328af8 in _list_release () from /usr/qnx650/target/qnx6/x86/lib/libc.so.3

        (gdb) bt

        0 0xb0328af8 in _list_release () from /usr/qnx650/target/qnx6/x86/lib/libc.so.3

        1 0xb032a464 in __free () from /usr/qnx650/target/qnx6/x86/lib/libc.so.3

        2 0xb0329f7d in free () from /usr/qnx650/target/qnx6/x86/lib/libc.so.3

      3. I am not using any dynamic memory (except for what might appear in Eigen (or other libraries)

      4. I can print all local variables just before the end of the function, so its not a double free.

      Last time this happened it was a memory fault which fits all of these problems. Annoyingly this time i cannot find the problem.

      What i would like to do is the following:

      1. This would be extra useful: How can I force this error in Debug mode, then GDB would be way more helpful.
      2. What is the best way to track down what little bugger is causing the problem. NOTE: I cannot use valgrind, it does not work on the operating system i am using (QNX)

      Any help would be great.

      解决方案

      It appears as a segfault and GDB tells me that it is in _list_release/_free()/free()

      Generally, any crash in free() is a sign of heap corruption (a double free, a write to free'd memory, freeing unallocated (e.g. stack or global) memory, or an overflow of a heap buffer).

      I am not using any dynamic memory

      Yes, you are. The fact that you do so indirectly via other libraries is irrelevant.

      I can print all local variables just before the end of the function, so its not a double free.

      As many commenters already said, your conclusion doesn't follow: you can access free'd memory just fine, and it may even still contain sensible values.

      How can I force this error in Debug mode, then GDB would be way more helpful.

      • You can build with '-O2 -g' (a "release" mode but with debug info enabled).
      • GDB will likely not be more helpful -- GDB is somewhat useless in debugging heap corruption.

      What is the best way to track down what little bugger

      You have a few choices:

      • Port your code to a platform where you can use Valgrind or AddressSanitizer
      • Use one of many debugging malloc implementations (dmalloc, mpatrol, etc.). QNX has one.
      • Read the code very carefully, making sure that you don't write more data to possibly-malloc'd buffers than you are supposed to.

      这篇关于识别导致内存错误的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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