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

[llvm-dwarfdump] pretty-print DW_AT_call_origin reference #71693

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

OCHyams
Copy link
Contributor

@OCHyams OCHyams commented Nov 8, 2023

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 8, 2023

@llvm/pr-subscribers-debuginfo

Author: Orlando Cazalet-Hyams (OCHyams)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDie.cpp (+2-1)
  • (added) llvm/test/tools/llvm-dwarfdump/X86/prettyprint_call_site.yaml (+87)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index fcedef8db82185c..0f01933002c06db 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -190,7 +190,8 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
   // We have dumped the attribute raw value. For some attributes
   // having both the raw value and the pretty-printed value is
   // interesting. These attributes are handled below.
-  if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
+  if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin ||
+      Attr == DW_AT_call_origin) {
     if (const char *Name =
             Die.getAttributeValueAsReferencedDie(FormValue).getName(
                 DINameKind::LinkageName))
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_call_site.yaml b/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_call_site.yaml
new file mode 100644
index 000000000000000..2e44fcbcb131318
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_call_site.yaml
@@ -0,0 +1,87 @@
+# RUN: yaml2obj %s | llvm-dwarfdump - | FileCheck %s
+
+## Check the name (preferring linkage name) of the DW_AT_call_origin DIE
+## reference is printed after the address.
+
+# CHECK: DW_TAG_call_site
+# CHECK-NEXT: DW_AT_call_origin (0x{{[0-9a-f]+}} "_Z2f2v")
+
+# CHECK: DW_TAG_call_site
+# CHECK-NEXT: DW_AT_call_origin (0x{{[0-9a-f]+}} "f1")
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+DWARF:
+  debug_str:
+    - "_Z2f2v"
+    - "f2"
+    - "f1"
+
+  debug_abbrev:
+    - Table:
+      - Code:            0x0000000000000001
+        Tag:             DW_TAG_compile_unit
+        Children:        DW_CHILDREN_yes
+        Attributes:
+          - Attribute:       DW_AT_low_pc
+            Form:            DW_FORM_addr
+      - Code:            0x0000000000000002
+        Tag:             DW_TAG_subprogram
+        Children:        DW_CHILDREN_yes
+        Attributes:
+          - Attribute:       DW_AT_name
+            Form:            DW_FORM_strp
+          - Attribute:       DW_AT_low_pc
+            Form:            DW_FORM_addr
+          - Attribute:       DW_AT_high_pc
+            Form:            DW_FORM_addr
+      - Code:            0x0000000000000003
+        Tag:             DW_TAG_call_site
+        Children:        DW_CHILDREN_no
+        Attributes:
+          - Attribute:   DW_AT_call_origin
+            Form:        DW_FORM_ref4
+      - Code:            0x0000000000000004
+        Tag:             DW_TAG_subprogram
+        Children:        DW_CHILDREN_no
+        Attributes:
+          - Attribute:       DW_AT_linkage_name
+            Form:            DW_FORM_strp
+          - Attribute:       DW_AT_name
+            Form:            DW_FORM_strp
+          - Attribute:       DW_AT_declaration
+            Form:            DW_FORM_flag_present
+  debug_info:
+    - Length:          0x3b
+      Version:         5
+      UnitType:        0x01 # DW_TU_compile
+      AbbrOffset:      0x0000000000000000
+      AddrSize:        8
+      Entries:
+        - AbbrCode:    0x00000001          # start compile unit
+          Values:                          #
+            - Value:   0x0000000000000000  #
+        - AbbrCode:    0x00000002          ## start f1
+          Values:                          ##
+            - Value:   0x000000000000000a  ##
+            - Value:   0x0000000000001000  ##
+            - Value:   0x0000000000002000  ##
+        - AbbrCode:    0x00000003          ### call site
+          Values:                          ###
+            - Value:   0x0000000000000035  ### (f2)
+        - AbbrCode:    0x00000003          ### call site
+          Values:                          ###
+            - Value:   0x0000000000000015  ### (f1)
+        - AbbrCode:    0x00000000          ## end f1
+          Values:      []                  #
+        - AbbrCode:    0x00000004          ## f2
+          Values:                          ##
+            - Value:   0x0000000000000000  ##
+            - Value:   0x0000000000000007  ##
+        - AbbrCode:    0x00000000          # end compile unit
+          Values:      []
+...

Copy link
Member

@jryans jryans left a comment

Choose a reason for hiding this comment

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

Looks great to me, thanks for improving llvm-dwarfdump output! 😄

If you search the DWARF spec for "a reference", it looks like there are various other attributes that could also be given the same treatment as well... No need to do that in this PR though, just passing it along as a potential further improvement.

@OCHyams
Copy link
Contributor Author

OCHyams commented Nov 8, 2023

Looks great to me, thanks for improving llvm-dwarfdump output!

I was inspired by your recent change!

If you search the DWARF spec for "a reference", it looks like there are various other attributes that could also be given the same treatment as well... No need to do that in this PR though, just passing it along as a potential further improvement.

Yeah agreed. FWIW I chose this one as I recently spent a decent amount of time looking at call site info.

Thanks for the review. I'll land this tomorrow to avoid knocking out bots before I sign off.

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.

Looks good to me.

I had a look around and couldn't find some existing code that already tests for whole DWARF attribute classes (like some kind of isReference function) - but maybe it's hiding somewhere, or would be nice to write one eventually.

@OCHyams OCHyams merged commit fbc6520 into llvm:main Nov 9, 2023
4 of 5 checks passed
@OCHyams OCHyams deleted the pretty-call-site branch January 5, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants