Thursday, March 23, 2006

Use !critsec to find out, which thread is waiting for a critical section

If you need to find out which thread is owning a critical section a blocked thread is waiting for you can first get the stack args by

kb

Then you need to get the critical section address from the stack. This is an argument passed to ntdll!RtlEnterCriticalSection API as first parameter.

By typing

!critsec 'address'

You'll get information about the section like: LockCount, RecursionCount, OwningThread, EntryCount, ContentionCount and the Locked state.

CritSec +81347c at 0081347c
LockCount 8
RecursionCount 1
OwningThread c6c
EntryCount 8
ContentionCount 8
*** Locked

Tuesday, March 14, 2006

Debug Tutorial Part 4: Writing WINDBG Extensions

Cool article from Toby Opferman about how extending windbg. Must read:
Debug Tutorial Part 4: Writing WINDBG Extensions

Friday, March 10, 2006

A word for WinDbg (Mike Taulty)

A very good starting point if you are planning to dig a bit into windbg:

W word for WinDbg
W word for WinDbg (2)

Wednesday, March 01, 2006

Starting UltraEdit from WinDbg

By setting follwoing env variable:
WINDBG_INVOKE_EDITOR=C:\PROGRA~1\ULTRAE~1\uedit32.exe %f/%l/1
{you might need to adapt the path}

You get the ability to open a source file from within windbg by simply right clicking on the source window header and then clicking "Edit this file..."

(this works also with other editors ;-) )

use "lmv m " to display detailed information about a specific module

e.g.:

0:003> lmv m actbar2
start end module name
35000000 350d0000 Actbar2 (export symbols) C:\SnapShots\voneinem_view_a0032858_c\VespucciPool\common\bin\debug\Actbar2.ocx
Loaded symbol image file: C:\SnapShots\voneinem_view_a0032858_c\VespucciPool\common\bin\debug\Actbar2.ocx
Image path: C:\SnapShots\voneinem_view_a0032858_c\VespucciPool\common\bin\debug\Actbar2.ocx
Image name: Actbar2.ocx
Timestamp: Wed Oct 27 16:52:02 2004 (417FB612)
CheckSum: 000D7481
ImageSize: 000D0000
File version: 2.5.2.121
Product version: 2.5.2.121
File flags: 0 (Mask 3F)
File OS: 40004 NT Win32
File type: 2.0 Dll
File date: 00000000.00000000
Translations: 0000.04b0 0409.04b0
CompanyName: Data Dynamics
ProductName: Data Dynamics ActiveBar 2.0 Control
InternalName: ActiveBar 2.5
OriginalFilename: ActiveBar2.ocx
ProductVersion: 2, 5, 2, 121
FileVersion: 2, 5, 2, 121
PrivateBuild: 2, 5, 2, 121
SpecialBuild: 2, 5, 2, 121
FileDescription: ActiveBar 2.5 Control
LegalCopyright: Copyright © 1999-2004 Data Dynamics
LegalTrademarks: Copyright © 1999-2004 Data Dynamics
Comments: Copyright © 1999-2004 Data Dynamics


To get a quick list of modules simply type "lm"

Display unicode strings the easy way

Did you ever wonder why windbg does not display unicode strings but simply shows the pointer?

Try ".enable_unicode 1"! This causes all 16-bit (USHORT) arrays and pointers to be displayed as Unicode strings.

(".enable_unicode 0" restores the default)

Wednesday, February 15, 2006

Monday, February 13, 2006

.NET debugging using WinDbg

This is a very good step by step cook book about .NET debugging using WinDbg

A word for WinDbg (2)

Thursday, November 17, 2005

Using DbgHelp.dll MiniDumpWriteDump function with Borland C++ Builder 5

I have written a handy class that allows to use the DbgHelp.dll MiniDumpWriteDump function in Borland C++ Builder 5 environment. Feel free to use it:

//DLL wrapper class
#define CALLING_CONVENTION __stdcall

