[fpc-pascal] Heaptrc with symbolic stack trace or map file on Mac OS X ?

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Oct 25 13:23:29 CEST 2010


On 25 Oct 2010, at 11:33, Tobias Giesen wrote:

> I'm trying to find a memory leak but I am unable to get a symbolic
> stack trace from the heaptrc dump.

Automatically symbolicating stack traces is currently only supported  
when using Stabs debug information on Mac OS X (make sure to also  
compile with -gl to include the symbolication unit).

> Also the option -Xm does not
> generate a map file on Mac OS X. Or at least I don't see it.

It's indeed not implemented for Mac OS X. You can manually tell the  
linker to create it by passing the following options to FPC:

-k-map -kmapfilename.map

> If I could get a detailed map file with line numbers and offsets,
> I would probably be happy.

It's probably easier to either (temporarily) switch to Stabs debug  
information, or to compile with DWARF debug info and then script gdb  
to convert the addresses to line numbers:

First convert a backtrace to gdb commands:

sed -e 's/^  \$/info line *0x/' > trace.gdb

(paste the backtrace) and then press ctrl-d

Then have gdb execute the commands:

gdb executable_name -batch -x trace.gdb

E.g.:

$ ./tt6
Heap dump by heaptrc unit
1 memory blocks allocated : 10/16
0 memory blocks freed     : 0/0
1 unfreed memory blocks : 10
True heap size : 327680 (16 used in System startup)
True free heap : 327568
Should be : 327584
Call trace for block $000C2060 size 10
   $00002578
   $000025A0
   $000025C4
   $00031F68
   $00002530
   $00002240
   $BFFFF104

$ sed -e 's/^  \$/info line *0x/' > trace.gdb
   $00002578
   $000025A0
   $000025C4
   $00031F68
   $00002530
   $00002240
   $BFFFF104

$ gdb tt6 -batch -x trace.gdb
Reading symbols for shared libraries .. done
Line 6 of "tt6.pp" starts at address 0x2578 <TEST+24> and ends at  
0x2588 <P$PROGRAM_TEST+40>.
Line 11 of "tt6.pp" starts at address 0x25a0 <TEST2+16> and ends at  
0x25b0 <PASCALMAIN>.
Line 15 of "tt6.pp" starts at address 0x25c4 <PASCALMAIN+20> and ends  
at 0x25d8 <main>.
Line 300 of "../bsd/system.pp" starts at address 0x31f68  
<FPC_SYSTEMMAIN+88> and ends at 0x31f7c <SYSTEM_FPC_SYSTEMMAIN$LONGINT 
$PPCHAR$PPCHAR+108>.
No line number information available for address 0x2530 <_start+748>
No line number information available for address 0x2240 <start+48>
No line number information available for address 0xbffff104


Jonas



More information about the fpc-pascal mailing list