I recently learned about the process for debugging managed code in Windbg with sos. I've looked through numerous examples and from what I've seen, this should work. But it doesn't. This is a .net core 3.1 app.
I'm simply trying to break inside of the very simple Main method below.
namespace ConsoleAppTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Console App!");
ThisPrints();
}
static void ThisPrints()
{
Console.WriteLine("This is a message");
}
}
}
My process is below
sxe ld clrjit
g
These steps result in the following output:0:000> g
ModLoad: 00007ffe`a0900000 00007ffe`a0930000 C:\Windows\System32\IMM32.DLL
ModLoad: 00007ffe`7df70000 00007ffe`7e004000 C:\Program Files\dotnet\host\fxr\3.1.8\hostfxr.dll
ModLoad: 00007ffe`64ef0000 00007ffe`64f82000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\hostpolicy.dll
ModLoad: 00007ffe`3c600000 00007ffe`3cb6f000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\coreclr.dll
ModLoad: 00007ffe`9fbb0000 00007ffe`9fcda000 C:\Windows\System32\ole32.dll
ModLoad: 00007ffe`9f690000 00007ffe`9f9e5000 C:\Windows\System32\combase.dll
ModLoad: 00007ffe`a0830000 00007ffe`a08fd000 C:\Windows\System32\OLEAUT32.dll
ModLoad: 00007ffe`9edb0000 00007ffe`9ee05000 C:\Windows\System32\SHLWAPI.dll
ModLoad: 00007ffe`9e840000 00007ffe`9e867000 C:\Windows\System32\bcrypt.dll
(5b4.40e8): Unknown exception - code 04242420 (first chance)
ModLoad: 00007ffe`32430000 00007ffe`32d4d000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Private.CoreLib.dll
ModLoad: 00007ffe`9c000000 00007ffe`9c012000 C:\Windows\SYSTEM32\kernel.appcore.dll
ModLoad: 00007ffe`9e520000 00007ffe`9e59f000 C:\Windows\System32\bcryptPrimitives.dll
ModLoad: 00007ffe`4ad30000 00007ffe`4ae72000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\clrjit.dll
ntdll!NtMapViewOfSection+0x14:
00007ffe`a0a0c2a4 c3 ret
!bpmd ConsoleAppTest Program.Main
g
The problem occurs after step 5, even though clrjit.dll is loaded, the break point is not hit after setting it in step 4. and I get this final output:
0:000> !bpmd ConsoleAppTest Program.Main
Adding pending breakpoints...
0:000> g
ModLoad: 00000221`90e50000 00000221`90e58000 C:\Users\Baruc\source\repos\ConsoleAppTest\ConsoleAppTest\bin\Release\netcoreapp3.1\ConsoleAppTest.dll
(5b4.40e8): CLR notification exception - code e0444143 (first chance)
Failed to set code notification
ModLoad: 00007ffe`98f60000 00007ffe`98f6e000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Runtime.dll
(5b4.40e8): CLR notification exception - code e0444143 (first chance)
ModLoad: 00007ffe`7d360000 00007ffe`7d385000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Console.dll
(5b4.40e8): CLR notification exception - code e0444143 (first chance)
ModLoad: 00007ffe`82050000 00007ffe`82063000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Threading.dll
(5b4.40e8): CLR notification exception - code e0444143 (first chance)
ModLoad: 00007ffe`72720000 00007ffe`72753000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Runtime.Extensions.dll
(5b4.40e8): CLR notification exception - code e0444143 (first chance)
ModLoad: 00007ffe`822b0000 00007ffe`822b3000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.8\System.Text.Encoding.Extensions.dll
(5b4.40e8): CLR notification exception - code e0444143 (first chance)
ntdll!NtFsControlFile+0x14:
00007ffe`a0a0c4c4 c3 ret
Any guidance will be greatly appreciated. Thanks!
The problem can be resolved by explicitly loading the correct version of the sos.dll. This needs to match the runtime version and bitness of your target.
Be aware that since .NET 5.0 has now been released, you will likely get the .NET 5.0 version when you don't specify a version explicitly.
This will install .NET 5.0 sos:
dotnet tool install -g dotnet-sos
This will install .NET 3.1 sos:
dotnet tool install -g dotnet-sos --version 3.1.141901
You'll also need to load sos explicitly (to ensure it matches your target's .NET version + x86/x64). I don't recall what version of sos (if any) that windbg will default to. (You'll need to amend paths shown below to reflect the correct username):
.load C:\Users\<username>\.dotnet\tools\.store\dotnet-sos\3.1.141901\dotnet-sos\3.1.141901\tools\netcoreapp2.1\any\win-x64\sos.dll
Full trace:
0:000> .load C:\Users\<username>\.dotnet\tools\.store\dotnet-sos\3.1.141901\dotnet-sos\3.1.141901\tools\netcoreapp2.1\any\win-x64\sos.dll
0:000> sxe ld clrjit
0:000> g
ModLoad: 00007ffd`ae750000 00007ffd`ae7ce000 C:\Program Files\dotnet\host\fxr\5.0.1\hostfxr.dll
ModLoad: 00007ffd`ddaf0000 00007ffd`ddb93000 C:\Windows\System32\ADVAPI32.dll
ModLoad: 00007ffd`dca30000 00007ffd`dcace000 C:\Windows\System32\msvcrt.dll
ModLoad: 00007ffd`ddd80000 00007ffd`dde1e000 C:\Windows\System32\sechost.dll
ModLoad: 00007ffd`ddba0000 00007ffd`ddcc2000 C:\Windows\System32\RPCRT4.dll
ModLoad: 00007ffd`ab5b0000 00007ffd`ab642000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.10\hostpolicy.dll
ModLoad: 00007ffd`919d0000 00007ffd`91f3f000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.10\coreclr.dll
ModLoad: 00007ffd`dc770000 00007ffd`dc8c6000 C:\Windows\System32\ole32.dll
ModLoad: 00007ffd`dcc40000 00007ffd`dcf6d000 C:\Windows\System32\combase.dll
ModLoad: 00007ffd`db760000 00007ffd`db7de000 C:\Windows\System32\bcryptPrimitives.dll
ModLoad: 00007ffd`dd250000 00007ffd`dd279000 C:\Windows\System32\GDI32.dll
ModLoad: 00007ffd`dc3f0000 00007ffd`dc58c000 C:\Windows\System32\gdi32full.dll
ModLoad: 00007ffd`db8e0000 00007ffd`db980000 C:\Windows\System32\msvcp_win.dll
ModLoad: 00007ffd`dd950000 00007ffd`ddae7000 C:\Windows\System32\USER32.dll
ModLoad: 00007ffd`db740000 00007ffd`db760000 C:\Windows\System32\win32u.dll
ModLoad: 00007ffd`dd2e0000 00007ffd`dd3a4000 C:\Windows\System32\OLEAUT32.dll
ModLoad: 00007ffd`dd280000 00007ffd`dd2d2000 C:\Windows\System32\SHLWAPI.dll
ModLoad: 00007ffd`db4d0000 00007ffd`db4f6000 C:\Windows\System32\bcrypt.dll
ModLoad: 00007ffd`ddcd0000 00007ffd`ddcfe000 C:\Windows\System32\IMM32.DLL
(37ec.25dc): Unknown exception - code 04242420 (first chance)
ModLoad: 00007ffd`910b0000 00007ffd`919cd000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.10\System.Private.CoreLib.dll
ModLoad: 00007ffd`db490000 00007ffd`db4a1000 C:\Windows\System32\kernel.appcore.dll
ModLoad: 00007ffd`a9b80000 00007ffd`a9cc2000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.10\clrjit.dll
ntdll!NtMapViewOfSection+0x14:
00007ffd`df4bfc64 c3 ret
0:000> !bpmd ConsoleAppTest Program.Main
Adding pending breakpoints...
0:000> g
ModLoad: 00000179`2e410000 00000179`2e418000 C:\Users\<username>\Documents\!My Stuff\Repos\Test Projects\ConsoleAppTest\ConsoleAppTest\bin\Debug\netcoreapp3.1\ConsoleAppTest.dll
(37ec.25dc): CLR notification exception - code e0444143 (first chance)
ModLoad: 00007ffd`d08e0000 00007ffd`d08ee000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.10\System.Runtime.dll
(37ec.25dc): CLR notification exception - code e0444143 (first chance)
ModLoad: 00007ffd`c8d10000 00007ffd`c8d35000 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.10\System.Console.dll
(37ec.25dc): CLR notification exception - code e0444143 (first chance)
(37ec.25dc): CLR notification exception - code e0444143 (first chance)
JITTED ConsoleAppTest!ConsoleAppTest.Program.Main(System.String[])
Setting breakpoint: bp 00007FFD32010FB0 [ConsoleAppTest.Program.Main(System.String[])]
Breakpoint 0 hit
00007ffd`32010fb0 55 push rbp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With