Skip to content

Commit 4096ae0

Browse files
committed
[lldb] Support DWARF-5 DW_FORM_line_strp (used by GCC)
LLDB has been failing on binaries produced by new GCC 11.0 with -gdwarf-5. Differential Revision: https://reviews.llvm.org/D97721
1 parent 818772a commit 4096ae0

File tree

3 files changed

+220
-35
lines changed

3 files changed

+220
-35
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &data,
173173
break;
174174

175175
case DW_FORM_strp:
176+
case DW_FORM_line_strp:
176177
case DW_FORM_sec_offset:
177178
data.GetU32(&offset);
178179
break;

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -150,40 +150,40 @@ struct FormSize {
150150
uint8_t valid:1, size:7;
151151
};
152152
static FormSize g_form_sizes[] = {
153-
{0,0}, // 0x00 unused
154-
{0,0}, // 0x01 DW_FORM_addr
155-
{0,0}, // 0x02 unused
156-
{0,0}, // 0x03 DW_FORM_block2
157-
{0,0}, // 0x04 DW_FORM_block4
158-
{1,2}, // 0x05 DW_FORM_data2
159-
{1,4}, // 0x06 DW_FORM_data4
160-
{1,8}, // 0x07 DW_FORM_data8
161-
{0,0}, // 0x08 DW_FORM_string
162-
{0,0}, // 0x09 DW_FORM_block
163-
{0,0}, // 0x0a DW_FORM_block1
164-
{1,1}, // 0x0b DW_FORM_data1
165-
{1,1}, // 0x0c DW_FORM_flag
166-
{0,0}, // 0x0d DW_FORM_sdata
167-
{1,4}, // 0x0e DW_FORM_strp
168-
{0,0}, // 0x0f DW_FORM_udata
169-
{0,0}, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for
170-
// DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
171-
{1,1}, // 0x11 DW_FORM_ref1
172-
{1,2}, // 0x12 DW_FORM_ref2
173-
{1,4}, // 0x13 DW_FORM_ref4
174-
{1,8}, // 0x14 DW_FORM_ref8
175-
{0,0}, // 0x15 DW_FORM_ref_udata
176-
{0,0}, // 0x16 DW_FORM_indirect
177-
{1,4}, // 0x17 DW_FORM_sec_offset
178-
{0,0}, // 0x18 DW_FORM_exprloc
179-
{1,0}, // 0x19 DW_FORM_flag_present
180-
{0,0}, // 0x1a
181-
{0,0}, // 0x1b
182-
{0,0}, // 0x1c
183-
{0,0}, // 0x1d
184-
{0,0}, // 0x1e
185-
{0,0}, // 0x1f
186-
{1,8}, // 0x20 DW_FORM_ref_sig8
153+
{0, 0}, // 0x00 unused
154+
{0, 0}, // 0x01 DW_FORM_addr
155+
{0, 0}, // 0x02 unused
156+
{0, 0}, // 0x03 DW_FORM_block2
157+
{0, 0}, // 0x04 DW_FORM_block4
158+
{1, 2}, // 0x05 DW_FORM_data2
159+
{1, 4}, // 0x06 DW_FORM_data4
160+
{1, 8}, // 0x07 DW_FORM_data8
161+
{0, 0}, // 0x08 DW_FORM_string
162+
{0, 0}, // 0x09 DW_FORM_block
163+
{0, 0}, // 0x0a DW_FORM_block1
164+
{1, 1}, // 0x0b DW_FORM_data1
165+
{1, 1}, // 0x0c DW_FORM_flag
166+
{0, 0}, // 0x0d DW_FORM_sdata
167+
{1, 4}, // 0x0e DW_FORM_strp
168+
{0, 0}, // 0x0f DW_FORM_udata
169+
{0, 0}, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes
170+
// for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
171+
{1, 1}, // 0x11 DW_FORM_ref1
172+
{1, 2}, // 0x12 DW_FORM_ref2
173+
{1, 4}, // 0x13 DW_FORM_ref4
174+
{1, 8}, // 0x14 DW_FORM_ref8
175+
{0, 0}, // 0x15 DW_FORM_ref_udata
176+
{0, 0}, // 0x16 DW_FORM_indirect
177+
{1, 4}, // 0x17 DW_FORM_sec_offset
178+
{0, 0}, // 0x18 DW_FORM_exprloc
179+
{1, 0}, // 0x19 DW_FORM_flag_present
180+
{0, 0}, // 0x1a DW_FORM_strx (ULEB128)
181+
{0, 0}, // 0x1b DW_FORM_addrx (ULEB128)
182+
{1, 4}, // 0x1c DW_FORM_ref_sup4
183+
{0, 0}, // 0x1d DW_FORM_strp_sup (4 bytes for DWARF32, 8 bytes for DWARF64)
184+
{1, 16}, // 0x1e DW_FORM_data16
185+
{1, 4}, // 0x1f DW_FORM_line_strp
186+
{1, 8}, // 0x20 DW_FORM_ref_sig8
187187
};
188188

