Skip to content

Commit f5148c7

Browse files
committed
fix some stuff and make the work in llvm 18 (but break llvm14)
1 parent 950f608 commit f5148c7

File tree

4 files changed

+63
-31
lines changed

4 files changed

+63
-31
lines changed

src/etc/lldb_lookup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def synthetic_lookup(valobj: lldb.SBValue, _dict: LLDBOpaque) -> object:
113113
if rust_type == RustType.STD_BTREE_MAP:
114114
return StdBTreeMapSyntheticProvider(valobj, _dict)
115115
if rust_type == RustType.STD_BTREE_SET:
116-
return StdBTreeMapSyntheticProvider(valobj, _dict, show_values=False)
116+
btree_map = valobj.GetChildAtIndex(0)
117+
return StdBTreeMapSyntheticProvider(btree_map, _dict, show_values=False)
117118

118119
if rust_type == RustType.STD_RC:
119120
return StdRcSyntheticProvider(valobj, _dict)

src/etc/lldb_providers.py

+31-30
Original file line numberDiff line numberDiff line change
@@ -1152,16 +1152,22 @@ def has_children(self) -> bool:
11521152

11531153

11541154
def children_of_node(node_ptr: SBValue, height: int):
1155-
def cast_to_internal(node: SBValue) -> SBValue:
1155+
def get_edges(node: SBValue) -> SBValue:
11561156
# BTreeMap implementation does ad-hoc polymorphism between LeafNode and InternalNode
11571157
# with raw pointers.
11581158
# https://github.com/rust-lang/rust/issues/90520#issuecomment-2211103129
1159-
internal_type_name = node.type.GetPointeeType().name.replace(
1160-
"LeafNode", "InternalNode", 1
1161-
)
1162-
target = node.GetTarget()
1163-
internal_type = target.FindFirstType(internal_type_name)
1164-
return node.Cast(internal_type.GetPointerType())
1159+
# Implementing this the same way as the GDB provider with type casting fails
1160+
# because LLDB does not find the target type for some reason.
1161+
# Therefore, we manually do the pointer arithmetic to get the edges array
1162+
# and handle it as raw pointers later instead of MaybeUninit<NonNull<LeafNode<K,V>>>.
1163+
# We can do that because InternalNode is repr(C).
1164+
leaf_ptr_type = node.GetType()
1165+
# Array has a constant length of 2 * B
1166+
edges_arr_type = leaf_ptr_type.GetArrayType(12)
1167+
node_addr = node.unsigned
1168+
leaf_size = leaf_ptr_type.GetPointeeType().size
1169+
edges_addr = node_addr + leaf_size
1170+
return node.CreateValueFromAddress("edges", edges_addr, edges_arr_type)
11651171

11661172
def unwrap_item_from_array_of_maybe_uninit(arr: SBValue, index: int) -> SBValue:
11671173
element = arr.GetChildAtIndex(index)
@@ -1170,20 +1176,21 @@ def unwrap_item_from_array_of_maybe_uninit(arr: SBValue, index: int) -> SBValue:
11701176
if node_ptr.type.name.startswith("alloc::collections::btree::node::BoxedNode<"):
11711177
# BACKCOMPAT: rust 1.49
11721178
node_ptr = node_ptr.GetChildMemberWithName("ptr")
1173-
node_ptr = unwrap_unique_or_non_null(node_ptr)
1179+
1180+
if not node_ptr.type.IsPointerType():
1181+
# After the first recursion, this method is called with a raw pointer type directly
1182+
# instead of NonNull<T>
1183+
node_ptr = unwrap_unique_or_non_null(node_ptr)
1184+
11741185
leaf = node_ptr.Dereference()
11751186
keys = leaf.GetChildMemberWithName("keys")
11761187
vals = leaf.GetChildMemberWithName("vals")
11771188
length = leaf.GetChildMemberWithName("len").unsigned
1178-
edges = (
1179-
cast_to_internal(node_ptr).GetChildMemberWithName("edges")
1180-
if height > 0
1181-
else None
1182-
)
1189+
edges = get_edges(node_ptr) if height > 0 else None
11831190

11841191
for i in range(length + 1):
11851192
if height > 0:
1186-
child_ptr = unwrap_item_from_array_of_maybe_uninit(edges, i)
1193+
child_ptr = edges.GetChildAtIndex(i)
11871194
yield from children_of_node(child_ptr, height - 1)
11881195
if i < length:
11891196
# Avoid "Cannot perform pointer math on incomplete type" on zero-sized arrays.
@@ -1202,19 +1209,11 @@ def unwrap_item_from_array_of_maybe_uninit(arr: SBValue, index: int) -> SBValue:
12021209
yield key, val
12031210

12041211

1205-
def strip_till_parentheses(text: str) -> str:
1206-
start = text.find("(")
1207-
end = text.find(")")
1208-
if start == -1 or end == -1:
1209-
return text
1210-
return text[start : end + 1]
1211-
1212-
12131212
class StdBTreeMapSyntheticProvider:
12141213
def __init__(self, valobj: SBValue, _dict: LLDBOpaque, show_values: bool = True):
12151214
self.valobj = valobj
12161215
self._dict = _dict
1217-
self.show_values = True
1216+
self.show_values = show_values
12181217

