-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[cdac] Read types from contract descriptor #101994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6cd4a60
Read types from descriptor, add list of well-known types
elinor-fung 8c92d38
Add tests
elinor-fung 8ff13a9
Add placeholder thread contract and thread store data
elinor-fung b282aa9
Store processed data
elinor-fung 0d6a4c2
Contract registry
elinor-fung c617a4e
Add name to IContract
elinor-fung fa4f669
Remove TryGetTypeInfo
elinor-fung 1ad1da3
Make Thread a readonly struct
elinor-fung 790a4f9
Update src/native/managed/cdacreader/src/Contracts/Thread.cs
elinor-fung 16830cd
Use address and type for processed data cache
elinor-fung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| internal interface IContract | ||
| { | ||
| static virtual string Name => throw new NotImplementedException(); | ||
| static virtual IContract Create(Target target, int version) => throw new NotImplementedException(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| internal sealed class Registry | ||
| { | ||
| // Contracts that have already been created for a target. | ||
| // Items should not be removed from this, only added. | ||
| private readonly Dictionary<Type, IContract> _contracts = []; | ||
| private readonly Target _target; | ||
|
|
||
| public Registry(Target target) | ||
| { | ||
| _target = target; | ||
| } | ||
|
|
||
| public IThread Thread => GetContract<IThread>(); | ||
|
|
||
| private T GetContract<T>() where T : IContract | ||
| { | ||
| if (_contracts.TryGetValue(typeof(T), out IContract? contractMaybe)) | ||
| return (T)contractMaybe; | ||
|
|
||
| if (!_target.TryGetContractVersion(T.Name, out int version)) | ||
| throw new NotImplementedException(); | ||
|
|
||
| // Create and register the contract | ||
| IContract contract = T.Create(_target, version); | ||
| if (_contracts.TryAdd(typeof(T), contract)) | ||
| return (T)contract; | ||
|
|
||
| // Contract was already registered by someone else | ||
| return (T)_contracts[typeof(T)]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| // TODO: [cdac] Add other counts / threads | ||
| internal record struct ThreadStoreData( | ||
| int ThreadCount, | ||
| TargetPointer FirstThread); | ||
|
|
||
| internal interface IThread : IContract | ||
| { | ||
| static string IContract.Name { get; } = nameof(Thread); | ||
| static IContract IContract.Create(Target target, int version) | ||
| { | ||
| TargetPointer threadStore = target.ReadGlobalPointer(Constants.Globals.ThreadStore); | ||
| return version switch | ||
| { | ||
| 1 => new Thread_1(target, threadStore), | ||
| _ => default(Thread), | ||
| }; | ||
| } | ||
|
|
||
| public virtual ThreadStoreData GetThreadStoreData() => throw new NotImplementedException(); | ||
| } | ||
|
|
||
| internal readonly struct Thread : IThread | ||
| { | ||
| // Everything throws NotImplementedException | ||
| } | ||
|
|
||
| internal readonly struct Thread_1 : IThread | ||
| { | ||
| private readonly Target _target; | ||
| private readonly TargetPointer _threadStoreAddr; | ||
|
|
||
| internal Thread_1(Target target, TargetPointer threadStore) | ||
| { | ||
| _target = target; | ||
| _threadStoreAddr = threadStore; | ||
| } | ||
|
|
||
| ThreadStoreData IThread.GetThreadStoreData() | ||
| { | ||
| Data.ThreadStore? threadStore; | ||
| if (!_target.ProcessedData.TryGet(_threadStoreAddr.Value, out threadStore)) | ||
| { | ||
| threadStore = new Data.ThreadStore(_target, _threadStoreAddr); | ||
|
|
||
| // Still okay if processed data is already registered by someone else | ||
| _ = _target.ProcessedData.TryRegister(_threadStoreAddr.Value, threadStore); | ||
| } | ||
|
|
||
| return new ThreadStoreData(threadStore.ThreadCount, threadStore.FirstThread); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Data; | ||
|
|
||
| internal sealed class ThreadStore | ||
| { | ||
| public ThreadStore(Target target, TargetPointer pointer) | ||
| { | ||
| Target.TypeInfo type = target.GetTypeInfo(DataType.ThreadStore); | ||
| TargetPointer addr = target.ReadPointer(pointer.Value); | ||
|
|
||
| ThreadCount = target.Read<int>(addr.Value + (ulong)type.Fields[nameof(ThreadCount)].Offset); | ||
| FirstThread = TargetPointer.Null; | ||
| } | ||
|
|
||
| public int ThreadCount { get; init; } | ||
|
|
||
| public TargetPointer FirstThread { get; init; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader; | ||
|
|
||
| public enum DataType | ||
| { | ||
| Unknown = 0, | ||
|
|
||
| int8, | ||
| uint8, | ||
| int16, | ||
| uint16, | ||
| int32, | ||
| uint32, | ||
| int64, | ||
| uint64, | ||
| nint, | ||
| nuint, | ||
| pointer, | ||
|
|
||
| GCHandle, | ||
| Thread, | ||
| ThreadStore, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.