Skip to content

Commit

Permalink
[Dynamic Instrumentation] Display interface properties in snapshot (#…
Browse files Browse the repository at this point in the history
…3761)

* Display interface properties in snapshot

* Fix PR's comments

* Add AsyncInterfaceProperties to exclude from unoptimize test
  • Loading branch information
dudikeleti committed Feb 8, 2023
1 parent 99befb1 commit f6fd6f8
Show file tree
Hide file tree
Showing 14 changed files with 669 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ private void AddAsyncMethodArguments<T>(DebuggerSnapshotCreator snapshotCreator,
continue;
}

snapshotCreator.AddScopeMember(arg.Name, arg.FieldType, arg.GetValue(asyncCaptureInfo.MoveNextInvocationTarget), ScopeMemberKind.Argument);
var argValue = arg.GetValue(asyncCaptureInfo.MoveNextInvocationTarget);
snapshotCreator.AddScopeMember(arg.Name, argValue?.GetType() ?? arg.FieldType, argValue, ScopeMemberKind.Argument);
}
}

Expand All @@ -286,7 +287,8 @@ private void AddAsyncMethodLocals<T>(DebuggerSnapshotCreator snapshotCreator, re
continue;
}

snapshotCreator.AddScopeMember(local.SanitizedName, local.Field.FieldType, local.Field.GetValue(asyncCaptureInfo.MoveNextInvocationTarget), ScopeMemberKind.Local);
var localValue = local.Field.GetValue(asyncCaptureInfo.MoveNextInvocationTarget);
snapshotCreator.AddScopeMember(local.SanitizedName, localValue?.GetType() ?? local.Field.FieldType, localValue, ScopeMemberKind.Local);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void LogLocal<TLocal>(ref TLocal local, int index, ref AsyncLineDe
return;
}

var captureInfo = new CaptureInfo<TLocal>(value: local, type: typeof(TLocal), methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);
var captureInfo = new CaptureInfo<TLocal>(value: local, methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);

if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static void LogLocal<TLocal>(ref TLocal local, int index, ref AsyncMethod
return;
}

