summaryrefslogtreecommitdiff
path: root/tools/windbg
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-06-04 23:27:56 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-06-04 23:27:56 +0100
commit78325572c1b2ae617dd5502ab726bfded1fd0506 (patch)
tree948ce8aa81770f4ed0a9170670b439a9ef912f85 /tools/windbg
parent4aebf7cc9ce07dfb20db217274a45680b3cb00ed (diff)
downloadsst-78325572c1b2ae617dd5502ab726bfded1fd0506.tar.gz
sst-78325572c1b2ae617dd5502ab726bfded1fd0506.zip
Add some WinDbg helpers and tidy up the README
Diffstat (limited to 'tools/windbg')
-rw-r--r--tools/windbg/.gitignore1
-rw-r--r--tools/windbg/initcmds6
-rw-r--r--tools/windbg/install.ps144
-rw-r--r--tools/windbg/natvis.xml5
-rw-r--r--tools/windbg/windbg.bat16
5 files changed, 72 insertions, 0 deletions
diff --git a/tools/windbg/.gitignore b/tools/windbg/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/tools/windbg/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/tools/windbg/initcmds b/tools/windbg/initcmds
new file mode 100644
index 0000000..fe0f62f
--- /dev/null
+++ b/tools/windbg/initcmds
@@ -0,0 +1,6 @@
+.nvload tools\windbg\natvis.xml
+
+$$ Emulate Source Thread Fix for high-core-count systems by breaking on
+$$ GetSystemInfo, grabbing the struct pointer from the stack, then fiddling
+$$ with its contents upon returning to the caller.
+bp kernelbase!GetSystemInfo "dx @$t1 = *(void **)(@esp + 4); bp /1 @$ra \"dx @$t2 = ((_SYSTEM_INFO *)@$t1)->dwNumberOfProcessors; dx ((_SYSTEM_INFO *)@$t1)->dwNumberOfProcessors = @$t2 > 24 ? 24 : @$t2; g\"; g"
diff --git a/tools/windbg/install.ps1 b/tools/windbg/install.ps1
new file mode 100644
index 0000000..4e206e0
--- /dev/null
+++ b/tools/windbg/install.ps1
@@ -0,0 +1,44 @@
+# This script is dedicated to the public domain.
+
+Add-Type -Assembly System.IO.Compression.FileSystem
+
+$OutDir = "tools\windbg\bin"
+$Arch = "x64" # can also use x86, arm64
+
+if (!(Test-Path $OutDir)) { $null = mkdir $OutDir }
+[xml]$content = (New-Object System.Net.WebClient).DownloadString("https://aka.ms/windbg/download")
+$bundleurl = $content.AppInstaller.MainBundle.Uri
+# Using curl.exe here instead because it has an actual useful progress bar.
+# Modern PowerShell does too, but not the PS 5.1 that still ships with W10
+#Invoke-WebRequest $bundleurl -OutFile $OutDir\__bundle.zip
+curl.exe "-#o$OutDir\__bundle.zip" "$bundleurl"
+$filename = switch ($Arch) {
+ "x64" { "windbg_win-x64.msix" }
+ "x86" { "windbg_win-x86.msix" }
+ "arm64" { "windbg_win-arm64.msix" }
+}
+$zip = [IO.Compression.ZipFile]::OpenRead("$OutDir\__bundle.zip")
+try {
+ if ($found = $zip.Entries.Where({ $_.FullName -eq $filename }, "First") ) {
+ $dest = "$OutDir\__msix.zip"
+ [IO.Compression.ZipFileExtensions]::ExtractToFile($found[0], $dest, $false)
+ }
+ else {
+ Write-Error "File not found in ZIP: $filename"
+ exit 100
+ }
+}
+finally {
+ if ($zip) { $zip.Dispose() }
+}
+rm $OutDir\__bundle.zip
+Expand-Archive -DestinationPath "$OutDir" "$OutDir\__msix.zip"
+rm $OutDir\__msix.zip
+# misc cleanup
+rm -r $OutDir\AppxMetadata\
+rm $OutDir\'``[Content_Types``].xml' # wtf, microsoft, wtf.
+rm $OutDir\AppxBlockMap.xml
+rm $OutDir\AppxManifest.xml
+rm $OutDir\AppxSignature.p7x
+rm -r $OutDir\runtimes\unix\
+mv "$OutDir\Third%20Party%20Notices.txt" "$OutDir\Third Party Notices.txt"
diff --git a/tools/windbg/natvis.xml b/tools/windbg/natvis.xml
new file mode 100644
index 0000000..159b4d0
--- /dev/null
+++ b/tools/windbg/natvis.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
+ <!-- trivial example, but we can add to this later! -->
+ <Type Name="con_var"><DisplayString>ConVar: {strval}</DisplayString></Type>
+</AutoVisualizer>
diff --git a/tools/windbg/windbg.bat b/tools/windbg/windbg.bat
new file mode 100644
index 0000000..11cf29c
--- /dev/null
+++ b/tools/windbg/windbg.bat
@@ -0,0 +1,16 @@
+:: This file is dedicated to the public domain.
+@echo off
+setlocal
+
+if not "%WINDBG_BIN%"=="" goto :ok
+set WINDBG_BIN=tools\windbg\bin
+if exist tools\windbg\bin\DbgX.Shell.exe goto :ok
+powershell tools\windbg\install.ps1 || goto :end
+
+:ok
+%WINDBG_BIN%\DbgX.Shell.exe /g /c $^<tools\windbg\initcmds
+
+:end
+exit /b %errorlevel%
+
+:: vi: sw=4 ts=4 noet tw=80 cc=80