Browse Source

dbgllvm: add scopeLine attribute for function debug info

Ensures that breaking on the function correctly sets the breakpoint on the
first source line of the function (rather than potentially in the prologue
without line information)
Jonas Maebe 3 years ago
parent
commit
9b280db2b1
1 changed files with 13 additions and 5 deletions
  1. 13 5
      compiler/llvm/dbgllvm.pas

+ 13 - 5
compiler/llvm/dbgllvm.pas

@@ -1214,7 +1214,6 @@ implementation
         fileref        : tai_simpletypedconst;
         fileref        : tai_simpletypedconst;
         procdeftai     : tai;
         procdeftai     : tai;
         st             : tsymtable;
         st             : tsymtable;
-        prologfileinfo : pfileposinfo;
         vmtoffset      : pint;
         vmtoffset      : pint;
         dispflags      : TSymStr;
         dispflags      : TSymStr;
         in_currentunit : boolean;
         in_currentunit : boolean;
@@ -1259,7 +1258,6 @@ implementation
 
 
         { we have to attach the debug info to the definition instruction of the
         { we have to attach the debug info to the definition instruction of the
           proc }
           proc }
-        prologfileinfo:=nil;
         procdeftai:=nil;
         procdeftai:=nil;
         if in_currentunit then
         if in_currentunit then
           begin
           begin
@@ -2445,8 +2443,9 @@ implementation
         hp: tai;
         hp: tai;
         functionscope,
         functionscope,
         positionmeta: tai_llvmspecialisedmetadatanode;
         positionmeta: tai_llvmspecialisedmetadatanode;
-        procdeffileindex: tfileposfileindex;
+        procdeffileinfo: tfileposinfo;
         nolineinfolevel : longint;
         nolineinfolevel : longint;
+        firstline: boolean;
       begin
       begin
         ensuremetainit;
         ensuremetainit;
         hp:=tai(list.first);
         hp:=tai(list.first);
@@ -2458,15 +2457,16 @@ implementation
            end;
            end;
         if not assigned(hp) then
         if not assigned(hp) then
           exit;
           exit;
-        procdeffileindex:=tprocdef(taillvmdecl(hp).def).fileinfo.fileindex;
+        procdeffileinfo:=tprocdef(taillvmdecl(hp).def).fileinfo;
         { might trigger for certain kinds of internally generated code }
         { might trigger for certain kinds of internally generated code }
-        if procdeffileindex=0 then
+        if procdeffileinfo.fileindex=0 then
           exit;
           exit;
 
 
         functionscope:=def_meta_node(taillvmdecl(hp).def);
         functionscope:=def_meta_node(taillvmdecl(hp).def);
 
 
         nolineinfolevel:=0;
         nolineinfolevel:=0;
         hp:=tai(hp.next);
         hp:=tai(hp.next);
+        firstline:=true;
         while assigned(hp) do
         while assigned(hp) do
           begin
           begin
             case hp.typ of
             case hp.typ of
@@ -2493,8 +2493,16 @@ implementation
                 { valid file -> add info }
                 { valid file -> add info }
                 if (tailineinfo(hp).fileinfo.fileindex<>0) then
                 if (tailineinfo(hp).fileinfo.fileindex<>0) then
                   begin
                   begin
+                    if firstline and
+                       (nolineinfolevel=0) then
+                      begin
+                        functionscope.addint64('scopeLine',tailineinfo(hp).fileinfo.line);
+                        firstline:=false;
+                      end;
                     positionmeta:=filepos_getmetanode(tailineinfo(hp).fileinfo,procdeffileinfo,functionscope,nolineinfolevel<>0);
                     positionmeta:=filepos_getmetanode(tailineinfo(hp).fileinfo,procdeffileinfo,functionscope,nolineinfolevel<>0);
                   end
                   end
+                { LLVM requires line info for call instructions that may
+                  potentially be inlined }
                 else if taillvm(hp).llvmopcode=la_call then
                 else if taillvm(hp).llvmopcode=la_call then
                   begin
                   begin
                     positionmeta:=filepos_getmetanode(tailineinfo(hp).fileinfo,procdeffileinfo,functionscope,true);
                     positionmeta:=filepos_getmetanode(tailineinfo(hp).fileinfo,procdeffileinfo,functionscope,true);