Tag Archives: dumps

How to take process dump using CDB

Just a short explanation of how to take process dump using CDB.

First you need to get Debugging Tools for Windows. To get Debugging Tools as a standalone tool set you can just download Windows SDK and during installation select Debugging Tools for Windows:

Installing Debugging Tools for Windows

Once Debugging tools for Windows are downloaded and installed you can find cdb.exe in the following location – C:\Program Files (x86)\Windows Kits\10\Debuggers\x64 (note that number highlighted in bold may vary depending on SDK version installed – in my case it is 10, and you obviously have cdb.exe for different platforms – x86/x64 etc. – just navigate to appropriate subfolder of Debuggers folder).

To take dump launch CMD in elevated mode, switch directory to CDB location and execute cdb -p <PROCESS PID> to take crash dump (remember that PID information can be found in Task Manager or retrieved with PowerShell using Get-Process “%ProcessName%” | select -expand id):

CDB attaching to the process by PID

At this stage CDB is attached to process and closing this CMD window will terminate process you are attached to. Once CDB is loaded type in the following commands:

..loadby sos clr

!Thread

You will receive “No export Thread found” error – it can be ignored, and some more commands needs to be executed. First run !StopOnException -create System.StackOverflowException it may not work from the first attempt, just re-run it once again until you see confirmation that breakpoint was created:

CDB set breakpoint

Once breakpoint is set type gn and wait for process crash:

When process crashed the following commands have to be executed:

.logopen C:\dumps\k2hostserver.log

!ClrStack

.logclose

.dump /ma /u C:\dumps\process.dmp

gn

gn

….

Repeat typing gn until you get “there is no debugee” message. Your dump will be written in the location you specified above (C:\dumps\process.dmp).

Please follow and like us:
error0

Scripts for taking K2 service memory dumps

I’ve spent some time today improving “create K2 service memory dump script” (one which I already mentioned in “K2 MSMQ thread & MSMQ abort exception” blog post) and creating “collect dump support files”. Next step will be merging them into one and adding some nice to have things I have no time for right now.

Collect dump support files script (GitHub link):

$DumpPath='C:\Dumps'
$NetV2='C:\Windows\Microsoft.NET\Framework\v2.0.50727'
$NetV2x64='C:\Windows\Microsoft.NET\Framework64\v2.0.50727'
$NetV4='C:\Windows\Microsoft.NET\Framework\v4.0.30319'
$NetV4x64='C:\Windows\Microsoft.NET\Framework64\v4.0.30319'

$NetV2Dump="$DumpPath\Microsoft.NET\Framework\v2.0.50727"
$NetV2x64Dump="$DumpPath\Microsoft.NET\Framework64\v2.0.50727"
$NetV4Dump="$DumpPath\Microsoft.NET\Framework\v4.0.30319"
$NetV4x64Dump="$DumpPath\Microsoft.NET\Framework64\v4.0.30319"

If (!(Test-Path $DumpPath))
{
Write-Host 'Creating folder'
(New-Item $DumpPath -ItemType Directory | out-null)
} 
Else {
Write-Host 'Folder already exist'
}

Write-Host "Attempting to copy $NetV2\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2\mscordacwks.dll"))
{
Write-Host "$NetV2\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2Dump")) {New-Item "$NetV2Dump" -Type Directory | out-null}
Copy-Item "$NetV2\mscordacwks.dll" -Destination "$NetV2Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV2\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2\sos.dll"))
{
Write-Host "$NetV2\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2Dump")) {New-Item "$NetV2Dump" -Type Directory | out-null}
Copy-Item "$NetV2\sos.dll" -Destination "$NetV2Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV2x64\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2x64\mscordacwks.dll"))
{
Write-Host "$NetV2x64\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2x64Dump")) {New-Item "$NetV2x64Dump" -Type Directory | out-null}
Copy-Item "$NetV2x64\mscordacwks.dll" -Destination "$NetV2x64Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV2x64\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2x64\sos.dll"))
{
Write-Host "$NetV2x64\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2x64Dump")) {New-Item "$NetV2x64Dump" -Type Directory | out-null}
Copy-Item "$NetV2x64\sos.dll" -Destination "$NetV2x64Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4\mscordacwks.dll"))
{
Write-Host "$NetV4\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4Dump")) {New-Item "$NetV4Dump" -Type Directory | out-null}
Copy-Item "$NetV4\mscordacwks.dll" -Destination "$NetV4Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4\sos.dll"))
{
Write-Host "$NetV4\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4Dump")) {New-Item "$NetV4Dump" -Type Directory | out-null}
Copy-Item "$NetV4\sos.dll" -Destination "$NetV4Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4x64\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4x64\mscordacwks.dll"))
{
Write-Host "$NetV4x64\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4x64Dump")) {New-Item "$NetV4x64Dump" -Type Directory | out-null}
Copy-Item "$NetV4x64\mscordacwks.dll" -Destination "$NetV4x64Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4x64\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4x64\sos.dll"))
{
Write-Host "$NetV4x64\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4x64Dump")) {New-Item "$NetV4x64Dump" -Type Directory | out-null}
Copy-Item "$NetV4x64\sos.dll" -Destination "$NetV4x64Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Take K2 service process dump (GitHub link):

# Obtain K2 service PID
$procid=get-process "K2HostServer" |select -expand id
# Create target folder if not exist:
$DumpPath="C:\dumps"
If (!(Test-Path $DumpPath))
{
Write-Host 'Creating folder'
(New-Item $DumpPath -ItemType Directory | out-null)
} 
Else {
Write-Host 'Folder already exist'
}
# -ma - Write a full dump file which includes All the Image, Mapped and Private memory
# -ma - Just takes a full dump immidiately from running process
# -e -ma - takes full dump file on unhandled exception aka crash dump
C:\procdump\procdump.exe -accepteula -ma $procid $DumpPath\k2hostserver.dmp

Be sure checking out GitHub links as I keep editing/updating these scripts there.

Please follow and like us:
error0