ソースを参照

* exeinfo: Return executable image base and current module base address on Windows.
* exeinfo: Properly handle long COFF section names. Bug #13499.
* lineinfo, lnfodwrf: Properly use executable image base and current module base address.

git-svn-id: trunk@13145 -

yury 16 年 前
コミット
628b0c23ac
3 ファイル変更14 行追加12 行削除
  1. 11 9
      rtl/inc/exeinfo.pp
  2. 2 2
      rtl/inc/lineinfo.pp
  3. 1 1
      rtl/inc/lnfodwrf.pp

+ 11 - 9
rtl/inc/exeinfo.pp

@@ -78,11 +78,12 @@ uses
 {$endif wince}
 {$endif wince}
   procedure GetModuleByAddr(addr: pointer; var baseaddr: pointer; var filename: string);
   procedure GetModuleByAddr(addr: pointer; var baseaddr: pointer; var filename: string);
     begin
     begin
-      baseaddr:= nil;
+      baseaddr:=nil;
       if VirtualQuery(addr, @Tmm, SizeOf(Tmm))<>sizeof(Tmm) then
       if VirtualQuery(addr, @Tmm, SizeOf(Tmm))<>sizeof(Tmm) then
         filename:=ParamStr(0)
         filename:=ParamStr(0)
       else
       else
         begin
         begin
+          baseaddr:=Tmm.AllocationBase;
           TST[0]:= #0;
           TST[0]:= #0;
           GetModuleFileName(THandle(Tmm.AllocationBase), TST, Length(TST));
           GetModuleFileName(THandle(Tmm.AllocationBase), TST, Length(TST));
 {$ifdef wince}
 {$ifdef wince}
@@ -494,9 +495,10 @@ begin
     exit;
     exit;
   e.sechdrofs:=filepos(e.f);
   e.sechdrofs:=filepos(e.f);
   e.nsects:=peheader.NumberOfSections;
   e.nsects:=peheader.NumberOfSections;
-  e.secstrofs:=peheader.PointerToSymbolTable+peheader.NumberOfSymbols*sizeof(coffsymbol)+4;
+  e.secstrofs:=peheader.PointerToSymbolTable+peheader.NumberOfSymbols*sizeof(coffsymbol);
   if e.secstrofs>e.size then
   if e.secstrofs>e.size then
     exit;
     exit;
+  e.processaddress:=peheader.ImageBase;
   OpenPeCoff:=true;
   OpenPeCoff:=true;
 end;
 end;
 {$endif PE32}
 {$endif PE32}
@@ -522,8 +524,7 @@ type
      SizeOfUninitializedData : longint;
      SizeOfUninitializedData : longint;
      AddressOfEntryPoint : longint;
      AddressOfEntryPoint : longint;
      BaseOfCode : longint;
      BaseOfCode : longint;
-     BaseOfData : longint;
-     ImageBase : longint;
+     ImageBase : qword;
      SectionAlignment : longint;
      SectionAlignment : longint;
      FileAlignment : longint;
      FileAlignment : longint;
      MajorOperatingSystemVersion : word;
      MajorOperatingSystemVersion : word;
@@ -538,10 +539,10 @@ type
      CheckSum : longint;
      CheckSum : longint;
      Subsystem : word;
      Subsystem : word;
      DllCharacteristics : word;
      DllCharacteristics : word;
-     SizeOfStackReserve : int64;
-     SizeOfStackCommit : int64;
-     SizeOfHeapReserve : int64;
-     SizeOfHeapCommit : int64;
+     SizeOfStackReserve : qword;
+     SizeOfStackCommit : qword;
+     SizeOfHeapReserve : qword;
+     SizeOfHeapCommit : qword;
      LoaderFlags : longint;
      LoaderFlags : longint;
      NumberOfRvaAndSizes : longint;
      NumberOfRvaAndSizes : longint;
      DataDirectory : array[1..$80] of byte;
      DataDirectory : array[1..$80] of byte;
@@ -561,9 +562,10 @@ begin
    exit;
    exit;
   e.sechdrofs:=filepos(e.f);
   e.sechdrofs:=filepos(e.f);
   e.nsects:=peheader.NumberOfSections;
   e.nsects:=peheader.NumberOfSections;
-  e.secstrofs:=peheader.PointerToSymbolTable+peheader.NumberOfSymbols*sizeof(coffsymbol)+4;
+  e.secstrofs:=peheader.PointerToSymbolTable+peheader.NumberOfSymbols*sizeof(coffsymbol);
   if e.secstrofs>e.size then
   if e.secstrofs>e.size then
     exit;
     exit;
+  e.processaddress:=peheader.ImageBase;
   OpenPePlusCoff:=true;
   OpenPePlusCoff:=true;
 end;
 end;
 {$endif PE32PLUS}
 {$endif PE32PLUS}

+ 2 - 2
rtl/inc/lineinfo.pp

@@ -95,7 +95,7 @@ begin
       if not OpenExeFile(e,dbgfn) then
       if not OpenExeFile(e,dbgfn) then
         exit;
         exit;
     end;
     end;
-  e.processaddress:=e.processaddress+dword(baseaddr);
+  e.processaddress:=ptruint(baseaddr)-e.processaddress;
   StabsFunctionRelative := E.FunctionRelative;
   StabsFunctionRelative := E.FunctionRelative;
   if FindExeSection(e,'.stab',stabofs,stablen) and
   if FindExeSection(e,'.stab',stabofs,stablen) and
      FindExeSection(e,'.stabstr',stabstrofs,stabstrlen) then
      FindExeSection(e,'.stabstr',stabstrofs,stabstrlen) then
@@ -142,7 +142,7 @@ begin
 
 
   { correct the value to the correct address in the file }
   { correct the value to the correct address in the file }
   { processaddress is set in OpenStabs                   }
   { processaddress is set in OpenStabs                   }
-  addr := addr - e.processaddress;
+  addr := dword(addr - e.processaddress);
 
 
 {$ifdef DEBUG_LINEINFO}
 {$ifdef DEBUG_LINEINFO}
   writeln(stderr,'Addr: ',hexstr(addr,sizeof(addr)*2));
   writeln(stderr,'Addr: ',hexstr(addr,sizeof(addr)*2));

+ 1 - 1
rtl/inc/lnfodwrf.pp

@@ -153,7 +153,7 @@ begin
         exit;
         exit;
     end;
     end;
 
 
-  e.processaddress:=e.processaddress+dword(baseaddr);
+  e.processaddress:=ptruint(baseaddr)-e.processaddress;
 
 
   if FindExeSection(e,'.debug_line',dwarfoffset,dwarfsize) then
   if FindExeSection(e,'.debug_line',dwarfoffset,dwarfsize) then
     Opendwarf:=true
     Opendwarf:=true