浏览代码

+ 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 -

Jonas Maebe 20 年之前
父节点
当前提交
bf51ab03af
共有 2 个文件被更改,包括 89 次插入1 次删除
  1. 2 1
      compiler/powerpc/cgcpu.pas
  2. 87 0
      rtl/inc/lineinfo.pp

+ 2 - 1
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));

+ 87 - 0
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