Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
199 lines (138 sloc) 6.9 KB

WinDbg brownbag

Prerequisites

Configure your sympath.

Slides

The slides can be downloaded here.

Scenarios

Crash

Project: src\CrashConsole

Outline: a console application crashes on startup with a meaningless exception. We want to get to the initial exception.

Video walkthrough: YouTube

  1. Compile using the Release Configuration
  2. Browse to the output directory (src\CrashConsole\bin\Release\net461\) in the Command Prompt
  3. Run the console application: .\CrashConsole.exe
    • Throws the base Exception
    • Exception Message is meaningless
    • But there is a line number

Meaningless Exception

The application swallows all Exceptions, loses the initial context and instead throws a meaningless exception:

Meaningless Exception

It seems as if we won't be able to retrieve the initial exception.

  1. C:\path-to-procdump\procdump64.exe -e -ma -x C:\dumps .\CrashConsole.exe
  2. Copy .\CrashConsole.pdb to your sympath
  3. Open the dump in WinDbg
  4. Type the command !analyze -v (see documentation)
    • Search for MANAGED_EXCEPTION_ADDRESS

MANAGED_EXCEPTION_ADDRESS

  1. Type the command !pe <address> (PrintException)

!pe <address>

  1. Type the command !pe -nested <address>

!pe -nested <address>

  1. Search for the DoSomeImportantWork function

!pe -nested <address>

Note: if you want to follow through the screenshots and the video walkthrough you can download the symbols and the dump I used. The WinDbg output can be downloaded.

Hang

Hang in ASP.NET WebAPI

Project: src\HangApi

Outline: an ASP.NET WebAPI hangs due to a blocked async call. All we see is the hang, how do we get to the faulty line?

Video walkthrough: YouTube

  1. Ctrl+F5
  2. GET http://localhost:5001/hang multiple times
  3. The requests hang
  4. C:\path-to-procdump\procdump64.exe -ma <pid> C:\dumps
    • Use Process Explorer to retrieve the PID of IIS Express (PID is not matching the one in the video walkthrough)

IIS Express PID

  1. Open the dump in WinDbg
  2. .load C:\path-to-mex\mex.dll
0:000> .load E:\symbols\winext\x64\mex.dll
Mex External 3.0.0.7172 Loaded!
  1. !mex.runaway2
0:000> !mex.runaway2
Showing top 10 threads
Thread ID   User Time
==============================
        6 | 0 days 0:00:00.515
       29 | 0 days 0:00:00.093
        0 | 0 days 0:00:00.062
       11 | 0 days 0:00:00.000
        9 | 0 days 0:00:00.000
       10 | 0 days 0:00:00.000
       14 | 0 days 0:00:00.000
       15 | 0 days 0:00:00.000
       12 | 0 days 0:00:00.000
       13 | 0 days 0:00:00.000
==============================
Thread ID   User Time

The threads barely consumed any user time on the CPU.

  1. !mex.mthreads

Monitor

Four managed threads are trying to acquire a monitor.

  1. .loadby sos clr
  2. !sos.SyncBlk
0:033> !sos.SyncBlk
c0000005 Exception in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.SyncBlk debugger extension.
      PC: 00007ffe`d7c17c11  VA: 00000000`00000000  R/W: 0  Parameter: 00000000`00000000
0:033> !sos.SyncBlk
Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner
-----------------------------
Total           72
CCW             5
RCW             15
ComClassFactory 0
Free            0

As seen above, you sometimes need to issue this command twice. In this instance we didn't find any SyncBlk.

  1. !mex.aspxpagesext

Requests

The four managed threads serving the requests are the four threads trying to acquire a monitor.

  1. !mex.us

Unique stacktraces

The four managed threads serving the requests have the same stacktrace.

  1. ~<thread-id>e !CLRStack

CLR Stack

We get the managed stacktrace of one the thread serving the requests.

  1. The stacktrace points to a Controller Action

Blocked async

Note: if you want to follow through the screenshots and the video walkthrough you can download the symbols and the dump I used. The WinDbg output can be downloaded.

No hang in ASP.NET Core

Project: src\NoHangApi

Outline: as ASP.NET Core does not have a synchronization context it won't hang.

  1. Ctrl+F5
  2. GET http://localhost:5000/no-hang multiple times
  3. The requests complete as expected

Tools used during the presentation

You can’t perform that action at this time.