Skip to content

Conversation

@VSadov
Copy link
Member

@VSadov VSadov commented Mar 24, 2025

Fixes: #4795

  • made the gcdecoder in sync with the 10.0 runtime.
  • made sure new SOS.dll can parse and do !gcinfo with both net10.0 and net8.0.

@VSadov
Copy link
Member Author

VSadov commented Mar 24, 2025

Prior to this change doing !gcinfo for System.Threading.ManualResetEventSlim.Wait on net8.0 runtime produces:

0:000> !gcinfo 00007fff2906893e
entry point 00007FFF29068780
preJIT generated code
GC info 00007FFF28D8C778
Pointer table:
Prolog size: 0
GS cookie: <none>
PSPSym: initial.sp+30
Generics inst context: <none>
PSP slot: caller.sp+30
GenericInst slot: <none>
Varargs: 0
Frame pointer: rbp
Wants Report Only Leaf: 1
Size of parameter area: 30
Return Kind: Scalar                                         <-- correctly reports return kind
Code size: 460
Untracked: +rbp+20 +rbp-48
00000035 interruptible
00000035 +rbp+10 +rcx
0000004d +rax
00000057 -rax
00000069 -rcx
000000a4 +rcx
000000be -rcx
000000c2 +rcx
000000c8 -rcx
000000ce +rax(interior)
000000d5 +r8
. . .   and so on. Long list of liveness changes.

Same with net10.0