189189
llvm::Optional<uint8_t>
@@ -286,6 +286,7 @@ bool DWARFFormValue::SkipValue(dw_form_t form,
286286
// 32 bit for DWARF 32, 64 for DWARF 64
287287
case DW_FORM_sec_offset:
288288
case DW_FORM_strp:
289+
case DW_FORM_line_strp:
289290
*offset_ptr += 4;
290291
return true;
291292

@@ -398,7 +399,8 @@ void DWARFFormValue::Dump(Stream &s) const {
398399
case DW_FORM_udata:
399400
s.PutULEB128(uvalue);
400401
break;
401-
case DW_FORM_strp: {
402+
case DW_FORM_strp:
403+
case DW_FORM_line_strp: {
402404
const char *dbg_str = AsCString();
403405
if (dbg_str) {
404406
s.QuotedCString(dbg_str);
@@ -606,6 +608,7 @@ bool DWARFFormValue::FormIsSupported(dw_form_t form) {
606608
case DW_FORM_flag:
607609
case DW_FORM_sdata:
608610
case DW_FORM_strp:
611+
case DW_FORM_line_strp:
609612
case DW_FORM_strx:
610613
case DW_FORM_strx1:
611614
case DW_FORM_strx2:
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Test handling of DWARF5 DW_FORM_line_strp from .debug_info as used by GCC.
2+
3+
# UNSUPPORTED: system-darwin, system-windows
4+
# REQUIRES: x86
5+
6+
# RUN: llvm-mc -filetype=obj -o %t -triple x86_64-pc-linux %s
7+
# RUN: %lldb %t -o "p main" \
8+
# RUN: -o exit | FileCheck %s
9+
10+
# CHECK: (void (*)()) $0 = 0x0000000000000000
11+
12+
.text
13+
.Ltext0:
14+
.globl main
15+
.type main, @function
16+
main:
17+
.LFB0:
18+
.LM1:
19+
.long 0
20+
.LM2:
21+
.long 0
22+
.LFE0:
23+
.size main, .-main
24+
.Letext0:
25+
.section .debug_info,"",@progbits
26+
.Ldebug_info0:
27+
.long .Ldebug_info0_end - .Ldebug_info0_start # Length of Compilation Unit Info
28+
.Ldebug_info0_start:
29+
.value 0x5 # DWARF version number
30+
.byte 0x1 # DW_UT_compile
31+
.byte 0x8 # Pointer Size (in bytes)
32+
.long .Ldebug_abbrev0 # Offset Into Abbrev. Section
33+
.uleb128 0x1 # (DIE (0xc) DW_TAG_compile_unit)
34+
.long .LASF2 # DW_AT_producer: "GNU C17 11.0.0 20210210 (Red Hat 11.0.0-0) -mtune=generic -march=x86-64 -gdwarf-5 -gno-as-loc-support"
35+
.byte 0x1d # DW_AT_language
36+
.long .LASF0 # DW_AT_name: "main.c"
37+
.long .LASF1 # DW_AT_comp_dir: ""
38+
.quad .Ltext0 # DW_AT_low_pc
39+
.quad .Letext0-.Ltext0 # DW_AT_high_pc
40+
.long .Ldebug_line0 # DW_AT_stmt_list
41+
.uleb128 0x2 # (DIE (0x2e) DW_TAG_subprogram)
42+
# DW_AT_external
43+
.long .LASF3 # DW_AT_name: "main"
44+
.byte 0x1 # DW_AT_decl_file (main.c)
45+
.byte 0x1 # DW_AT_decl_line
46+
.quad .LFB0 # DW_AT_low_pc
47+
.quad .LFE0-.LFB0 # DW_AT_high_pc
48+
.byte 0 # end of children of DIE 0xc
49+
.Ldebug_info0_end:
50+
.section .debug_abbrev,"",@progbits
51+
.Ldebug_abbrev0:
52+
.uleb128 0x1 # (abbrev code)
53+
.uleb128 0x11 # (TAG: DW_TAG_compile_unit)
54+
.byte 0x1 # DW_children_yes
55+
.uleb128 0x25 # (DW_AT_producer)
56+
.uleb128 0xe # (DW_FORM_strp)
57+
.uleb128 0x13 # (DW_AT_language)
58+
.uleb128 0xb # (DW_FORM_data1)
59+
.uleb128 0x3 # (DW_AT_name)
60+
.uleb128 0x1f # (DW_FORM_line_strp)
61+
.uleb128 0x1b # (DW_AT_comp_dir)
62+
.uleb128 0x1f # (DW_FORM_line_strp)
63+
.uleb128 0x11 # (DW_AT_low_pc)
64+
.uleb128 0x1 # (DW_FORM_addr)
65+
.uleb128 0x12 # (DW_AT_high_pc)
66+
.uleb128 0x7 # (DW_FORM_data8)
67+
.uleb128 0x10 # (DW_AT_stmt_list)
68+
.uleb128 0x17 # (DW_FORM_sec_offset)
69+
.byte 0
70+
.byte 0
71+
.uleb128 0x2 # (abbrev code)
72+
.uleb128 0x2e # (TAG: DW_TAG_subprogram)
73+
.byte 0 # DW_children_no
74+
.uleb128 0x3f # (DW_AT_external)
75+
.uleb128 0x19 # (DW_FORM_flag_present)
76+
.uleb128 0x3 # (DW_AT_name)
77+
.uleb128 0xe # (DW_FORM_strp)
78+
.uleb128 0x3a # (DW_AT_decl_file)
79+
.uleb128 0xb # (DW_FORM_data1)
80+
.uleb128 0x3b # (DW_AT_decl_line)
81+
.uleb128 0xb # (DW_FORM_data1)
82+
.uleb128 0x11 # (DW_AT_low_pc)
83+
.uleb128 0x1 # (DW_FORM_addr)
84+
.uleb128 0x12 # (DW_AT_high_pc)
85+
.uleb128 0x7 # (DW_FORM_data8)
86+
.byte 0
87+
.byte 0
88+
.uleb128 0x3 # (abbrev code)
89+
.uleb128 0x24 # (TAG: DW_TAG_base_type)
90+
.byte 0 # DW_children_no
91+
.uleb128 0xb # (DW_AT_byte_size)
92+
.uleb128 0xb # (DW_FORM_data1)
93+
.uleb128 0x3e # (DW_AT_encoding)
94+
.uleb128 0xb # (DW_FORM_data1)
95+
.uleb128 0x3 # (DW_AT_name)
96+
.uleb128 0x8 # (DW_FORM_string)
97+
.byte 0
98+
.byte 0
99+
.byte 0
100+
.section .debug_line,"",@progbits
101+
.Ldebug_line0:
102+
.long .LELT0-.LSLT0 # Length of Source Line Info
103+
.LSLT0:
104+
.value 0x5 # DWARF version number
105+
.byte 0x8 # Address Size
106+
.byte 0 # Segment Size
107+
.long .LELTP0-.LASLTP0 # Prolog Length
108+
.LASLTP0:
109+
.byte 0x1 # Minimum Instruction Length
110+
.byte 0x1 # Maximum Operations Per Instruction
111+
.byte 0x1 # Default is_stmt_start flag
112+
.byte 0xf6 # Line Base Value (Special Opcodes)
113+
.byte 0xf2 # Line Range Value (Special Opcodes)
114+
.byte 0xd # Special Opcode Base
115+
.byte 0 # opcode: 0x1 has 0 args
116+
.byte 0x1 # opcode: 0x2 has 1 args
117+
.byte 0x1 # opcode: 0x3 has 1 args
118+
.byte 0x1 # opcode: 0x4 has 1 args
119+
.byte 0x1 # opcode: 0x5 has 1 args
120+
.byte 0 # opcode: 0x6 has 0 args
121+
.byte 0 # opcode: 0x7 has 0 args
122+
.byte 0 # opcode: 0x8 has 0 args
123+
.byte 0x1 # opcode: 0x9 has 1 args
124+
.byte 0 # opcode: 0xa has 0 args
125+
.byte 0 # opcode: 0xb has 0 args
126+
.byte 0x1 # opcode: 0xc has 1 args
127+
.byte 0x1 # Directory entry format count
128+
.uleb128 0x1 # DW_LNCT_path
129+
.uleb128 0x1f # DW_FORM_line_strp
130+
.uleb128 0x2 # Directories count
131+
.long .LASF1 # Directory Entry: 0: ""
132+
.long .LASF4 # Directory Entry: 0: ""
133+
.byte 0x2 # File name entry format count
134+
.uleb128 0x1 # DW_LNCT_path
135+
.uleb128 0x1f # DW_FORM_line_strp
136+
.uleb128 0x2 # DW_LNCT_directory_index
137+
.uleb128 0xb # DW_FORM_data1
138+
.uleb128 0x2 # File names count
139+
.long .LASF0 # File Entry: 0: "main.c"
140+
.byte 0
141+
.long .LASF5 # File Entry: 0: "main.c"
142+
.byte 0x1
143+
.LELTP0:
144+
.byte 0 # set address *.LM1
145+
.uleb128 0x9
146+
.byte 0x2
147+
.quad .LM1
148+
.byte 0x1 # copy line 1
149+
.byte 0x5 # column 12
150+
.uleb128 0xc # 12
151+
.byte 0 # set address *.LM2
152+
.uleb128 0x9
153+
.byte 0x2
154+
.quad .LM2
155+
.byte 0x1 # copy line 1
156+
.byte 0x5 # column 13
157+
.uleb128 0xd # 13
158+
.byte 0 # set address *.Letext0
159+
.uleb128 0x9
160+
.byte 0x2
161+
.quad .Letext0
162+
.byte 0 # end sequence
163+
.uleb128 0x1
164+
.byte 0x1
165+
.LELT0:
166+
.section .debug_str,"MS",@progbits,1
167+
.LASF2:
168+
.string "GNU C17 11.0.0 20210210 (Red Hat 11.0.0-0) -mtune=generic -march=x86-64 -gdwarf-5 -gno-as-loc-support"
169+
.LASF3:
170+
.string "main"
171+
.section .debug_line_str,"MS",@progbits,1
172+
.LASF1:
173+
.string ""
174+
.LASF4:
175+
.string ""
176+
.LASF0:
177+
.string "main.c"
178+
.LASF5:
179+
.string "main.c"
180+
.ident "GCC: (GNU) 11.0.0 20210210 (Red Hat 11.0.0-0)"
181+
.section .note.GNU-stack,"",@progbits

0 commit comments

Comments
 (0)