Browse Source

+ Add preliminary debugging support on the UEFI target with
basic checkpointer and heaptrc support.
Output need to be fixed, though...

git-svn-id: branches/olivier/uefi@36932 -

olivier 8 years ago
parent
commit
07e3d361bf
3 changed files with 80 additions and 2 deletions
  1. 2 1
      compiler/systems.pas
  2. 75 1
      rtl/inc/heaptrc.pp
  3. 3 0
      rtl/inc/system.inc

+ 2 - 1
compiler/systems.pas

@@ -385,7 +385,8 @@ interface
                              + [system_i386_GO32V2]
                              + [system_i386_GO32V2]
                              + [system_i386_os2]
                              + [system_i386_os2]
                              + [system_i386_beos,system_i386_haiku]
                              + [system_i386_beos,system_i386_haiku]
-                             + [system_powerpc_morphos];
+                             + [system_powerpc_morphos] 
+                             + [system_i386_uefi];
 
 
        cpu2str : array[TSystemCpu] of string[10] =
        cpu2str : array[TSystemCpu] of string[10] =
             ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
             ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',

+ 75 - 1
rtl/inc/heaptrc.pp

@@ -63,6 +63,39 @@ const
 {$else EXTRA}
 {$else EXTRA}
   tracesize = 8;
   tracesize = 8;
 {$endif EXTRA}
 {$endif EXTRA}
+
+{$ifdef UEFI}
+  { install heaptrc memorymanager }
+  useheaptrace : boolean=true;
+  { less checking }
+  quicktrace : boolean=false;
+  { calls halt() on error by default !! }
+  HaltOnError : boolean = true;
+  { Halt on exit if any memory was not freed }
+  HaltOnNotReleased : boolean = false;
+
+  { set this to true if you suspect that memory
+    is freed several times }
+{$ifdef EXTRA}
+  keepreleased : boolean=true;
+{$else EXTRA}
+  keepreleased : boolean=false;
+{$endif EXTRA}
+  { add a small footprint at the end of memory blocks, this
+    can check for memory overwrites at the end of a block }
+  add_tail : boolean = true;
+  tail_size : longint = sizeof(ptruint);
+
+  { put crc in sig
+    this allows to test for writing into that part }
+  usecrc : boolean = true;
+
+  printleakedblock: boolean = false;
+  printfaultyblock: boolean = false;
+  maxprintedblocklength: integer = 128;
+
+  GlobalSkipIfNoLeaks : Boolean = False;
+{$else}
   { install heaptrc memorymanager }
   { install heaptrc memorymanager }
   useheaptrace : boolean=true;
   useheaptrace : boolean=true;
   { less checking }
   { less checking }
@@ -93,6 +126,7 @@ const
   maxprintedblocklength: integer = 128;
   maxprintedblocklength: integer = 128;
 
 
   GlobalSkipIfNoLeaks : Boolean = False;
   GlobalSkipIfNoLeaks : Boolean = False;
+{$endif}
 
 
 implementation
 implementation
 
 
@@ -975,6 +1009,16 @@ function TlsGetValue(dwTlsIndex : DWord) : pointer;
   {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'TlsGetValue';
   {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'TlsGetValue';
 {$endif}
 {$endif}
 
 
+{$ifdef UEFI}
+// Same as Windows as it is the same file format...
+var
+   sdata : ptruint; external name '__data_start__';
+   edata : ptruint; external name '__data_end__';
+   sbss : ptruint; external name '__bss_start__';
+   ebss : ptruint; external name '__bss_end__';
+
+{$endif}
+
 {$ifdef BEOS}
 {$ifdef BEOS}
 const
 const
   B_ERROR = -1;
   B_ERROR = -1;
@@ -1010,6 +1054,20 @@ begin
   else
   else
     ptext:=textoutput;
     ptext:=textoutput;
 
 
+{$ifdef UEFI}
+  // Same as Windows as it is the same file format...
+  // Good enough until proven totally wrong.
+  // Incomplete for sure...
+  { inside stack ? }
+  if (ptruint(p)>ptruint(get_frame)) and
+     (p<StackTop) then
+    exit;
+  { inside data, rdata ... bss }
+  if (ptruint(p)>=ptruint(@sdata)) and (ptruint(p)<ptruint(@ebss)) then
+    exit;
+
+{$endif}
+
 {$ifdef go32v2}
 {$ifdef go32v2}
   if ptruint(p)<$1000 then
   if ptruint(p)<$1000 then
     runerror(216);
     runerror(216);
@@ -1147,7 +1205,14 @@ begin
          halt(1);
          halt(1);
       end;
       end;
    end;
    end;
-  writeln(ptext^,'pointer $',hexstr(p),' does not point to valid memory block');
+
+  //Debugger('heaptrc : Here...');
+  // Maybe error here...
+  // probably ptext^...
+  //writeln(ptext^,'pointer $',hexstr(p),' does not point to valid memory block');
+  // TODO : test with a WideString...
+  //debugger('pointer $' + hexstr(p) + ' does not point to valid memory block');
+  //Debugger('After the supposed crash...');
   dump_stack(ptext^,1);
   dump_stack(ptext^,1);
   runerror(204);
   runerror(204);
 end;
 end;
@@ -1632,6 +1697,14 @@ var
   s,s2   : string;
   s,s2   : string;
   err : word;
   err : word;
 begin
 begin
+  {$ifdef UEFI}
+  // Avoid GetEnv in case it cause the problem when initializing heaptrc unit
+  keepreleased:=true;
+  useheaptrace:=false;
+  haltonerror:=true;
+  HaltOnNotReleased :=true;
+  GlobalSkipIfNoLeaks :=true;
+  {$else}
   s:=Getenv('HEAPTRC');
   s:=Getenv('HEAPTRC');
   if pos('keepreleased',s)>0 then
   if pos('keepreleased',s)>0 then
    keepreleased:=true;
    keepreleased:=true;
@@ -1668,6 +1741,7 @@ begin
       j:=length(outputstr)+1;
       j:=length(outputstr)+1;
      delete(outputstr,j,255);
      delete(outputstr,j,255);
    end;
    end;
+  {$endif}
 end;
 end;
 
 
 
 

+ 3 - 0
rtl/inc/system.inc

@@ -1207,11 +1207,14 @@ var
   pcaddr : codepointer;
   pcaddr : codepointer;
 begin
 begin
   errorcode:=w;
   errorcode:=w;
+  {$ifndef UEFI}
+  // TODO : some work required here to support this under UEFI
   pcaddr:=get_pc_addr;
   pcaddr:=get_pc_addr;
   bp:=get_frame;
   bp:=get_frame;
   get_caller_stackinfo(bp,pcaddr);
   get_caller_stackinfo(bp,pcaddr);
   erroraddr:=pcaddr;
   erroraddr:=pcaddr;
   errorbase:=bp;
   errorbase:=bp;
+  {$endif}
   Halt(errorcode);
   Halt(errorcode);
 end;
 end;