Can I call my debugging Zig functions inside lldb?

Found a temporary solution that fits my needs:

dap> p *(uint8_t (*)[`needle_pos - index`])(queue_item.string + index)
(uint8_t[8]) "лмао"
dap> p *(uint8_t (*)[`needle.len`])(needle.ptr)
(uint8_t[3]) "\U000000011\U00000001"
dap> 

Printing a select substring from [N]u8 (fixed-size array of u8)

This p *(uint8_t (*)[`needle_pos - index`])(queue_item.string + index) does casting. It casts the array to an N-sized array, i.e., cuts off the array. The (queue_item.string + index) part tells where to start the array.

This is not a great explanation.

:warning: Without backticks, it can’t evaluate needle_pos - index

So, basically, it’s array_u8[start_usize .. end_usize], but super ugly.

Printing a select substring from [ ]u8 (slice structs)

Just access the slice’s ptr – address of the actual u8 array – with dot notation.

Don’t forget to import lldb_pretty_printers.py

Here’s my related nvim settings.

I think we can create a custom lldb syntax using Python scripting, so we can just do array_u8[start_usize .. end_usize] inside lldb. But I don’t have time to do that right now.

3 Likes