Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link: Add natvis file support #19873

Conversation

The-King-of-Toasters
Copy link
Contributor

@The-King-of-Toasters The-King-of-Toasters commented May 6, 2024

This PR the ability to include Natvis files into a module's PDB using Compile.addObjectFile. This is eventually passed to the linker via the -NATVIS:[file] flag. Fixes: #19646.

This is my first PR that touches the compiler, so review by people working in that area would be great.

Features:

  • Link natvis files for executables.
  • Include natvis files specified by any dependency using Compile.linkLibrary.
  • Create a set of visualisations for the language & standard library and add them to every PDB by default.

Reasons for Inclusion

  • Enhances the ability for the Zig build system to be used to build existing C/C++ projects on Windows.
  • Improves the debugging experience for Zig devs on windows, which is already an underserved market.
  • Doesn't modify/bloat the code as it only add a named stream to PDBs.

Issues

There is no way to add visualizers for slices as they have square brackets in their type name, which isn't allowed for C++ types. This is an issue the Rust devs ran into and AFAIK still hasn't been fixed. Note that it is still possible to do (char*)buf.ptr,[buf.len]s8 for a []u8 slice when in the debugger.

Some types like packed structs/comptime known enums are lowered to their integer representation when debugging, and these base types cannot be selected for visualization.

Adds the ability to include Natvis[1] files into a module's PDB using
`Compile.addObjectFile`. This is eventually passed to the linker via the
`-NATVIS:[file]` flag.

Fixes: ziglang#19646
@The-King-of-Toasters
Copy link
Contributor Author

@kubkon Could you put this on your review queue? I don't want the pr to get deleted due to being a draft for a month :x.

@andrewrk
Copy link
Member

closing 30+ days old draft

@andrewrk andrewrk closed this Oct 15, 2024
@kubkon
Copy link
Member

kubkon commented Oct 15, 2024

@kubkon Could you put this on your review queue? I don't want the pr to get deleted due to being a draft for a month :x.

Oh no, I'm so sorry for not reviewing your PR on time - your PR slipped under my radar! Having said that though, I do not feel qualified at reviewing it since 1) I do not really use Windows on a daily basis, and 2) I have no idea what natvis actually is. If I did implement support for natvis in our self-hosted COFF linker, then I would be in a much better position to review, but we are far away from that I think given the state COFF linker is in.

@The-King-of-Toasters
Copy link
Contributor Author

The issue at the top has more info but TL;DR it's way to add custom visualisations for types when run using a Microsoft debugger (WinDbg, Visual Studio, VSCode). You define them in XML files (yes, I know) and the linker adds it as a stream in a PDB. AFAICT we don't even produce PDBs in self-hosted so this only works when using the LLVM linker (with the -NATVIS flag).

This was mainly me hacking around the linking code so don't feel too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to link Natvis files into PDBs
3 participants