:000> !gcinfo 00007ffeb9c01302
entry point 00007FFEB9C01130
preJIT generated code
GC info 00007FFEB989684C
Pointer table:
Prolog size: 0
GS cookie: <none>
PSPSym: initial.sp+200
Generics inst context: <none>
PSP slot: caller.sp+200
GenericInst slot: <none>
Varargs: 0
Frame pointer: r13
Wants Report Only Leaf: 1
Size of parameter area: 6160
Return Kind: {ByRef, Object}         <-   10.0 no longer includes Return Kind in GC Info. This is bogus. And most other info too, since the return kind was right after header flags.
Code size: 93
c0000005 Exception in C:\Users\<userName>\.dotnet\sos\sos.dll.gcinfo debugger extension.
      PC: 00007ffe`b9403065  VA: 0000028d`2c14de28  R/W: 0  Parameter: 00000000`00000000

After this PR with net10.0

0:000> !gcinfo 00007ffeb9d51302
entry point 00007FFEB9D51130
preJIT generated code
GC info 00007FFEB99E684C
Pointer table:
Prolog size: 0
GS cookie: <none>
PSPSym: initial.sp+30
Generics inst context: <none>
PSP slot: caller.sp+30
GenericInst slot: <none>
Varargs: 0
Frame pointer: rbp
Wants Report Only Leaf: 1
Size of parameter area: 30
Code size: 436
Untracked: +rbp+20 +rbp-48
00000034 interruptible
00000034 +rbp+10 +rcx
0000004c +r8
00000057 -r8
0000005c -rbp+10 -rcx
00000066 +r8
00000073 -r8
00000074 +rbp+10 +rcx
0000007a -rcx
000000b1 +rcx
000000c7 -rcx

@VSadov VSadov marked this pull request as ready for review March 24, 2025 22:13
@VSadov VSadov requested a review from a team as a code owner March 24, 2025 22:13
@noahfalk
Copy link
Member

@mikem8361 to take a closer look from the SOS side

@VSadov - SOS needs to work with both new and old versions of .NET and it wasn't clear to me if the current PR handles that? I noticed over on #4795 that discussion around that was already happening so great 👍

@VSadov
Copy link
Member Author

VSadov commented Mar 25, 2025

and now the new SPS.dll can also decode gcinfo in a net8.0 process:

The same System.Threading.ManualResetEventSlim.Wait on net8.0 runtime produces:

0:000> !gcinfo 00007ffeb445893e 
entry point 00007FFEB4458780
preJIT generated code
GC info 00007FFEB417C778
Pointer table:
Prolog size: 0
GS cookie: <none>
PSPSym: initial.sp+30
Generics inst context: <none>
PSP slot: caller.sp+30
GenericInst slot: <none>
Varargs: 0
Frame pointer: rbp
Wants Report Only Leaf: 1
Size of parameter area: 30
Return Kind: Scalar                            <-- reports Return Kind for old format that tracks it.
Code size: 460
Untracked: +rbp+20 +rbp-48
00000035 interruptible
00000035 +rbp+10 +rcx
0000004d +rax
00000057 -rax
00000069 -rcx
000000a4 +rcx
000000be -rcx
000000c2 +rcx
000000c8 -rcx
000000ce +rax(interior)
. . .

@VSadov
Copy link
Member Author

VSadov commented Mar 25, 2025

Looks like an unrelated failure: System.Net.Sockets.SocketException : Connection refused

@VSadov
Copy link
Member Author

VSadov commented Mar 25, 2025

I think the change has all that was planned. Please take a look.
CC: @jkotas

bool GcInfoDecoder::IsInterruptibleSafePoint()
{
return IsSafePoint() && AreSafePointsInterruptible();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were helpers for where we can suspend and where we cannot (it all got simpler now).
This does not need to be shimmed as this has no effect on gcinfo dumper.

#define CODE_OFFSETS_NEED_NORMALIZATION 1
#define NORMALIZE_CODE_OFFSET(x) (x) // Instructions are 2/4 bytes long in Thumb/ARM states,
#define DENORMALIZE_CODE_OFFSET(x) (x) // but the safe-point offsets are encoded with a -1 adjustment.
#define NORMALIZE_CODE_OFFSET(x) ((x)>>1) // Instructions are 2/4 bytes long in Thumb/ARM states,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These macros were changed to methods in dotnet/runtime main. Do you plan to pick up that update separately?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must have happened recently. I used fairly recent baseline, but perhaps not the latest.

I am thinking to open a parallel PR in runtime with same files content, to make sure we do not need to shuffle changes back and forth.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking to open a parallel PR in runtime with same files content,

Yes, I think that's a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@VSadov VSadov Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also re-tested in WinDbg if !gcinfo still works after updating from runtime/main, with both 8.0 and 10.0

@VSadov
Copy link
Member Author

VSadov commented Mar 27, 2025

This code can tell you if it is .NET Framework:

if (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop)

That does not want to work at the level of GC Info Decoder. I noticed that all the calls to this in at the strike.cpp level.
I think we can check for .NET FX for the purpose of GC Info version at strike.cpp level as well.

We do not need .NET FX detection in the Core repo anyways. As long as decoder specialcases V1 and V1 is set somehow for .Net FX, this should work as before.

@VSadov
Copy link
Member Author

VSadov commented Mar 27, 2025

I am not sure how to test .NET FX support in SOS though.

The same thing as I try for Core (i.e. load SOS.dll in WinDbg and examine some methods) does not work for me.
I am getting errors when trying to load.

0:000> .load E:\diagnostics\diagnostics\artifacts\bin\Windows_NT.x64.Release\sos.dll
The call to LoadLibrary(E:\diagnostics\diagnostics\artifacts\bin\Windows_NT.x64.Release\sos.dll) failed, Win32 error 0n193
    "%1 is not a valid Win32 application."
Please check your debugger configuration and/or network access.
Extension DLL search Path:
    C:\Program Files\WindowsApps\Microsoft.WinDbg_1.2502.25002.0_x64__8wekyb3d8bbwe\x86\WINXP;C:\Program Files\WindowsApps\Microsoft.WinDbg_1.2502.25002.0_x64__8wekyb3d8bbwe\x86\winext;C:\Program Files\WindowsApps\Microsoft.WinDbg_1.2502.25002.0_x64__8wekyb3d8bbwe\x86\winext\arcade;C:\Program Files\WindowsApps\Microsoft.WinDbg_1.2502.25002.0_x64__8wekyb3d8bbwe\x86\pri;C:\Program 

. . . lots of directories in search path . . .

You may also consider deploying your extension to the UserExtensions extension gallery repository
located at %LOCALAPPDATA%\dbg\UserExtensions folder. It would require an extension manifest.
Error: Failed to load extension E:\diagnostics\diagnostics\artifacts\bin\Windows_NT.x64.Release\sos.dll

Same error happens with the SOS.dll from C:\Users\<user>\.dotnet\sos

I do not think this is related to the change. Maybe I am using this incorrectly... (I am not a frequent user of SOS)

@VSadov
Copy link
Member Author

VSadov commented Mar 27, 2025

Figured why I could not test. .Net FX defaults to 32bit and thus I had a bitness mismatch.

Also I found that the change that supposedly "fixes" !gcinfo on .Net FX actually breaks it.

The reason is that the switch from GC Info v1 --> GC info v2 seems like happened in .Net FX times.

The NDP sources that I have (which are by themselves very old) have
(NDP\clr\src\inc\gcinfo.h)

#define GCINFO_VERSION 2

. . . 

    static UINT32 ReadyToRunVersionToGcInfoVersion(UINT32 readyToRunMajorVersion)
    {
        // GcInfo version is 1 up to ReadyTorun version 1.x
        // GcInfo version is current from  ReadyToRun version 2.0
        return (readyToRunMajorVersion == 1) ? 1 : GCINFO_VERSION;
    }

Since R2R is a CoreClr thing, does this mean that GCInfo v1 is effectively dead - either on .Net FX or on CoreCLR ?

@jkotas
Copy link
Member

jkotas commented Mar 27, 2025

GCInfo v1 is effectively dead - either on .Net FX or on CoreCLR ?

Sounds like it.

@VSadov
Copy link
Member Author

VSadov commented Mar 27, 2025

I will revert to the commit that does not handle GC_INFO_FLAGS_BIT_SIZE_VERSION_1

@VSadov
Copy link
Member Author

VSadov commented Mar 27, 2025

@mikem8361 The runtime part of this change is ready to go. Please take one more look from diagnostics side.

@VSadov
Copy link
Member Author

VSadov commented Apr 4, 2025

Thanks!!

@VSadov
Copy link
Member Author

VSadov commented Apr 4, 2025

Looks like I do not have permissions to merge in this repo, so someone else should merge.

@mikem8361 mikem8361 merged commit 07a1f3e into dotnet:main Apr 4, 2025
21 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update GCInfo deserializer once https://github.com/dotnet/runtime/pull/104336 merges

4 participants