Skip to content
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

changes to allow compatibility with ClrMdV2 #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

neilmsimmons
Copy link

No description provided.

@neilmsimmons
Copy link
Author

I've been using this with linqpad, it seems to work but it might still need some tidying up

Copy link
Owner

@JeffCyr JeffCyr left a comment

Choose a reason for hiding this comment

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

Hey Neil, sorry for being so late for this review!

I left a lot of comments in case you want to continue on this path. But I'm wondering if ClrMD.Extensions still have a reason to exist with ClrMD v2. In any case, supporting v2 would probably need to be in a side branch, I'm surprised to see that BlockingObject was removed from v2. The v1 wrapper would need to continue on the side to support the missing features and older .NET frameworks no longer supported by v2.

ClrMD.Extensions was built when ClrMD itself was very hard to use, but now it looks like the proper abstractions exist to directly use ClrMD in a productive way.

Maybe it would be best to just tell LINQPad how to Dump() the ClrMD classes (https://www.linqpad.net/CustomizingDump.aspx)

@@ -60,7 +61,8 @@ public class ClrDynamic : DynamicObject, IEnumerable<ClrDynamic>, IComparable, I
if (!Type.IsArray)
throw new InvalidOperationException(string.Format("Type '{0}' is not an array", Type.Name));

int arrayLength = Type.GetArrayLength(Address);
//int arrayLength = Type.GetArrayLength(Address);
Copy link
Owner

Choose a reason for hiding this comment

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

Commented code should be removed

@@ -91,12 +94,14 @@ public object SimpleDisplayValue
get
{
if (Type.IsEnum)
return Type.GetEnumName(SimpleValue) ?? SimpleValue.ToString();
{
return Type.AsEnum().EnumerateValues().FirstOrDefault(f => Convert.ToInt64(f.Value) == Convert.ToInt64(SimpleValue)).Name ?? SimpleValue.ToString();
Copy link
Owner

Choose a reason for hiding this comment

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

This probably won't be a bottleneck, but Type.AsEnum().EnumerateValues().FirstOrDefault seems inefficient. That said I don't know how Type.GetEnumName used to work, maybe it was already implemented with something simliar.


var heapTypes = ClrMDSession.Current.Heap.EnumerateTypes();

var target = heapTypes.First(type => type.Name == declaringType);
Copy link
Owner

Choose a reason for hiding this comment

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

This will iterate all types to find the declaringType everytime ClrDynamic.FindField is called. This probably introduces a performance bottleneck.

If there isn't a way to lookup by type name, a cached map should be preprocessed to do this only once

Type.Heap.ReadPointer(pointer, out fieldAddress);

Type.Heap.Runtime.DataTarget.DataReader.ReadPointer(pointer, out fieldAddress);
//Console.WriteLine(fieldAddress);
Copy link
Owner

Choose a reason for hiding this comment

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

Remove commented line

@@ -284,18 +290,19 @@ private ClrDynamic GetInnerObject(ulong pointer, ClrType type)
// Unfortunately, ClrType.GetValue for primitives assumes that the value is boxed,
// we decrement PointerSize because it will be added when calling ClrType.GetValue.
// ClrMD should be updated in a future version to include ClrType.GetValue(int interior).
Copy link
Owner

Choose a reason for hiding this comment

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

Is this still true in ClrMD v2?

}

public static ClrMDSession AttachToProcess(int pid, uint millisecondsTimeout = 5000, AttachFlag attachFlag = AttachFlag.Invasive)
public static ClrMDSession AttachToProcess(int pid)
Copy link
Owner

Choose a reason for hiding this comment

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

AttachFlag no longer exists? Is there an alternative to attach without freezing the process?

//(from objects in ClrMDSession.Current.Heap.EnumerateObjects()
//group objects by objects.Type into tn
//select (tn.Key)
//);
Copy link
Owner

Choose a reason for hiding this comment

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

Cleanup commented code

var types =
from type in Heap.EnumerateTypes()
from type in heapTypes
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like heap.EnumerateTypes() can be used directly

s_currentSession.Runtime.ReadMemory(0, dummy, 8, out bytesRead);
Span<byte> dummy = new byte[8];
//int bytesRead;
s_currentSession.Target.DataReader.Read(0,dummy);
Copy link
Owner

Choose a reason for hiding this comment

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

Missing space after comma

Span<byte> dummy = new byte[8];
//int bytesRead;
s_currentSession.Target.DataReader.Read(0,dummy);
//s_currentSession.Runtime.ReadMemory(0, dummy, 8, out bytesRead);
Copy link
Owner

Choose a reason for hiding this comment

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

Cleanup commented code

@neilmsimmons
Copy link
Author

neilmsimmons commented Sep 8, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants