单步调试就是 IDE 的主要功能,如果这个也可以让你共享,那 M$ 要哭了... 找个开源的 IDE 研究一下吧。link 的设置请参考 MSDN ,摘录如下:LINK is a 32-bit tool that links Common Object File Format (COFF) object files and libraries to create a 32-bit executable (.EXE) file or dynamic-link library (DLL). Following is a comprehensive list of options for LINK.EXE. For information on how to specify an option, see Set Linker Options. This section also includes information on Compiler-Controlled LINK Options, LINK Input Files, and LINK Output.Option Action /ALIGN:number Specifies the alignment of each section /BASE:{address | @filename,key} Sets a base address for the program /COMMENT:["]comment["] Inserts a comment string into header /DEBUG Creates debugging information /DEBUGTYPE:CV /DEBUGTYPE:COFF /DEBUGTYPE:BOTH Creates particular formats of debugging information /DEF:filename Passes a module-definition (.DEF) file to the linker /DEFAULTLIB:library Searches specified library when resolving external references /DELAY Controls the delayed loading of DLLs /DELAYLOAD Causes the delayed loading of the specified DLL /DLL Builds a DLL /DRIVER[:UPONLY] Creates a Windows NT kernel mode driver /ENTRY:function Sets the starting address /EXETYPE:DYNAMIC Builds a virtual device driver /EXPORT Exports a function /FIXED[:NO] Creates a program that can be loaded only at its preferred base address /FORCE[:{MULTIPLE|UNRESOLVED}] Forces link to complete in spite of unresolved or multiply defined symbols /GPSIZE:# Specifies the size of communal variables for MIPS and Alpha platforms /HEAP:reserve[,commit] Sets the size of the heap in bytes /IMPLIB:filename Overrides the default import library name /INCLUDE:symbol Forces symbol references /INCREMENTAL:{YES|NO} Controls incremental linking /LARGEADDRESSAWARE Tells the compiler that the application supports addresses larger than two gigabytes. /LIBPATH:path Allows the user to override the environmental library path /LINK50COMPAT Generates import libraries in Visual C++ Version 5.0 format /MACHINE:{IX86|ALPHA|ARM|MIPS|MIPSR41XX|PPC|SH3|SH4} Specifies the target platform /MAP Creates a map file /MAPINFO:{EXPORTS|FIXUPS|LINES} Includes the specified information in the map file /MERGE:from=to Combines sections /NODEFAULTLIB[:library] Ignores all (or specified) default libraries when resolving external references /NOENTRY Creates a resource-only DLL /NOLOGO Suppresses startup banner /OPT:{REF|NOREF|ICF[,iterations]|NOICF} Controls LINK optimizations /ORDER:@filename Places COMDATs into the image in a predetermined order /OUT:filename Specifies the output file name /PDB:filename Creates a program database (.PDB) file /PDBTYPE:{con[solidate]|sept[ypes]} Specifies where to store the Program Database (PDB) debug type information. /PROFILE Enables profiling (creates a mapfile) /RELEASE Sets the checksum in the .EXE header /SECTION:name,attributes Overrides the attributes of a section /STACK:reserve[,commit] Sets the size of the stack in bytes /STUB:filename Attaches an MS-DOS stub program to a Win32 program /SUBSYSTEM:{CONSOLE|WINDOWS|NATIVE|POSIX|WINDOWSCE} [,major[.minor] ] Tells the operating system how to run the .EXE file /SWAPRUN:{NET|CD} Tells the operating system to copy the linker output to a swap file before running it /VERBOSE[:LIB] Prints linker progress messages /VERSION:major[.minor] Assigns a version number /VXD Creates a virtual device driver (VxD) /WARN[:level] Specifies warning level /WS:AGGRESSIVE Aggressively trim process memory
void CLinkmestDoc::OnProjComply()
{
// TODO: Add your command handler code here
/***************************保存文件*****************************/
OnFileSaveAll();
/****************************************************************/
bErrFlag = FALSE;
strShowCompiler="";
AppandToShow(strShowCompiler);//将通道得到的信息在指定编辑窗显示 CString strBuf;
m_xTextBuffer.GetText( 0, 0, m_xTextBuffer.GetLineCount() - 1,
m_xTextBuffer.GetLineLength(m_xTextBuffer.GetLineCount() - 1), strBuf );
if( strBuf.IsEmpty() )
return;
CString strPathName = GetPathName(); int index1 = strPathName.ReverseFind('.');
CString tmp = strPathName;
strPathName = strPathName.Left(index1);
if(2 == (tmp.GetLength() - strPathName.GetLength()))
{
tmp = "cl.exe \/c " + strPathName + ".c";
}
else
{
tmp = "cl.exe \/c " + strPathName + ".cpp";
}
SECURITY_ATTRIBUTES sa;
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
if(!CreatePipe(&hRead,&hWrite,&sa,0))
{
AfxMessageBox("创建匿名管道失败");
return;
}
STARTUPINFO sui;
PROCESS_INFORMATION pi;
ZeroMemory(&sui,sizeof(STARTUPINFO));
sui.cb = sizeof(STARTUPINFO);
sui.dwFlags = STARTF_USESTDHANDLES;
sui.hStdInput = hRead;
sui.hStdOutput = hWrite;
sui.hStdError = GetStdHandle(STD_ERROR_HANDLE); int count = tmp.ReverseFind('\\');
CString tmpn;
tmpn = tmp.Left(count);
tmpn = tmpn.Right(tmpn.GetLength()-10);
AfxMessageBox(tmpn);
/*********************编译***************************/
if(!CreateProcess(NULL,tmp.GetBuffer(0),NULL,NULL,TRUE,0,NULL,tmpn.GetBuffer(0),&sui,&pi))
{
CloseHandle(hRead);
CloseHandle(hWrite);
hRead = NULL;
hWrite = NULL;
return;
}
else
{
AfxMessageBox("编译成功");
WaitForSingleObject(pi.hProcess, INFINITE);
char buf[800];
DWORD dwRead;
if(!ReadFile(hRead,buf,800,&dwRead,NULL))
{
return;
}
strShowCompiler = buf;
AppandToShow(buf);
if(pi.hThread)
{
CloseHandle(pi.hThread);
}
if(pi.hProcess)
{
CloseHandle(pi.hProcess);
}
}
/*********************链接***************************/
tmp = "link.exe " + strPathName + ".obj";
tmpn = tmp.Left(count);
tmpn = tmpn.Right(tmpn.GetLength()-9);
// AfxMessageBox(tmpn);
if(!CreateProcess(NULL,tmp.GetBuffer(0),NULL,NULL,TRUE,0,NULL,tmpn.GetBuffer(0),&sui,&pi))
{
CloseHandle(hRead);
CloseHandle(hWrite);
hRead = NULL;
hWrite = NULL;
return;
}
else
{
AfxMessageBox("链接成功");
WaitForSingleObject( pi.hProcess, INFINITE );
char buf[800];
DWORD dwRead;
if(!ReadFile(hRead,buf,800,&dwRead,NULL))
{
return;
}
strShowCompiler = buf;
AppandToShow(buf);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
/ALIGN:number Specifies the alignment of each section
/BASE:{address | @filename,key} Sets a base address for the program
/COMMENT:["]comment["] Inserts a comment string into header
/DEBUG Creates debugging information
/DEBUGTYPE:CV
/DEBUGTYPE:COFF
/DEBUGTYPE:BOTH Creates particular formats of debugging information
/DEF:filename Passes a module-definition (.DEF) file to the linker
/DEFAULTLIB:library Searches specified library when resolving external references
/DELAY Controls the delayed loading of DLLs
/DELAYLOAD Causes the delayed loading of the specified DLL
/DLL Builds a DLL
/DRIVER[:UPONLY] Creates a Windows NT kernel mode driver
/ENTRY:function Sets the starting address
/EXETYPE:DYNAMIC Builds a virtual device driver
/EXPORT Exports a function
/FIXED[:NO] Creates a program that can be loaded only at its preferred base address
/FORCE[:{MULTIPLE|UNRESOLVED}] Forces link to complete in spite of unresolved or multiply defined symbols
/GPSIZE:# Specifies the size of communal variables for MIPS and Alpha platforms
/HEAP:reserve[,commit] Sets the size of the heap in bytes
/IMPLIB:filename Overrides the default import library name
/INCLUDE:symbol Forces symbol references
/INCREMENTAL:{YES|NO} Controls incremental linking
/LARGEADDRESSAWARE Tells the compiler that the application supports addresses larger than two gigabytes.
/LIBPATH:path Allows the user to override the environmental library path
/LINK50COMPAT Generates import libraries in Visual C++ Version 5.0 format
/MACHINE:{IX86|ALPHA|ARM|MIPS|MIPSR41XX|PPC|SH3|SH4} Specifies the target platform
/MAP Creates a map file
/MAPINFO:{EXPORTS|FIXUPS|LINES} Includes the specified information in the map file
/MERGE:from=to Combines sections
/NODEFAULTLIB[:library] Ignores all (or specified) default libraries when resolving external references
/NOENTRY Creates a resource-only DLL
/NOLOGO Suppresses startup banner
/OPT:{REF|NOREF|ICF[,iterations]|NOICF} Controls LINK optimizations
/ORDER:@filename Places COMDATs into the image in a predetermined order
/OUT:filename Specifies the output file name
/PDB:filename Creates a program database (.PDB) file
/PDBTYPE:{con[solidate]|sept[ypes]} Specifies where to store the Program Database (PDB) debug type information.
/PROFILE Enables profiling (creates a mapfile)
/RELEASE Sets the checksum in the .EXE header
/SECTION:name,attributes Overrides the attributes of a section
/STACK:reserve[,commit] Sets the size of the stack in bytes
/STUB:filename Attaches an MS-DOS stub program to a Win32 program
/SUBSYSTEM:{CONSOLE|WINDOWS|NATIVE|POSIX|WINDOWSCE} [,major[.minor] ] Tells the operating system how to run the .EXE file
/SWAPRUN:{NET|CD} Tells the operating system to copy the linker output to a swap file before running it
/VERBOSE[:LIB] Prints linker progress messages
/VERSION:major[.minor] Assigns a version number
/VXD Creates a virtual device driver (VxD)
/WARN[:level] Specifies warning level
/WS:AGGRESSIVE Aggressively trim process memory
-----------------------------------------
实现单步调试其实是比较容易的,即使你没有机会去写一个调试器,也非常需要看看这本著名的书,
《Microsoft.NET和Windows应用程序调试》
http://www.china-pub.com/computers/common/info.asp?id=20508
4.3 MinDBG:一个简单的Win32调试器