Onega's profileOnegaBlogListsNetwork Tools Help

Blog


    September 29

    self debugging on XP

    It is nice to save some useful information at the point of application crash. The useful methods including call stack and minidump file. Call stack can be obtained by installing exception filter via  AddVectoredExceptionHandler Function, stack trace can be obtained via StackWalk64 Function, and minidump file can be created via MiniDumpWriteDump Function.

    WinDbg can open the minidump file. Use .sympath+ <pdb path name> to let WinDBG search this folder before _NT_SYMBOL_PATH. Use .exepath+ command to inform windbg search for executable image file.

    July 26

    DevPartner 9.02 coverage analysis

    DevPartner failed to instrument two projects with “Error and Coverage” type, the only common fact is that there is a medium size CPP file in thos projects, one is around 40k, another is around 64k. It seems to be bug because those two projects can be instrumented successfully with “Error detection” or “Coverage or performance” type, and the debug configuration is also working, at last a colleague found a workaround with release configuration – disable optimization.

    June 18

    VC++ Debug tips

    NoStepInto How to Not Step Into Functions using the Visual C++ Debugger

    In the Debug library, all allocated memory blocks are bracketed with a series of "guard bytes." Diagnostic Services

    PageHeap utility

    May 28

    Fastest IPC method on Windows XP/Vista

    Problem: Find out a fastest method sending 1000 messages of 2MB size from one process to another process.

    Result table provide by Onega on XP SP2 and Vista.

    IPC method XP(seconds) Vista(seconds)
    Remote memory access (ReadProcessMemory) 5.5 5.75 -- max 8 pending blocks
    3.5 -- max 80 pending blocks

    boost::interprocess::windows_shared_memory

    7.1 5.9 -- max 8 pending blocks
    4.0 -- max 80 pending blocks
    Named Pipe 7.17 4.58
    Mailslot 7.25 5.66
    WM_COPYDATA 10.84 7.34
    Boost.asio synchronous mode 18~20 17.4

    boost::interprocess::shared_memory_object

    49.9 36.2/35.9
    MFC CSocket 150~212 37

    From the above table, we can find out that the answer is OS dependent. On XP, we’d better choose “Remote memory access” method since it is 22% faster than windows_shared_memory; but if we are targeting Vista, we’d better choose windows_shared_memory because “Remote memory access” is mostly used for debugging purpose instead of a general purpose IPC method.

    May 19

    Patch another process

    http://www.codeproject.com/KB/DLL/subhook.aspx

    Cross Process Subclassing

     

    http://forum.mess.be/index.php?showtopic=11966

    Hooking MSN Messenger 7 with VC++, A tutorial on how to hook MSN Messenger

    http://www.codeguru.com/cpp/w-p/dll/hooking/article.php/c3639/

    Hijack Textout Calls From Notepad

    http://www.codeproject.com/KB/DLL/apihijack.aspx

    APIHijack - A Library for easy DLL function hooking.

     

    http://www.codeproject.com/KB/system/hooksys.aspx

    API hooking revealed

    March 20

    Debugging handle leak on Windows XP

    Rational Purify 7.0 can detect memory leak but does not tell me handle leak. I can watch handles of a process via Procexp.exe, but that is not very convenient to check, so I used the ListHandlers function from Examine Information on Windows NT System Level Primitives and write all the handle information and count by type into log file.

    All threads created by AfxBeginThread must have its handle closed if you don't save it for later use.
    CWinThread* ptmp_thread_obj = AfxBeginThread(...);
    if (ptmp_thread_obj)
        CloseHandle(ptmp_thread_obj->m_hThread);

    I also pass verbose name to all calls to CreateEvent for the purpose of tracking named event leakage. In this way the problem was traced to leak of File handle type, but the path is actually a directory name.

    Searching fopen, _open, _fdopen gives no clue. At last it turned out to be unmatching FindFirstFile/FindClose. Note, there is some problems with SystemProcessInformation::Refresh() and some people discussed it already. For my case, I just removed the call since I don't need it for enumerating handles of current process. Keywords related to CPU usage: NtQuerySystemInformation PERF_100NSEC_TIMER_INV.

    April 03

    assert error in wincore.cpp line 979

    Create a MFC DOC/View application via project wizard, add ATL simple object to it, then create a console COM client project to test the ATL object. Run COM client out of debugger, I got an assert error in COM server, and the call stack is like the following. But interestingly if I build the COM server and client in VC6.0, there is no runtime error.

    mfc80d.dll!CWnd::DestroyWindow() Line 979 + 0x25 bytes C++
    mfc80d.dll!AfxOleOnReleaseAllObjects() Line 39 C++
    mfc80d.dll!AfxOleUnlockApp() Line 69 C++
    MyApp.exe!CMyAppModule::Unlock() Line 186 C++
    MyApp.exe!ATL::CComObject<CTestIfc>::~CComObject<CTestIfc>() Line 2572 C++
    MyApp.exe!ATL::CComObject<CTestIfc>::`scalar deleting destructor'() + 0xf bytes C++
    MyApp.exe!ATL::CComObject<CTestIfc>::Release() Line 2580 + 0x21 bytes C++
    ole32.dll!7750de71()
    [Frames below may be incorrect and/or missing, no symbols loaded for ole32.dll]
    ole32.dll!7750dbd2()
    ole32.dll!77511512()
    ole32.dll!77511327()
    rpcrt4.dll!77e7b7f4()
    ole32.dll!775111c9()
    rpcrt4.dll!77e79dc9()
    rpcrt4.dll!77ef321a()
    kernel32.dll!7c80e4a4()
    kernel32.dll!7c80e4a4()
    kernel32.dll!7c80e4a4()
    kernel32.dll!7c80e5ab()
    advapi32.dll!77dd880a()
    advapi32.dll!77dd8867()
    kernel32.dll!7c80b643()
    advapi32.dll!77dd8921()
    advapi32.dll!77dd892a()
    advapi32.dll!77dd8771()
    advapi32.dll!77dd877f()
    ntdll.dll!7c910732()
    ntdll.dll!7c911596()
    ntdll.dll!7c9106eb()
    ntdll.dll!7c911596()
    ntdll.dll!7c9106eb()
    rpcrt4.dll!77ef3bf3()
    ole32.dll!77600c31()
    ole32.dll!77600bdb()
    ole32.dll!7750f237()
    ntdll.dll!7c911596()
    ntdll.dll!7c910732()
    ntdll.dll!7c910732()
    ntdll.dll!7c9106ab()
    ntdll.dll!7c9106eb()
    ole32.dll!7750f15c()
    ole32.dll!77600b11()
    ole32.dll!776009bc()
    ole32.dll!7750bf35()
    ole32.dll!77600715()
    rpcrt4.dll!77e7988c()
    rpcrt4.dll!77e797f1()
    ole32.dll!7750efb7()
    rpcrt4.dll!77e7971d()
    rpcrt4.dll!77e8a067()
    rpcrt4.dll!77e8a0a8()
    rpcrt4.dll!77e7bb6a()
    rpcrt4.dll!77e9e3eb()
    rpcrt4.dll!77e76784()
    rpcrt4.dll!77e76699()
    rpcrt4.dll!77e766a9()
    rpcrt4.dll!77e76c22()
    rpcrt4.dll!77e76a3b()
    rpcrt4.dll!77e76c0a()
    kernel32.dll!7c80b683()

    Re: dynamic memory allocation checker

    PageHeap (part of the operating system itself) is very effective in finding various
    kinds of heap corruptions and other misuses; here you can find additional information
    about it:
    http://support.microsoft.com/?id=286470
    http://www.debuginfo.com/tips/userbpntdll.html
    (the latter also contains links to some standalone products that do the same,
    though I personally find PageHeap more effective than those that I have used)
    
    If you are interested in memory leak checking, the products listed in the previous
    link can be considered (I used Purify and BoundsChecker and they were good
    enough, though not perfect). There is also a free alternative UMDH (part of
    Debugging Tools for Windows), not that easy to use, but often effective enough:
    http://www.microsoft.com/whdc/devtools/debugging/default.mspx
    
    Note also that many other similar products and libraries exist, just search the net.
    
    Regards,
    Oleg
    [VC++ MVP http://www.debuginfo.com/]

    Re: Why my application(exe) exit without any information

    From news.microsoft.com
    Symptom:I developed a VC++ application with GUI. It read some type file and convert 
    to another type file.
    
    Now, we found when this program batch process the mass files,sometime,the 
    process will disappear! It mean no exception dialog,no memory illegal access 
    dialog, nothing information left. The application disappear at all.
    
    So I only want to know which kind bug can cause this error?  If the stack is 
    corrupt?
    Stack corruption is one of the most typical reasons, but many others are also
    possible. For example:
    - Stack overflow
    - Unhandled C++ exception (though unlikely in GUI applications)
    - Someone in the application calls abort(), ExitProcess(), other similar function
    - Corruption of the process heap
    - Someone calls SetErrorMode(SEM_NOGPFAULTERRORBOX)
    - Memory / resource leaks
    - Others
    
    Most of these problems can be detected and diagnosed if you run the application
    under debugger (better not to start it under debugger, but attach to the already
    running application) and set breakpoint at NtTerminateProcess function:
    {,,ntdll.dll}_NtTerminateProcess@8
    (good symbols for system DLLs will be needed)
    
    When the application is about to terminate, the debugger will either report an
    unhandled exception, or break at NtTerminateProcess (in the latter case, use
    the call stack to see who is trying to terminate the application).
    
    If stack corruption has been confirmed, tracing is usually the best way to find out
    who is corrupting it, as well as /GS and /RTC compiler options (in VS2002 and
    newer versions).
    
    Also it makes sense to monitor for memory/resource leaks (e.g. with PerfMon)
    and check for heap corruptions (e.g. with PageHeap).
    
    Regards,
    Oleg
    [VC++ MVP http://www.debuginfo.com/]