高手救命:用writefile向gdb写命令为什么它不执行?

rsp19801226 2007-06-26 09:45:37
只是个实验版本:
CString tmp;
tmp = szFilename;//路径加文件名
HANDLE hRead = NULL;
HANDLE hWrite = NULL;
SECURITY_ATTRIBUTES sad;
STARTUPINFO suid;
PROCESS_INFORMATION pid;
sad.bInheritHandle = TRUE;
sad.lpSecurityDescriptor = NULL;
sad.nLength = sizeof(SECURITY_ATTRIBUTES);

if(NULL == hRead || NULL == hWrite )
{
if(!CreatePipe(&hRead,&hWrite,&sad,0))//创建匿名管道
{
AfxMessageBox("创建匿名管道失败");
Complying = 0;
return -1;
}
}

ZeroMemory(&suid,sizeof(STARTUPINFO));
suid.cb = sizeof(STARTUPINFO);
GetStartupInfo(&suid);
suid.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
suid.wShowWindow = SW_SHOW;
suid.hStdInput = /*GetStdHandle(STD_INPUT_HANDLE);//*/hRead;
suid.hStdOutput = /*GetStdHandle(STD_OUTPUT_HANDLE);//*/hWrite;
suid.hStdError = /*GetStdHandle(STD_ERROR_HANDLE);//*/hWrite;
tmp = "D:\\MinGWStudio\\MinGW\\bin\\gdb.exe -x -v " + tmp;

/***************开始调试************************/
if(!CreateProcess(NULL,tmp.GetBuffer(0),NULL,NULL,TRUE,0,NULL,NULL,&suid,&pid))
{
DWORD Error;
Error = GetLastError();
Info.pComplyShow->SetWindowText("调试失败!");
OnDebug = 0;
if(pid.hThread)
{
CloseHandle(pid.hThread);
pid.hThread = NULL;
}
if(pid.hProcess)
{
CloseHandle(pid.hProcess);
pid.hProcess = NULL;
}
if(hRead)
{
CloseHandle(hRead);
hRead = NULL;
}
if(hWrite)
{
CloseHandle(hWrite);
hWrite = NULL;
}
return 1;
}
DWORD dwBytesWritten;
DWORD t;
int s_stdin;
int s_stdout;
int s_stderr;
s_stdin = setmode (fileno(stdin), O_BINARY);
s_stdout = setmode (fileno(stdout), O_BINARY);
s_stderr = setmode (fileno(stderr), O_BINARY);
/* while()
{

}*/
t = WaitForSingleObject(pid.hProcess,INFINITE);
if(!WriteFile(hWrite,"r\n",2,&dwBytesWritten,NULL))
{

DWORD Error;
Error = GetLastError();
Info.pComplyShow->SetWindowText("调试失败!");
OnDebug = 0;
if(pid.hThread)
{
CloseHandle(pid.hThread);
pid.hThread = NULL;
}
if(pid.hProcess)
{
CloseHandle(pid.hProcess);
pid.hProcess = NULL;
}
if(hRead)
{
CloseHandle(hRead);
hRead = NULL;
}
if(hWrite)
{
CloseHandle(hWrite);
hWrite = NULL;
}
return 1;
}

t = dwBytesWritten;
//t = WaitForSingleObject(pid.hProcess,INFINITE);
char buf[4096] = {'\0'};
DWORD dwRead;

if(!ReadFile(hRead,buf,4095,&dwRead,NULL))
{
Complying = 2;
if(pid.hThread)
{
CloseHandle(pid.hThread);
pid.hThread = NULL;
}
if(pid.hProcess)
{
CloseHandle(pid.hProcess);
pid.hProcess = NULL;
}
if(NULL != hRead)
{
CloseHandle(hRead);
hRead = NULL;
}
if(NULL != hWrite)
{
CloseHandle(hWrite);
hWrite = NULL;
}
return 1;
}

strShowCompiler = buf;
Info.pComplyShow->SetWindowText(strShowCompiler.GetBuffer(0));

if(pid.hThread)
{
CloseHandle(pid.hThread);
pid.hThread = NULL;
}
if(pid.hProcess)
{
CloseHandle(pid.hProcess);
pid.hProcess = NULL;
}
if(hRead)
{
CloseHandle(hRead);
hRead = NULL;
}
if(hWrite)
{
CloseHandle(hWrite);
hWrite = NULL;
}
setmode (fileno(stdin), s_stdin); /* 恢复 */
setmode (fileno(stdout), s_stdout); /* 恢复 */
setmode (fileno(stderr), s_stderr); /* 恢复 */
...全文
281 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ReverseEngineering 2007-09-19
  • 打赏
  • 举报
回复
蹭点分
rsp19801226 2007-06-27
  • 打赏
  • 举报
回复
已经解决了可惜不能加给自己,郁闷啊~~只好积累下来给下个帖了,为什么都是只有靠自己呢?
rsp19801226 2007-06-26
  • 打赏
  • 举报
回复
如果有人帮我解决了编写IDE的问题我就把我另外两个帖子的分一起给总共100分。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