summaryrefslogtreecommitdiffstats
path: root/llvm/test/DebugInfo
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test/DebugInfo')
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-dwp.s277
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.s34
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.x86_64.obin0 -> 824 bytes
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.s36
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.x86_64.obin0 -> 832 bytes
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.s88
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.x86_64.obin0 -> 2296 bytes
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.s50
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.x86_64.obin0 -> 1264 bytes
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.s10
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.x86_64.obin0 -> 464 bytes
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.s500
-rw-r--r--llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.x86_64.obin0 -> 4000 bytes
-rw-r--r--llvm/test/DebugInfo/dwarfdump-str-offsets-invalid.test24
-rw-r--r--llvm/test/DebugInfo/dwarfdump-str-offsets.test76
15 files changed, 1095 insertions, 0 deletions
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-dwp.s b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-dwp.s
new file mode 100644
index 00000000000..8a9c03b77c0
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-dwp.s
@@ -0,0 +1,277 @@
+# Test object to verify that dwarfdump handles dwp files with DWARF v5 string
+# offset tables. We have 2 CUs and 2 TUs, where it is assumed that
+# CU1 and TU1 came from one object file, CU2 and TU2 from a second object
+# file.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets-dwp.s -filetype=obj \
+# -o dwarfdump-str_offsets-dwp.x86_64.o
+
+ .section .debug_str.dwo,"MS",@progbits,1
+str_producer:
+ .asciz "Handmade DWARF producer"
+str_CU1:
+ .asciz "Compile_Unit_1"
+str_CU1_dir:
+ .asciz "/home/test/CU1"
+str_CU2:
+ .asciz "Compile_Unit_2"
+str_CU2_dir:
+ .asciz "/home/test/CU2"
+str_TU1:
+ .asciz "Type_Unit_1"
+str_TU1_type:
+ .asciz "MyStruct_1"
+str_TU2:
+ .asciz "Type_Unit_2"
+str_TU2_type:
+ .asciz "MyStruct_2"
+
+ .section .debug_str_offsets.dwo,"",@progbits
+# Object files 1's portion of the .debug_str_offsets.dwo section.
+.debug_str_offsets_object_file1:
+
+# CU1's contribution (from object file 1)
+.debug_str_offsets_start_CU1:
+ .long .debug_str_offsets_end_CU1-.debug_str_offsets_base_CU1
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base_CU1:
+ .long str_producer-.debug_str.dwo
+ .long str_CU1-.debug_str.dwo
+ .long str_CU1_dir-.debug_str.dwo
+.debug_str_offsets_end_CU1:
+
+# TU1's contribution (from object file 1)
+.debug_str_offsets_start_TU1:
+ .long .debug_str_offsets_end_TU1-.debug_str_offsets_base_TU1
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base_TU1:
+ .long str_TU1-.debug_str.dwo
+ .long str_TU1_type-.debug_str.dwo
+.debug_str_offsets_end_TU1:
+
+# Object files 2's portion of the .debug_str_offsets.dwo section.
+.debug_str_offsets_object_file2:
+
+# CU2's contribution (from object file 2)
+.debug_str_offsets_start_CU2:
+ .long .debug_str_offsets_end_CU2-.debug_str_offsets_base_CU2
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base_CU2:
+ .long str_producer-.debug_str.dwo
+ .long str_CU2-.debug_str.dwo
+ .long str_CU2_dir-.debug_str.dwo
+.debug_str_offsets_end_CU2:
+
+# TU2's contribution (from object file 2)
+.debug_str_offsets_start_TU2:
+ .long .debug_str_offsets_end_TU2-.debug_str_offsets_base_TU2
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base_TU2:
+ .long str_TU2-.debug_str.dwo
+ .long str_TU2_type-.debug_str.dwo
+.debug_str_offsets_end_TU2:
+
+
+# Abbrevs are shared for all compile and type units
+ .section .debug_abbrev.dwo,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x25 # DW_AT_producer
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x02 # Abbrev code
+ .byte 0x41 # DW_TAG_type_unit
+ .byte 0x01 # DW_CHILDREN_yes
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x03 # Abbrev code
+ .byte 0x13 # DW_TAG_structure_type
+ .byte 0x00 # DW_CHILDREN_no (no members)
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+abbrev_end:
+
+ .section .debug_info.dwo,"",@progbits
+
+# DWARF v5 CU header.
+CU1_5_start:
+ .long CU1_5_end-CU1_5_version # Length of Unit
+CU1_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev. Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+# The DW_AT_str_offsets_base attribute for CU1 contains the offset of CU1's
+# contribution relative to the start of object file 1's portion of the
+# .debug_str_offsets section.
+ .long .debug_str_offsets_base_CU1-.debug_str_offsets_object_file1
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU1_5_end:
+
+CU2_5_start:
+ .long CU2_5_end-CU2_5_version # Length of Unit
+CU2_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev. Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+# The DW_AT_str_offsets_base attribute for CU2 contains the offset of CU2's
+# contribution relative to the start of object file 2's portion of the
+# .debug_str_offsets section.
+ .long .debug_str_offsets_base_CU2-.debug_str_offsets_object_file2
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU2_5_end:
+
+ .section .debug_types.dwo,"",@progbits
+# DWARF v5 Type unit header.
+TU1_5_start:
+ .long TU1_5_end-TU1_5_version # Length of Unit
+TU1_5_version:
+ .short 5 # DWARF version number
+ .byte 2 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev. Section
+ .quad 0x0011223344556677 # Type Signature
+ .long TU1_5_type-TU1_5_start # Type offset
+# The type-unit DIE, which has a name.
+ .byte 2 # Abbreviation code
+ .byte 0 # Index of the unit type name string
+# The DW_AT_str_offsets_base attribute for TU1 contains the offset of TU1's
+# contribution relative to the start of object file 1's portion of the
+# .debug_str_offsets section.
+ .long .debug_str_offsets_base_TU1-.debug_str_offsets_object_file1
+# The type DIE, which has a name.
+TU1_5_type:
+ .byte 3 # Abbreviation code
+ .byte 1 # Index of the type name string
+ .byte 0 # NULL
+ .byte 0 # NULL
+TU1_5_end:
+
+TU2_5_start:
+ .long TU2_5_end-TU2_5_version # Length of Unit
+TU2_5_version:
+ .short 5 # DWARF version number
+ .byte 2 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev. Section
+ .quad 0x00aabbccddeeff99 # Type Signature
+ .long TU2_5_type-TU2_5_start # Type offset
+# The type-unit DIE, which has a name.
+ .byte 2 # Abbreviation code
+ .byte 0 # Index of the unit type name string
+# The DW_AT_str_offsets_base attribute for TU2 contains the offset of TU2's
+# contribution relative to the start of object file 2's portion of the
+# .debug_str_offsets section.
+ .long .debug_str_offsets_base_TU2-.debug_str_offsets_object_file2
+# The type DIE, which has a name.
+TU2_5_type:
+ .byte 3 # Abbreviation code
+ .byte 1 # Index of the type name string
+ .byte 0 # NULL
+ .byte 0 # NULL
+TU2_5_end:
+
+ .section .debug_cu_index,"",@progbits
+ # The index header
+ .long 2 # Version
+ .long 3 # Columns of contribution matrix
+ .long 2 # number of units
+ .long 2 # number of hash buckets in table
+
+ # The signatures for both CUs.
+ .quad 0xddeeaaddbbaabbee # signature 1
+ .quad 0xff00ffeeffaaff00 # signature 2
+ # The indexes for both CUs.
+ .long 1 # index 1
+ .long 2 # index 2
+ # The sections to which both CUs contribute.
+ .long 1 # DW_SECT_INFO
+ .long 3 # DW_SECT_ABBREV
+ .long 6 # DW_SECT_STR_OFFSETS
+
+ # The starting offsets of both CU's contributions to info,
+ # abbrev and string offsets table.
+ .long CU1_5_start-.debug_info.dwo
+ .long 0
+ .long .debug_str_offsets_object_file1-.debug_str_offsets.dwo
+ .long CU2_5_start-.debug_info.dwo
+ .long 0
+ .long .debug_str_offsets_object_file2-.debug_str_offsets.dwo
+
+ # The lengths of both CU's contributions to info, abbrev and
+ # string offsets table.
+ .long CU1_5_end-CU1_5_start
+ .long abbrev_end-.debug_abbrev.dwo
+ .long .debug_str_offsets_end_CU1-.debug_str_offsets_start_CU1
+ .long CU2_5_end-CU2_5_start
+ .long abbrev_end-.debug_abbrev.dwo
+ .long .debug_str_offsets_end_CU2-.debug_str_offsets_start_CU2
+
+ .section .debug_tu_index,"",@progbits
+ # The index header
+ .long 2 # Version
+ .long 3 # Columns of contribution matrix
+ .long 2 # number of units
+ .long 2 # number of hash buckets in table
+
+ # The signatures for both TUs.
+ .quad 0xeeaaddbbaabbeedd # signature 1
+ .quad 0x00ffeeffaaff00ff # signature 2
+ # The indexes for both TUs.
+ .long 1 # index 1
+ .long 2 # index 2
+ # The sections to which both TUs contribute.
+ .long 2 # DW_SECT_TYPES
+ .long 3 # DW_SECT_ABBREV
+ .long 6 # DW_SECT_STR_OFFSETS
+
+ # The starting offsets of both TU's contributions to info,
+ # abbrev and string offsets table.
+ .long TU1_5_start-.debug_types.dwo
+ .long 0
+ .long .debug_str_offsets_object_file1-.debug_str_offsets.dwo
+ .long TU2_5_start-.debug_types.dwo
+ .long 0
+ .long .debug_str_offsets_object_file2-.debug_str_offsets.dwo
+
+ # The lengths of both TU's contributions to info, abbrev and
+ # string offsets table.
+ .long TU1_5_end-TU1_5_start
+ .long abbrev_end-.debug_abbrev.dwo
+ .long .debug_str_offsets_end_TU1-.debug_str_offsets_start_TU1
+ .long TU2_5_end-TU2_5_start
+ .long abbrev_end-.debug_abbrev.dwo
+ .long .debug_str_offsets_end_TU2-.debug_str_offsets_start_TU2
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.s b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.s
new file mode 100644
index 00000000000..361448af0e8
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.s
@@ -0,0 +1,34 @@
+# Test object to verify that llvm-dwarfdump handles an invalid string offsets
+# table.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets-invalid-1.s -filetype=obj \
+# -o dwarfdump-str-offsets-invalid-1.x86_64.o
+#
+# A rudimentary abbrev section.
+ .section .debug_abbrev,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+# A rudimentary compile unit to convince dwarfdump that we are dealing with a
+# DWARF v5 string offsets table.
+ .section .debug_info,"",@progbits
+
+# DWARF v5 CU header.
+ .long CU1_5_end-CU1_5_version # Length of Unit
+CU1_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# A compile-unit DIE, which has no attributes.
+ .byte 1 # Abbreviation code
+CU1_5_end:
+
+ .section .debug_str_offsets,"",@progbits
+# A degenerate section, not enough for a single contribution size.
+ .byte 2
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.x86_64.o b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.x86_64.o
new file mode 100644
index 00000000000..65aae84c22f
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-1.x86_64.o
Binary files differ
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.s b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.s
new file mode 100644
index 00000000000..2f0fdfce243
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.s
@@ -0,0 +1,36 @@
+# Test object to verify that llvm-dwarfdump handles an invalid string offsets
+# table.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets-invalid-2.s -filetype=obj \
+# -o dwarfdump-str-offsets-invalid-2.x86_64.o
+
+# A rudimentary abbrev section.
+ .section .debug_abbrev,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+# A rudimentary compile unit to convince dwarfdump that we are dealing with a
+# DWARF v5 string offsets table.
+ .section .debug_info,"",@progbits
+
+# DWARF v5 CU header.
+ .long CU1_5_end-CU1_5_version # Length of Unit
+CU1_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# A compile-unit DIE, which has no attributes.
+ .byte 1 # Abbreviation code
+CU1_5_end:
+
+ .section .debug_str_offsets,"",@progbits
+# A degenerate section with fewer bytes than required for a DWARF64 size.
+ .long 0xffffffff
+ .long 0
+ .short 4
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.x86_64.o b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.x86_64.o
new file mode 100644
index 00000000000..90d2074f19f
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-2.x86_64.o
Binary files differ
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.s b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.s
new file mode 100644
index 00000000000..b4355fe27f7
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.s
@@ -0,0 +1,88 @@
+# Test object to verify that llvm-dwarfdump handles an invalid string offsets
+# table.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets-invalid-3.s -filetype=obj \
+# -o dwarfdump-str-offsets-invalid-3.x86_64.o
+
+ .section .debug_str,"MS",@progbits,1
+str_producer:
+ .asciz "Handmade DWARF producer"
+str_CU1:
+ .asciz "Compile_Unit_1"
+str_CU1_dir:
+ .asciz "/home/test/CU1"
+str_CU2:
+ .asciz "Compile_Unit_2"
+str_CU2_dir:
+ .asciz "/home/test/CU2"
+str_TU:
+ .asciz "Type_Unit"
+str_TU_type:
+ .asciz "MyStruct"
+
+ .section .debug_str.dwo,"MS",@progbits,1
+dwo_str_CU_5_producer:
+ .asciz "Handmade split DWARF producer"
+dwo_str_CU_5_name:
+ .asciz "V5_split_compile_unit"
+dwo_str_CU_5_comp_dir:
+ .asciz "/home/test/splitCU"
+dwo_str_TU_5:
+ .asciz "V5_split_type_unit"
+dwo_str_TU_5_type:
+ .asciz "V5_split_Mystruct"
+
+# A rudimentary abbrev section.
+ .section .debug_abbrev,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+# A rudimentary compile unit to convince dwarfdump that we are dealing with a
+# DWARF v5 string offsets table.
+ .section .debug_info,"",@progbits
+
+# DWARF v5 CU header.
+ .long CU1_5_end-CU1_5_version # Length of Unit
+CU1_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# A compile-unit DIE, which has no attributes.
+ .byte 1 # Abbreviation code
+CU1_5_end:
+
+ .section .debug_str_offsets,"",@progbits
+# CU1's contribution
+# Invalid length
+ .long 0xfffffffe
+ .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base0:
+ .long str_producer
+ .long str_CU1
+ .long str_CU1_dir
+.debug_str_offsets_segment0_end:
+# CU2's contribution
+ .long .debug_str_offsets_segment1_end-.debug_str_offsets_base1
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base1:
+ .long str_producer
+ .long str_CU2
+ .long str_CU2_dir
+.debug_str_offsets_segment1_end:
+# The TU's contribution
+ .long .debug_str_offsets_segment2_end-.debug_str_offsets_base2
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base2:
+ .long str_TU
+ .long str_TU_type
+.debug_str_offsets_segment2_end:
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.x86_64.o b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.x86_64.o
new file mode 100644
index 00000000000..68f8c5f3be0
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-3.x86_64.o
Binary files differ
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.s b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.s
new file mode 100644
index 00000000000..8ec288151ec
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.s
@@ -0,0 +1,50 @@
+# Test object to verify that llvm-dwarfdump handles an invalid string offsets
+# table.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets-invalid-4.s -filetype=obj \
+# -o dwarfdump-str-offsets-invalid-4.x86_64.o
+
+ .section .debug_str,"MS",@progbits,1
+str_producer:
+ .asciz "Handmade DWARF producer"
+str_CU1:
+ .asciz "Compile_Unit_1"
+
+# A rudimentary abbrev section.
+ .section .debug_abbrev,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+# A rudimentary compile unit to convince dwarfdump that we are dealing with a
+# DWARF v5 string offsets table.
+ .section .debug_info,"",@progbits
+
+# DWARF v5 CU header.
+ .long CU1_5_end-CU1_5_version # Length of Unit
+CU1_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# A compile-unit DIE, which has no attributes.
+ .byte 1 # Abbreviation code
+CU1_5_end:
+
+# Every unit contributes to the string_offsets table.
+ .section .debug_str_offsets,"",@progbits
+# CU1's contribution
+# The length is not a multiple of 4. Check that we don't read off the
+# end.
+ .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base0:
+ .long str_producer
+ .long str_CU1
+ .byte 0
+.debug_str_offsets_segment0_end:
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.x86_64.o b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.x86_64.o
new file mode 100644
index 00000000000..8a17b0e6a51
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-4.x86_64.o
Binary files differ
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.s b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.s
new file mode 100644
index 00000000000..e185e407b63
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.s
@@ -0,0 +1,10 @@
+# Test object to verify that llvm-dwarfdump handles a degenerate string offsets
+# section.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets-invalid-5.s -filetype=obj \
+# -o dwarfdump-str-offsets-invalid-5.x86_64.o
+# Every unit contributes to the string_offsets table.
+ .section .debug_str_offsets,"",@progbits
+# A degenerate section, not enough for a single entry.
+ .byte 2
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.x86_64.o b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.x86_64.o
new file mode 100644
index 00000000000..6cfce83e565
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets-invalid-5.x86_64.o
Binary files differ
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.s b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.s
new file mode 100644
index 00000000000..e0a634c7c4a
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.s
@@ -0,0 +1,500 @@
+# Test object to verify dwarfdump handles v5 string offset tables.
+# We have 2 v5 CUs, a v5 TU, and a split v5 CU and TU.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets.s -filetype=obj \
+# -o dwarfdump-str-offsets.x86_64.o
+
+ .section .debug_str,"MS",@progbits,1
+str_producer:
+ .asciz "Handmade DWARF producer"
+str_CU1:
+ .asciz "Compile_Unit_1"
+str_CU1_dir:
+ .asciz "/home/test/CU1"
+str_CU2:
+ .asciz "Compile_Unit_2"
+str_CU2_dir:
+ .asciz "/home/test/CU2"
+str_TU:
+ .asciz "Type_Unit"
+str_TU_type:
+ .asciz "MyStruct"
+
+# Every unit contributes to the string_offsets table.
+ .section .debug_str_offsets,"",@progbits
+# CU1's contribution
+ .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base0:
+ .long str_producer
+ .long str_CU1
+ .long str_CU1_dir
+.debug_str_offsets_segment0_end:
+# CU2's contribution
+ .long .debug_str_offsets_segment1_end-.debug_str_offsets_base1
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base1:
+ .long str_producer
+ .long str_CU2
+ .long str_CU2_dir
+.debug_str_offsets_segment1_end:
+# The TU's contribution
+ .long .debug_str_offsets_segment2_end-.debug_str_offsets_base2
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base2:
+ .long str_TU
+ .long str_TU_type
+.debug_str_offsets_segment2_end:
+
+ .section .debug_str.dwo,"MS",@progbits,1
+dwo_str_CU_5_producer:
+ .asciz "Handmade split DWARF producer"
+dwo_str_CU_5_name:
+ .asciz "V5_split_compile_unit"
+dwo_str_CU_5_comp_dir:
+ .asciz "/home/test/splitCU"
+dwo_str_TU_5:
+ .asciz "V5_split_type_unit"
+dwo_str_TU_5_type:
+ .asciz "V5_split_Mystruct"
+
+ .section .debug_str_offsets.dwo,"",@progbits
+# The split CU's contribution
+ .long .debug_dwo_str_offsets_segment0_end-.debug_dwo_str_offsets_base0
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_dwo_str_offsets_base0:
+ .long dwo_str_CU_5_producer-.debug_str.dwo
+ .long dwo_str_CU_5_name-.debug_str.dwo
+ .long dwo_str_CU_5_comp_dir-.debug_str.dwo
+.debug_dwo_str_offsets_segment0_end:
+# The split TU's contribution
+ .long .debug_dwo_str_offsets_segment1_end-.debug_dwo_str_offsets_base1
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_dwo_str_offsets_base1:
+ .long dwo_str_TU_5-.debug_str.dwo
+ .long dwo_str_TU_5_type-.debug_str.dwo
+.debug_dwo_str_offsets_segment1_end:
+
+# All CUs/TUs use the same abbrev section for simplicity.
+ .section .debug_abbrev,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x25 # DW_AT_producer
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x1b # DW_AT_comp_dir
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x02 # Abbrev code
+ .byte 0x41 # DW_TAG_type_unit
+ .byte 0x01 # DW_CHILDREN_yes
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x03 # Abbrev code
+ .byte 0x13 # DW_TAG_structure_type
+ .byte 0x00 # DW_CHILDREN_no (no members)
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+# And a .dwo copy for the .dwo sections.
+ .section .debug_abbrev.dwo,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x25 # DW_AT_producer
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x1b # DW_AT_comp_dir
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x02 # Abbrev code
+ .byte 0x41 # DW_TAG_type_unit
+ .byte 0x01 # DW_CHILDREN_yes
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x03 # Abbrev code
+ .byte 0x13 # DW_TAG_structure_type
+ .byte 0x00 # DW_CHILDREN_no (no members)
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+ .section .debug_info,"",@progbits
+
+# DWARF v5 CU header.
+ .long CU1_5_end-CU1_5_version # Length of Unit
+CU1_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+ .long .debug_str_offsets_base0
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU1_5_end:
+
+# DWARF v5 CU header
+ .long CU2_5_end-CU2_5_version # Length of Unit
+CU2_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+ .long .debug_str_offsets_base1
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU2_5_end:
+
+ .section .debug_types,"",@progbits
+# DWARF v5 Type unit header.
+TU_5_start:
+ .long TU_5_end-TU_5_version # Length of Unit
+TU_5_version:
+ .short 5 # DWARF version number
+ .byte 2 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .quad 0x0011223344556677 # Type Signature
+ .long TU_5_type-TU_5_start # Type offset
+# The type-unit DIE, which has a name.
+ .byte 2 # Abbreviation code
+ .byte 0 # Index of the unit type name string
+ .long .debug_str_offsets_base2 # offset into the str_offsets section
+# The type DIE, which has a name.
+TU_5_type:
+ .byte 3 # Abbreviation code
+ .byte 1 # Index of the type name string
+ .byte 0 # NULL
+ .byte 0 # NULL
+TU_5_end:
+
+ .section .debug_info.dwo,"",@progbits
+
+# DWARF v5 split CU header.
+ .long CU_split_5_end-CU_split_5_version # Length of Unit
+CU_split_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+ .long .debug_dwo_str_offsets_base0-.debug_str_offsets.dwo
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU_split_5_end:
+
+ .section .debug_types.dwo,"",@progbits
+
+# DWARF v5 split type unit header.
+TU_split_5_start:
+ .long TU_split_5_end-TU_split_5_version # Length of Unit
+TU_split_5_version:
+ .short 5 # DWARF version number
+ .byte 6 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev Section
+ .quad 0x8899aabbccddeeff # Type Signature
+ .long TU_split_5_type-TU_split_5_start # Type offset
+# The type-unit DIE, which has a name.
+ .byte 2 # Abbreviation code
+ .byte 0 # The index of the type unit name string
+ .long .debug_dwo_str_offsets_base1-.debug_str_offsets.dwo
+# The type DIE, which has a name.
+TU_split_5_type:
+ .byte 3 # Abbreviation code
+ .byte 1 # The index of the type name string
+ .byte 0 # NULL
+ .byte 0 # NULL
+TU_split_5_end:
+# Test object to verify dwarfdump handles v5 string offset tables.
+# We have 2 v5 CUs, a v5 TU, and a split v5 CU and TU.
+#
+# To generate the test object:
+# llvm-mc -triple x86_64-unknown-linux dwarfdump-str-offsets.s -filetype=obj \
+# -o dwarfdump-str-offsets.elf-x86-64
+
+ .section .debug_str,"MS",@progbits,1
+str_producer:
+ .asciz "Handmade DWARF producer"
+str_CU1:
+ .asciz "Compile_Unit_1"
+str_CU1_dir:
+ .asciz "/home/test/CU1"
+str_CU2:
+ .asciz "Compile_Unit_2"
+str_CU2_dir:
+ .asciz "/home/test/CU2"
+str_TU:
+ .asciz "Type_Unit"
+str_TU_type:
+ .asciz "MyStruct"
+
+# Every unit contributes to the string_offsets table.
+ .section .debug_str_offsets,"",@progbits
+# CU1's contribution
+ .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base0:
+ .long str_producer
+ .long str_CU1
+ .long str_CU1_dir
+.debug_str_offsets_segment0_end:
+# CU2's contribution
+ .long .debug_str_offsets_segment1_end-.debug_str_offsets_base1
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base1:
+ .long str_producer
+ .long str_CU2
+ .long str_CU2_dir
+.debug_str_offsets_segment1_end:
+# The TU's contribution
+ .long .debug_str_offsets_segment2_end-.debug_str_offsets_base2
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_str_offsets_base2:
+ .long str_TU
+ .long str_TU_type
+.debug_str_offsets_segment2_end:
+
+ .section .debug_str.dwo,"MS",@progbits,1
+dwo_str_CU_5_producer:
+ .asciz "Handmade split DWARF producer"
+dwo_str_CU_5_name:
+ .asciz "V5_split_compile_unit"
+dwo_str_CU_5_comp_dir:
+ .asciz "/home/test/splitCU"
+dwo_str_TU_5:
+ .asciz "V5_split_type_unit"
+dwo_str_TU_5_type:
+ .asciz "V5_split_Mystruct"
+
+ .section .debug_str_offsets.dwo,"",@progbits
+# The split CU's contribution
+ .long .debug_dwo_str_offsets_segment0_end-.debug_dwo_str_offsets_base0
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_dwo_str_offsets_base0:
+ .long dwo_str_CU_5_producer-.debug_str.dwo
+ .long dwo_str_CU_5_name-.debug_str.dwo
+ .long dwo_str_CU_5_comp_dir-.debug_str.dwo
+.debug_dwo_str_offsets_segment0_end:
+# The split TU's contribution
+ .long .debug_dwo_str_offsets_segment1_end-.debug_dwo_str_offsets_base1
+ .short 5 # DWARF version
+ .short 0 # Padding
+.debug_dwo_str_offsets_base1:
+ .long dwo_str_TU_5-.debug_str.dwo
+ .long dwo_str_TU_5_type-.debug_str.dwo
+.debug_dwo_str_offsets_segment1_end:
+
+# All CUs/TUs use the same abbrev section for simplicity.
+ .section .debug_abbrev,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x25 # DW_AT_producer
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x1b # DW_AT_comp_dir
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x02 # Abbrev code
+ .byte 0x41 # DW_TAG_type_unit
+ .byte 0x01 # DW_CHILDREN_yes
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x03 # Abbrev code
+ .byte 0x13 # DW_TAG_structure_type
+ .byte 0x00 # DW_CHILDREN_no (no members)
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+# And a .dwo copy for the .dwo sections.
+ .section .debug_abbrev.dwo,"",@progbits
+ .byte 0x01 # Abbrev code
+ .byte 0x11 # DW_TAG_compile_unit
+ .byte 0x00 # DW_CHILDREN_no
+ .byte 0x25 # DW_AT_producer
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x1b # DW_AT_comp_dir
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x02 # Abbrev code
+ .byte 0x41 # DW_TAG_type_unit
+ .byte 0x01 # DW_CHILDREN_yes
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x72 # DW_AT_str_offsets_base
+ .byte 0x17 # DW_FORM_sec_offset
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x03 # Abbrev code
+ .byte 0x13 # DW_TAG_structure_type
+ .byte 0x00 # DW_CHILDREN_no (no members)
+ .byte 0x03 # DW_AT_name
+ .byte 0x1a # DW_FORM_strx
+ .byte 0x00 # EOM(1)
+ .byte 0x00 # EOM(2)
+ .byte 0x00 # EOM(3)
+
+ .section .debug_info,"",@progbits
+
+# DWARF v5 CU header.
+ .long CU1_5_end-CU1_5_version # Length of Unit
+CU1_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+ .long .debug_str_offsets_base0
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU1_5_end:
+
+# DWARF v5 CU header
+ .long CU2_5_end-CU2_5_version # Length of Unit
+CU2_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+ .long .debug_str_offsets_base1
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU2_5_end:
+
+ .section .debug_types,"",@progbits
+# DWARF v5 Type unit header.
+TU_5_start:
+ .long TU_5_end-TU_5_version # Length of Unit
+TU_5_version:
+ .short 5 # DWARF version number
+ .byte 2 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .quad 0x0011223344556677 # Type Signature
+ .long TU_5_type-TU_5_start # Type offset
+# The type-unit DIE, which has a name.
+ .byte 2 # Abbreviation code
+ .byte 0 # Index of the unit type name string
+ .long .debug_str_offsets_base2 # offset into the str_offsets section
+# The type DIE, which has a name.
+TU_5_type:
+ .byte 3 # Abbreviation code
+ .byte 1 # Index of the type name string
+ .byte 0 # NULL
+ .byte 0 # NULL
+TU_5_end:
+
+ .section .debug_info.dwo,"",@progbits
+
+# DWARF v5 split CU header.
+ .long CU_split_5_end-CU_split_5_version # Length of Unit
+CU_split_5_version:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev Section
+# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
+# DW_AT_str_offsets and DW_AT_compdir.
+ .byte 1 # Abbreviation code
+ .byte 0 # The index of the producer string
+ .byte 1 # The index of the CU name string
+ .long .debug_dwo_str_offsets_base0-.debug_str_offsets.dwo
+ .byte 2 # The index of the comp dir string
+ .byte 0 # NULL
+CU_split_5_end:
+
+ .section .debug_types.dwo,"",@progbits
+
+# DWARF v5 split type unit header.
+TU_split_5_start:
+ .long TU_split_5_end-TU_split_5_version # Length of Unit
+TU_split_5_version:
+ .short 5 # DWARF version number
+ .byte 6 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev.dwo # Offset Into Abbrev Section
+ .quad 0x8899aabbccddeeff # Type Signature
+ .long TU_split_5_type-TU_split_5_start # Type offset
+# The type-unit DIE, which has a name.
+ .byte 2 # Abbreviation code
+ .byte 0 # The index of the type unit name string
+ .long .debug_dwo_str_offsets_base1-.debug_str_offsets.dwo
+# The type DIE, which has a name.
+TU_split_5_type:
+ .byte 3 # Abbreviation code
+ .byte 1 # The index of the type name string
+ .byte 0 # NULL
+ .byte 0 # NULL
+TU_split_5_end:
diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.x86_64.o b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.x86_64.o
new file mode 100644
index 00000000000..e15ac1c1542
--- /dev/null
+++ b/llvm/test/DebugInfo/Inputs/dwarfdump-str-offsets.x86_64.o
Binary files differ
diff --git a/llvm/test/DebugInfo/dwarfdump-str-offsets-invalid.test b/llvm/test/DebugInfo/dwarfdump-str-offsets-invalid.test
new file mode 100644
index 00000000000..45916d28de0
--- /dev/null
+++ b/llvm/test/DebugInfo/dwarfdump-str-offsets-invalid.test
@@ -0,0 +1,24 @@
+; Verify that llvm-dwarfdump handles invalid string offset tables.
+
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets-invalid-1.x86_64.o | \
+RUN: FileCheck --check-prefix=INVALIDCONTRIB %s
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets-invalid-2.x86_64.o | \
+RUN: FileCheck --check-prefix=INVALIDCONTRIB %s
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets-invalid-3.x86_64.o | \
+RUN: FileCheck --check-prefix=INVALIDCONTRIB %s
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets-invalid-4.x86_64.o | \
+RUN: FileCheck --check-prefix=INVALIDLENGTH %s
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets-invalid-5.x86_64.o | \
+RUN: FileCheck --check-prefix=INVALIDSECTIONLENGTH %s
+
+INVALIDCONTRIB: .debug_str_offsets contents:
+INVALIDCONTRIB-NOT: contents:
+INVALIDCONTRIB: error: invalid contribution to string offsets table in section .debug_str_offsets.
+
+INVALIDLENGTH: .debug_str_offsets contents:
+INVALIDLENGTH-NOT: contents:
+INVALIDLENGTH: error: contribution to string offsets table in section .debug_str_offsets has invalid length.
+
+INVALIDSECTIONLENGTH: .debug_str_offsets contents:
+INVALIDSECTIONLENGTH-NOT: contents:
+INVALIDSECTIONLENGTH: error: size of .debug_str_offsets is not a multiple of 4.
diff --git a/llvm/test/DebugInfo/dwarfdump-str-offsets.test b/llvm/test/DebugInfo/dwarfdump-str-offsets.test
new file mode 100644
index 00000000000..937c9c4d6ec
--- /dev/null
+++ b/llvm/test/DebugInfo/dwarfdump-str-offsets.test
@@ -0,0 +1,76 @@
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets.x86_64.o | FileCheck %s
+
+; We are using a hand-constructed object file and are interest in the correct
+; diplay of the DW_str_offsetsbase attribute, the correct display of strings
+; and the dump of the .debug_str_offsets[.dwo] table.
+;
+; Abbreviation for DW_AT_str_offsets_base
+CHECK: .debug_abbrev contents:
+CHECK-NOT: contents:
+CHECK: DW_TAG_compile_unit
+CHECK-NOT: DW_TAG
+CHECK: DW_AT_str_offsets_base DW_FORM_sec_offset
+
+; Verify that strings are displayed correctly as indexed strings
+CHECK: .debug_info contents:
+CHECK-NOT: contents:
+CHECK: DW_TAG_compile_unit
+CHECK-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
+CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_1")
+CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
+CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU1")
+
+; Second compile unit (b.cpp)
+CHECK: DW_TAG_compile_unit
+CHECK-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
+CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_2")
+CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000001c)
+CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU2")
+
+; The split CU
+CHECK: .debug_info.dwo contents:
+CHECK-NOT: contents:
+CHECK: DW_TAG_compile_unit
+CHECK-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade split DWARF producer")
+CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "V5_split_compile_unit")
+CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
+CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/splitCU")
+
+; The type unit
+CHECK: .debug_types contents:
+CHECK: DW_TAG_type_unit
+CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000000) string = "Type_Unit")
+CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000030)
+CHECK: DW_TAG_structure_type
+CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "MyStruct")
+
+; The split type unit
+CHECK: .debug_types.dwo contents:
+CHECK: DW_TAG_type_unit
+CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000000) string = "V5_split_type_unit")
+CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000001c)
+CHECK: DW_TAG_structure_type
+CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "V5_split_Mystruct")
+
+; The .debug_str_offsets section
+CHECK: .debug_str_offsets contents:
+CHECK-NEXT: 0x00000000: Contribution size = 12, Version = 5
+CHECK-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
+CHECK-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
+CHECK-NEXT: 0x00000010: 00000027 "/home/test/CU1"
+CHECK-NEXT: 0x00000014: Contribution size = 12, Version = 5
+CHECK-NEXT: 0x0000001c: 00000000 "Handmade DWARF producer"
+CHECK-NEXT: 0x00000020: 00000036 "Compile_Unit_2"
+CHECK-NEXT: 0x00000024: 00000045 "/home/test/CU2"
+CHECK-NEXT: 0x00000028: Contribution size = 8, Version = 5
+CHECK-NEXT: 0x00000030: 00000054 "Type_Unit"
+CHECK-NEXT: 0x00000034: 0000005e "MyStruct"
+
+CHECK: .debug_str_offsets.dwo contents:
+CHECK-NEXT: 0x00000000: Contribution size = 12, Version = 5
+CHECK-NEXT: 0x00000008: 00000000 "Handmade split DWARF producer"
+CHECK-NEXT: 0x0000000c: 0000001e "V5_split_compile_unit"
+CHECK-NEXT: 0x00000010: 00000034 "/home/test/splitCU"
+CHECK-NEXT: 0x00000014: Contribution size = 8, Version = 5
+CHECK-NEXT: 0x0000001c: 00000047 "V5_split_type_unit"
+CHECK-NEXT: 0x00000020: 0000005a "V5_split_Mystruct"
OpenPOWER on IntegriCloud