有一个CGI程序,很简单。原来写的时候没用到调试。但现在想加入很多复杂的功能,如果不能Debug(单步跟踪)如何调试?
请有类似经验的朋友不吝指教。

解决方案 »

  1.   

    you can reference a text from MSDN
    It tell you how to debug a Windows service program that is similar to CGI.
    I had wrote a FileTrace function that like a TRACE MACRO in vc++.
    It can write trace infomation to a file.
     you can rewite it easily. see the definition of TRACE to know how MACRO TRACE work.
    ok.
    good luck.
      

  2.   

    cgi实际上就是一个标准的输入输出过程,你可以模拟在控制台键盘输入字符,打印处理结果来判断运行状态
      

  3.   

    HOW the MACRO TRACE work.
    And the file trace.// zmjTrace.h: interface for the CTraceFile class.
    //
    //////////////////////////////////////////////////////////////////////#if !defined(AFX_TRACEFILE_H__B31699F5_714D_418A_A1D7_FF5A5F1927CE__INCLUDED_)
    #define AFX_TRACEFILE_H__B31699F5_714D_418A_A1D7_FF5A5F1927CE__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000#ifdef 
    #include <stdio.h>
    #include <assert.h>
    #define  OUTPUT_MAX_SIZE  512
    #define  DEBUG_OUTPUT_FILE  "output.txt" //file debug to output to
    #ifdef  DEBUG  //if debug
    //////////////////////////////////////////////////////////////////////////
    #define  TRACE_OUTPUT AfxTraceOutput
    ///////////////////
    #define  TRACE_FILE AfxDebugToFile
    #define  TRACE_FILE_CLEAR   AfxClearTraceFile()
    //////////////////////////////////////////////////////////////////////////
    #else
    #define TRACE_OUTPUT DoNotingDTF
    /////////////////////
    #define TRACE_FILE DoNothingDTF
    #define TRACE_FILE_CLEAR    DoNotingCTF()
    #endif
    //////////////////////////////////////////////////////////////////////////
    /// declare  
    void AfxTraceOutput(LPCTSTR lpszFormat,...);//////////////////////////////////////////////////////////////////////////
    /// to file
    void AfxDebugToFile(LPCTSTR lpszFormat,...);
    inline void DoNothingDTF(LPCTSTR lpszFormat,...){};//////////////////////////////
    // clear file
    void AfxClearTraceFile(void );
    inline void DoNotingCTF(void ){};//////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////
    /// implement
    ///
    void AfxTraceOutput(LPCTSTR lpszFormat,...)
    {

    int nBuf;
    TCHAR szBuffer[OUTPUT_MAX_SIZE];
    memset(szBuffer,0,OUTPUT_MAX_SIZE*(sizeof(TCHAR)) );

    va_list args;
    va_start(args, lpszFormat);

    nBuf = _vsnprintf(szBuffer, sizeof(szBuffer)*(sizeof(TCHAR)), lpszFormat, args);

    // was there an error? was the expanded string too long?
    assert(nBuf >= 0);

    OutputDebugString(szBuffer);
    va_end(args);
    }void AfxDebugToFile(LPCTSTR lpszFormat,...)
    {

    int nBuf;
    TCHAR szBuffer[OUTPUT_MAX_SIZE];
    memset(szBuffer,0,OUTPUT_MAX_SIZE*(sizeof(TCHAR)) );

    va_list args;
    va_start(args, lpszFormat);

    nBuf = _vsnprintf(szBuffer, sizeof(szBuffer), lpszFormat, args);

    // was there an error? was the expanded string too long?
    assert(nBuf >= 0); FILE* pOutPutFile = fopen(DEBUG_OUTPUT_FILE,"a+") ;
        assert(pOutPutFile);
    fwrite(szBuffer,sizeof(char),nBuf,pOutPutFile);
    fclose(pOutPutFile);
    va_end(args);
    }
    //////////////////////////////////////////////////////////////////////////void AfxClearTraceFile()
    {

    FILE* pOutPutFile = fopen(DEBUG_OUTPUT_FILE,"w+") ;
        assert(pOutPutFile);
    fclose(pOutPutFile);}#endif // !defined(AFX_TRACEFILE_H__B31699F5_714D_418A_A1D7_FF5A5F1927CE__INCLUDED_)