Currently when debugging on Windows, slices show up as just ptr+len, which is a bit inconvenient, especially when debuggers can show arrays.
I was setting up a *.natvis file to assist with this, but have run into a problem. Can’t seem to get dynamic arrays or slices with *.natvis files (apparently because their exported debug symbols have a square bracket in them?).
This is the file I had written so far:
(paraphrased)
<Type Name="string">
<DisplayString>{data,[len]s8}</DisplayString>
<StringView>data,[len]s8</StringView>
<Expand>
<Item Name="[length]">len</Item>
<ArrayItems>
<Size>len</Size>
<ValuePointer>data</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="[]*">
<DisplayString>Length = {len}</DisplayString>
</Type>
The string
visualizer seems to be working perfectly, but not the slice one. I have also tried: \[\]*
, []u8
(to see if i can get specific types to work), \[\]u8
, []u8
, [*]u8
and so many other combos. Does anyone here have an idea how to make it work?
My first instinct would have been to take apart the .pdb
file if you’re on windows and the DWARF data inside the ELF file if you’re on linux and try to find how the slice type is named in there. But then I realised that the debug info, is generated by the Odin compiler.
- The string types are output by calling this function with the literal
"string"
as &name
parameter.
- For slices the generation of the
&name
parameter is generated via name canonicalization, where it picks up the value "[]u8"
.
So as far as the compiler concerned, one of your attempts should have been correct: <Type Name="[]u8">
should have matched the slice type. But I guess for some reason it doesnt.
I guess there are others things to try:
And also I dont think the brackets need to be escaped. There are examples on the documentation page that use them for property names, so that should be fine.
Good luck with figuring it out
Found the reason; apparently vsdbg
considers []u8
to be an invalid name; here’s the error from natvis messages:
Natvis: D:\Projects\C++\Cool\Cool\cool\odin.natvis(28,4): Error: Invalid type name '[]u8'.
----- Update -----
I did some more debugging, apparently vsdbg
just altogether doesn’t support square brackets as valid type names.
Will it be overkill if I modify odin’s exported type names in symbols so that it can be natvis compatible and make a pr?
@gingerBill @flysand7
I’m not the person to ask for whether it is a good idea, but what I can say is that it is pretty hard to do so without potentially breaking the logic for something else. For example, if you named it Slice<T>
, then you’d potentially conflict with a user-defined type Slice
. If you want to hide it behind a standard type, something like runtime.Raw_Slice<T>
, then it is not clear how actual raw slices should be represented. Maybe using a $
(which is a valid character for a symbol to have), could be better. $slice<T>
or something.
Regardless, here’s some other types to consider (you might need to check the compiler for how they are exported):
- Slices:
[]T
→ $slice<T>
- Arrays:
[N]T
→ $array<T>
- Enum-indexed arrays:
[E]T
→ $enum_array<E, T>
- Dynamic arrays:
dynamic [T]U
→ $dynamic_array<T, U>
- Maps:
map[T]U
→ $map<T, U>
Speaking of arrays, how does C or C++ use natvis arrays? If I’m not mistaken their type names also contain brackets. Maybe this investigation could lead you to a better solution than what I’ve come up with.
The other point I’d like to discuss is simply naming them slice
, map
etc., since all user (and standard/runtime library) types would probably be something like package.Type
(with a package name).
1 Like