Visual Studio has an option called Do not launch, but debug my code when it launches.
For a long time, I was confused by this setting. It’s like telling someone, “Don’t drive my car, but wear a seat belt when you drive my car.”
I also tried to parse this as
(Do not launch, but debug my code) when it launches.
In other words, “When my code launches, don’t launch it; just debug it.”
Which makes no sense. “When my code launches, don’t launch it.”
I eventually got clued in that both of those attempts at parsing the statement were incorrect. The intended parse is
Do not launch, but (debug my code when it launches).
In other words, “Don’t launch it right now. Wait for somebody else to launch it, and then debug it when that launch happens.”
It’s the Visual Studio way of AeDebug (https://docs.microsoft.com/en-us/windows/win32/debug/configuring-automatic-debugging): don’t launch the code, but debug whenever it is launched. I wonder whether it’s using that Registry key do achieve the result.
The two uses of launch are different predicates, one with two places (transitive) and one with only one place (anticausative). It’s analogous to the storm sank the ship, so the ship sank. This is called causative alternation.
Perhaps a single additional word would have alleviated some of the confusion: “Do not launch now, but debug my code when it runs”.
Very useful. I was wondering how this is implemented, but currently searching all the google for “Do not launch, but debug my code when it launches”, or just “debug my code when it launches” only finds this blog entry. A guess would be some user-mode windows api trace call (WMI apparently can do it), or even IFEO if it handles Visual Studio not already running when launch occurs. It could also add code or some dependency during app build so extra stuff happens at process launch.
I would assume it temporarily sets AeDebugger for the filename to itself (and when it’s invoked first checks if it’s actually the right file and not just the right filename, and if it isn’t, runs the process normally and detaches).