authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-05 23:40:54-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-06 05:58:46-05:00
logc29c4c6f70ccde441ff8e40e94c2848fef1f86da
treef12b977417e21a4c319008ca8f0de8f7dc797fb7
parentac1b0e832b4b9d151098050e1d29e28a568e215c

tools: add lldb pretty printer for std.MultiArrayList.Slice


2 files changed, 50 insertions(+), 6 deletions(-)

lib/std/multi_array_list.zig+13-2
......@@ -68,6 +68,15 @@ pub fn MultiArrayList(comptime S: type) type {
6868 other.deinit(gpa);
6969 self.* = undefined;
7070 }
71
72 /// This function is used in the debugger pretty formatters in tools/ to fetch the
73 /// child field order and entry type to facilitate fancy debug printing for this type.
74 fn dbHelper(self: *Slice, child: *S, field: *Field, entry: *Entry) void {
75 _ = self;
76 _ = child;
77 _ = field;
78 _ = entry;
79 }
7180 };
7281
7382 const Self = @This();
......@@ -463,16 +472,18 @@ pub fn MultiArrayList(comptime S: type) type {
463472 } });
464473 };
465474 /// This function is used in the debugger pretty formatters in tools/ to fetch the
466 /// child type to facilitate fancy debug printing for this type.
467 fn dbHelper(self: *Self, child: *S, entry: *Entry) void {
475 /// child field order and entry type to facilitate fancy debug printing for this type.
476 fn dbHelper(self: *Self, child: *S, field: *Field, entry: *Entry) void {
468477 _ = self;
469478 _ = child;
479 _ = field;
470480 _ = entry;
471481 }
472482
473483 comptime {
474484 if (builtin.mode == .Debug) {
475485 _ = dbHelper;
486 _ = Slice.dbHelper;
476487 }
477488 }
478489 };
tools/lldb_pretty_printers.py+37-4
......@@ -201,7 +201,7 @@ class std_MultiArrayList_SynthProvider:
201201
202202 value_type = self.value.type
203203 for helper in self.value.target.FindFunctions('%s.dbHelper' % value_type.name, lldb.eFunctionNameTypeFull):
204 ptr_self_type, ptr_child_type, ptr_entry_type = helper.function.type.GetFunctionArgumentTypes()
204 ptr_self_type, ptr_child_type, ptr_field_type, ptr_entry_type = helper.function.type.GetFunctionArgumentTypes()
205205 if ptr_self_type.GetPointeeType() == value_type: break
206206 else: return
207207
......@@ -221,12 +221,44 @@ class std_MultiArrayList_SynthProvider:
221221 offset = 0
222222 data = lldb.SBData()
223223 for field in self.entry_type.fields:
224 ptr_field_type = field.type
225 field_size = ptr_field_type.GetPointeeType().size
226 data.Append(self.bytes.CreateChildAtOffset(field.name, offset + index * field_size, ptr_field_type).address_of.data)
224 field_type = field.type.GetPointeeType()
225 field_size = field_type.size
226 data.Append(self.bytes.CreateChildAtOffset(field.name, offset + index * field_size, field_type).address_of.data)
227227 offset += self.capacity * field_size
228228 return self.bytes.CreateValueFromData('[%d]' % index, data, self.entry_type)
229229 except: return None
230class std_MultiArrayList_Slice_SynthProvider:
231 def __init__(self, value, _=None): self.value = value
232 def update(self):
233 try:
234 self.len = 0
235
236 value_type = self.value.type
237 for helper in self.value.target.FindFunctions('%s.dbHelper' % value_type.name, lldb.eFunctionNameTypeFull):
238 ptr_self_type, ptr_child_type, ptr_field_type, ptr_entry_type = helper.function.type.GetFunctionArgumentTypes()
239 if ptr_self_type.GetPointeeType() == value_type: break
240 else: return
241
242 self.fields = {member.name: index for index, member in enumerate(ptr_field_type.GetPointeeType().enum_members)}
243 self.entry_type = ptr_entry_type.GetPointeeType()
244 self.ptrs = self.value.GetChildMemberWithName('ptrs')
245 self.len = self.value.GetChildMemberWithName('len').unsigned
246 self.capacity = self.value.GetChildMemberWithName('capacity').unsigned
247 except: pass
248 def has_children(self): return True
249 def num_children(self): return self.len
250 def get_child_index(self, name):
251 try: return int(name.removeprefix('[').removesuffix(']'))
252 except: return -1
253 def get_child_at_index(self, index):
254 try:
255 if index < 0 or index >= self.len: return None
256 data = lldb.SBData()
257 for field in self.entry_type.fields:
258 field_type = field.type.GetPointeeType()
259 data.Append(self.ptrs.child[self.fields[field.name.removesuffix('_ptr')]].CreateChildAtOffset(field.name, index * field_type.size, field_type).address_of.data)
260 return self.ptrs.CreateValueFromData('[%d]' % index, data, self.entry_type)
261 except: return None
230262
231263class std_HashMapUnmanaged_SynthProvider:
232264 def __init__(self, value, _=None): self.value = value
......@@ -556,6 +588,7 @@ def __lldb_init_module(debugger, _=None):
556588 add(debugger, category='zig.std', type='mem.Allocator', summary='${var.ptr}')
557589 add(debugger, category='zig.std', regex=True, type='^segmented_list\\.SegmentedList\\(.*\\)$', identifier='std_SegmentedList', synth=True, expand=True, summary='len=${var.len}')
558590 add(debugger, category='zig.std', regex=True, type='^multi_array_list\\.MultiArrayList\\(.*\\)$', identifier='std_MultiArrayList', synth=True, expand=True, summary='len=${var.len} capacity=${var.capacity}')
591 add(debugger, category='zig.std', regex=True, type='^multi_array_list\\.MultiArrayList\\(.*\\)\\.Slice$', identifier='std_MultiArrayList_Slice', synth=True, expand=True, summary='len=${var.len} capacity=${var.capacity}')
559592 add(debugger, category='zig.std', regex=True, type=MultiArrayList_Entry('.*'), identifier='std_Entry', synth=True, inline_children=True, summary=True)
560593 add(debugger, category='zig.std', regex=True, type='^hash_map\\.HashMapUnmanaged\\(.*\\)$', identifier='std_HashMapUnmanaged', synth=True, expand=True, summary=True)
561594 add(debugger, category='zig.std', regex=True, type='^hash_map\\.HashMapUnmanaged\\(.*\\)\\.Entry$', identifier = 'std_Entry', synth=True, inline_children=True, summary=True)