Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-02

BackTraceStrFunc / reset to system handler

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin

In light of a recent mail thread on the topic and
http://bugs.freepascal.org/view.php?id=21370

From: rtl\inc\lnfodwrf.pp

function DwarfBackTraceStr(addr : Pointer) : shortstring;
var
...
   Success : boolean;
begin
   { reset to prevent infinite recursion if problems inside the code }
   Success:=false;
   Store := BackTraceStrFunc;
   BackTraceStrFunc := @SysBackTraceStr;
   Success:=GetLineInfo(ptruint(addr), func, source, line);
   { create string }
.... // no access to Success
   if Success then
     BackTraceStrFunc := Store;
end;

This also unsets the procedure for the perfectly valid case, that some part of the code has no debug info (e.g kernel)
Of course, if there are many such frames this has a speed up effect too...

But as protection against recursion, it would be better to do something like:

Var DwarfBackTraceStrCount: Integer = 0; // global/ maybe thread
function DwarfBackTraceStr(addr : Pointer) : shortstring;
var
...
   Success : boolean;
begin
   { reset to prevent infinite recursion if problems inside the code }
   if DwarfBackTraceStrCount > 0 then begin
     result := SysBackTraceStr(addr);
     exit;
   end;
   inc(DwarfBackTraceStrCount);
   ....
   dec(DwarfBackTraceStrCount); // in case of crash, this will not be
reached
end;

Of course, then an app that has its own painter to the function will no longer benefit from that. But it could reset the global variable...

Reply by email