-
Notifications
You must be signed in to change notification settings - Fork 5k
[cdac] Implement GetObjectStringData #105061
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
6 commits
Select commit
Hold shift + click to select a range
5e60587
Add data descriptor for String, Object
elinor-fung b2a0776
Add Object contract
elinor-fung fa5d598
Implement ISOSDacInterface::GetObjectStringData
elinor-fung b2ddd91
Update docs/design/datacontracts/Object.md
elinor-fung 98138c0
Update src/coreclr/debug/runtimeinfo/datadescriptor.h
elinor-fung 682f1db
Update docs/design/datacontracts/Object.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Contract Object | ||
|
||
This contract is for getting information about well-known managed objects | ||
|
||
## APIs of contract | ||
|
||
``` csharp | ||
// Get the method table address for the object | ||
TargetPointer GetMethodTableAddress(TargetPointer address); | ||
|
||
// Get the string corresponding to a managed string object. Error if address does not represent a string. | ||
string GetStringValue(TargetPointer address); | ||
``` | ||
|
||
## Version 1 | ||
|
||
Data descriptors used: | ||
| Data Descriptor Name | Field | Meaning | | ||
| --- | --- | --- | | ||
| `Object` | `m_pMethTab` | Method table for the object | | ||
| `String` | `m_FirstChar` | First character of the string - `m_StringLength` can be used to read the full string (encoded in UTF-16) | | ||
| `String` | `m_StringLength` | Length of the string in characters (encoded in UTF-16) | | ||
|
||
Global variables used: | ||
| Global Name | Type | Purpose | | ||
| --- | --- | --- | | ||
| `ObjectToMethodTableUnmask` | uint8 | Bits to clear for converting to a method table address | | ||
| `StringMethodTable` | TargetPointer | The method table for System.String | | ||
|
||
``` csharp | ||
TargetPointer GetMethodTableAddress(TargetPointer address) | ||
{ | ||
TargetPointer mt = _targetPointer.ReadPointer(address + /* Object::m_pMethTab offset */); | ||
return mt.Value & ~target.ReadGlobal<byte>("ObjectToMethodTableUnmask"); | ||
} | ||
|
||
string GetStringValue(TargetPointer address) | ||
{ | ||
TargetPointer mt = GetMethodTableAddress(address); | ||
TargetPointer stringMethodTable = target.ReadPointer(target.ReadGlobalPointer("StringMethodTable")); | ||
if (mt != stringMethodTable) | ||
throw new ArgumentException("Address does not represent a string object", nameof(address)); | ||
|
||
// Validates the method table | ||
_ = target.Contracts.RuntimeTypeSystem.GetTypeHandle(mt); | ||
|
||
Data.String str = _target.ProcessedData.GetOrAdd<Data.String>(address); | ||
uint length = target.Read<uint>(address + /* String::m_StringLength offset */); | ||
Span<byte> span = stackalloc byte[(int)length * sizeof(char)]; | ||
target.ReadBuffer(address + /* String::m_FirstChar offset */, span); | ||
return new string(MemoryMarshal.Cast<byte, char>(span)); | ||
} | ||
``` |
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
"DacStreams": 1, | ||
"Exception": 1, | ||
"Loader": 1, | ||
"Object": 1, | ||
"RuntimeTypeSystem": 1, | ||
"Thread": 1 | ||
} |
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,31 @@ | ||
// 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 IObject : IContract | ||
{ | ||
static string IContract.Name { get; } = nameof(Object); | ||
static IContract IContract.Create(Target target, int version) | ||
{ | ||
ulong methodTableOffset = (ulong)target.GetTypeInfo(DataType.Object).Fields["m_pMethTab"].Offset; | ||
byte objectToMethodTableUnmask = target.ReadGlobal<byte>(Constants.Globals.ObjectToMethodTableUnmask); | ||
TargetPointer stringMethodTable = target.ReadPointer( | ||
target.ReadGlobalPointer(Constants.Globals.StringMethodTable)); | ||
return version switch | ||
{ | ||
1 => new Object_1(target, methodTableOffset, objectToMethodTableUnmask, stringMethodTable), | ||
_ => default(Object), | ||
}; | ||
} | ||
|
||
public virtual TargetPointer GetMethodTableAddress(TargetPointer address) => throw new NotImplementedException(); | ||
public virtual string GetStringValue(TargetPointer address) => throw new NotImplementedException(); | ||
} | ||
|
||
internal readonly struct Object : IObject | ||
{ | ||
// Everything throws 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,41 @@ | ||
// 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.Runtime.InteropServices; | ||
|
||
namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
||
internal readonly struct Object_1 : IObject | ||
{ | ||
private readonly Target _target; | ||
private readonly ulong _methodTableOffset; | ||
private readonly TargetPointer _stringMethodTable; | ||
private readonly byte _objectToMethodTableUnmask; | ||
|
||
internal Object_1(Target target, ulong methodTableOffset, byte objectToMethodTableUnmask, TargetPointer stringMethodTable) | ||
{ | ||
_target = target; | ||
_methodTableOffset = methodTableOffset; | ||
_stringMethodTable = stringMethodTable; | ||
_objectToMethodTableUnmask = objectToMethodTableUnmask; | ||
} | ||
|
||
public TargetPointer GetMethodTableAddress(TargetPointer address) | ||
{ | ||
TargetPointer mt = _target.ReadPointer(address + _methodTableOffset); | ||
return mt.Value & (ulong)~_objectToMethodTableUnmask; | ||
} | ||
|
||
string IObject.GetStringValue(TargetPointer address) | ||
{ | ||
TargetPointer mt = GetMethodTableAddress(address); | ||
if (mt != _stringMethodTable) | ||
throw new ArgumentException("Address does not represent a string object", nameof(address)); | ||
|
||
Data.String str = _target.ProcessedData.GetOrAdd<Data.String>(address); | ||
Span<byte> span = stackalloc byte[(int)str.StringLength * sizeof(char)]; | ||
_target.ReadBuffer(str.FirstChar, span); | ||
return new string(MemoryMarshal.Cast<byte, char>(span)); | ||
} | ||
} |
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,21 @@ | ||
// 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 String : IData<String> | ||
{ | ||
static String IData<String>.Create(Target target, TargetPointer address) | ||
=> new String(target, address); | ||
|
||
public String(Target target, TargetPointer address) | ||
{ | ||
Target.TypeInfo type = target.GetTypeInfo(DataType.String); | ||
|
||
FirstChar = address + (ulong)type.Fields["m_FirstChar"].Offset; | ||
StringLength = target.Read<uint>(address + (ulong)type.Fields["m_StringLength"].Offset); | ||
} | ||
|
||
public TargetPointer FirstChar { get; init; } | ||
public uint StringLength { 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 |
---|---|---|
|
@@ -37,4 +37,6 @@ public enum DataType | |
TypeVarTypeDesc, | ||
FnPtrTypeDesc, | ||
DynamicMetadata, | ||
Object, | ||
String, | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DAC also does
DacValidateMethodTable
(cDAC equivalent would beRuntimeTypeSystem.GetTypeHandle
), but it seemed unnecessary since we check that it is the known string method table.