-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cdac] Read types from contract descriptor (#101994)
- Read/store types from contract descriptor into an internal representation of the type layout info - Add functions to `Target` for getting type info and contract version - Add placeholder for thread contract and getting thread store data - Add ThreadStore to data descriptor - `GetThreadStoreData` continues to return E_NOTIMPL, but will go through trying to use the contract - Store processed data for the target by its address and data model type - Add unit tests for getting type info
- Loading branch information
1 parent
2385d08
commit 4b8fcd5
Showing
12 changed files
with
394 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.