Skip to content

Commit fc440f2

Browse files
siggi-alpheuslabath
authored andcommitted
Filter non-external static members from SBType::GetFieldAtIndex.
See [[ #55040 | issue 55040 ]] where static members of classes declared in the anonymous namespace are incorrectly returned as member fields from lldb::SBType::GetFieldAtIndex(). It appears that attrs.member_byte_offset contains a sentinel value for members that don't have a DW_AT_data_member_location. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D124409
1 parent fef8113 commit fc440f2

File tree

2 files changed

+177
-7
lines changed

2 files changed

+177
-7
lines changed

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -2408,8 +2408,6 @@ struct MemberAttributes {
24082408
/// structure.
24092409
uint32_t member_byte_offset;
24102410
bool is_artificial = false;
2411-
/// On DW_TAG_members, this means the member is static.
2412-
bool is_external = false;
24132411
};
24142412

24152413
/// Parsed form of all attributes that are relevant for parsing Objective-C
@@ -2485,9 +2483,6 @@ MemberAttributes::MemberAttributes(const DWARFDIE &die,
24852483
case DW_AT_artificial:
24862484
is_artificial = form_value.Boolean();
24872485
break;
2488-
case DW_AT_external:
2489-
is_external = form_value.Boolean();
2490-
break;
24912486
default:
24922487
break;
24932488
}
@@ -2632,8 +2627,10 @@ void DWARFASTParserClang::ParseSingleMember(
26322627
if (class_is_objc_object_or_interface)
26332628
attrs.accessibility = eAccessNone;
26342629

2635-
// Handle static members
2636-
if (attrs.is_external && attrs.member_byte_offset == UINT32_MAX) {
2630+
// Handle static members, which is any member that doesn't have a bit or a
2631+
// byte member offset.
2632+
if (attrs.member_byte_offset == UINT32_MAX &&
2633+
attrs.data_bit_offset == UINT64_MAX) {
26372634
Type *var_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
26382635

26392636
if (var_type) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# RUN: llvm-mc --triple=x86_64-pc-linux --filetype=obj %s -o %t
2+
# RUN: %lldb -o "target variable ug U::s" -b %t | FileCheck %s
3+
4+
# CHECK: (lldb) target variable ug
5+
# CHECK: (U) ug = (m = 14159265)
6+
# CHECK: (int) U::s = 65295141
7+
8+
# This tests that a static member in a class declared in the anonymous namespace
9+
# does not appear as a field of the class. There is a difference between the
10+
# debug info generated by gcc and clang, where clang flags the static member
11+
# with DW_AT_external, but gcc does not.
12+
#
13+
# Roughly corresponds to this source code:
14+
#
15+
# namespace {
16+
# struct U {
17+
# static int s;
18+
# int m = 14159265;
19+
# };
20+
# int U::s = 65295141;
21+
# }
22+
#
23+
# U ug;
24+
25+
.file "test.cpp"
26+
.data
27+
.quad 0
28+
ug:
29+
.long 14159265
30+
.Lug_s:
31+
.long 65295141
32+
33+
.section .debug_info,"",@progbits
34+
.Ldebug_info0:
35+
.long .Lcu_end-.Lcu_begin
36+
.Lcu_begin:
37+
.value 0x4
38+
.long .Ldebug_abbrev0
39+
.byte 0x8
40+
.uleb128 0x1
41+
.asciz "GCC DWARF reduced by hand"
42+
.byte 0x4
43+
.asciz "test.cpp"
44+
.uleb128 0x2
45+
.LU:
46+
.uleb128 0x3
47+
.string "U"
48+
.byte 0x4
49+
.LU_s:
50+
.uleb128 0x4
51+
.string "s"
52+
.long .Lint-.Ldebug_info0
53+
.uleb128 0x5
54+
.string "m"
55+
.long .Lint-.Ldebug_info0
56+
.byte 0
57+
.byte 0
58+
.byte 0
59+
.uleb128 0x6
60+
.long 0x2d
61+
.Lint:
62+
.uleb128 0x7
63+
.byte 0x4
64+
.byte 0x5
65+
.string "int"
66+
.uleb128 0x9
67+
.string "ug"
68+
.long .LU-.Ldebug_info0
69+
.uleb128 0x9
70+
.byte 0x3
71+
.quad ug
72+
.uleb128 0xa
73+
.long .LU_s-.Ldebug_info0
74+
.uleb128 0x9
75+
.byte 0x3
76+
.quad .Lug_s
77+
.byte 0
78+
.Lcu_end:
79+
.section .debug_abbrev,"",@progbits
80+
.Ldebug_abbrev0:
81+
.uleb128 0x1
82+
.uleb128 0x11
83+
.byte 0x1
84+
.uleb128 0x25
85+
.uleb128 0x8
86+
.uleb128 0x13
87+
.uleb128 0xb
88+
.uleb128 0x3
89+
.uleb128 0x8
90+
.byte 0
91+
.byte 0
92+
.uleb128 0x2
93+
.uleb128 0x39
94+
.byte 0x1
95+
.byte 0
96+
.byte 0
97+
.uleb128 0x3
98+
.uleb128 0x13
99+
.byte 0x1
100+
.uleb128 0x3
101+
.uleb128 0x8
102+
.uleb128 0xb
103+
.uleb128 0xb
104+
.byte 0
105+
.byte 0
106+
.uleb128 0x4
107+
.uleb128 0xd
108+
.byte 0
109+
.uleb128 0x3
110+
.uleb128 0x8
111+
.uleb128 0x49
112+
.uleb128 0x13
113+
.uleb128 0x3c
114+
.uleb128 0x19
115+
.byte 0
116+
.byte 0
117+
.uleb128 0x5
118+
.uleb128 0xd
119+
.byte 0
120+
.uleb128 0x3
121+
.uleb128 0x8
122+
.uleb128 0x49
123+
.uleb128 0x13
124+
.uleb128 0x38
125+
.uleb128 0xb
126+
.byte 0
127+
.byte 0
128+
.uleb128 0x6
129+
.uleb128 0x3a
130+
.byte 0
131+
.uleb128 0x18
132+
.uleb128 0x13
133+
.byte 0
134+
.byte 0
135+
.uleb128 0x7
136+
.uleb128 0x24
137+
.byte 0
138+
.uleb128 0xb
139+
.uleb128 0xb
140+
.uleb128 0x3e
141+
.uleb128 0xb
142+
.uleb128 0x3
143+
.uleb128 0x8
144+
.byte 0
145+
.byte 0
146+
.uleb128 0x8
147+
.uleb128 0x26
148+
.byte 0
149+
.uleb128 0x49
150+
.uleb128 0x13
151+
.byte 0
152+
.byte 0
153+
.uleb128 0x9
154+
.uleb128 0x34
155+
.byte 0
156+
.uleb128 0x3
157+
.uleb128 0x8
158+
.uleb128 0x49
159+
.uleb128 0x13
160+
.uleb128 0x2
161+
.uleb128 0x18
162+
.byte 0
163+
.byte 0
164+
.uleb128 0xa
165+
.uleb128 0x34
166+
.byte 0
167+
.uleb128 0x47
168+
.uleb128 0x13
169+
.uleb128 0x2
170+
.uleb128 0x18
171+
.byte 0
172+
.byte 0
173+
.byte 0

0 commit comments

Comments
 (0)