Skip to content

Metaissue for Visual Studio debugging Rust #40460

Closed

Description

@sophiajt

Recently, I started playing with the new VS 2017 Community edition. Specifically, I wanted to see if Rust debugging works with VS. Good news: out of the box, you can attach to running Rust applications compiled in debug mode, pause them, and begin debugging.

The experience isn't perfect, and I hope to grow this issue to include the places where the experience can be improved.

Activity

  1. Boddlnagg commented on Mar 12, 2017

    @Boddlnagg
    Contributor

    There was some previous work trying to use natvis: #36503

    Notably, the following natvis code enables the VS "Text Visualizer" for strings, using the correct UTF-8 encoding (at least this worked in VS 2015):

      <Type Name="collections::string::String">
        <DisplayString>{vec.buf.ptr.pointer.__0, [vec.len]s8}</DisplayString>
        <StringView>vec.buf.ptr.pointer.__0, [vec.len]s8</StringView>
      </Type>
  2. sophiajt commented on Mar 12, 2017

    @sophiajt
    ContributorAuthor

    @Boddlnagg - I noticed that only works if you have patched s8 support? I tried just copying/pasting your example with out and wasn't able to get it to work.

    I also noticed that #39843 is related to the natvis work.

  3. Boddlnagg commented on Mar 13, 2017

    @Boddlnagg
    Contributor

    @jonathandturner I did not patch s8 support (I don't even know what you mean by that) ... but I had to manually work around #36646 by patching the type information in the PDB.

    I'd also like to point out that #36503 (comment) explains the ability to embed natvis files into PDBs (maybe rustc could do that automatically at some point).

  4. codec-abc commented on Mar 13, 2017

    @codec-abc

    I think that if it is possible, conditional breakpoints would be a nice addition.

  5. mzji commented on Mar 15, 2017

    @mzji

    rustc/cargo don't copy the .pdb file to the directory of the executable automatically anymore, is that a decision/design of rustc/cargo? IIRC rustc 1.13 will copy the .pdb file.

  6. retep998 commented on Mar 15, 2017

    @retep998
    Contributor

    @mzji The .exe or .dll has the absolute path to the .pdb hardcoded so the debugger can still find the .pdb even if you moved the .exe or .dll.

  7. mzji commented on Mar 15, 2017

    @mzji

    @retep998 So if the debugger failed to load the .pdb files automatically, does that means there is a bug in the debugger?

    Here is the log when I try to debug my new project with x64dbg:

    SYMSRV:  C:\Users\admin\Documents\x64dbg\x64\symbols\vs2017detect-18f12543191b1f33.pdb\98880B4BE9AF44E5A205282AEBB1C814d\vs2017detect-18f12543191b1f33.pdb not found
    DBGHELP: C:\Users\admin\Documents\vs2017detect\target\debug\vs2017detect-18f12543191b1f33.pdb - file not found
    ...(unrelated part eliminated)
    

    After failed loading from the symbol cache, x64dbg just tries to load the file from the working directory of the executable. And the DBGHELP part made me believe that x64dbg is using some windows system library to do this. Is there a bug in the debugger, or this behavior is just what windows will do?

  8. lnicola commented on Mar 15, 2017

    @lnicola
    Member

    @mzji I think VS loads the PDB, but in VS Code I had to change the launch configuration to run the executable from the deps folder (with the PDB next to it). I would have expected WinDbg to behave just like VS does, though.

  9. mzji commented on Mar 15, 2017

    @mzji

    @lnicola Then I think we should at least leave a copy in the directory of binaries, since different debuggers do different things (VS will find and load pdb files automatically, VS Code/Ollydbg/x64dbg and all debuggers which is only using DBGHELP won't).

  10. codec-abc commented on Mar 15, 2017

    @codec-abc

    Back to the original issues, the most 2 annoying things that happen when I try to debug Servo is that:

    • Breakpoints are hit multiple times per line in some cases.
    • Enums values are not understood in the "local" inspector. This is annoying since most Rust code use heavily Option and Result.
  11. sophiajt commented on Mar 15, 2017

    @sophiajt
    ContributorAuthor

    @codec-abc - by chance, have you tried using the natvis from this PR to see if it helps with your second bullet point? #39843

    I've been chatting with the author and would like to potentially make it part of the pdb at some point.

  12. codec-abc commented on Mar 15, 2017

    @codec-abc

    I used the one in the opening message of the issue. So they are probably different.

    Edit : Damned the "good" one was just a few characters away. How stupid I am.

  13. sophiajt commented on Mar 15, 2017

    @sophiajt
    ContributorAuthor

    @codec-abc - yeah, the one in the PR is much better than mine, with support for more common Rust std lib structures.

  14. added
    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)
    O-windowsOperating system: Windows
    metabugIssues about issues themselves ("bugs about bugs")
    on Jun 13, 2017
  15. MaulingMonkey commented on Jul 13, 2017

    @MaulingMonkey
    Contributor
    • Fixes for u8/i8 have landed in nightly.
    • Some stdlib visualizers have landed in stable.
    • I have a hacky changelist I'm working on to enable visualization of &str and array slices (via renaming debug info), and to auto-embed .natvis files into the resulting pdbs for maximum convenience.
  16. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jul 27, 2017
  17. added a commit that references this issue on Jul 28, 2017
  18. added
    O-windows-msvcToolchain: MSVC, Operating system: Windows
    and removed
    O-windowsOperating system: Windows
    on Mar 23, 2019
  19. abonander commented on Jun 13, 2019

    @abonander
    Contributor

    @MaulingMonkey's PR brought visualization quite a long way but there's still a few shortcomings in the debugging experience as of the latest nightly:

    • Mutable slices need a separate visualizer entry, as their type name is mut slice<*>; I was able to fix this just by duplicating the visualizer entry for slice in intrinsic.natvis:
     <Type Name="slice&lt;*&gt;">
        <DisplayString>{{ length={length} }}</DisplayString>
        <Expand>
          <Item Name="[size]" ExcludeView="simple">length</Item>
          <ArrayItems>
            <Size>length</Size>
            <ValuePointer>data_ptr</ValuePointer>
          </ArrayItems>
        </Expand>
        </Type>
        <!-- added -->
        <Type Name="mut slice&lt;*&gt;">
        <DisplayString>{{ length={length} }}</DisplayString>
        <Expand>
          <Item Name="[size]" ExcludeView="simple">length</Item>
          <ArrayItems>
            <Size>length</Size>
            <ValuePointer>data_ptr</ValuePointer>
          </ArrayItems>
        </Expand>
      </Type>
    • Slice visualization works fine in the same stack frame that the slice is created but breaks down when the slice is passed to a function call:
    Source frame Top frame
    image image
    • Also, you look closely in the screenshot above you can see that the fn main() stack frame is shown at the wrong source line.

    (This is VS2017, but it's the same in VS2019.)

  20. added a commit that references this issue on Nov 23, 2019
  21. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 26, 2019
  22. rylev commented on Feb 26, 2021

    @rylev
    Contributor

    There has been progress on this issue from several fronts lately:

    Some additional todos/issues:

    • Arrays cannot provide custom DisplayStrings
    • Option where the option can take advantage of the None == 0 niche not showing in WinDbg
    • No debug info for char locals
  23. pnkfelix commented on Mar 18, 2022

    @pnkfelix
    Contributor

    Visiting for T-compiler backlog bonanza.

    After discussion, we think its an anti-pattern to have an issue with an ever-growing list of features that will evolve, especially to match a debugger that is also growing new features over time. (If you want to see all the debugging issues on windows, you can use a github issue query for A-debuginfo and O-windows, or something along those lines.)

    So, we think the main focus of this issue should be the four points that were raised in the description (and new issues should be filed to cover new goals).

    As for the four points in the description, @wesleywiser says that the first three are fixed today, and believes the fourth to be fixed if you are using Visual Studio 2022.

    Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCO-windows-msvcToolchain: MSVC, Operating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.metabugIssues about issues themselves ("bugs about bugs")

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions