LLVM: enable DWARF debug info generation

This commit is contained in:
Jonas Maebe 2022-04-09 14:48:38 +02:00
parent 527c68b6c3
commit d294731542
6 changed files with 57 additions and 6 deletions

View File

@ -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

View File

@ -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 } [],

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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;