使用 CreateProcess 调试 [英] Debugging with CreateProcess
问题描述
我正在使用带有 DEBUG_ONLY_THIS_PROCESS
标志的 CreateProcess
.新进程创建了,但新运行的应用程序没有做任何事情,当我用任务管理器查看进程列表时,我看到的只是分配了 70KB 内存的 exe 文件的名称!
I'm using CreateProcess
with DEBUG_ONLY_THIS_PROCESS
flag. The new process is created, but the newly run application doesn't do anything and when I look at the process list with Task Manager, all I see is the name of the exe file with only 70KB of memory allocated!
如果我创建的进程没有 DEBUG_ONLY_THIS_PROCESS
标志,则应用程序可以完美运行.
If I create the process without DEBUG_ONLY_THIS_PROCESS
flag, the application is run perfectly.
这是我的代码:
function TDebugger.StartDebug;
var
ProcInfo: TProcessInformation;
ProcessCreationFlags: Cardinal;
StartupInfo: TStartupInfo;
DE: TDebugEvent;
begin
// == init process info
ZeroMemory(@ProcInfo, SizeOf(TProcessInformation));
// == init startup info
ZeroMemory(@StartupInfo, SizeOf(TStartupInfo));
with StartupInfo do begin
cb := SizeOf(TStartupInfo);
lpDesktop := '';
dwX := CW_USEDEFAULT;
dwY := CW_USEDEFAULT;
dwXSize := CW_USEDEFAULT;
dwYSize := CW_USEDEFAULT;
wShowWindow := SW_SHOWDEFAULT;
end;
// == Create the process
ProcessCreationFlags := DEBUG_ONLY_THIS_PROCESS;
if (not CreateProcess(PWideChar(Path), Nil, Nil, Nil, False, ProcessCreationFlags, Nil, PWideChar(CurrentDirectory), StartupInfo,
ProcInfo)) then
RaiseLastOSError;
end;
我认为在创建进程后应该调用一些 API 函数,但我不知道它是什么.有人能帮我解决这个问题吗?
I think there is some API function I should call after creating the process, but I have no idea what it is. Can anyone help me with this problem?
附加信息:我的主要应用程序是一个 IDE,它需要调试播放器应用程序.
Additional Info: My main application is an IDE and it needs to debug its player application.
推荐答案
当您创建用于调试的进程时,使用 DEBUG_ONLY_THIS_PROCESS,该进程实际上并未开始运行.它等待您的调试器启动它.所以,是的,您确实必须调用一些函数来启动和运行进程.您现在需要编写调试器!其主体是您的调试器循环.
When you create a process for debugging, with DEBUG_ONLY_THIS_PROCESS, the process does not actually start running. It waits for your debugger to start it up. So, yes, you do have to call some functions to get the process up and running. You now you need to write your debugger! The main body of which is your debugger loop.
一些可能有帮助的参考资料:
Some references that might help:
这篇关于使用 CreateProcess 调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!