-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Better tooling support to debug source generators (breakpoints) #51962
Comments
CC: @jasonmalinowski and @chsienki we are working something like this to improve the experience here: dotnet/roslyn-sdk#738 that should make it into Visual Studio 16.10 Preview 2. The intent is that you just set a break point and start debugging as you describe. Chris has also built https://github.com/chsienki/Kittitas which I hope to leverage so we can make debugging source generators for developers on linux an easy thing to accomplish. |
That's awesome, glad to hear this is already in the works and coming soon! |
This is now supported via generator debugging the roslyn sdk. |
Just double checking I'm not getting something wrong, I'm not sure I'm follow what the suggested approach is here.
I'm using VS2022 Preview 3, and just trying to add a breakpoint into a generator and then building a project consuming the generator doesn't actually seem to be working, the breakpoint is never hit and enabled. I still have to add a |
@Sergio0694 There's a bit of setup you do -- you set the generator project as the thing being debugged and you pick one of your other projects in the project properties. There's some documentation here: http://stevetalkscode.co.uk/debug-source-generators-with-vs2019-1610 @chsienki Did we write docs anywhere for this? |
Just to circle back on this - I realize the issue has been closed as completely but the debugging situation still seems not ideal. I can't find any official docs on MS Docs to debug source generators, and even just reading that blog post the setup seems clunky enough (extra VS workload needed, have to edit the .csproj, then edit the properties, etc.) that I find myself still just literally adding a As in, the same steps are already possible (and I use them all the time), so it'd just be about providing better tooling for it? |
Overview
Since I started using source generators (which again, are brilliant!), I find the debugging experience particularly clunky. Not sure if I'm using the wrong approach here, but more or less my workflow to investigate crashes in my source generators is this:
Debugger.Launch();
call at the first line of theExecute
method in that source generatorDebugger.Launch();
)Now, this is somewhat clunky but overall not the worst, and it works fine. The issue though is that since Roslyn just tries to run the generator all the time, once you add that line you basically start having VS open the popup "an exception was thrown, launch a debugger?" every 2 seconds, forever. You basically can't work anymore as that window keeps popping up constantly: you have to delete that line, rebuild the generator, clean the other project and then it stops. If you close VS and reopen it, that popup starts showing up every 2 seconds again unless you've also cleaned the solution (since the compiled generator references is cached by VS.
The main issue is that if you just try to add a breakpoint into your source generator, and then rebuild the project using it, that breakpoint will just never actually be hit, despite Roslyn running the shader just fine. Same for using the "Exceptions Settings" window, even if you check an exception to have VS break on it, that doesn't work for a source generator.
Proposal
Would it be possible to just have breakpoints work from source generators? 😄
As in, so that if you set one and rebuild a project referencing the generator, the breakpoint would just be hit as expected. Then after that you could just remove it and go about your day. Since the generated assembly wouldn't be changed (no more
Debugger.Launch()
call), that isssue with VS just spamming those popups would go away as well.The text was updated successfully, but these errors were encountered: