Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo] Support for -gpubnames option in flang #1033

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions test/debug_info/debug_module_import.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ program hello
print *, var2
end program hello

! //CHECK: ![[DBG_MOD1:[0-9]+]] = !DIModule({{.*}}, name: "first"
! //CHECK: ![[DBG_DIC:[0-9]+]] = distinct !DICompileUnit({{.*}}, imports: ![[DBG_IMPORTS:[0-9]+]])
! //CHECK: ![[DBG_MOD2:[0-9]+]] = !DIModule({{.*}}, name: "second"
! //CHECK: ![[DBG_IMPORTS]] = !{![[DBG_IE1:[0-9]+]], ![[DBG_IE2:[0-9]+]], ![[DBG_IE3:[0-9]+]]}
! //CHECK: ![[DBG_IE1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[DBG_SP1:[0-9]+]], entity: ![[DBG_MOD1]],
! //CHECK: ![[DBG_SP1]] = distinct !DISubprogram(name: "init", scope: ![[DBG_MOD2]]
! //CHECK: ![[DBG_IE2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[DBG_SP2:[0-9]+]], entity: ![[DBG_MOD1]],
! //CHECK: ![[DBG_SP2]] = distinct !DISubprogram(name: "hello", scope: ![[DBG_DIC]]
! //CHECK: ![[DBG_IE3]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[DBG_SP2]], entity: ![[DBG_MOD2]],
! CHECK: ![[DBG_MOD1:[0-9]+]] = !DIModule({{.*}}, name: "first"
! CHECK: ![[DBG_DIC:[0-9]+]] = distinct !DICompileUnit({{.*}}, imports: ![[DBG_IMPORTS:[0-9]+]], nameTableKind: None
! CHECK: ![[DBG_MOD2:[0-9]+]] = !DIModule({{.*}}, name: "second"
! CHECK: ![[DBG_IMPORTS]] = !{![[DBG_IE1:[0-9]+]], ![[DBG_IE2:[0-9]+]], ![[DBG_IE3:[0-9]+]]}
! CHECK: ![[DBG_IE1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[DBG_SP1:[0-9]+]], entity: ![[DBG_MOD1]],
! CHECK: ![[DBG_SP1]] = distinct !DISubprogram(name: "init", scope: ![[DBG_MOD2]]
! CHECK: ![[DBG_IE2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[DBG_SP2:[0-9]+]], entity: ![[DBG_MOD1]],
! CHECK: ![[DBG_SP2]] = distinct !DISubprogram(name: "hello", scope: ![[DBG_DIC]]
! CHECK: ![[DBG_IE3]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[DBG_SP2]], entity: ![[DBG_MOD2]],
16 changes: 16 additions & 0 deletions test/debug_info/nametable.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
!RUN: %flang %s -gdwarf-5 -c -o - | llvm-readelf -S - | FileCheck %s --check-prefix=NONAMESECTION
!RUN: %flang %s -g -c -o - | llvm-readelf -S - | FileCheck %s --check-prefix=NOPUBNAMESECTION

!RUN: %flang %s -gdwarf-5 -gpubnames -c -o - | llvm-readelf -S - | FileCheck %s --check-prefix=NAMESECTION
!RUN: %flang %s -g -gpubnames -c -o - | llvm-readelf -S - | FileCheck %s --check-prefix=PUBNAMESECTION

!Ensure that `.debug_names` or `.debug_pubnames` are NOT present by default.
!NONAMESECTION-NOT: .debug_names
!NOPUBNAMESECTION-NOT: .debug_pubnames
!Ensure that `.debug_names` or `.debug_pubnames` are present when `-gpubnames` is specified.
!NAMESECTION: .debug_names
!PUBNAMESECTION: .debug_pubnames

PROGRAM main
END PROGRAM main

2 changes: 1 addition & 1 deletion tools/flang2/docs/xflag.n
Original file line number Diff line number Diff line change
Expand Up @@ -3303,7 +3303,7 @@ Generating eh_frame.
.XB 0x20000000:
Generating eh_frame with .cfi directives: requires 120,0x10000000 to be on
.XB 0x40000000
AVAILABLE
Generate .debug_names/.debug_pubnames section.
.XB 0x80000000:
no license check in executable.

Expand Down
30 changes: 27 additions & 3 deletions tools/flang2/flang2exe/ll_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ enum FieldType {
DWVirtualityField,
DWEncodingField,
DWEmissionField,
SignedOrMDField
SignedOrMDField,
DebugNameTableKindField
};

enum FieldFlags {
Expand Down Expand Up @@ -957,7 +958,7 @@ static const MDTemplate Tmpl_DICompileUnit[] = {

/* "subprograms" removed from DICompileUnit in LLVM 3.9 */
static const MDTemplate Tmpl_DICompileUnit_ver39[] = {
{ "DICompileUnit", TF, 13 },
{ "DICompileUnit", TF, 14 },
{ "tag", DWTagField, FlgHidden },
{ "file", NodeField },
{ "language", DWLangField },
Expand All @@ -970,7 +971,8 @@ static const MDTemplate Tmpl_DICompileUnit_ver39[] = {
{ "globals", NodeField },
{ "emissionKind", DWEmissionField },
{ "imports", NodeField },
{ "splitDebugFilename", StringField }
{ "splitDebugFilename", StringField },
{ "nameTableKind", DebugNameTableKindField }
};

static const MDTemplate Tmpl_DICompileUnit_pre34[] = {
Expand Down Expand Up @@ -1556,6 +1558,24 @@ dwarf_emission_name(int value)
}
}

/**
\brief generate DWARF table kind
*/
static const char *
dwarf_table_name(int value)
{
switch (value) {
case 0:
return "Default";
case 1:
return "GNU";
case 2:
return "None";
default:
return "None";
}
}

/**
\brief Write out an an LL_MDRef as a field in a specialised MDNode class
\param out file to write to
Expand Down Expand Up @@ -1694,6 +1714,10 @@ write_mdfield(FILE *out, LL_Module *module, int needs_comma, LL_MDRef mdref,
fprintf(out, "%s%s: %s", prefix, tmpl->name, dwarf_emission_name(value));
break;

case DebugNameTableKindField:
fprintf(out, "%s%s: %s", prefix, tmpl->name, dwarf_table_name(value));
break;

default:
interr("metadata elem should not be an int", tmpl->type, ERR_unused);
}
Expand Down
2 changes: 2 additions & 0 deletions tools/flang2/flang2exe/lldebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ lldbg_create_compile_unit_mdnode(LL_DebugInfo *db, int lang_tag, char *filename,
llmd_add_i32(mdb, 1); /* emissionMode: FullDebug */
llmd_add_md(mdb, *imported_entity_list);
llmd_add_string(mdb, "");
if (!XBIT(120, 0x40000000))
llmd_add_i32(mdb, 2); /* nameTableKind: None */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the other values (0,1)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, these are just provision of other accelerated table like GNU but llvm prefers it own kind of tables by default.

}

llmd_set_distinct(mdb);
Expand Down