From bf51ab03afd01a9cac0de0764dc5ac92af3fd87b Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Thu, 21 Jul 2005 13:09:45 +0000 Subject: [PATCH] + support for Mach-O in lineinfo.pp (by Jan Ruzicka) * always store the return address in the stack frame on ppc if debuginfo or lineinfo is turned on (otherwise the parent of a leaf function is missing in backtraces) git-svn-id: trunk@724 - --- compiler/powerpc/cgcpu.pas | 3 +- rtl/inc/lineinfo.pp | 87 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/compiler/powerpc/cgcpu.pas b/compiler/powerpc/cgcpu.pas index 34c3bf7d86..2ab9ae8127 100644 --- a/compiler/powerpc/cgcpu.pas +++ b/compiler/powerpc/cgcpu.pas @@ -1096,7 +1096,8 @@ const { save link register? } if not (po_assembler in current_procinfo.procdef.procoptions) then - if (pi_do_call in current_procinfo.flags) then + if (pi_do_call in current_procinfo.flags) or + ([cs_lineinfo,cs_debuginfo] * aktmoduleswitches <> []) then begin { save return address... } list.concat(taicpu.op_reg(A_MFLR,NR_R0)); diff --git a/rtl/inc/lineinfo.pp b/rtl/inc/lineinfo.pp index 285149dcec..819acc5f24 100644 --- a/rtl/inc/lineinfo.pp +++ b/rtl/inc/lineinfo.pp @@ -790,6 +790,86 @@ begin end; {$endif beos} +{$ifdef darwin} +type +MachoFatHeader= +packed record + magic: longint; + nfatarch: longint; +end; + +MachoHeader= +packed record + magic: longword; + cpu_type_t: longint; + cpu_subtype_t: longint; + filetype: longint; + ncmds: longint; + sizeofcmds: longint; + flags: longint; + +end; + +cmdblock= +packed record + cmd: longint; + cmdsize: longint; +end; + +symbSeg= +packed record + symoff : longint; + nsyms : longint; + stroff : longint; + strsize: longint; +end; + + +function readCommand: boolean; +var + block:cmdblock; + readMore :boolean; + symbolsSeg: symbSeg; + +begin + readCommand := false; + readMore := true; + blockread (f, block, sizeof(block)); + if block.cmd = $2 then + begin + blockread (f, symbolsSeg, sizeof(symbolsSeg)); + stabstrofs:=symbolsSeg.stroff; + stabofs:=symbolsSeg.symoff; + stabcnt:=symbolsSeg.nsyms; + + readMore := false; + readCommand := true; + exit; + end; + if readMore then + begin + Seek(f, FilePos (f) + block.cmdsize - sizeof(block)); + end; +end; + +function LoadMachO32PPC:boolean; +var + mh:MachoHeader; + i: longint; +begin + StabsFunctionRelative:=false; + LoadMachO32PPC := false; + blockread (f, mh, sizeof(mh)); + for i:= 1 to mh.ncmds do + begin + if readCommand then + begin + LoadMachO32PPC := true; + exit; + end; + end; +end; +{$endif darwin} {**************************************************************************** Executable Open/Close @@ -859,6 +939,13 @@ begin exit; end; {$endif} +{$ifdef darwin} + if LoadMachO32PPC then + begin + OpenStabs:=true; + exit; + end; +{$endif darwin} {$ifdef netware} if LoadNetwareNLM then begin