12191218
def num_children(self) -> int:
12201219
return self.size
@@ -1244,20 +1243,22 @@ def update(self) -> bool:
12441243
# - Type lookup after get_template_args helper fails with codelldb for unclear reasons
12451244
# - Native `template_args[0]` from LLDB fails with codelldb and just says `T` if printed
12461245
# on console
1247-
marker_type_name = self.valobj.GetChildMemberWithName("_marker").GetTypeName()
1248-
pair_type_name = strip_till_parentheses(marker_type_name)
1249-
target = self.valobj.GetTarget()
1250-
self.pair_type = target.FindFirstType(pair_type_name)
1246+
marker = self.valobj.GetChildMemberWithName("_marker")
1247+
marker_type = marker.GetType()
1248+
box = marker_type.GetTemplateArgumentType(0)
1249+
self.pair_type = box.GetPointeeType()
12511250

12521251
if self.size == 0:
12531252
return
12541253

12551254
root = self.valobj.GetChildMemberWithName("root")
12561255

12571256
if root.type.name.startswith("core::option::Option<"):
1258-
target = self.valobj.GetTarget()
1259-
type_some = target.FindFirstType(get_template_args(root.GetTypeName())[0])
1260-
root = root.Cast(type_some)
1257+
synthetic_children = root.children[0]
1258+
current_variant = synthetic_children.GetChildMemberWithName("$variant$")
1259+
root = current_variant.GetChildMemberWithName(
1260+
"value"
1261+
).GetChildMemberWithName("__0")
12611262

12621263
height = root.GetChildMemberWithName("height")
12631264
node_ptr = root.GetChildMemberWithName("node")

src/tools/compiletest/src/runtest/debugger.rs

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ impl DebuggerCommands {
111111
}
112112

113113
/// Check that the pattern in `check_line` applies to `line`. Returns `true` if they do match.
114+
/// Note that this matching is lazy, i.e. matches as little as possible and thus might leave
115+
/// stuff unparsed, failing the check.
116+
/// This is different to usual regex or global matching that is typically eager.
114117
fn check_single_line(line: &str, check_line: &str) -> bool {
115118
// Allow check lines to leave parts unspecified (e.g., uninitialized
116119
// bits in the wrong case of an enum) with the notation "[...]".

tests/debuginfo/pretty-std-collections.rs

+27
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@
5151

5252
// lldb-command:run
5353

54+
// lldb-command: v btree_set
55+
// lldb-check:[...] size=15 { [0] = 0 [1] = 1 [2] = 2 [3] = 3 [4] = 4 [5] = 5 [6] = 6 [7] = 7 [8] = 8 [9] = 9 [10] = 10 [11] = 11 [12] = 12 [13] = 13 [14] = 14 }
56+
57+
// lldb-command: v empty_btree_set
58+
// lldb-check:[...] size=0
59+
60+
// lldb-command: v btree_map
61+
// lldb-check:[...] size=15 { [0] = { 0 = 0 1 = 0 } [1] = { 0 = 1 1 = 1 } [2] = { 0 = 2 1 = 2 } [3] = { 0 = 3 1 = 3 } [4] = { 0 = 4 1 = 4 } [5] = { 0 = 5 1 = 5 } [6] = { 0 = 6 1 = 6 } [7] = { 0 = 7 1 = 7 } [8] = { 0 = 8 1 = 8 } [9] = { 0 = 9 1 = 9 } [10] = { 0 = 10 1 = 10 } [11] = { 0 = 11 1 = 11 } [12] = { 0 = 12 1 = 12 } [13] = { 0 = 13 1 = 13 } [14] = { 0 = 14 1 = 14 } }
62+
63+
// lldb-command: v option_btree_map
64+
// lldb-check:[...] size=2 { [0] = { 0 = false 1 = [...] } [1] = { 0 = true 1 = [...]
65+
// (The matching here is lazy, so we cannot add braces at the end because they would match
66+
// intermediate braces and fail because not the entire input was consumed.)
67+
68+
// lldb-command: v nasty_btree_map
69+
// lldb-check:[...] size=15 { [0] = { 0 = 0 1 = { 0 = 0 } } [1] = { 0 = 1 1 = { 0 = 1 } } [2] = { 0 = 2 1 = { 0 = 2 } } [3] = { 0 = 3 1 = { 0 = 3 } } [4] = { 0 = 4 1 = { 0 = 4 } } [5] = { 0 = 5 1 = { 0 = 5 } } [6] = { 0 = 6 1 = { 0 = 6 } } [7] = { 0 = 7 1 = { 0 = 7 } } [8] = { 0 = 8 1 = { 0 = 8 } } [9] = { 0 = 9 1 = { 0 = 9 } } [10] = { 0 = 10 1 = { 0 = 10 } } [11] = { 0 = 11 1 = { 0 = 11 } } [12] = { 0 = 12 1 = { 0 = 12 } } [13] = { 0 = 13 1 = { 0 = 13 } } [14] = { 0 = 14 1 = { 0 = 14 } } }
70+
// (Does not print out the type name in lldb)
71+
72+
// lldb-command: v zst_key_btree_map
73+
// lldb-check:[...] size=1 { [0] = { 1 = 1 } }
74+
75+
// lldb-command: v zst_val_btree_map
76+
// lldb-check:[...] size=1 { [0] = { 0 = 1 } }
77+
78+
// lldb-command: v zst_key_val_btree_map
79+
// lldb-check:[...] size=1 { [0] = {} }
80+
5481
// lldb-command:v vec_deque
5582
// lldb-check:[...] size=3 { [0] = 5 [1] = 3 [2] = 7 }
5683

0 commit comments

Comments
 (0)