class CDbgHelpDLL
{
public:
CDbgHelpDLL()
{
m_hDLL = ::LoadLibraryA("dbghelp.dll");
if(NULL != m_hDLL)
{
//CodeSite API
DLLMiniDumpWriteDump = (BOOL (CALLING_CONVENTION *)
(HANDLE,
DWORD,
HANDLE,
MINIDUMP_TYPE,
CONST PMINIDUMP_EXCEPTION_INFORMATION,
CONST PMINIDUMP_USER_STREAM_INFORMATION,
CONST PMINIDUMP_CALLBACK_INFORMATION))
::GetProcAddress(m_hDLL, "MiniDumpWriteDump");
}
else
{
DLLMiniDumpWriteDump = NULL;
}
}
~CDbgHelpDLL()
{
if(NULL != m_hDLL)
{
::FreeLibrary(m_hDLL);
m_hDLL = NULL;
}
}

BOOL MiniDumpWriteDump(
HANDLE hProcess,
DWORD ProcessId,
HANDLE hFile,
MINIDUMP_TYPE DumpType,
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
PMINIDUMP_CALLBACK_INFORMATION CallbackParam
)
{
if (DLLMiniDumpWriteDump){
return DLLMiniDumpWriteDump( hProcess,
ProcessId,
hFile,
DumpType,
ExceptionParam,
UserStreamParam,
CallbackParam);
}
else
{
return FALSE;
}
}



private:
HINSTANCE m_hDLL;
//DLL functions
BOOL (CALLING_CONVENTION *DLLMiniDumpWriteDump)( HANDLE hProcess,
DWORD ProcessId,
HANDLE hFile,
MINIDUMP_TYPE DumpType,
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
};

In order to compile with dbghelp.h from ms, you need to "patch" it:

before // for those without specstrings.h add:

//CBuilder
#ifdef __BORLANDC__
using namespace System;
#endif

Change this:
#ifdef __BORLANDC__
enum hdEnums {
#else
typedef enum {
#endif
hdBase = 0, // root directory for dbghelp
hdSym, // where symbols are stored
hdSrc, // where source is stored
hdMax // end marker
};

and this:
#ifdef __BORLANDC__
enum sfEnums {
#else
typedef enum {
#endif
sfImage = 0,
sfDbg,
sfPdb,
sfMpd,
sfMax
};

and here we go ...
Happy crash dumping with borland ;-)

Wednesday, November 16, 2005

Using WinDbg with Borland

I'm using this tool and I must say it's great! Of course you just get the info that is there in the map file. Therefore no info about local variables. But with a bit knowledge, you can oracle those from the stack memory :-)

Ms-dbg
brings microsoft-compatible debugging to Borland. With "map2dbg" you can convert from a borland MAP file to a ms DBG file. This lets you use standard debugging tools like DrWatson and imagehlp.dll. For instance, in "calldemo" we use it to generate a callstack of the current program. Helpful for debugging clients a thousand miles away.

Source:
http://www.wischik.com/lu/programmer/

Application debugging in a production environment (Hans De Smaele)

Very, very cool article:

http://www.microsoft.com/belux/nl/msdn/community/articles/feb05_applicationdebugging.mspx

Application debugging in a production environment


Summary: This document is made for people who have to support and maintain a production environment. Answers are given on questions like: "Yesterday it still worked and now it doesn't anymore, what did happen?" or "Why does it work on this computer and not on another one?". Every part of the paper is explained as a walkthrough in order to use it as reference material and/or as a workbook to learn some particular debugging scenarios. (125 printed pages)

This article covers the following topics:
  • Debugging and instrumenting scripts
  • Using tools to do first analysis (FileMon, RegMon, Dependency Walker, ...)
  • A step-by-step guide for using the WinDbg debugger
  • Symbol and symbol servers
  • Calling conventions
  • Stack tracing and related subjects
  • Debugging of "free builds"
  • Creation and debugging of "dump files"
  • Working with ILDASM and ILASM
  • Other useful WinDbg extensions
  • Remote debugging
  • Debug scenarios

Tuesday, November 15, 2005