xref: /llvm-project/llvm/test/DebugInfo/X86/string-offsets-table.ll (revision 5e6e545cbab05589c8fcef5f03eca60dc227a6ca)
1; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj < %s | llvm-dwarfdump -v - \
2; RUN:   | FileCheck --check-prefix=MONOLITHIC %s
3; RUN: llc -mtriple=x86_64-unknown-linux-gnu -split-dwarf-file=foo.dwo -filetype=obj < %s \
4; RUN:   | llvm-dwarfdump -v - | FileCheck --check-prefix=SPLIT %s
5
6; This basic test checks the emission of a DWARF v5 string offsets table in
7; the split and non-split (monolithic) scenario.
8;
9; Constructed from the following source with
10; clang -S -emit-llvm -gdwarf-5
11;
12; enum E {a, b, c};
13; E glob;
14;
15; In the non-split scenario, check the DW_AT_str_offsets_base attribute
16; in .debug_abbrev.
17; MONOLITHIC:          .debug_abbrev contents:
18; MONOLITHIC-NOT:      contents:
19; MONOLITHIC:          DW_TAG_compile_unit
20; MONOLITHIC-NOT:      DW_TAG
21; MONOLITHIC:          DW_AT_str_offsets_base DW_FORM_sec_offset
22
23; Check that indexed strings come out correctly and that the DW_str_offsets_base attribute
24; is there and has the right value.
25; MONOLITHIC:          .debug_info contents:
26; MONOLITHIC-NOT:      contents:
27; MONOLITHIC:          DW_TAG_compile_unit
28; MONOLITHIC-NOT:      {{DW_TAG|NULL}}
29; MONOLITHIC:          DW_AT_producer [DW_FORM_strx1] (indexed (00000000) string = "clang{{.*}}")
30; MONOLITHIC-NOT:      {{DW_TAG|NULL}}
31; MONOLITHIC:          DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
32; MONOLITHIC-NOT:      {{DW_TAG|NULL}}
33; MONOLITHIC:          DW_AT_comp_dir [DW_FORM_strx1] (indexed (00000002) string = "/home/{{.*}}")
34
35; Extract the string offsets from the .debug_str section so we can check that
36; they are referenced correctly in the .debug_str_offsets section.
37; MONOLITHIC:          .debug_str contents:
38; MONOLITHIC-NEXT:     0x00000000:
39; MONOLITHIC-NEXT:     0x[[STRING2:[0-9a-f]]]
40; MONOLITHIC-NEXT:     0x[[STRING3:[0-9a-f]]]
41; MONOLITHIC-NEXT:     0x[[STRING4:[0-9a-f]]]
42
43; Verify that the .debug_str_offsets section is there and that it starts
44; with an 8-byte header, followed by offsets into the .debug_str section.
45; MONOLITHIC:          .debug_str_offsets contents:
46; MONOLITHIC-NEXT:     Contribution size = 36, Format = DWARF32, Version = 5
47; MONOLITHIC-NEXT:     0x00000008: 00000000
48; MONOLITHIC-NEXT:     0x0000000c: [[STRING2]]
49; MONOLITHIC-NEXT:     0x00000010: [[STRING3]]
50; MONOLITHIC-NEXT:     0x00000014: [[STRING4]]
51
52; For split dwarf, verify that the skeleton unit has the DW_AT_str_offsets_base
53; attribute and that it has the right value.
54;
55; SPLIT:      .debug_info contents:
56; SPLIT-NEXT: 0x00000000: Compile Unit:{{.*}}DW_UT_skeleton
57; SPLIT-NOT:  contents:
58; SPLIT:      DW_TAG_skeleton_unit
59; SPLIT-NOT:  {{DW_TAG|contents:}}
60; SPLIT:      DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
61; SPLIT:      DW_AT_comp_dir [DW_FORM_strx1] (indexed (00000000) string = "/home/test")
62; SPLIT:      DW_AT_dwo_name [DW_FORM_strx1] (indexed (00000001) string = "foo.dwo")
63
64; Check for the split CU in .debug_info.dwo.
65; SPLIT:      .debug_info.dwo contents:
66; SPLIT-NEXT: 0x00000000: Compile Unit:{{.*}}DW_UT_split_compile
67; SPLIT-NOT:  contents:
68; SPLIT:      DW_TAG_compile_unit
69;
70; Check that a couple of indexed strings are displayed correctly and that
71; they have the right format (DW_FORM_strx1).
72; SPLIT-NOT:  contents:
73; SPLIT:      DW_TAG_enumerator
74; SPLIT-NOT:  {{DW_TAG|NULL}}
75; SPLIT:      DW_AT_name [DW_FORM_strx1]    (indexed (00000001) string = "a")
76; SPLIT-NOT:  contents:
77; SPLIT:      DW_TAG_enumerator
78; SPLIT-NOT:  {{DW_TAG|NULL}}
79; SPLIT:      DW_AT_name [DW_FORM_strx1]    (indexed (00000002) string = "b")
80;
81; Extract the string offsets referenced in the main file by the skeleton unit.
82; SPLIT:      .debug_str contents:
83; SPLIT-NEXT: 0x[[STRHOMETESTSPLIT:[0-9a-f]*]]: "/home/test"
84; SPLIT-NEXT: 0x[[STRESPLIT:[0-9a-f]*]]: "E"
85; SPLIT-NEXT: 0x[[STRGLOBSPLIT:[0-9a-f]*]]: "glob"
86; SPLIT-NEXT: 0x[[STRFOODWOSPLIT:[0-9a-f]*]]: "foo.dwo"
87;
88; Extract the string offsets referenced in the .dwo file by the split unit.
89; SPLIT:      .debug_str.dwo contents:
90; SPLIT-NEXT: 0x00000000:{{.*}}
91; SPLIT-NEXT: 0x[[STRING2DWO:[0-9a-f]*]]{{.*}}
92; SPLIT-NEXT: 0x[[STRING3DWO:[0-9a-f]*]]{{.*}}
93;
94; Check the string offsets sections in both the main and the .dwo files and
95; verify that the extracted string offsets are referenced correctly. The
96; sections should contain only the offsets of strings that are actually
97; referenced by the debug info.
98; SPLIT:      .debug_str_offsets contents:
99; SPLIT-NEXT: 0x00000000: Contribution size = 12, Format = DWARF32, Version = 5
100; SPLIT-NEXT: 0x00000008: [[STRHOMETESTSPLIT]] "/home/test"
101; SPLIT-NEXT: 0x0000000c: [[STRFOODWOSPLIT]] "foo.dwo"
102; SPLIT-EMPTY:
103
104; SPLIT:      .debug_str_offsets.dwo contents:
105; SPLIT-NEXT: 0x00000000: Contribution size = 36, Format = DWARF32, Version = 5
106; SPLIT-NEXT: 0x00000008: 00000000{{.*}}
107; SPLIT-NEXT: 0x0000000c: [[STRING2DWO]]{{.*}}
108; SPLIT-NEXT: 0x00000010: [[STRING3DWO]]
109
110@glob = global i32 0, align 4, !dbg !0
111
112!llvm.dbg.cu = !{!2}
113!llvm.module.flags = !{!11, !12, !13}
114!llvm.ident = !{!14}
115
116!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
117!1 = distinct !DIGlobalVariable(name: "glob", scope: !2, file: !3, line: 3, type: !5, isLocal: false, isDefinition: true)
118!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 (trunk 322415)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !10)
119!3 = !DIFile(filename: "en.cpp", directory: "/home/test", checksumkind: CSK_MD5, checksum: "d96b2e2d618e550f0ddd0b6a49c98b02")
120!4 = !{!5}
121!5 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E", file: !3, line: 1, size: 32, elements: !6, identifier: "_ZTS1E")
122!6 = !{!7, !8, !9}
123!7 = !DIEnumerator(name: "a", value: 0)
124!8 = !DIEnumerator(name: "b", value: 1)
125!9 = !DIEnumerator(name: "c", value: 2)
126!10 = !{!0}
127!11 = !{i32 2, !"Dwarf Version", i32 5}
128!12 = !{i32 2, !"Debug Info Version", i32 3}
129!13 = !{i32 1, !"wchar_size", i32 4}
130!14 = !{!"clang version 7.0.0 (trunk 322415)"}
131