Browse Source

morphos: fixed stabs line number parsing, and off-by-one line issue with backtraces. i think this should be a generic fix and can be backported to the global lineinfo

git-svn-id: trunk@40857 -
Károly Balogh 6 years ago
parent
commit
b3ad384547
1 changed files with 22 additions and 13 deletions
  1. 22 13
      rtl/morphos/lineinfo.pp

+ 22 - 13
rtl/morphos/lineinfo.pp

@@ -281,6 +281,7 @@ var
   stabscnt,i : longint;
   found : boolean;
   lastfunc : tstab;
+  lastline : tstab;
 
 begin
   GetLineInfo:=false;
@@ -328,20 +329,21 @@ begin
      begin
        case stabs[i].ntype of
          N_BssLine,
-         N_DataLine,
+         N_DataLine:
+           begin
+             // for code line info, we don't care about these
+           end;
          N_TextLine :
            begin
-             if (stabs[i].ntype=N_TextLine) and StabsFunctionRelative then
-               inc(stabs[i].nvalue,lastfunc.nvalue);
-             if (stabs[i].nvalue<=addr) and
-                (stabs[i].nvalue>linestab.nvalue) then
-              begin
-                { if it's equal we can stop and take the last info }
-                if stabs[i].nvalue=addr then
-                 found:=true
-                else
-                 linestab:=stabs[i];
-              end;
+             lastline:=stabs[i];
+             if StabsFunctionRelative then
+               inc(lastline.nvalue,lastfunc.nvalue);
+             if (addr>=linestab.nvalue) and (addr<lastline.nvalue) then
+               begin
+                 found:=true;
+                 break;
+               end;
+             linestab:=lastline;
            end;
          N_Function :
            begin
@@ -431,7 +433,14 @@ begin
   Success:=false;
   Store:=BackTraceStrFunc;
   BackTraceStrFunc:=@SysBackTraceStr;
-  Success:=GetLineInfo(ptruint(addr),func,source,line);
+
+  { for valid stacktraces at least you have to substract sizeof(pointer)
+    from the trace address otherwise the lineinfo might be off-by-one,
+    because of course the backtrace addresses don't point to the jump
+    instructions, but the following address, which might belong to a
+    different source line entirely (KB) }
+  Success:=GetLineInfo(ptruint(addr-sizeof(pointer)),func,source,line);
+
 { create string }
 {$ifdef netware}
   { we need addr relative to code start on netware }