如何在Mac OS X上获取行号堆栈跟踪以解决内存泄漏? [英] How to get a line-numbered stack trace for a memory leak on Mac OS X?

查看:247
本文介绍了如何在Mac OS X上获取行号堆栈跟踪以解决内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法获得Xcode leaks工具来报告我的命令行GCC Ada程序中的泄漏(通过在末尾添加delay 11.0;以便让leaks进行检查),然后

I've managed to get the Xcode leaks tool to report leaks in my command-line GCC Ada program (by adding delay 11.0; at the end to let leaks make its checks) and then

$ export MallocStackLogging=1
$ (./foobar &)  && leaks foobar

导致(摘录)

Process 52027: 18 nodes malloced for 2053 KB
Process 52027: 2 leaks for 32 total leaked bytes.
Leak: 0x1002000c0  size=16  zone: DefaultMallocZone_0x100175000 string '*'
        Call stack: [thread 0x7fff70bbcca0]: | start | main | _ada_foobar | __gnat_malloc | malloc | malloc_zone_malloc 
Leak: 0x1002000d0  size=16  zone: DefaultMallocZone_0x100175000 string 'T'
        Call stack: [thread 0x7fff70bbcca0]: | start | main | _ada_foobar | __gnat_malloc | malloc | malloc_zone_malloc 

这总比没有好很多,但是行号会大大改善.

which is a great deal better than nothing, but would be considerably improved with line numbers.

我应该使用任何构建选项吗?如果将Ada编译器(FSF GCC 4.6.0,不是来自Apple)与Xcode集成,是否会更好?

Are there any build options I should have used? Would it work better if the Ada compiler (FSF GCC 4.6.0, not from Apple) was integrated with Xcode?

这是在10.6.7,Xcode 3.2.6上构建的x86_64.使用-g没有区别.

This is an x86_64 build on 10.6.7, Xcode 3.2.6. Using -g makes no difference.

在调用堆栈中,maingnatmake生成的main()_ada_foobar是实际发生泄漏的Ada程序.其他框架来自运行时系统.

In the call stack, main is the main() generated by gnatmake, _ada_foobar is the Ada program in which the leak actually occurs. The other frames are from the run time system.

推荐答案

Valgrind 3.7.0适用于Mac OS X;我的代码测试是

Valgrind 3.7.0 is available for Mac OS X; my code test was

with Ada.Text_IO; use Ada.Text_IO;
procedure Leaker is
   type P is access Integer;
   procedure Inner is
      V : P;
   begin
      Put_Line ("allocating for 42");
      V := new Integer'(42);
      Put_Line ("allocating for 0");
      V := new Integer'(0);
      Put_Line ("done.");
   end Inner;
begin
   Inner;
end Leaker;

我和

valgrind --leak-check=full --dsymutil=yes ./leaker

获取包含以下内容的报告

to get a report including

8 bytes in 2 blocks are definitely lost in loss record 2 of 9
   at 0xB823: malloc (vg_replace_malloc.c:266)
   by 0x100010CC7: __gnat_malloc (s-memory.adb:92)
   by 0x100001C7D: _ada_leaker (leaker.adb:14)
   by 0x100001BAA: main (b~leaker.adb:191)

leaker.adb:14是对Inner的调用.

这篇关于如何在Mac OS X上获取行号堆栈跟踪以解决内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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