How to set a breakpoint in code
-
I am dynamically loading a second process (via CreateProcess) and would like to automatically set breakpoints in that process. VS2005 doesn't automatically set the breakpoints even though the code I want to break on exists in both projects. Is there an API I can call to set a breakpoint on a function in another process?
-
I am dynamically loading a second process (via CreateProcess) and would like to automatically set breakpoints in that process. VS2005 doesn't automatically set the breakpoints even though the code I want to break on exists in both projects. Is there an API I can call to set a breakpoint on a function in another process?
After it is started via the CreateProcess, fire up another instance of VS2005 and "attach" to the just launched process. You can set breakpoints now. If you need to debug the process's startup code, use DebugBreak and connect VS2005. I've always used a new instance of VS to debug each different process - don't know if you can do multiple processes all in one. Judy
-
After it is started via the CreateProcess, fire up another instance of VS2005 and "attach" to the just launched process. You can set breakpoints now. If you need to debug the process's startup code, use DebugBreak and connect VS2005. I've always used a new instance of VS to debug each different process - don't know if you can do multiple processes all in one. Judy
Ah, but that's the problem. By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap. I can't modify the source to the program I want to attach to. I need to find a way to set breakpoints in the launched process via the application I am writing. Something like: { CreateProcess("newprogram.exe", ... CREATE_SUSPENDED, ... ); SetBreakpoint(newProcessHandle, "FunctionToDebug"); ResumeProcess(newProcessHandle); }
-
Ah, but that's the problem. By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap. I can't modify the source to the program I want to attach to. I need to find a way to set breakpoints in the launched process via the application I am writing. Something like: { CreateProcess("newprogram.exe", ... CREATE_SUSPENDED, ... ); SetBreakpoint(newProcessHandle, "FunctionToDebug"); ResumeProcess(newProcessHandle); }
Soundman32.2 wrote:
By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap.
In your processes code, call DebugBreak(), and the code execution will stop and you will be given the chance to attach a debugger.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
Ah, but that's the problem. By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap. I can't modify the source to the program I want to attach to. I need to find a way to set breakpoints in the launched process via the application I am writing. Something like: { CreateProcess("newprogram.exe", ... CREATE_SUSPENDED, ... ); SetBreakpoint(newProcessHandle, "FunctionToDebug"); ResumeProcess(newProcessHandle); }
That's a tough one without being able to modify the source of the target. Just to make sure you haven't missed the obvious, have you tried to Attach after the process is created in the suspended state? I don't expect it to work, but I personally don't know what else to try. You're down to the point of having to do something to modify the target. If you can't touch the source, the only thing left is modifying the asm code in the .exe file. Can't help there. Sorry, Judy