I’ve come to know that we can’t have nice things such as printing slices or slice expressions and much more in a debugger in Zig, or in low-level programming languages like C in general.
At least, that’s how it feels to me. I could very well be horribly wrong and these could just be skill issues of looking up an info.
Anyways, these are the words of someone who is used to taking Python REPL’s niceties for granted. So, to ease the pain, I think there should at least be a workaround to call my Zig functions inside lldb
.
For example, this will satisfy my greedy needs:
debug_tools.zig
:
pub fn asSlice(input: []u8, start: usize, end: usize) []const u8 {
if (end == 0)
return input[start..input.len]
else
return input[start .. end - 1];
}
pub fn asSliceToEnd(input: []u8, start: usize) []const u8 {
return asSlice(input, start, 0);
}
combining with lldb_pretty_printers.py
.
But I can’t seem to call these functions:
* thread #1, name = 'zigxatolik', stop reason = step over
frame #0: 0x0000000001a68dc5 zigxatolik`preprocessor.unfreeze(queue_item=0x00007fffff5e97fc) at preprocessor.zig:189:43
186 for (0..queue_item.entity_count) |i| {
187 const needle = try std.fmt.bufPrint(&needle_buf, "\x01{d}\x01", .{i});
188 const needle_pos = std.mem.indexOf(u8, &queue_item.string, needle).?;
-> 189 const entity_len = std.mem.indexOf(u8, &queue_item.entities[i], "\x00").?;
190 std.mem.copyForwards(u8, output_buf[index_buf..], queue_item.string[index..needle_pos]);
191 index += needle_pos + needle.len;
192 if (i == 0)
(lldb) expression asSliceToEnd(needle, 0)
error: <user expression 0>:1:1: use of undeclared identifier 'asSliceToEnd'
1 | asSliceToEnd(needle, 0)
| ^
(lldb) p asSliceToEnd(needle, 0)
error: <user expression 1>:1:1: use of undeclared identifier 'asSliceToEnd'
1 | asSliceToEnd(needle, 0)
| ^
I’ll get down on my knees if someone can point me in the right direction