Attach visual studio to a short lived process
Asked Answered
C

1

5

I have a console application that dies very quickly, and upon inspecting the code, I can't tell exactly where it'll die (I've basically narrowed it down to a 10 line radius) so that I further debug it.

For reasons I won't go into, I can't execute the process from VS (I have the binaries, source, and pdbs though, but I can't build outside of the build server's environment), and would like to attach to the process... but when I start the process, it dies much sooner than I could ever hope to refresh the attach to process dialog.

Ideas?

Curly answered 20/2, 2013 at 0:25 Comment(4)
If you start the application in the debugger of VS and place a break point on the first (or any consistently) called constructor, you should be able to step through it line by line until it exits.Discordance
possible duplicate of How to set breakpoint at the very beginning of program executionWallie
I probably am missing something, but you should be able to use any existing project (just create an tiny one if needed) and then specify the application that you are debugging as the "Command" to run in the debugger options. Then you can just run it and should not need to attach to it.Pervade
@MarkWilkins: You weren't missing anything, that was it. I have to "run the most recent successful build" which doesn't exist... but it still runs and I can step through it. Thanks. If you want to promote your comment to an answer, I'll mark it as the answer.Curly
P
8

One possibility for doing this is to use any existing Visual Studio project and specify the application as the application to debug. The steps (in Visual Studio 2010) are:

  • Go to the project properties.
  • Choose Debugging (under Configuration Properties)
  • Edit the Command and fill in the path to the binary

Then it should be possible just to start debugging (e.g., F5 or Debug\Start Debugging).

Another option that might be a bit quicker if you have the debugging tools installed would be to use WinDbg.exe. It would avoid needing to use a Visual Studio project. You can open the executable, specify command line parameters, etc. and then type g<ret> in the command line to fire it up.

Pervade answered 20/2, 2013 at 18:11 Comment(1)
+1 this is brilliant, you don't even need to have the remote debugger running.Perchloride

© 2022 - 2024 — McMap. All rights reserved.