--- Merging r31025 into '.':

U    rtl/inc/lineinfo.pp
--- Recording mergeinfo for merge of r31025 into '.':
 U   .
--- Merging r31026 into '.':
G    rtl/inc/lineinfo.pp
--- Recording mergeinfo for merge of r31026 into '.':
 G   .

# revisions: 31025,31026

git-svn-id: branches/fixes_3_0@31216 -
This commit is contained in:
marco 2015-07-18 12:26:05 +00:00
parent e99d0c17e6
commit 50caed7f5f

View File

@ -22,7 +22,14 @@ interface
{$S-} {$S-}
{$Q-} {$Q-}
{$IF FPC_VERSION<3}
Type
CodePointer = Pointer;
{$ENDIF}
function GetLineInfo(addr:ptruint;var func,source:string;var line:longint) : boolean; function GetLineInfo(addr:ptruint;var func,source:string;var line:longint) : boolean;
function StabBackTraceStr(addr:CodePointer):string;
procedure CloseStabs;
implementation implementation
@ -59,7 +66,6 @@ type
{$WARNING This code is not thread-safe, and needs improvement } {$WARNING This code is not thread-safe, and needs improvement }
var var
e : TExeFile; e : TExeFile;
staberr : boolean;
stabcnt, { amount of stabs } stabcnt, { amount of stabs }
stablen, stablen,
stabofs, { absolute stab section offset in executable } stabofs, { absolute stab section offset in executable }
@ -72,22 +78,48 @@ var
dirstab, { stab with current directory info } dirstab, { stab with current directory info }
filestab : tstab; { stab with current file info } filestab : tstab; { stab with current file info }
filename, filename,
lastfilename, { store last processed file }
dbgfn : string; dbgfn : string;
lastopenstabs: Boolean; { store last result of processing a file }
function OpenStabs(addr : pointer) : boolean; function OpenStabs(addr : pointer) : boolean;
var var
baseaddr : pointer; baseaddr : pointer;
begin begin
// False by default
OpenStabs:=false; OpenStabs:=false;
if staberr then
exit;
// Empty so can test if GetModuleByAddr has worked
filename := '';
// Get filename by address using GetModuleByAddr
GetModuleByAddr(addr,baseaddr,filename); GetModuleByAddr(addr,baseaddr,filename);
{$ifdef DEBUG_LINEINFO} {$ifdef DEBUG_LINEINFO}
writeln(stderr,filename,' Baseaddr: ',hexstr(ptruint(baseaddr),sizeof(baseaddr)*2)); writeln(stderr,filename,' Baseaddr: ',hexstr(ptruint(baseaddr),sizeof(baseaddr)*2));
{$endif DEBUG_LINEINFO} {$endif DEBUG_LINEINFO}
// Check if GetModuleByAddr has worked
if filename = '' then
exit;
// If target filename same as previous, then re-use previous result
if filename = lastfilename then
begin
OpenStabs:=lastopenstabs;
exit;
end;
// Close previously opened stabs
CloseStabs;
// Reset last open stabs result
lastopenstabs := false;
// Save newly processed filename
lastfilename := filename;
// Open exe file or debug link
if not OpenExeFile(e,filename) then if not OpenExeFile(e,filename) then
exit; exit;
if ReadDebugLink(e,dbgfn) then if ReadDebugLink(e,dbgfn) then
@ -96,6 +128,8 @@ begin
if not OpenExeFile(e,dbgfn) then if not OpenExeFile(e,dbgfn) then
exit; exit;
end; end;
// Find stab section
{$ifdef BeOS} {$ifdef BeOS}
{ Do not change ProcessAddress field for BeOS/Haiku { Do not change ProcessAddress field for BeOS/Haiku
if baseAddr is lower than ProcessAdress } if baseAddr is lower than ProcessAdress }
@ -107,11 +141,12 @@ begin
FindExeSection(e,'.stabstr',stabstrofs,stabstrlen) then FindExeSection(e,'.stabstr',stabstrofs,stabstrlen) then
begin begin
stabcnt:=stablen div sizeof(tstab); stabcnt:=stablen div sizeof(tstab);
lastopenstabs:=true;
OpenStabs:=true; OpenStabs:=true;
end end
else else
begin begin
staberr:=true; CloseExeFile(e);
exit; exit;
end; end;
end; end;
@ -119,7 +154,13 @@ end;
procedure CloseStabs; procedure CloseStabs;
begin begin
CloseExeFile(e); if e.isopen then
begin
CloseExeFile(e);
// Reset last processed filename
lastfilename := '';
end;
end; end;
@ -138,13 +179,9 @@ begin
fillchar(func,high(func)+1,0); fillchar(func,high(func)+1,0);
fillchar(source,high(source)+1,0); fillchar(source,high(source)+1,0);
line:=0; line:=0;
if staberr then
if not OpenStabs(pointer(addr)) then
exit; exit;
if not e.isopen then
begin
if not OpenStabs(pointer(addr)) then
exit;
end;
{ 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 }
@ -252,17 +289,16 @@ begin
if i>0 then if i>0 then
Delete(func,i,255); Delete(func,i,255);
end; end;
if e.isopen then
CloseStabs;
GetLineInfo:=true; GetLineInfo:=true;
end; end;
function StabBackTraceStr(addr:CodePointer):shortstring; function StabBackTraceStr(addr:CodePointer):string;
var var
func, func,
source : string; source : string;
hs : string[32]; hs : string;
line : longint; line : longint;
Store : TBackTraceStrFunc; Store : TBackTraceStrFunc;
Success : boolean; Success : boolean;
@ -296,15 +332,16 @@ begin
end; end;
StabBackTraceStr:=StabBackTraceStr+' of '+source; StabBackTraceStr:=StabBackTraceStr+' of '+source;
end; end;
if Success then BackTraceStrFunc:=Store;
BackTraceStrFunc:=Store;
end; end;
initialization initialization
lastfilename := '';
lastopenstabs := false;
BackTraceStrFunc:=@StabBackTraceStr; BackTraceStrFunc:=@StabBackTraceStr;
finalization finalization
if e.isopen then CloseStabs;
CloseStabs;
end. end.