Attaching debugger to multiple processes - visual-studio

Very simple question from new user of multiple processes debugging.
Whenever I read MSDN articles regarding this topic, I read:
"You can attach to multiple processes when you are debugging, but only one process is active in the debugger at any given time"
If you can debug only single process actively, seemingly attaching multiple processes is not very useful if I can only activate a single process in the debugger.
Please correct me if I am not understanding the statement correct.

It means that while debugging, VS studio will switch between processes being debugged to gather information needed for debugging, otherwise would be a mess to understand what is happening to a process if multiple processes information are shown together.
An example to see it happening is creating a solution with two web applications and start debugging, VS itself will run both and attach to then, if you put a breakpoint in one endpoint of each app and call one endpoint, let's say here on app1, VS will stop on that breakpoint, and then call the endpoint on app2 before continuing the debugging on app1, visual Studio Will only switch to the other breakpoint when the first one gets released, than VS Will switch to app2 breakpoint.

Related

Attach debugger to app pool on recycle

I need to debug a dll that's getting loaded on a specific application pool process. I'm using WinDbg, and so far I have successfully found the correct w3wp.exe process. Problem is, the app pool recycles itself, sometimes before it reaches what I want to find (a very elusive second chance exception). Then, I need to start over.
How do I configure WinDbg to automatically attach to a w3wp.exe process that's connected to a specific app pool, every time it starts?
Another solution would be to get the crash dump - I tried using ADPlus.exe for this but it also needs to be started on a process and I didn't find a way to re-run it automatically on only the process I need AND every time it starts.
So to sum it up, I need a way to get a crash dump from a w3wp.exe process that's connected to a specific IIS App Pool when it crashes on a second chance exception, while the process gets restarted once in a while (not enough time for me to run the debug tools manually each time).
Eventually, I discovered this awesome tool called DebugDiag, which is an official Microsoft tool. It has a nice interface that allows collecting dumps on certain events, such as exceptions, and creates very useful logs.
On top of that - it has a special section specifically for IIS debugging, which allowed me to select the app pool I was interested in.
Download available here.

How to run a test while attached to a process in Visual Studio

I'm trying to debug some web services. I have a number of integration tests setup. I want to attach the debugger to my web process and then execute one of my tests. The problem is Visual Studio doesn't seem to allow me to run a test while I'm already attached to a process. Is there any way around this? The only way I've been able to do it is set a breakpoint in the test prior to calling the webservice, debug the unit test, and then once it hits the breakpoint attach the debugger to my webservice process. That's too many steps.
No I don't believe you could. You can however start up a second instance of visual studio and attach it to your web process with the appropriate breakpoints.
I know this is late but it's still relevant, at least up to VS2019.
What I do to work around this is this:
Attach the debugger to my web service
Detach the debugger
Take note of the 'Reattach to process' shortcut. I think the default is Shift+Alt+P
Run the unit test
Immediately hit the reattach shortcut
Unless your test starts up exceptionally quickly, this method will reattach the debugger before the tests start running.
Allen's answer is better if your machine can handle 2 instances of VS.

Visual studio process Unable to copy file

i have a visual studio 2010 , when i run project normal runs, and when i close window then make some changes and run, they says
"Error 5 Unable to copy file "obj\x86\Debug\Passport.exe" to "bin\Debug\Passport.exe". The process cannot access the file 'bin\Debug\Passport.exe' because it is being used by another process. Passport"
as i see in Passport.exe still in task manager. why?
(when i end that process again i can build project)
NOTE for my other projects no that problem, only for this.
Many thanks who can help :)
There are many reasons why this could happen, but basically it boils down to your passport process or a child process of it, not closing as soon as you "close the window".
Things to check:
1. Extra threads not being terminated (worker threads not complete etc.)
2. Debug, breakpoints causing closure process to hang.
First I would remove all breakpoints and then look at what processes you may be running that could be holding up process closure e.g. worker threads, file writing, hardware access.
Sometimes it's best to kill processes using the stop button in Visual Studio.

What's the advantage for 'attach to process' compared with 'Start Debugging'?

I am new to programming.
I know only Start debug before. Maybe start debug suit for some small application develop better.
I found Visual studio IDE provide another method of attach to process for using.
When & Why must I use the attach debugging?
Such as multi-threading application debugging. Client/Service application debugging. etc. Thank you.
Sometimes you need to debug a process started by another program.
For example you need a reliable solution and in order to protect against access violations, memory leaks and other barely recoverable stuff, you have a master program and several worker programs. The master program starts the worker program and passes parameters to it. How do you debug a worker program which is not intended to be started by anything except the master program?
You use "attach to process for that".
Typically you do it this way: insert a statement that blocks the worker program for some time - for example, call Sleep() for 15 seconds. Then you kindly ask the master program to start the worker program. When the worker program is started it blocks and you now have 15 seconds to attach to it.
This way you can debug almost any issues - problems at early startup stages, wrong parameters, etc, which you wouldn't reliably reproduce with "run with debugging".
Attaching to a process is useful if you don't want to debug right from starting the process. For example, debugging usually slows down execution, so it can be quicker to start the app, get it to a state where a bug appears, and then attach a debugger.
It's also useful if you already have an external means of launching the process that you don't want or can't to import into the IDE.
Start debugging from VS launches an instance of the VS webserver and attaches the debugger to it.
Attach to process allows you to attach to any process and debug it, usually you'd do this to your instance of w3wp.exe running your code in IIS
Attach to process is mostly used when you can't run the application from Visual Studio.
For example, if it's a service or if it is a process that has run for a long time and now you want to start debugging it.
Sometimes you also want to debug a remote process, not on your machine - and you can do that using attach to process.

Automatically attach vs2005 debugger to a child processes

I have a main C++ app built in Visual Studio 2005, called A.exe. It spawns a child process, B.exe. I run process A in the debugger by hitting F5 -- the only way I know to hit breakpoints in process B is to wait for A to kick it off, then run Debug -> Attach to Process, and manually select B.exe. This doesn't work very well if I need to debug initialization code in process B -- I have to start putting in 10 second sleeps at the beginning.
Is there some trick in the vs2005 GUI that I'm missing?
I'm using native code, by the way.
Thanks,
Nathan
You can tell Windows to automatically attach the debugger when a certain process is started (by specifying the process name in a registry setting).
The details are here:
http://msdn.microsoft.com/en-us/library/a329t4ed(v=vs.100).aspx
You'd be hard pushed to make use of the debugbreak command in the child process as the debug process is not yet attached.
However, there is another that may be of use. Seeing as your creating the process, you'll have the handle to it. So give the DebugBreakProcess function a whirl.

Resources