-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
dotnet.exe host should have a --debug switch #2456
Comments
@eerhardt Are you not able to use VS debugger do the same by pointing it to a command line? |
That approach is less than ideal because:
|
@eerhardt so, in summary, the proposal is to, at least, have an easy way for people to get a PID of the host running? |
BTW - without this 'feature', folks have been inventing it themselves by using See https://github.com/search?p=3&q=org%3Adotnet+DebugHelper&type=Code for all the places it is used in our 'dotnet' repos today. |
AND pause the app until I say "GO" |
@eerhardt got it. The pause part is actually the more useful one, as getting the PID can be done in different ways. I have to say, this could be useful actually, from a user's POV. |
@eerhardt trying to understand this ask... how did desktop framework work without this feature? AFAIK, no program suspends on its own for a potential debugger attach, so why should a managed program host do this? |
See my link above. That shows at least 3 programs that we wrote in the CLI and in core-setup. Also, CoreRun.exe does this today:
I won't go searching for all the programs in the world that do this, but suffice it to say, this seems valuable to a lot of people if we have that DebugHelper class, and CoreRun.exe implemented it. And the only reason I knew about CoreRun.exe is because @rainersigwald pointed it out to me, because he uses it. So we have users outside of the .NET team who use this switch in CoreRun.
desktop framework was very "VS centric". .NET Core runs on platforms VS isn't capable of running on. |
@schellap The problem is that it's easy to Also, every program I maintain has a clause like this: if (Environment.GetEnvironmentVariable("{something}DEBUGONSTART") == 1)
{
Debugger.Launch();
} Sure would be nice if it were built in. |
@rainersigwald and @eerhardt, thanks. We can bake this in with some switch that doesn't conflict with dotnet.dll. @eerhardt, sorry... I wanted to call out that most programs native or managed (incl. Desktop apps) don't have this support, for these handful of programs you quoted. They are being debugged fine... did not ask to list what programs do this today. |
I guess I still have more questions to understand this better. If the goal is to attach the debugger before any managed application is launched, then doing "windbg dotnet <app.dll>" is equivalent to what you are requesting for. @rainersigwald Can you please explain your workflow while using the switch? Is it the case that you do not own the process that launches the application? |
@gkhanna79 I use this all the time to debug unit tests with xunit: I like being able to use VS to debug using the session I'm using to develop, with persistent breakpoints and mental state built up over multiple runs of the program under test. But when the entry-point application is a netcore app that's not my code, it's really inconvenient to set VS up to launch it. Maybe there's a better way, but the only way I know is to create a new bogus xproj and configure it to launch the application. My mental cost/benefit calculation always makes it seem like it's cheaper to launch with the debug flag and manually attach from my VS. Just prefixing the command line with If there's an actually-easy way to get a running instance of VS to attach to a short-lived program via command line, I'd be happy. This seems like a way to get that. |
@gkhanna79 this sounds like a feature, and we're past feature complete.. |
Yeah, this nice to have and can move out. |
I would also like to have this option for so I can debug during |
If you think about implementing that, please make sure that the implementation does not print to console. If you write a .net core console application that is used to stream out some data into stdout and you want to pipe that to another console application, any extra console output will mess that up. |
Moving this out again; feature complete is next week and this won't make it |
Moving to 3.0 Summary:
|
See https://twitter.com/migueldeicaza/status/1013061980284997632?s=21 for others talking about this same thing. It would be great if this was just built in to the platform. (Note the link to the tweet about forgetting to remove Thread.Sleep(30s) from the code, causing slow startup) |
I'd love to see this make it into 3.0. |
I would like to get @tommcdon perspective on this feature ask. |
Adding @noahfalk and @mikem8361. The "wait for attach" approach sounds interesting and is potentially useful, esp for remote VS debug scenarios. |
We need to be clear about what the flag is waiting for: a native debugger attach (which is what corerun's /d is waiting for) or a managed debugger attach (like from VS or VSCode). These are very different features. |
Maybe |
I don't think we can assume what debugger is going to used. It depends on the dev. Some devs want to debug the runtime itself or debug natively using VS, windbg, cdb on Windows or lldb on Linux/MacOS. Others may want to debug the just the managed code using VS/VSCode on Windows or VSCode on Linux/MacOS. Either we purpose two flags like "--native-debug" and "--managed-debug" or be very clear about which scenario we are talking about here. |
Maybe then |
I want to help convince people that this is an important feature by looking at an example from the Java ecosystem. This may also inform the design that you eventually choose. Ever since Java 1.3 (or maybe 1.5), when you launch a java program, you can pass args like the following to java.exe:
The JRE then acts like a remote debugging host over port 1234. I understand that
I think
|
I would also like to suggest that being able to specify a unique port at startup eliminates the need to know the PID of the process that you are trying to debug. I get that you have committed to using
... such that you can now ask |
This functionality would be tremendously helpful when debugging startup issues in a remote container. |
@jeffschwMSFT any chance this can be addressed since June 2016? That would be really helpful, a lot. My example: when a Service Fabric services which is just a |
Question: Now that we have self-contained and runtime-dependent executables, is this feature needed only when doing The approaches suggested here only work in that scenario because any variation of --debug may already be a switch. System.CommandLine solved this by providing an alternate syntax for switches going to the startup model |
Well if the dotnet.exe used the System.CommandLine for parsing its args, then that would be great too (you'd get [debug] for free) |
Yes please, It's a pain to debug tests/apps in (e.g. local) kube clusters (and this should be the de-facto standard imo), and VS is so so slow to release support in tools for these environments. And half of my team don't use VS anyway, and some others aren't even on windows. Anything to make this easier and remove random stuff from our code/tooling. Moved rant to end: And then it's some convoluted stuff e.g. that docker stuff that's supported in the csproj with some rapid build stuff, or connect to azure kube cluster but don't actually run your app in it - most of us have a local kube cluster or some other cloud service...just such a pain, I have just a container for you to connect to and run a proc my dude, I've mounted my host/source fs, when I press F5 or run test...why so complex? I swear I'm going to write a extension for vs that supports remote/container test run and debug at some point, it's like, an excel macro of a few clicks at best. I'm sure the laggy test explorer is easily replaced too, for those who have ever virtualized a listview 🤦 |
Something nobody here has thought of: this would be nice to exist on compiled platform dependent executables as well. And that means if you use command line arguments, you'd be getting in the way of their processing. An environmental variable might be better. |
Don't think it would get in the way: |
Steps to reproduce
It is too hard to debug applications when they aren't launched from VS. Today, you need to add some "Console.ReadLine()" calls in order to have the process wait for you to attach to the process.
Expected behavior
There should be an easy way to say "launch this .net core app and attach a debugger" or "wait for a debugger to be attached".
Actual behavior
This isn't possible today.
Notes
I think even if we enabled something simple in the host like:
if
--debug
is passed before the assembly to run, print out a message like: "DEBUG MODE: attach a debugger to process<process id>
and then hit ENTER to continue". That waits for the ENTER, and then your entry method is invoked./cc @schellap @gkhanna79 @piotrpMSFT @blackdwarf @brthor @ericstj @weshaggard
The text was updated successfully, but these errors were encountered: