diagnostics icon indicating copy to clipboard operation
diagnostics copied to clipboard

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

Open VSadov opened this issue 1 year ago • 17 comments
trafficstars

https://github.com/dotnet/runtime/pull/104336 changes the encoding of GC info in a breaking way. (arm/arm64 code offsets are encoded with fewer bits)

Once the runtime change goes in, the SOS copy will need to be updated correspondingly, to be able to dump from GcInfo v3

Re: https://github.com/dotnet/runtime/pull/104336#discussion_r1664993184

VSadov avatar Jul 16 '24 23:07 VSadov

Note: this change was reverted on https://github.com/dotnet/runtime/pull/105234

tommcdon avatar Jul 23 '24 20:07 tommcdon

@VSadov is the reverted runtime change going to eventually make it into .NET 9? Can I change this issue to .NET 10?

mikem8361 avatar Aug 28 '24 23:08 mikem8361

Pushed out to dev10. Sorry, I forgot to change this issue once it was clear it is not going to make it into 9.

VSadov avatar Aug 29 '24 01:08 VSadov

Hmm, it does not look like i can change the milestone.

VSadov avatar Aug 29 '24 01:08 VSadov

The GCInfo change was merged into .NET 10 main. The commands to dump GCInfo are broken in SOS as of right now.

jkotas avatar Feb 11 '25 19:02 jkotas

Now that the GC commands have been rewritten in C# and use CLRMD, this is problem a change in CLRMD.

mikem8361 avatar Feb 11 '25 19:02 mikem8361

This is about https://github.com/dotnet/diagnostics/blob/main/src/shared/vm/gcinfodecoder.cpp and related files. Was this decoder rewritten in C#? I am not aware of it.

jkotas avatar Feb 11 '25 21:02 jkotas

Your right, the GCInfo is still in C++. @VSadov could you handle this?

mikem8361 avatar Feb 11 '25 22:02 mikem8361

Your right, the GCInfo is still in C++. @VSadov could you handle this?

I'd need some pointers where that code lives and how to test. As I understand there is a copy of gcinfodecoder somewhere in SOS/diagnostics and that is updated once in a while to pick changes. and that is what needs to be done.

VSadov avatar Feb 19 '25 22:02 VSadov

Yes, it lives at https://github.com/dotnet/diagnostics/blob/main/src/shared/vm/gcinfodecoder.cpp

Note that this copy needs to be able to decode GCInfo for both current and past runtimes. The current copy in dotnet/runtime is not able to do that.

how to test.

Build the repo, load sos.dll from your local build into windbg, and inspect the output of !gcinfo command of a few methods on different versions of the runtime (e.g. .NET 8 and live .NET 10 should be enough).

jkotas avatar Feb 19 '25 22:02 jkotas

Note that this copy needs to be able to decode GCInfo for both current and past runtimes.

Is that actually expected? GC info changes almost every release, but there seems to be nothing in SOS to handle versioning for different runtimes. Is it not expected that SOS.dll matches the version of the runtime?

VSadov avatar Mar 24 '25 22:03 VSadov

Is it not expected that SOS.dll matches the version of the runtime?

We expect the same SOS.dll to work for all versions of the runtime.

jkotas avatar Mar 24 '25 22:03 jkotas

It seems the GC info version is hardcoded in SOS the same way as in runtime - #define GCINFO_VERSION 3 which is in gcinfo.h

We may need a variant of ReadyToRunVersionToGcInfoVersion, but for JIT code. How SOS code figures the runtime version in general?

We probably only need the major version here. (doubtful we will change GC info format in minor releases).

VSadov avatar Mar 24 '25 22:03 VSadov

There are a set of helper functions like

bool IsRuntimeVersion(DWORD major)
bool IsRuntimeVersionAtLeast(DWORD major)

that will help.

mikem8361 avatar Mar 24 '25 23:03 mikem8361

Just checking: Is there any way to get the GCINFO version from the target and go from there?

mikem8361 avatar Mar 24 '25 23:03 mikem8361

The GC info itself does not record its version as it would be fairly wasteful when everything in the process is the same version.

R2R has some way of associating R2R version with GC Info version, but all the last times that we used this mechanism it was for small semantical differences in how info is interpreted. (i.e. safe points are interruptible or not). It would not typically affect actual parsing of the info.

Parsing of GC info is not shimmed/versioned in the runtime for performance reasons. If R2R assembly has a version that requires different kind of parsing, we will just ignore the R2R part of it and switch to JITing.

I think from the dumping/parsing point we can assume that pre-10.0 runtimes use v3 GC Info, and 10.0+ use v4

VSadov avatar Mar 24 '25 23:03 VSadov

My current plan is to shim version-specific parts of GCInfo parsing in the SOS copy, but put the shimming under #ifdef so that we could backport that to runtime and continue keeping the files synchronized.

VSadov avatar Mar 24 '25 23:03 VSadov