Skip to content

Instantly share code, notes, and snippets.

@Criteo-dotnet-blog
Last active June 28, 2017 09:51
Show Gist options
  • Select an option

  • Save Criteo-dotnet-blog/08600339ee3e7fd59a1b5d37534e0580 to your computer and use it in GitHub Desktop.

Select an option

Save Criteo-dotnet-blog/08600339ee3e7fd59a1b5d37534e0580 to your computer and use it in GitHub Desktop.
private string BuildTimerCallbackMethodName(ClrRuntime runtime, ulong timerCallbackRef)
{
var heap = runtime.GetHeap();
var methodPtr = GetFieldValue(heap, timerCallbackRef, "_methodPtr");
if (methodPtr != null)
{
ClrMethod method = runtime.GetMethodByAddress((ulong)(long)methodPtr);
if (method != null)
{
// figure out the real callback implementor type thanks to _target
string thisTypeName = "?";
var thisPtr = GetFieldValue(heap, timerCallbackRef, "_target");
if ((thisPtr != null) && ((ulong) thisPtr) != 0)
{
ulong thisRef = (ulong) thisPtr;
var thisType = heap.GetObjectType(thisRef);
if (thisType != null)
{
thisTypeName = thisType.Name;
}
}
else
{
thisTypeName = (method.Type != null) ? method.Type.Name : "?";
}
return string.Format("{0}.{1}", thisTypeName, method.Name);
}
}
return string.Empty;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment