Skip to content

Conversation

@CarlosAlbertoEnciso
Copy link
Member

Consider the case when the compiler generates a static member. Any consumer of the debug info generated for that case, would benefit if that member has the DW_AT_artificial flag.

Consider the case when the compiler generates a static member. Any consumer of the debug info generated for that case, would benefit if that member has the DW_AT_artificial flag.
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2024

@llvm/pr-subscribers-debuginfo

Author: Carlos Alberto Enciso (CarlosAlbertoEnciso)

Changes

Consider the case when the compiler generates a static member. Any consumer of the debug info generated for that case, would benefit if that member has the DW_AT_artificial flag.


Full diff: https://github.com/llvm/llvm-project/pull/115851.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (+4)
  • (added) llvm/test/DebugInfo/Generic/artificial-static-member.ll (+41)
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index c6d9fcfb0b76c1..76f7b0920434bb 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1784,6 +1784,10 @@ DIE *DwarfUnit::getOrCreateStaticMemberDIE(const DIDerivedType *DT) { addFlag(StaticMemberDIE, dwarf::DW_AT_external); addFlag(StaticMemberDIE, dwarf::DW_AT_declaration); + // Consider the case when the static member was created by the compiler. + if (DT->isArtificial()) + addFlag(StaticMemberDIE, dwarf::DW_AT_artificial); + // FIXME: We could omit private if the parent is a class_type, and // public if the parent is something else. addAccess(StaticMemberDIE, DT->getFlags()); diff --git a/llvm/test/DebugInfo/Generic/artificial-static-member.ll b/llvm/test/DebugInfo/Generic/artificial-static-member.ll new file mode 100644 index 00000000000000..3263c976e39158 --- /dev/null +++ b/llvm/test/DebugInfo/Generic/artificial-static-member.ll @@ -0,0 +1,41 @@ +; RUN: llc -O0 -filetype=obj < %s | \ +; RUN: llvm-dwarfdump --debug-info - | FileCheck %s + +; LLVM IR generated from: + +; struct S { +; static int Member; <-- Manually marked as artificial +; }; +; int S::Member = 1; + +source_filename = "artificial-static-member.cpp" +target triple = "x86_64-pc-linux-gnu" + +@_ZN1S6MemberE = dso_local global i32 1, align 4, !dbg !0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!9, !10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "Member", linkageName: "_ZN1S6MemberE", scope: !2, type: !5, isLocal: false, isDefinition: true, declaration: !6) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, emissionKind: FullDebug, globals: !4) +!3 = !DIFile(filename: "artificial-static-member.cpp", directory: "") +!4 = !{!0} +!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!6 = !DIDerivedType(tag: DW_TAG_variable, name: "Member", scope: !7, baseType: !5, flags: DIFlagArtificial | DIFlagStaticMember) +!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", size: 8, flags: DIFlagTypePassByValue, elements: !8, identifier: "_ZTS1S") +!8 = !{!6} +!9 = !{i32 7, !"Dwarf Version", i32 5} +!10 = !{i32 2, !"Debug Info Version", i32 3} + +; CHECK: {{.*}}DW_TAG_structure_type +; CHECK-NEXT: DW_AT_calling_convention +; CHECK-NEXT: DW_AT_name	("S") +; CHECK-NEXT: DW_AT_byte_size + +; CHECK: {{.*}}DW_TAG_variable +; CHECK-NEXT: DW_AT_name	("Member") +; CHECK-NEXT: DW_AT_type +; CHECK-NEXT: DW_AT_external	(true) +; CHECK-NEXT: DW_AT_declaration	(true) +; CHECK-NEXT: DW_AT_artificial	(true) 
@dwblaikie
Copy link
Collaborator

Any particular compiler generated static variables you have in mind? There aren't any C++ ones that come to mind - though of course LLVM isn't just for Clang/C++, but would be nice to have some documented use case, if there is one, for this. If there isn't one we can document/mention, it's probably still OK to do though, it's simple enough/cheap enough that it's not a big deal.

@CarlosAlbertoEnciso
Copy link
Member Author

CarlosAlbertoEnciso commented Nov 14, 2024

For classes with virtual functions, Clang generates a class member _vptr$XXX with XXX being the class name. It points to the vtable function pointers.

.debug_info contents: DW_TAG_structure_type DW_AT_name	("MyClass") ... DW_TAG_member DW_AT_name	("_vptr$MyClass") DW_AT_type	(0x000000ba "int (**)()") DW_AT_data_member_location	(0x00) DW_AT_artificial	(true) ... 
@CarlosAlbertoEnciso
Copy link
Member Author

We want to allow our (SCE) debugger to have a direct access to the whole vtable, thru a static data member _vtable$.

.debug_info contents: ... DW_TAG_variable DW_AT_specification	("_vtable$") DW_AT_location	(DW_OP_addrx 0x0) --> index (0) in the '.debug_addr' DW_AT_linkage_name	("_ZTVN7MyClassE") ... DW_TAG_structure_type DW_AT_name	("MyClass") ... DW_TAG_variable DW_AT_name	("_vtable$") DW_AT_type	(0x000000d7 "void *") DW_AT_artificial	(true) ... .debug_addr contents: ... Addrs: [ Address of vtable for MyClass ... ] 

We need for the generated static data member to be artificial.

Copy link
Collaborator

@dwblaikie dwblaikie left a comment

Choose a reason for hiding this comment

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

SGTM

@CarlosAlbertoEnciso
Copy link
Member Author

@dwblaikie Thanks for your feedback.

@CarlosAlbertoEnciso CarlosAlbertoEnciso merged commit c2a9bba into llvm:main Nov 15, 2024
8 of 10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 15, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-5 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/9521

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure) ******************** TEST 'LLVM :: DebugInfo/Generic/artificial-static-member.ll' FAILED ******************** Exit Code: 2 Command Output (stderr): -- RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llc -O0 -filetype=obj < /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/DebugInfo/Generic/artificial-static-member.ll | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-dwarfdump --debug-info - | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/DebugInfo/Generic/artificial-static-member.ll + /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llc -O0 -filetype=obj + /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/DebugInfo/Generic/artificial-static-member.ll + /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llvm-dwarfdump --debug-info - /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/llc: error: unable to get target for 'x86_64-pc-linux-gnu', see --version and --triple.error: -: The file was not recognized as a valid object file FileCheck error: '<stdin>' is empty. FileCheck command line: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/DebugInfo/Generic/artificial-static-member.ll -- ******************** 
@CarlosAlbertoEnciso
Copy link
Member Author

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-5 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/9521

Created PR that fix the test case: #116327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants