llvm-project/llvm/test/tools/llvm-dwarfdump/X86
Pedro Alves ac6df7fcc5 llvm-dwarfdump: Don't crash if DW_AT_{decl,call}_{file,line} uses signed form
The DWARF spec says:

 Any debugging information entry representing the declaration of an object,
 module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and
 DW_AT_decl_column attributes, each of whose value is an unsigned integer
							 ^^^^^^^^
 constant.

If however, a producer happens to emit DW_AT_decl_file /
DW_AT_decl_line using a signed integer form, llvm-dwarfdump crashes,
like so:

     (... snip ...)
     0x000000b4:   DW_TAG_structure_type
                     DW_AT_name      ("test_struct")
                     DW_AT_byte_size (136)
                     DW_AT_decl_file (llvm-dwarfdump: (... snip ...)/llvm/include/llvm/ADT/Optional.h:197: T& llvm::optional_detail::OptionalStorage<T, true>::getValue() &
 [with T = long unsigned int]: Assertion `hasVal' failed.
     PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
     Stack dump:
     0.      Program arguments: /opt/rocm/llvm/bin/llvm-dwarfdump ./testsuite/outputs/gdb.rocm/lane-pc-vega20/lane-pc-vega20-kernel.so
      #0 0x000055cc8e78315f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
      #1 0x000055cc8e780d3d SignalHandler(int) Signals.cpp:0:0
      #2 0x00007f8f2cae8420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
      #3 0x00007f8f2c58d00b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
      #4 0x00007f8f2c56c859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
      #5 0x00007f8f2c56c729 get_sysdep_segment_value /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:509:8
      #6 0x00007f8f2c56c729 _nl_load_domain /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:970:34
      #7 0x00007f8f2c57dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
      #8 0x000055cc8e58ceb9 llvm::DWARFDie::dump(llvm::raw_ostream&, unsigned int, llvm::DIDumpOptions) const (/opt/rocm/llvm/bin/llvm-dwarfdump+0x2e0eb9)
      #9 0x000055cc8e58bec3 llvm::DWARFDie::dump(llvm::raw_ostream&, unsigned int, llvm::DIDumpOptions) const (/opt/rocm/llvm/bin/llvm-dwarfdump+0x2dfec3)
     #10 0x000055cc8e5b28a3 llvm::DWARFCompileUnit::dump(llvm::raw_ostream&, llvm::DIDumpOptions) (.part.21) DWARFCompileUnit.cpp:0:0

Likewise with DW_AT_call_file / DW_AT_call_line.

The problem is that the code in llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
dumping these attributes assumes that
FormValue.getAsUnsignedConstant() returns an armed optional.  If in
debug mode, we get an assertion line the above.  If in release mode,
and asserts are compiled out, then we proceed as if the optional had a
value, running into undefined behavior, printing whatever random
value.

Fix this by checking whether the optional returned by
FormValue.getAsUnsignedConstant() has a value, like done in other
places.

In addition, DWARFVerifier.cpp is validating DW_AT_call_file /
DW_AT_decl_file, but not AT_call_line / DW_AT_decl_line.  This commit
fixes that too.

The llvm-dwarfdump/X86/verify_file_encoding.yaml testcase is extended
to cover these cases.  Current llvm-dwarfdump crashes running the
newly-extended test.

"make check-llvm-tools-llvm-dwarfdump" shows no regressions, on x86-64
GNU/Linux.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D129392
2022-07-08 21:35:32 +00:00
..
Inputs Move dwarfdump-invalid.test into the tools/llvm-dwarfdump directory. 2021-06-23 12:00:34 -07:00
DW_AT_defaulted.s [DebugInfo] Add test for dumping DW_AT_defaulted 2021-09-20 16:43:53 -04:00
DW_AT_object_pointer.s DebugInfo: Correct/improve type formatting (pointers to function types especially) 2021-09-03 12:22:28 -07:00
LTO_CCU_zero_loc_cov.ll [llvm-dwarfdump][Statistics] Handle LTO cases with cross CU referencing 2021-11-24 13:50:47 +01:00
apple-names-die-offset-data.s
apple-names-die-offset-ref.s
apple_names_verify_data.s
apple_names_verify_form.s
apple_names_verify_num_atoms.s
apple_types_verify_tag.s
archive.test
brief.s
callsite-invalid.s
debug-abbrev.s
debug-entry-invalid.s llvm-dwarfdump: Print warnings on invalid DWARF 2021-06-27 11:38:35 +02:00
debug-line-dw-lne-end-sequence.s
debug-line-dw-lns-copy.s
debug-line.s
debug-names-find-dwo.s
debug-names-find.s
debug-names-many-tu.s
debug-names-misaligned.s
debug-names-multi-find.s
debug-names-verify-abbrev-duplicate.s
debug-names-verify-abbrev-forms.s
debug-names-verify-abbrev-short.s
debug-names-verify-buckets.s
debug-names-verify-completeness.s
debug-names-verify-cu-lists.s
debug-names-verify-entries.s
debug-names-verify-no-buckets.s
debug-names-verify-short1.s
debug-names-verify-short2.s
debug-names-verify-short3.s
debug-names-verify-unhashed-names.s
debug-names-verify-wrong-hash.s
debug-verify-object.s
debug_addr.s
debug_addr_64bit_address.s
debug_addr_absent.s
debug_addr_address_size_mismatch.s
debug_addr_address_size_not_multiple.s
debug_addr_dwarf4.s
debug_addr_dwarf64.s
debug_addr_empty.s
debug_addr_invalid_addr_size.s [DebugInfo] Expand ability to load 2-byte addresses in dwarf sections 2021-10-21 17:31:00 -07:00
debug_addr_rela.s
debug_addr_reserved_length.s
debug_addr_segment_selector.s
debug_addr_small_length_field.s
debug_addr_too_small_for_extended_length_field.s
debug_addr_too_small_for_length_field.s
debug_addr_too_small_for_section.s
debug_addr_unsupported_version.s
debug_aranges-error.s
debug_expr_convert.s
debug_expr_convert_generic.s
debug_frame_GNU_args_size.s
debug_frame_LLVM_def_cfa_aspace.s Implement DW_CFA_LLVM_* for Heterogeneous Debugging 2021-06-14 08:51:50 +05:30
debug_frame_offset.test Fix bug in .eh_frame/.debug_frame PC offset calculation for DW_EH_PE_pcrel 2021-04-15 15:06:20 +04:00
debug_info_addrx.s
debug_info_min_dwarf64.s
debug_info_offset.test
debug_line_dwarf64_large_table.s
debug_line_invalid.test
debug_line_many_files_v5.s
debug_line_offset.test
debug_line_short_prologue.s
debug_line_short_prologue_v4.s
debug_loc-OP_addr.s
debug_loc_OP_GNU_entry_value.s
debug_loc_OP_entry_value.s llvm-dwarfdump: fix the counting when printing DW_OP_entry_value 2021-02-11 11:17:04 -08:00
debug_loc_base_address.s
debug_loc_dwo.s
debug_loc_offset.test
debug_loclists.s
debug_loclists_multiple.s
debug_loclists_nouse.s
debug_loclists_startx_length.s
debug_loclists_unused_invalid.s libDebugInfoDWARF: Don't try to parse loclist[.dwo] headers when parsing debug_info[.dwo] 2020-10-13 22:28:59 -07:00
debug_pub_tables_error_cases.s
debug_rnglists.s llvm-dwarfdump: Add support for DW_RLE_startx_endx 2020-10-04 17:50:43 -07:00
debug_rnglists_dwarf64.s
debug_rnglists_empty.s
debug_rnglists_invalid.s [DebugInfo] Expand ability to load 2-byte addresses in dwarf sections 2021-10-21 17:31:00 -07:00
debug_rnglists_reserved_length.s
debug_tls_relocs.s
debug_type_offset.test
debugloc.s
diff.test
dw_op_regval_type.s
dwarfdump-invalid.test Move dwarfdump-invalid.test into the tools/llvm-dwarfdump directory. 2021-06-23 12:00:34 -07:00
eh-frame-return-address-reg.s
empty-CU.s
enum.s
exprloc.s
find.test
form.test
formclass2.s
formclass3.s [Debug-Info][llvm-dwarfdump] Don't try to dump location 2021-07-27 07:28:59 +00:00
formclass4.s
gnu_call_site.s
inlined_variables_with_zero_cov.test [llvm-dwarfdump] Fix split-dwarf bug in stats for inlined var loc cov 2021-04-26 01:56:15 -07:00
invalid_abbrev_offset.s
invalid_abstract_origin.s
lc_malformed.test Improve error handling in llvm-dwarfdump. 2021-06-23 10:44:13 -07:00
lit.local.cfg
locstats-big-number-of-bytes.yaml [llvm-dwarfdump] Fix unsigned overflow when calculating stats 2021-10-15 12:15:58 +02:00
locstats-bytes-overflow.yaml [llvm-locstats] Move the test from D110621 into test/llvm-locstats/ dir 2021-10-27 17:36:19 +02:00
locstats-for-absctract-origin-vars.yaml [llvm-dwarfdump] Fix unsigned overflow when calculating stats 2021-10-15 12:15:58 +02:00
locstats.ll
lookup.s
multiple-sections.test
name.test
no-children.yaml
no_apple_names_verify.s
no_debug_addr.s
output.s [test] Use host platform specific error message substitution 2021-06-07 10:06:38 -04:00
parent_recurse_depth.s [test] Fix accidental match in parent_recurse_depth.s 2021-06-04 11:23:27 +01:00
prettyprint_local_types.s [llvm-dwarfdump] Do not print preceding :: for local types 2021-12-03 12:27:29 +02:00
prettyprint_type_units.s llvm-dwarfdump: Rebuild type names in dwo type units 2021-11-18 14:12:48 -08:00
prettyprint_type_units_split_v4.s llvm-dwarfdump: Rebuild type names in dwo type units 2021-11-18 14:12:48 -08:00
prettyprint_type_units_split_v5.s llvm-dwarfdump: Rebuild type names in dwo type units 2021-11-18 14:12:48 -08:00
prettyprint_types.s DebugInfo: Don't use enumerators in template names for debug info as they are not canonical 2022-04-05 17:16:42 +00:00
prettyprint_types_handcrafted.s Use {LITERAL} instead of regex escaping in some lit tests. NFC. 2022-01-14 10:55:00 +00:00
quiet.s [llvm-dwarfdump][test] Add missing dedicated tests for some options 2021-06-01 14:57:00 +01:00
section_sizes_archive.test
section_sizes_coff.test [llvm-dwarfdump] StringMap -> MapVector to make iteration order stable 2021-02-25 20:05:05 -08:00
section_sizes_elf.test Revert "Use the default seed value for djb hash for StringMap" 2021-03-01 14:00:39 +01:00
section_sizes_fat_binary.test
section_sizes_macho.test Revert "Use the default seed value for djb hash for StringMap" 2021-03-01 14:00:39 +01:00
section_sizes_no_debug_sections.test
simplified-template-names-fail.s DebugInfo: Make the simplified template names prefix more unique 2022-04-06 18:25:46 +00:00
simplified-template-names.s DebugInfo: Make the simplified template names prefix more unique 2022-04-06 18:25:46 +00:00
sources.test [llvm-dwarfdump] --show-sources option to show all sources 2022-06-30 09:53:08 -07:00
statistics-base-address.s
statistics-dwo.test [llvm-dwarfdump] Fix unsigned overflow when calculating stats 2021-10-15 12:15:58 +02:00
statistics-v3.test [llvm-dwarfdump] Fix unsigned overflow when calculating stats 2021-10-15 12:15:58 +02:00
statistics.ll [llvm-dwarfdump] Fix unsigned overflow when calculating stats 2021-10-15 12:15:58 +02:00
stats-dbg-callsite-info.ll
stats-inlining-multi-cu.ll
stats-inlining-single-cu.ll
stats-mulitple-cu-out-of-line.ll
stats-multiple-cu-members.ll
stats-multiple-cu-same-name.ll
stats-scope-bytes-covered.yaml [llvm-dwarfdump] Fix unsigned overflow when calculating stats 2021-10-15 12:15:58 +02:00
stats-v5-ranges-dwo.s Fix test - mistaken hardcoded path from my local machine. 2021-07-12 18:39:41 -07:00
stripped.test
tag-parent-offset.yaml [llvm-dwarfdump] dump link to the immediate parent. 2021-11-09 14:14:06 +03:00
tombstone.s llvm-dwarfdump: Don't try to parse rnglist tables when dumping CUs 2020-10-04 19:18:14 -07:00
typeunit-name.s
typeunit-v4-dwarf64.s
typeunit-v5-dwarf64.s
valid-call-site-GNU-extensions.ll
verbose.test [llvm-dwarfdump] dump link to the immediate parent. 2021-11-09 14:14:06 +03:00
verify_attr_file_indexes.yaml DWARFVerifier: Verbosely dump DIEs in verifier reports 2021-12-13 19:00:38 -08:00
verify_attr_file_indexes_no_files.yaml DWARFVerifier: Verbosely dump DIEs in verifier reports 2021-12-13 19:00:38 -08:00
verify_broken_exprloc.s DWARFVerifier: Verbosely dump DIEs in verifier reports 2021-12-13 19:00:38 -08:00
verify_compatible_tags.s
verify_cu_dont_share_line_table.yaml Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml 2021-08-13 19:09:41 -07:00
verify_cu_ranges.yaml [DWARF][Verifier] Do not add child DieRangeInfo with empty address range to the parent. 2021-08-22 19:39:21 +03:00
verify_curanges_incomplete.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_debug_abbrev.s
verify_debug_info.s DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_debug_info2.s
verify_die_ranges.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_duplicate_file_warning.yaml Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml 2021-08-13 19:09:41 -07:00
verify_elided_doesnt_fail.yaml Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml 2021-08-13 19:09:41 -07:00
verify_file_encoding.yaml llvm-dwarfdump: Don't crash if DW_AT_{decl,call}_{file,line} uses signed form 2022-07-08 21:35:32 +00:00
verify_invalid_cu_ref.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_invalid_die_range.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_invalid_line_file_index.yaml Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml 2021-08-13 19:09:41 -07:00
verify_invalid_line_sequence.yaml Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml 2021-08-13 19:09:41 -07:00
verify_invalid_line_table_prologue_dir_index.yaml Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml 2021-08-13 19:09:41 -07:00
verify_invalid_ranges.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_invalid_ref_addr.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_invalid_ref_addr_between.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_invalid_ref_multi_section.s Add missing triple for test 2021-08-15 12:32:12 -07:00
verify_invalid_rnglists.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_invalid_stmt_list.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_invalid_strp.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_lexical_block_ranges.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_nested_functions.yaml Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml 2021-08-13 19:09:41 -07:00
verify_no_linkage_name.s
verify_overlapping_cu_ranges.yaml DWARFVerifier: Verbosely dump DIEs in verifier reports 2021-12-13 19:00:38 -08:00
verify_overlapping_function_ranges.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_overlapping_function_ranges_distinct_sections.s llvm-dwarfdump --verify: Don't diagnose functions in different sections as overlapping 2021-10-28 17:13:57 -07:00
verify_overlapping_lexical_block_ranges.yaml DWARFVerifier: fix remaining tests and compact/rephrase the output 2021-12-29 14:47:43 -08:00
verify_parent_zero_length.yaml DWARFVerifier: Verbosely dump DIEs in verifier reports 2021-12-13 19:00:38 -08:00
verify_split_cu.s DWARFVerifier: Skip resolution failures for locations in dwo files 2021-12-16 22:24:32 -08:00
verify_split_cu_ranges.s DWARFVerifier: Don't error on missing ranges in Split DWARF 2021-12-16 20:34:44 -08:00
verify_strings.s DebugInfo: Fix test to match comment 2021-12-14 16:03:34 -08:00
verify_unit_header_chain.s DWARFVerifier: Don't parse all units twice 2021-11-24 14:03:56 -08:00