Skip to content

Commit 78d41a1

Browse files
committed
lldb: Add support for printing variables with DW_AT_ranges on DW_TAG_subprograms
Finishing out the support (to the best of my knowledge/based on current testing running the whole check-lldb with a clang forcibly using DW_AT_ranges on all DW_TAG_subprograms) for this feature. Differential Revision: https://reviews.llvm.org/D94064
1 parent b3fcc72 commit 78d41a1

File tree

3 files changed

+85
-38
lines changed

3 files changed

+85
-38
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "lldb/Interpreter/OptionValueProperties.h"
3636

3737
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
38+
#include "Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h"
3839
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
3940
#include "lldb/Symbol/Block.h"
4041
#include "lldb/Symbol/CompileUnit.h"
@@ -3040,8 +3041,12 @@ size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) {
30403041
if (sc.function) {
30413042
DWARFDIE function_die = GetDIE(sc.function->GetID());
30423043

3043-
const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsAddress(
3044-
DW_AT_low_pc, LLDB_INVALID_ADDRESS);
3044+
dw_addr_t func_lo_pc = LLDB_INVALID_ADDRESS;
3045+
DWARFRangeList ranges;
3046+
if (function_die.GetDIE()->GetAttributeAddressRanges(
3047+
function_die.GetCU(), ranges,
3048+
/*check_hi_lo_pc=*/true))
3049+
func_lo_pc = ranges.GetMinRangeBase(0);
30453050
if (func_lo_pc != LLDB_INVALID_ADDRESS) {
30463051
const size_t num_variables = ParseVariables(
30473052
sc, function_die.GetFirstChild(), func_lo_pc, true, true);

lldb/test/Shell/SymbolFile/DWARF/Inputs/subprogram_ranges.s

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
.text
2-
.file "main.c"
2+
.file "subprogram_ranges.c"
33
.globl main # -- Begin function main
44
.p2align 4, 0x90
55
.type main,@function
66
main: # @main
77
.Lfunc_begin0:
8-
.file 1 "/usr/local/google/home/blaikie/dev/scratch" "main.c"
9-
.loc 1 1 0 # main.c:1:0
8+
.file 1 "/usr/local/google/home/blaikie/dev/scratch" "subprogram_ranges.c"
9+
.loc 1 2 0 # subprogram_ranges.c:2:0
1010
.cfi_startproc
1111
# %bb.0: # %entry
12-
pushq %rbp
13-
.cfi_def_cfa_offset 16
14-
.cfi_offset %rbp, -16
15-
movq %rsp, %rbp
16-
.cfi_def_cfa_register %rbp
17-
xorl %eax, %eax
12+
#DEBUG_VALUE: main:var <- 3
13+
.loc 1 4 5 prologue_end # subprogram_ranges.c:4:5
14+
movl $1, i(%rip)
1815
.Ltmp0:
19-
.loc 1 2 7 prologue_end # main.c:2:7
20-
movl $3, -4(%rbp)
21-
.loc 1 3 1 # main.c:3:1
22-
popq %rbp
23-
.cfi_def_cfa %rsp, 8
16+
#DEBUG_VALUE: main:var <- 5
17+
.loc 1 6 5 # subprogram_ranges.c:6:5
18+
movl $2, i(%rip)
19+
.loc 1 7 1 # subprogram_ranges.c:7:1
20+
xorl %eax, %eax
2421
retq
2522
.Ltmp1:
2623
.Lfunc_end0:
2724
.size main, .Lfunc_end0-main
2825
.cfi_endproc
2926
# -- End function
27+
.type i,@object # @i
28+
.bss
29+
.globl i
30+
.p2align 2
31+
i:
32+
.long 0 # 0x0
33+
.size i, 4
34+
35+
.section .debug_loc,"",@progbits
36+
.Ldebug_loc0:
37+
.quad .Lfunc_begin0-.Lfunc_begin0
38+
.quad .Ltmp0-.Lfunc_begin0
39+
.short 3 # Loc expr size
40+
.byte 17 # DW_OP_consts
41+
.byte 3 # 3
42+
.byte 159 # DW_OP_stack_value
43+
.quad .Ltmp0-.Lfunc_begin0
44+
.quad .Lfunc_end0-.Lfunc_begin0
45+
.short 3 # Loc expr size
46+
.byte 17 # DW_OP_consts
47+
.byte 5 # 5
48+
.byte 159 # DW_OP_stack_value
49+
.quad 0
50+
.quad 0
3051
.section .debug_abbrev,"",@progbits
3152
.byte 1 # Abbreviation Code
3253
.byte 17 # DW_TAG_compile_unit
@@ -54,6 +75,8 @@ main: # @main
5475
.byte 23 # DW_FORM_sec_offset
5576
.byte 64 # DW_AT_frame_base
5677
.byte 24 # DW_FORM_exprloc
78+
.ascii "\227B" # DW_AT_GNU_all_call_sites
79+
.byte 25 # DW_FORM_flag_present
5780
.byte 3 # DW_AT_name
5881
.byte 14 # DW_FORM_strp
5982
.byte 58 # DW_AT_decl_file
@@ -70,7 +93,7 @@ main: # @main
7093
.byte 52 # DW_TAG_variable
7194
.byte 0 # DW_CHILDREN_no
7295
.byte 2 # DW_AT_location
73-
.byte 24 # DW_FORM_exprloc
96+
.byte 23 # DW_FORM_sec_offset
7497
.byte 3 # DW_AT_name
7598
.byte 14 # DW_FORM_strp
7699
.byte 58 # DW_AT_decl_file
@@ -100,33 +123,32 @@ main: # @main
100123
.short 4 # DWARF version number
101124
.long .debug_abbrev # Offset Into Abbrev. Section
102125
.byte 8 # Address Size (in bytes)
103-
.byte 1 # Abbrev [1] 0xb:0x47 DW_TAG_compile_unit
126+
.byte 1 # Abbrev [1] 0xb:0x48 DW_TAG_compile_unit
104127
.long .Linfo_string0 # DW_AT_producer
105128
.short 12 # DW_AT_language
106129
.long .Linfo_string1 # DW_AT_name
107130
.long .Lline_table_start0 # DW_AT_stmt_list
108131
.long .Linfo_string2 # DW_AT_comp_dir
109132
.quad .Lfunc_begin0 # DW_AT_low_pc
110133
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
111-
.byte 2 # Abbrev [2] 0x2a:0x20 DW_TAG_subprogram
134+
.byte 2 # Abbrev [2] 0x2a:0x21 DW_TAG_subprogram
112135
.long .Ldebug_ranges0 # DW_AT_ranges
113136
.byte 1 # DW_AT_frame_base
114-
.byte 86
137+
.byte 87
138+
# DW_AT_GNU_all_call_sites
115139
.long .Linfo_string3 # DW_AT_name
116140
.byte 1 # DW_AT_decl_file
117-
.byte 1 # DW_AT_decl_line
118-
.long 74 # DW_AT_type
141+
.byte 2 # DW_AT_decl_line
142+
.long 75 # DW_AT_type
119143
# DW_AT_external
120-
.byte 3 # Abbrev [3] 0x3b:0xe DW_TAG_variable
121-
.byte 2 # DW_AT_location
122-
.byte 145
123-
.byte 124
144+
.byte 3 # Abbrev [3] 0x3b:0xf DW_TAG_variable
145+
.long .Ldebug_loc0 # DW_AT_location
124146
.long .Linfo_string5 # DW_AT_name
125147
.byte 1 # DW_AT_decl_file
126-
.byte 2 # DW_AT_decl_line
127-
.long 74 # DW_AT_type
148+
.byte 3 # DW_AT_decl_line
149+
.long 75 # DW_AT_type
128150
.byte 0 # End Of Children Mark
129-
.byte 4 # Abbrev [4] 0x4a:0x7 DW_TAG_base_type
151+
.byte 4 # Abbrev [4] 0x4b:0x7 DW_TAG_base_type
130152
.long .Linfo_string4 # DW_AT_name
131153
.byte 5 # DW_AT_encoding
132154
.byte 4 # DW_AT_byte_size
@@ -140,20 +162,20 @@ main: # @main
140162
.quad 0
141163
.section .debug_str,"MS",@progbits,1
142164
.Linfo_string0:
143-
.asciz "clang version 12.0.0 ([email protected]:llvm/llvm-project.git 1c15aa171b2f67d9198a8498945cbdb936c0cd3b)" # string offset=0
165+
.asciz "clang version 12.0.0 ([email protected]:llvm/llvm-project.git 439e8f6c05584c36ea3f79d9b83a78098d40e629)" # string offset=0
144166
.Linfo_string1:
145-
.asciz "main.c" # string offset=101
167+
.asciz "subprogram_ranges.c" # string offset=101
146168
.Linfo_string2:
147-
.asciz "/usr/local/google/home/blaikie/dev/scratch" # string offset=108
169+
.asciz "/usr/local/google/home/blaikie/dev/scratch" # string offset=121
148170
.Linfo_string3:
149-
.asciz "main" # string offset=151
171+
.asciz "main" # string offset=164
150172
.Linfo_string4:
151-
.asciz "int" # string offset=156
173+
.asciz "int" # string offset=169
152174
.Linfo_string5:
153-
.asciz "var" # string offset=160
154-
.ident "clang version 12.0.0 ([email protected]:llvm/llvm-project.git 1c15aa171b2f67d9198a8498945cbdb936c0cd3b)"
175+
.asciz "var" # string offset=173
176+
.ident "clang version 12.0.0 ([email protected]:llvm/llvm-project.git 439e8f6c05584c36ea3f79d9b83a78098d40e629)"
155177
.section ".note.GNU-stack","",@progbits
156178
.addrsig
179+
.addrsig_sym i
157180
.section .debug_line,"",@progbits
158181
.Lline_table_start0:
159-

lldb/test/Shell/SymbolFile/DWARF/subprogram_ranges.test

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
# especially useful, but don't dismiss it as pointless just because it's a bit
1515
# weird.
1616

17+
# * Using volatile writes to create instructions the location may be valid over
18+
# * Using two values for the variable so it is described by a location list,
19+
# not a single location description
20+
# * Not using function calls, so that the function has no frame pointer
21+
# initialization/no prologue instructions, so the location of "var" is valid
22+
# at the start of the function, so 'image lookup -v -s main' will include it.
23+
#
24+
# Source:
25+
# __attribute__((nodebug)) volatile int i;
26+
# int main() {
27+
# int var = 3;
28+
# i = 1;
29+
# var = 5;
30+
# i = 2;
31+
# }
32+
1733
b main
1834
# CHECK: (lldb) b main
19-
# CHECK-NEXT: Breakpoint 1: where = {{.*}}`main + 6 at main.c:2:7
35+
# CHECK-NEXT: Breakpoint 1: where = {{.*}}`main at subprogram_ranges.c:4:5
36+
37+
image lookup -v -s main
38+
# CHECK: 1 symbols match 'main'
39+
# CHECK: Variable: {{.*}}, name = "var", type = "int", {{.*}}, decl = subprogram_ranges.c:3

0 commit comments

Comments
 (0)