Skip to content

Add test for dwarf verification JSON output #124936

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

Merged
merged 2 commits into from
Jan 30, 2025
Merged

Add test for dwarf verification JSON output #124936

merged 2 commits into from
Jan 30, 2025

Conversation

youngd007
Copy link
Contributor

Summary:
6244dfe LLVM commit added the ability
for llvm-dwarfdump to specify --verify-json and get a JSON aggregation of the DWARF errors in a file. This diff improves the testing by ensuring we validate the expected JSON shape.
A follow up diff will modify the JSON and this ensures we can verify.

Test Plan:
ninja check-llvm-tools-llvm-dwarfdump

Summary:
    6244dfe LLVM commit added the ability
for llvm-dwarfdump to specify --verify-json and get a JSON aggregation of t
he DWARF errors.  This diff improves the testing by ensuring we validate th
e expected JSON shape.
    A follow up diff will modify the JSON and this ensures we can verify.
he DWARF errors.  This diff improves the testing by ensuring we validate th
e expected JSON shape.
    A follow up diff will modify the JSON and this ensures we can verify.

    Test Plan:
       ninja check-llvm-tools-llvm-dwarfdump
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2025

@llvm/pr-subscribers-debuginfo

Author: None (youngdfb)

Changes

Summary:
6244dfe LLVM commit added the ability
for llvm-dwarfdump to specify --verify-json and get a JSON aggregation of the DWARF errors in a file. This diff improves the testing by ensuring we validate the expected JSON shape.
A follow up diff will modify the JSON and this ensures we can verify.

Test Plan:
ninja check-llvm-tools-llvm-dwarfdump


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

2 Files Affected:

  • (added) llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify--completeness-json-output.s (+172)
  • (modified) llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-completeness.s (-1)
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify--completeness-json-output.s b/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify--completeness-json-output.s
new file mode 100644
index 00000000000000..c4b7ffe1d2d8e7
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify--completeness-json-output.s
@@ -0,0 +1,172 @@
+# RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj -o - | not llvm-dwarfdump -verify --verify-json=%t.json -
+# RUN: FileCheck %s --input-file %t.json
+
+# CHECK: {"error-categories":{"Name Index DIE entry missing name":{"count":10}},"error-count":10}
+# CHECK-NOT: error: Name Index @ 0x0: Entry for DIE @ {{.*}} (DW_TAG_variable) with name var_block_addr missing.
+
+        .section        .debug_loc,"",@progbits
+.Ldebug_loc0:
+        .quad   0
+        .quad   1
+        .short  .Lloc0_end-.Lloc0_start # Loc expr size
+.Lloc0_start:
+        .byte   3                       # DW_OP_addr
+        .quad 0x47
+.Lloc0_end:
+        .quad   0
+        .quad   0
+
+        .section        .debug_abbrev,"",@progbits
+        .byte   1                       # Abbreviation Code
+        .byte   17                      # DW_TAG_compile_unit
+        .byte   1                       # DW_CHILDREN_yes
+        .byte   37                      # DW_AT_producer
+        .byte   8                       # DW_FORM_string
+        .byte   17                      # DW_AT_low_pc
+        .byte   1                       # DW_FORM_addr
+        .byte   18                      # DW_AT_high_pc
+        .byte   6                       # DW_FORM_data4
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   2                       # Abbreviation Code
+        .byte   52                      # DW_TAG_variable
+        .byte   0                       # DW_CHILDREN_no
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   2                       # DW_AT_location
+        .byte   24                      # DW_FORM_exprloc
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   3                       # Abbreviation Code
+        .byte   46                      # DW_TAG_subprogram
+        .byte   1                       # DW_CHILDREN_yes
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   110                     # DW_AT_linkage_name
+        .byte   8                       # DW_FORM_string
+        .byte   82                      # DW_AT_entry_pc
+        .byte   1                       # DW_FORM_addr
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   4                       # Abbreviation Code
+        .byte   57                      # DW_TAG_namespace
+        .byte   1                       # DW_CHILDREN_yes
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   5                       # Abbreviation Code
+        .byte   52                      # DW_TAG_variable
+        .byte   0                       # DW_CHILDREN_no
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   2                       # DW_AT_location
+        .byte   23                      # DW_FORM_sec_offset
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   6                       # Abbreviation Code
+        .byte   57                      # DW_TAG_namespace
+        .byte   1                       # DW_CHILDREN_yes
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   7                       # Abbreviation Code
+        .byte   29                      # DW_TAG_inlined_subroutine
+        .byte   0                       # DW_CHILDREN_no
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   17                      # DW_AT_low_pc
+        .byte   1                       # DW_FORM_addr
+        .byte   18                      # DW_AT_high_pc
+        .byte   1                       # DW_FORM_addr
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   8                       # Abbreviation Code
+        .byte   10                      # DW_TAG_label
+        .byte   0                       # DW_CHILDREN_no
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   82                      # DW_AT_entry_pc
+        .byte   1                       # DW_FORM_addr
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+
+        .byte   0                       # EOM(3)
+        .section        .debug_info,"",@progbits
+
+.Lcu_begin0:
+        .long   .Lcu_end0-.Lcu_start0   # Length of Unit
+.Lcu_start0:
+        .short  4                       # DWARF version number
+        .long   .debug_abbrev           # Offset Into Abbrev. Section
+        .byte   8                       # Address Size (in bytes)
+        .byte   1                       # Abbrev [1] DW_TAG_compile_unit
+        .asciz  "hand-written DWARF"    # DW_AT_producer
+        .quad   0x0                     # DW_AT_low_pc
+        .long   0x100                   # DW_AT_high_pc
+
+        .byte   4                       # Abbrev [4] DW_TAG_namespace
+        .asciz  "namesp"                # DW_AT_name
+        .byte   2                       # Abbrev [2] DW_TAG_variable
+        .asciz  "var_block_addr"        # DW_AT_name
+        .byte   9                       # DW_AT_location
+        .byte   3                       # DW_OP_addr
+        .quad   0x47
+        .byte   0                       # End Of Children Mark
+
+        .byte   6                       # Abbrev [6] DW_TAG_namespace
+        .byte   5                       # Abbrev [5] DW_TAG_variable
+        .asciz  "var_loc_addr"          # DW_AT_name
+        .long   .Ldebug_loc0            # DW_AT_location
+        .byte   0                       # End Of Children Mark
+
+        .byte   2                       # Abbrev [2] DW_TAG_variable
+        .asciz  "var_loc_tls"           # DW_AT_name
+        .byte   1                       # DW_AT_location
+        .byte   0x9b                    # DW_OP_form_tls_address
+
+        .byte   2                       # Abbrev [2] DW_TAG_variable
+        .asciz  "var_loc_gnu_tls"       # DW_AT_name
+        .byte   1                       # DW_AT_location
+        .byte   0xe0                    # DW_OP_GNU_push_tls_address
+
+        .byte   3                       # Abbrev [3] DW_TAG_subprogram
+        .asciz  "fun_name"              # DW_AT_name
+        .asciz  "_Z8fun_name"           # DW_AT_linkage_name
+        .quad   0x47                    # DW_AT_entry_pc
+        .byte   7                       # Abbrev [7] DW_TAG_inlined_subroutine
+        .asciz  "fun_inline"            # DW_AT_name
+        .quad   0x48                    # DW_AT_low_pc
+        .quad   0x49                    # DW_AT_high_pc
+        .byte   8                       # Abbrev [8] DW_TAG_label
+        .asciz  "label"                 # DW_AT_name
+        .quad   0x4a                    # DW_AT_entry_pc
+        .byte   0                       # End Of Children Mark
+
+        .byte   0                       # End Of Children Mark
+.Lcu_end0:
+
+        .section        .debug_names,"",@progbits
+        .long   .Lnames_end0-.Lnames_start0 # Header: contribution length
+.Lnames_start0:
+        .short  5                       # Header: version
+        .short  0                       # Header: padding
+        .long   1                       # Header: compilation unit count
+        .long   0                       # Header: local type unit count
+        .long   0                       # Header: foreign type unit count
+        .long   0                       # Header: bucket count
+        .long   0                       # Header: name count
+        .long   .Lnames_abbrev_end0-.Lnames_abbrev_start0 # Header: abbreviation table size
+        .long   0                       # Header: augmentation length
+        .long   .Lcu_begin0             # Compilation unit 0
+.Lnames_abbrev_start0:
+        .byte   0                       # End of abbrev list
+.Lnames_abbrev_end0:
+.Lnames_entries0:
+.Lnames_end0:
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-completeness.s b/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-completeness.s
index b16f8658f87eca..9886968fdab996 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-completeness.s
+++ b/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-completeness.s
@@ -177,4 +177,3 @@
 .Lnames_abbrev_end0:
 .Lnames_entries0:
 .Lnames_end0:
-

@youngd007
Copy link
Contributor Author

@Jlalond check out this new test

@youngd007
Copy link
Contributor Author

This test is basically a copy of
https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-completeness.s
but we have the llvm-dwarfdump command emit JSON and then validate the JSON and be sure a line from raw output is not in JSON.

@felipepiovezan
Copy link
Contributor

is your intent to verify errors in the debug_names section? If so, you don't need to use assembly, it's possible to use a YAML format too, e.g.: llvm-project/llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp

@youngd007
Copy link
Contributor Author

is your intent to verify errors in the debug_names section? If so, you don't need to use assembly, it's possible to use a YAML format too, e.g.: llvm-project/llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp

The idea of the test is to validate the JSON emitted from the LLVM-dwarfdump script invocation is correct as there was no existing test for that that I could find.
The specifics of the test file aren't super important; I simply copied from an existing because it was already set up with several errors that I could then see in the JSON. Additionally, those types of errors, on missing names with different tags, is the extension I am looking to follow up with. By either making keys more precise or adding a sub-breakdown under the category. Hence a JSON output change that should have a test.
Begs question of whether should be validating JSON for a clean DWARF, too to make sure JSON is empty.

The changes to modify JSON are in DWARFVerifier.h & llvm-project/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp I don't see a unit test setup for DWARFVerifier.

Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

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

Just remove the whitespace only change to a different file and this is good to go.

@Jlalond
Copy link
Contributor

Jlalond commented Jan 29, 2025

A follow up diff will modify the JSON and this ensures we can verify.

@youngdfb does this mean this test will fail on check-in? Or do you intend to extend this test after your future patch

@youngd007
Copy link
Contributor Author

A follow up diff will modify the JSON and this ensures we can verify.

@youngdfb does this mean this test will fail on check-in? Or do you intend to extend this test after your future patch

No this is simply testing the existing JSON structure. So it passes now. A change would break this test, though, which is good.

@youngd007
Copy link
Contributor Author

Eliminate white space change. Add another test for simple, empty DWARF that validates good and produces the empty, 'no error' JSON. @clayborg this should be ready

@clayborg clayborg merged commit e058c73 into llvm:main Jan 30, 2025
8 checks passed
Copy link

@youngdfb Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Jlalond pushed a commit that referenced this pull request Feb 19, 2025
Looks like #124936 was reverted
(for modifying JSON output), but the test for JSON output with errors
was deleted in #126587 (to
attempt to fix failing build)
This will add back a test and a new one for llvm-dwarfdump to validate
the JSON for errors. One case where the sub-categories will eventually
appear and another where not.

test plan:
ninja check-llvm-tools-llvm-dwarfdump
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 19, 2025
…685)

Looks like llvm/llvm-project#124936 was reverted
(for modifying JSON output), but the test for JSON output with errors
was deleted in llvm/llvm-project#126587 (to
attempt to fix failing build)
This will add back a test and a new one for llvm-dwarfdump to validate
the JSON for errors. One case where the sub-categories will eventually
appear and another where not.

test plan:
ninja check-llvm-tools-llvm-dwarfdump
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.

5 participants