How to get a stack trace of lines for memory leak in Mac OS X?

I managed to get the Xcode tool leaksto report leaks in my GCC Ada program from the command line (adding delay 11.0;to the end to leakscomplete my checks), and then

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

resulting in (exposure)

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 much better than nothing, but will be greatly improved with line numbers.

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

This is the x86_64 build on 10.6.7, Xcode 3.2.6. Using -g doesn't matter.

main main(), gnatmake, _ada_foobar - Ada, . .

+3
2

Valgrind 3.7.0 Mac OS X;

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

,

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.

+2

, - , . Gnat, ACT, libraray addr2line.lib, .

Gnat, FSF, . , addr2line, Gnu "binutils". Mac-, ?

, . , leaks addr2line, .

+3

All Articles