# Display slices in the debugger

**URL:** <https://ziggit.dev/t/display-slices-in-the-debugger/5079>\
**Category:** Help\
**Tags:** debugger\
**Created:** [July 10, 2024, 7:30pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079 "2024-07-10T19:30:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [July 10, 2024, 7:30pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079/1 "2024-07-10T19:30:48Z")

</div>

I’m debugging some slice-heavy code using `lldb` from VSCode, and it’s excessively difficult to follow, because the slices aren’t null-terminated, so the debugger displays arbitrary amounts of string, and I have to figure out how much of it actually belongs to the slice.

Is there a trick to get the `slice.ptr` section to display just the amount covered by `slice.len`?

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [July 10, 2024, 9:10pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079/2 "2024-07-10T21:10:12Z")

</div>

In zig repository there is a python pretty printer extension for lldb that can print slices, strings, optional, etc.: [tools/lldb\_pretty\_printers.py](https://github.com/ziglang/zig/blob/master/tools/lldb_pretty_printers.py)

```zig
❯ lldb ./test
(lldb) target create "./test"
Current executable set to '/home/din/test' (x86_64).
(lldb) b main
Breakpoint 1: where = test`test.main + 8 at test.zig:4:5, address = 0x00000000010350d8
(lldb) r
Process 30732 launched: '/home/din/test' (x86_64)
Process 30732 stopped
* thread #1, name = 'test', stop reason = breakpoint 1.1
    frame #0: 0x00000000010350d8 test`test.main at test.zig:4:5
   1 const std = @import("std");
   2   
   3 pub fn main() void {
-> 4 const data: []const u8 = &[_]u8{ 'a', 'b', 'c' };
   5 std.debug.print("{s}", .{data});
   6 }
   7   
(lldb) s
Process 30732 stopped
* thread #1, name = 'test', stop reason = step in
    frame #0: 0x00000000010350e8 test`test.main at test.zig:5:20
   2   
   3 pub fn main() void {
   4 const data: []const u8 = &[_]u8{ 'a', 'b', 'c' };
-> 5 std.debug.print("{s}", .{data});
   6 }
   7   
(lldb) p data
([]u8) "abc"
(lldb) 

```

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [July 10, 2024, 11:05pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079/3 "2024-07-10T23:05:26Z")

</div>

Perfect, thank you. I figured there must be something like that available, but it isn’t configured into ZLS or the Zig Extras package for VSCode (or if it is, I don’t have my settings right). That’s going to make my life a lot easier.

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [July 13, 2024, 3:31pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079/4 "2024-07-13T15:31:32Z")

</div>

As a breadcrumb for others who might be searching for LLDB pretty-printing, or how to display Zig data structures in the debugger, or other such phrases, this was fairly simple to add to VSCode.

In addition to the [Zig Language](https://github.com/ziglang/vscode-zig) plugin, you’ll want [Zig Language Extras](https://github.com/ianic/zig-language-extras). This advice may become outdated at some point, if and when the main plugin adds debug functionality. A particularly useful feature of the extras plugin is launching a debug session from a test block, as well as just running them one block at a time in the editor.

With that configured, you’ll need a local copy of the Zig repo, or at least of the file linked in the marked reply. Add the commands you need from Settings like so: search LLDB, and find this field:

 ![LLDB init commands](https://ziggit.dev/uploads/default/original/2X/a/a4027cf8c2edcad9802cc346194e1cc4b384f8ac.jpeg)

Just like in the top of the pretty-print script. You need to do it this way because the plugin won’t read your `.lldbinit` from the home directory. There may be a way to set that up, but I found this first, and it works fine.

That’s it, now your `[]const u8`s look like strings and so on.

---

<div class="post-metadata">

**Author:** ![TFManual](https://ziggit.dev/user_avatar/ziggit.dev/tfmanual/32/4513_2.png) [@TFManual](https://ziggit.dev/u/TFManual)\
**Post date:** [February 8, 2025, 3:39pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079/5 "2025-02-08T15:39:02Z")

</div>

I had to also add

```zig
type category enable zig.lang

```

to make it work for me.

`type category enable zig.stage2` may also be needed

---

<div class="post-metadata">

**Author:** ![cryptocode](https://ziggit.dev/user_avatar/ziggit.dev/cryptocode/32/817_2.png) [@cryptocode](https://ziggit.dev/u/cryptocode)\
**Post date:** [April 16, 2025, 12:45pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079/6 "2025-04-16T12:45:11Z")

</div>

If you want to share the pretty printer script between vscode and command line lldb, simply add this to `launch.json`:

```zig
"initCommands": [
    "command source ~/.lldbinit"
],

```

my ~./lldbinit looks like this:

```zig
command script import /path/to/zig/tools/lldb_pretty_printers.py

type category enable zig.lang
type category enable zig.std
type category enable zig.stage2

```

Finally, since I build lldb myself, I had to specify the path like so in `launch.json`:

```zig
"env": {
    "LLDB_LAUNCHER": "/opt/homebrew/opt/llvm/bin/lldb"
}

```

---

<div class="post-metadata">

**Author:** ![amelvil2](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@amelvil2](https://ziggit.dev/u/amelvil2)\
**Post date:** [February 13, 2026, 3:30pm UTC](https://ziggit.dev/t/display-slices-in-the-debugger/5079/7 "2026-02-13T15:30:05Z")

</div>

Thanks for the sample ~/.lldbinit script,

The `type category enable` lines are very necessary for printing hashmaps to work – when I originally posted this I thought the pretty print script was doing the heavy lifting on that, but I did more investigation and it seems like it might be really coming from `zig.std`

Just as a bit of troubleshooting help if anyone needs it, on MacOS if you see an error like this,

```log
error: module importing failed: Traceback (most recent call last):
File “”, line 1, in
File “path/to/zig-0.15.2/tools/lldb_pretty_printers.py”, line 22
match struct_data.byte_order:
^
SyntaxError: invalid syntax

```

That probably means that it’s trying to use the old version of python that might come from doing `xcode-select` at some point.

If you installed llvm through homebrew (what I did), you can enable it like this:

```sh
export PATH=“$(brew --prefix llvm@21)/bin:$PATH”

```

You can verify what version of python you’re running for yourself by telling llvm to run a python script like this:

In ~/.lldbinit:

```sh
command script import path/to/lldb_version_check.py

```

In lldb\_version\_check.py:

```python
import sys

print('python version is', sys.version)
print('python path is', sys.executable)

```

If it’s configured right, that script should output something like this:

```zig
python version is 3.14.3 (main, Feb 3 2026, 15:32:20) [Clang 17.0.0 (clang-1700.6.3.2)]
python path is /opt/homebrew/opt/llvm/bin/lldb

```

But if you see this output, it’s the old version of python:

```zig
python version is 3.9.6 (default, Dec 2 2025, 07:27:58)
[Clang 17.0.0 (clang-1700.6.3.2)]
python path is /Library/Developer/CommandLineTools/usr/bin/lldb

```

Just figured I’d share that, in case people are reading this that don’t have a strong python background.

Also another tip, since there doesn’t seem to be a way to just get a particular key (or a range of keys) in lldb, you might find that the output from p is truncated.

I don’t know if there’s a better way to do this, but I put this in my ~/.lldbinit. Note that the `set set` is correct, it’s not a typo.

```sh
set set target.max-string-summary-length 100000
set set target.max-children-count 10000

```