var captureInfo = new CaptureInfo<TLocal>(value: local, type: typeof(TLocal), methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);
var captureInfo = new CaptureInfo<TLocal>(value: local, methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);
if (!asyncState.ProbeData.Processor.Process(ref captureInfo, asyncState.SnapshotCreator))
{
asyncState.IsActive = false;
Expand Down Expand Up @@ -192,7 +192,7 @@ public static DebuggerReturn EndMethod_StartMarker<TTarget>(TTarget instance, Ex
}

var asyncCaptureInfo = new AsyncCaptureInfo(asyncState.MoveNextInvocationTarget, asyncState.KickoffInvocationTarget, asyncState.MethodMetadataInfo.KickoffInvocationTargetType, hoistedLocals: asyncState.MethodMetadataInfo.AsyncMethodHoistedLocals, hoistedArgs: asyncState.MethodMetadataInfo.AsyncMethodHoistedArguments);
var capture = new CaptureInfo<Exception>(value: exception, methodState: MethodState.ExitStartAsync, type: exception?.GetType(), asyncCaptureInfo: asyncCaptureInfo, memberKind: ScopeMemberKind.Exception);
var capture = new CaptureInfo<Exception>(value: exception, methodState: MethodState.ExitStartAsync, asyncCaptureInfo: asyncCaptureInfo, memberKind: ScopeMemberKind.Exception);

if (!asyncState.ProbeData.Processor.Process(ref capture, asyncState.SnapshotCreator))
{
Expand Down Expand Up @@ -226,15 +226,15 @@ public static DebuggerReturn<TReturn> EndMethod_StartMarker<TTarget, TReturn>(TT
var asyncCaptureInfo = new AsyncCaptureInfo(asyncState.MoveNextInvocationTarget, asyncState.KickoffInvocationTarget, asyncState.MethodMetadataInfo.KickoffInvocationTargetType, hoistedLocals: asyncState.MethodMetadataInfo.AsyncMethodHoistedLocals, hoistedArgs: asyncState.MethodMetadataInfo.AsyncMethodHoistedArguments);
if (exception != null)
{
var captureInfo = new CaptureInfo<Exception>(value: exception, type: exception.GetType(), methodState: MethodState.ExitStartAsync, memberKind: ScopeMemberKind.Exception, asyncCaptureInfo: asyncCaptureInfo);
var captureInfo = new CaptureInfo<Exception>(value: exception, methodState: MethodState.ExitStartAsync, memberKind: ScopeMemberKind.Exception, asyncCaptureInfo: asyncCaptureInfo);
if (!asyncState.ProbeData.Processor.Process(ref captureInfo, asyncState.SnapshotCreator))
{
asyncState.IsActive = false;
}
}
else if (returnValue != null)
{
var captureInfo = new CaptureInfo<TReturn>(value: returnValue, name: "@return", type: typeof(TReturn), methodState: MethodState.ExitStartAsync, memberKind: ScopeMemberKind.Return, asyncCaptureInfo: asyncCaptureInfo);
var captureInfo = new CaptureInfo<TReturn>(value: returnValue, name: "@return", methodState: MethodState.ExitStartAsync, memberKind: ScopeMemberKind.Return, asyncCaptureInfo: asyncCaptureInfo);
if (!asyncState.ProbeData.Processor.Process(ref captureInfo, asyncState.SnapshotCreator))
{
asyncState.IsActive = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void LogArg<TArg>(ref TArg arg, int index, ref LineDebuggerState s
}

var paramName = state.MethodMetadataInfo.ParameterNames[index];
var captureInfo = new CaptureInfo<TArg>(value: arg, type: typeof(TArg), methodState: MethodState.LogArg, name: paramName, memberKind: ScopeMemberKind.Argument);
var captureInfo = new CaptureInfo<TArg>(value: arg, methodState: MethodState.LogArg, name: paramName, memberKind: ScopeMemberKind.Argument);

if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
Expand Down Expand Up @@ -85,7 +85,7 @@ public static void LogLocal<TLocal>(ref TLocal local, int index, ref LineDebugge
return;
}

var captureInfo = new CaptureInfo<TLocal>(value: local, type: typeof(TLocal), methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);
var captureInfo = new CaptureInfo<TLocal>(value: local, methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);

if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void LogArg<TArg>(ref TArg arg, int index, ref MethodDebuggerState
}

var paramName = state.MethodMetadataInfo.ParameterNames[index];
var captureInfo = new CaptureInfo<TArg>(value: arg, type: typeof(TArg), methodState: MethodState.LogArg, name: paramName, memberKind: ScopeMemberKind.Argument);
var captureInfo = new CaptureInfo<TArg>(value: arg, methodState: MethodState.LogArg, name: paramName, memberKind: ScopeMemberKind.Argument);

if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public static void LogLocal<TLocal>(ref TLocal local, int index, ref MethodDebug
return;
}

var captureInfo = new CaptureInfo<TLocal>(value: local, type: typeof(TLocal), methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);
var captureInfo = new CaptureInfo<TLocal>(value: local, methodState: MethodState.LogLocal, name: localName, memberKind: ScopeMemberKind.Local);

if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
Expand Down Expand Up @@ -168,7 +168,7 @@ public static DebuggerReturn EndMethod_StartMarker<TTarget>(TTarget instance, Ex

state.MethodPhase = EvaluateAt.Exit;

var captureInfo = new CaptureInfo<Exception>(value: exception, type: exception?.GetType(), invocationTargetType: state.MethodMetadataInfo.DeclaringType, methodState: MethodState.ExitStart, memberKind: ScopeMemberKind.Exception, localsCount: state.MethodMetadataInfo.LocalVariableNames.Length, argumentsCount: state.MethodMetadataInfo.ParameterNames.Length);
var captureInfo = new CaptureInfo<Exception>(value: exception, invocationTargetType: state.MethodMetadataInfo.DeclaringType, methodState: MethodState.ExitStart, memberKind: ScopeMemberKind.Exception, localsCount: state.MethodMetadataInfo.LocalVariableNames.Length, argumentsCount: state.MethodMetadataInfo.ParameterNames.Length);

if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
Expand Down Expand Up @@ -200,15 +200,15 @@ public static DebuggerReturn<TReturn> EndMethod_StartMarker<TTarget, TReturn>(TT

if (exception != null)
{
var captureInfo = new CaptureInfo<Exception>(value: exception, type: exception.GetType(), invocationTargetType: state.MethodMetadataInfo.DeclaringType, methodState: MethodState.ExitStart, memberKind: ScopeMemberKind.Exception, localsCount: state.MethodMetadataInfo.LocalVariableNames.Length, argumentsCount: state.MethodMetadataInfo.ParameterNames.Length);
var captureInfo = new CaptureInfo<Exception>(value: exception, invocationTargetType: state.MethodMetadataInfo.DeclaringType, methodState: MethodState.ExitStart, memberKind: ScopeMemberKind.Exception, localsCount: state.MethodMetadataInfo.LocalVariableNames.Length, argumentsCount: state.MethodMetadataInfo.ParameterNames.Length);
if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
state.IsActive = false;
}
}
else
{
var captureInfo = new CaptureInfo<TReturn>(value: returnValue, name: "@return", type: typeof(TReturn), invocationTargetType: state.MethodMetadataInfo.DeclaringType, methodState: MethodState.ExitStart, memberKind: ScopeMemberKind.Return, localsCount: state.MethodMetadataInfo.LocalVariableNames.Length, argumentsCount: state.MethodMetadataInfo.ParameterNames.Length);
var captureInfo = new CaptureInfo<TReturn>(value: returnValue, name: "@return", invocationTargetType: state.MethodMetadataInfo.DeclaringType, methodState: MethodState.ExitStart, memberKind: ScopeMemberKind.Return, localsCount: state.MethodMetadataInfo.LocalVariableNames.Length, argumentsCount: state.MethodMetadataInfo.ParameterNames.Length);
if (!state.ProbeData.Processor.Process(ref captureInfo, state.SnapshotCreator))
{
state.IsActive = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private void ExitMethodStart<TReturnOrException>(ref CaptureInfo<TReturnOrExcept
}
else if (info.MemberKind == ScopeMemberKind.Return)
{
CaptureLocal(info.Value, "@return");
CaptureLocal(info.Value, "@return", info.Type);
}

break;
Expand Down Expand Up @@ -460,7 +460,7 @@ private bool CaptureAsyncMethodArguments(System.Reflection.FieldInfo[] asyncHois
}

var argumentValue = argument.GetValue(moveNextInvocationTarget);
CaptureArgument(argumentValue, argument.Name, argument.FieldType);
CaptureArgument(argumentValue, argument.Name, argumentValue?.GetType() ?? argument.FieldType);
hasArgument = true;
}

Expand Down Expand Up @@ -489,7 +489,7 @@ private void CaptureAsyncMethodLocals(AsyncHelper.FieldInfoNameSanitized[] hoist
}

var localValue = local.Field.GetValue(moveNextInvocationTarget);
CaptureLocal(localValue, local.SanitizedName, local.Field.FieldType);
CaptureLocal(localValue, local.SanitizedName, localValue?.GetType() ?? local.Field.FieldType);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
[
{
"dd.span_id": "ScrubbedValue",
"dd.trace_id": "ScrubbedValue",
"ddsource": "dd_debugger",
"ddtags": "Unknown",
"debugger": {
"snapshot": {
"captures": {
"entry": {
"arguments": {
"parameter": {
"fields": {
"_privateField": {
"type": "String",
"value": "bla bla"
},
"Field": {
"type": "String",
"value": "I'm a class field"
},
"ShowMe": {
"type": "String",
"value": "Show Me!"
}
},
"type": "Class",
"value": "Class"
},
"this": {
"type": "AsyncInterfaceProperties",
"value": "AsyncInterfaceProperties"
}
}
},
"return": {
"arguments": {
"parameter": {
"fields": {
"_privateField": {
"type": "String",
"value": "This string should never be visible"
},
"Field": {
"type": "String",
"value": "I'm a class field"
},
"ShowMe": {
"type": "String",
"value": "Show Me!"
}
},
"type": "Class",
"value": "Class"
},
"this": {
"type": "AsyncInterfaceProperties",
"value": "AsyncInterfaceProperties"
}
},
"locals": {
"@return": {
"type": "String",
"value": "Show Me!"
},
"iInterface": {
"isNull": "true",
"type": "IInterface"
}
}
}
},
"duration": "ScrubbedValue",
"id": "ScrubbedValue",
"language": "dotnet",
"probe": {
"id": "ScrubbedValue",
"location": {
"method": "Method",
"type": "Samples.Probes.TestRuns.SmokeTests.AsyncInterfaceProperties"
}
},
"stack": "ScrubbedValue",
"timestamp": "ScrubbedValue"
}
},
"logger": {
"method": "Method",
"name": "Samples.Probes.TestRuns.SmokeTests.AsyncInterfaceProperties",
"thread_id": "ScrubbedValue",
"thread_name": "ScrubbedValue",
"version": "2"
},
"message": "ScrubbedValue",
"service": "probes"
},
{
"dd.span_id": "ScrubbedValue",
"dd.trace_id": "ScrubbedValue",
"ddsource": "dd_debugger",
"ddtags": "Unknown",
"debugger": {
"snapshot": {
"captures": {
"lines": {
"34": {
"arguments": {
"parameter": {
"fields": {
"_privateField": {
"type": "String",
"value": "This string should never be visible"
},
"Field": {
"type": "String",
"value": "I'm a class field"
},
"ShowMe": {
"type": "String",
"value": "Show Me!"
}
},
"type": "Class",
"value": "Class"
},
"this": {
"type": "AsyncInterfaceProperties",
"value": "AsyncInterfaceProperties"
}
},
"locals": {
"iInterface": {
"fields": {
"_privateField": {
"isNull": "true",
"type": "String"
},
"Field": {
"type": "String",
"value": "I'm a class field"
},
"ShowMe": {
"type": "String",
"value": ""
}
},
"type": "Class",
"value": "Class"
}
}
}
}
},
"duration": "ScrubbedValue",
"id": "ScrubbedValue",
"language": "dotnet",
"probe": {
"id": "ScrubbedValue",
"location": {
"file": "AsyncInterfaceProperties.cs",
"lines": [
34
]
}
},
"stack": "ScrubbedValue",
"timestamp": "ScrubbedValue"
}
},
"logger": {
"method": "Method",
"name": "Samples.Probes.TestRuns.SmokeTests.AsyncInterfaceProperties",
"thread_id": "ScrubbedValue",
"thread_name": "ScrubbedValue",
"version": "2"
},
"message": "ScrubbedValue",
"service": "probes"
}
]
Loading

0 comments on commit f6fd6f8

Please sign in to comment.