diff options
author | Artem Bukhonov <artem.bukhonov@jetbrains.com> | 2017-01-30 23:41:38 +0300 |
---|---|---|
committer | Artem Bukhonov <Artem.Bukhonov@jetbrains.com> | 2017-03-11 21:20:35 +0300 |
commit | a3b1cef5ed13747ca750bc1791084aac2f8300ee (patch) | |
tree | d46019445fc790ef47f03e07e319359aa80f7b36 /main/src/addins/MonoDevelop.Debugger.Win32 | |
parent | 92fd2c95f0406802d65d5c8072693139e38b8829 (diff) |
A lot of calls in CorObjectAdaptor were made more safe - wrapped with try-catch and logging.
(cherry picked from commit 80432e5)
Diffstat (limited to 'main/src/addins/MonoDevelop.Debugger.Win32')
3 files changed, 75 insertions, 63 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/CorDebugUtil.cs b/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/CorDebugUtil.cs new file mode 100644 index 0000000000..16203bdda8 --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/CorDebugUtil.cs @@ -0,0 +1,19 @@ +using System;
+using System.Runtime.InteropServices;
+using Mono.Debugging.Client;
+
+namespace Mono.Debugging.Win32
+{
+ public static class CorDebugUtil
+ {
+ public static T CallHandlingComExceptions<T> (Func<T> factory, string callName, T defaultValue = default(T))
+ {
+ try {
+ return factory ();
+ } catch (COMException e) {
+ DebuggerLoggingService.LogMessage ("Exception in {0}: {1}", callName, e.Message);
+ return defaultValue;
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/CorObjectAdaptor.cs b/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/CorObjectAdaptor.cs index fbabdc3902..fb41baaed3 100644 --- a/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/CorObjectAdaptor.cs +++ b/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/CorObjectAdaptor.cs @@ -1364,16 +1364,13 @@ namespace Mono.Debugging.Win32 ValueReference GetHoistedThisReference (CorEvaluationContext cx)
{
- try {
+ return CorDebugUtil.CallHandlingComExceptions (() => {
CorValRef vref = new CorValRef (delegate {
return cx.Frame.GetArgument (0);
});
var type = (CorType) GetValueType (cx, vref);
return GetHoistedThisReference (cx, type, vref);
- } catch (COMException e) {
- DebuggerLoggingService.LogMessage ("Exception in GetHoistedThisReference(): {0}", e.Message);
- }
- return null;
+ }, "GetHoistedThisReference()");
}
ValueReference GetHoistedThisReference (CorEvaluationContext cx, CorType type, object val)
@@ -1451,7 +1448,7 @@ namespace Mono.Debugging.Win32 if (mi == null || mi.IsStatic)
return null;
- try {
+ return CorDebugUtil.CallHandlingComExceptions (() => {
CorValRef vref = new CorValRef (delegate {
var result = ctx.Frame.GetArgument (0);
if (result.Type == CorElementType.ELEMENT_TYPE_BYREF)
@@ -1460,12 +1457,18 @@ namespace Mono.Debugging.Win32 });
return new VariableReference (ctx, vref, "this", ObjectValueFlags.Variable | ObjectValueFlags.ReadOnly);
- } catch (COMException e) {
- DebuggerLoggingService.LogMessage("Exception in GetThisReference(): {0}", e.Message);
- return null;
- }
+ }, "GetThisReference()");
+ }
+
+ static VariableReference CreateParameterReference (CorEvaluationContext ctx, int paramIndex, string paramName, ObjectValueFlags flags = ObjectValueFlags.Parameter)
+ {
+ CorValRef vref = new CorValRef (delegate {
+ return ctx.Frame.GetArgument (paramIndex);
+ });
+ return new VariableReference (ctx, vref, paramName, flags);
}
+
protected override IEnumerable<ValueReference> OnGetParameters (EvaluationContext gctx)
{
CorEvaluationContext ctx = (CorEvaluationContext) gctx;
@@ -1476,28 +1479,19 @@ namespace Mono.Debugging.Win32 int pos = pi.Position;
if (met.IsStatic)
pos--;
- CorValRef vref = null;
- try {
- vref = new CorValRef (delegate {
- return ctx.Frame.GetArgument (pos);
- });
- }
- catch (Exception /*ex*/) {
- }
- if (vref != null)
- yield return new VariableReference (ctx, vref, pi.Name, ObjectValueFlags.Parameter);
+
+ yield return CorDebugUtil.CallHandlingComExceptions (() => CreateParameterReference (ctx, pos, pi.Name),
+ string.Format ("Get parameter {0} of {1}", pi.Name, met.Name));
}
yield break;
}
}
- int count = ctx.Frame.GetArgumentCount ();
+ int count = CorDebugUtil.CallHandlingComExceptions (() => ctx.Frame.GetArgumentCount (), "GetArgumentCount()", 0);
for (int n = 0; n < count; n++) {
int locn = n;
- var vref = new CorValRef (delegate {
- return ctx.Frame.GetArgument (locn);
- });
- yield return new VariableReference (ctx, vref, "arg_" + (n + 1), ObjectValueFlags.Parameter);
+ yield return CorDebugUtil.CallHandlingComExceptions (() => CreateParameterReference (ctx, locn, "arg_" + (locn + 1)),
+ string.Format ("Get parameter {0}", n));
}
}
@@ -1568,13 +1562,10 @@ namespace Mono.Debugging.Win32 {
uint offset;
CorDebugMappingResult mr;
- try {
+ return CorDebugUtil.CallHandlingComExceptions (() => {
cx.Frame.GetIP (out offset, out mr);
return GetLocals (cx, null, (int) offset, false);
- } catch (Exception e) {
- cx.WriteDebuggerError (e);
- return null;
- }
+ }, "GetLocalVariables()", new ValueReference[0]);
}
public override ValueReference GetCurrentException (EvaluationContext ctx)
@@ -1582,28 +1573,28 @@ namespace Mono.Debugging.Win32 CorEvaluationContext wctx = (CorEvaluationContext) ctx;
CorValue exception = wctx.Thread.CurrentException;
- try {
- if (exception != null)
- {
- CorHandleValue exceptionHandle = wctx.Session.GetHandle (exception);
-
- CorValRef vref = new CorValRef (delegate {
- return exceptionHandle;
- });
-
- return new VariableReference (ctx, vref, ctx.Options.CurrentExceptionTag, ObjectValueFlags.Variable);
- }
- return base.GetCurrentException(ctx);
- } catch (Exception e) {
- ctx.WriteDebuggerError (e);
+ if (exception == null)
return null;
- }
+ return CorDebugUtil.CallHandlingComExceptions (() => {
+ CorValRef vref = new CorValRef (delegate {
+ return wctx.Session.GetHandle (exception);
+ });
+ return new VariableReference (ctx, vref, ctx.Options.CurrentExceptionTag, ObjectValueFlags.Variable);
+ }, "Get current exception");
+ }
+
+ static VariableReference CreateLocalVariableReference (CorEvaluationContext ctx, int varIndex, string varName, ObjectValueFlags flags = ObjectValueFlags.Variable)
+ {
+ CorValRef vref = new CorValRef (delegate {
+ return ctx.Frame.GetLocalVariable (varIndex);
+ });
+ return new VariableReference (ctx, vref, varName, flags);
}
IEnumerable<ValueReference> GetLocals (CorEvaluationContext ctx, ISymbolScope scope, int offset, bool showHidden)
{
- if (ctx.Frame.FrameType != CorFrameType.ILFrame)
- yield break;
+ if (ctx.Frame.FrameType != CorFrameType.ILFrame)
+ yield break;
if (scope == null) {
ISymbolMethod met = ctx.Frame.Function.GetSymbolMethod (ctx.Session);
@@ -1613,10 +1604,8 @@ namespace Mono.Debugging.Win32 int count = ctx.Frame.GetLocalVariablesCount ();
for (int n = 0; n < count; n++) {
int locn = n;
- CorValRef vref = new CorValRef (delegate {
- return ctx.Frame.GetLocalVariable (locn);
- });
- yield return new VariableReference (ctx, vref, "local_" + (n + 1), ObjectValueFlags.Variable);
+ yield return CorDebugUtil.CallHandlingComExceptions (() => CreateLocalVariableReference (ctx, locn, "local_" + (locn + 1)),
+ string.Format ("Get local variable {0}", locn));
}
yield break;
}
@@ -1626,20 +1615,23 @@ namespace Mono.Debugging.Win32 if (var.Name == "$site")
continue;
if (IsClosureReferenceLocal (var)) {
- int addr = var.AddressField1;
- var vref = new CorValRef (delegate {
- return ctx.Frame.GetLocalVariable (addr);
- });
-
- foreach (var gv in GetHoistedLocalVariables (ctx, new VariableReference (ctx, vref, var.Name, ObjectValueFlags.Variable))) {
- yield return gv;
+ var variableReference = CorDebugUtil.CallHandlingComExceptions (() => {
+ int addr = var.AddressField1;
+ return CreateLocalVariableReference (ctx, addr, var.Name);
+ }, string.Format ("Get local variable {0}", var.Name));
+
+ if (variableReference != null) {
+ foreach (var gv in GetHoistedLocalVariables (ctx, variableReference)) {
+ yield return gv;
+ }
}
} else if (!IsGeneratedTemporaryLocal (var) || showHidden) {
- int addr = var.AddressField1;
- var vref = new CorValRef (delegate {
- return ctx.Frame.GetLocalVariable (addr);
- });
- yield return new VariableReference (ctx, vref, var.Name, ObjectValueFlags.Variable);
+ var variableReference = CorDebugUtil.CallHandlingComExceptions (() => {
+ int addr = var.AddressField1;
+ return CreateLocalVariableReference (ctx, addr, var.Name);
+ }, string.Format ("Get local variable {0}", var.Name));
+ if (variableReference != null)
+ yield return variableReference;
}
}
diff --git a/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/Mono.Debugging.Win32.csproj b/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/Mono.Debugging.Win32.csproj index dde76e512c..c91872dc00 100644 --- a/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/Mono.Debugging.Win32.csproj +++ b/main/src/addins/MonoDevelop.Debugger.Win32/Mono.Debugging.Win32/Mono.Debugging.Win32.csproj @@ -69,6 +69,7 @@ <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="PropertyReference.cs" /> <Compile Include="StringAdaptor.cs" /> + <Compile Include="CorDebugUtil.cs" /> <Compile Include="VariableReference.cs" /> <Compile Include="Win32.cs" /> </ItemGroup> |