Quellcode durchsuchen

LLVM: enable DWARF debug info generation

Jonas Maebe vor 3 Jahren
Ursprung
Commit
d294731542

+ 7 - 0
compiler/dbgbase.pas

@@ -630,7 +630,14 @@ implementation
             Comment(V_Fatal,'cg_f_debuginfo_output_not_supported');
             exit;
           end;
+{$ifndef llvm}
         hp.DebugInfo:=CDebugInfo[target_dbg.id].Create;
+{$else}
+        { we can't override the assignment of target_dbg with the LLVM class,
+          because we still need to know whether to tell LLVM to generate
+          DWARFv2/3/4/5/... }
+        hp.DebugInfo:=CDebugInfo[dbg_llvm].Create;
+{$endif}
         if restore_current_debuginfo then
           begin
             if current_debuginfo=nil then

+ 13 - 0
compiler/llvm/llvminfo.pas

@@ -73,6 +73,19 @@ Const
      '11.0'
    );
 
+   llvm_debuginfo_metadata_format : array[tllvmversion] of byte = (
+     0,
+     3,
+     3,
+     3,
+     3,
+     3,
+     3,
+     3,
+     3,
+     3
+   );
+
    llvmversion_properties: array[tllvmversion] of tllvmversionflags =
      (
        { invalid         } [],

+ 2 - 1
compiler/llvm/llvmnode.pas

@@ -41,6 +41,7 @@ implementation
     nllvmmat,nllvmmem,nllvmset,nllvmtcon,nllvmutil,
     llvmpara,llvmpi,
     symllvm,
-    llvmcfi;
+    llvmcfi,
+    dbgllvm;
 
 end.

+ 34 - 2
compiler/llvm/nllvmutil.pas

@@ -53,7 +53,7 @@ implementation
       aasmtai,cpubase,llvmbase,aasmllvm,
       aasmcnst,nllvmtcon,
       symbase,symtable,defutil,
-      llvmtype,llvmdef,
+      llvminfo,llvmtype,llvmdef,
       objcasm;
 
   class procedure tllvmnodeutils.insertbsssym(list: tasmlist; sym: tstaticvarsym; size: asizeint; varalign: shortint; _typ:Tasmsymtype);
@@ -257,7 +257,8 @@ implementation
   class procedure tllvmnodeutils.GenerateObjCImageInfo;
     var
       llvmmoduleflags,
-       objcmoduleflag: tai_llvmbasemetadatanode;
+      objcmoduleflag,
+      dwarfversionflag: tai_llvmbasemetadatanode;
       objcabiversion: longint;
     begin
       llvmmoduleflags:=tai_llvmnamedmetadatanode.create('llvm.module.flags');
@@ -299,6 +300,37 @@ implementation
       objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(0)));
       llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
       current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
+
+      { debug information }
+      if (([cs_debuginfo,cs_lineinfo]*current_settings.moduleswitches)<>[]) and
+         (target_dbg.id in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4]) then
+        begin
+          { the debug info version is the version of the debug info metadata
+            format }
+          dwarfversionflag:=tai_llvmunnamedmetadatanode.create;
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Debug Info Version')));
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(llvm_debuginfo_metadata_format[current_settings.llvmversion])));
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(dwarfversionflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(dwarfversionflag);
+
+          { dwarf version }
+          dwarfversionflag:=tai_llvmunnamedmetadatanode.create;
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Dwarf Version')));
+          case target_dbg.id of
+            dbg_dwarf2:
+              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
+            dbg_dwarf3:
+              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(3)));
+            dbg_dwarf4:
+              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(4)));
+            else
+              internalerror(2022022012);
+          end;
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(dwarfversionflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(dwarfversionflag);
+        end;
     end;
 
 

+ 1 - 1
compiler/systems.inc

@@ -347,7 +347,7 @@
 
        tdbg = (dbg_none
             ,dbg_stabs,dbg_stabx,dbg_dwarf2,dbg_dwarf3,dbg_dwarf4,dbg_jasmin
-            ,dbg_codeview
+            ,dbg_codeview,dbg_llvm
        );
 
        tscripttype = (script_none

+ 0 - 2
compiler/systems.pas

@@ -685,14 +685,12 @@ function set_target_dbg(t:tdbg):boolean;
 begin
   result:=false;
 { no debugging support for llvm yet }
-{$ifndef llvm}
   if assigned(dbginfos[t]) then
    begin
      target_dbg:=dbginfos[t]^;
      result:=true;
      exit;
    end;
-{$endif}
 end;