Browse Source

Never return null when Debugger.Value is expected - throw GetValueException instead

pull/32/merge
David Srbecký 13 years ago
parent
commit
07c333b1f6
  1. 2
      src/AddIns/Debugger/Debugger.Core/Eval.cs
  2. 5
      src/AddIns/Debugger/Debugger.Core/StackFrame.cs
  3. 22
      src/AddIns/Debugger/Debugger.Core/Value.cs

2
src/AddIns/Debugger/Debugger.Core/Eval.cs

@ -62,7 +62,7 @@ namespace Debugger
case EvalState.Evaluating: throw new GetValueException("Evaluating..."); case EvalState.Evaluating: throw new GetValueException("Evaluating...");
case EvalState.EvaluatedSuccessfully: return result; case EvalState.EvaluatedSuccessfully: return result;
case EvalState.EvaluatedException: return result; case EvalState.EvaluatedException: return result;
case EvalState.EvaluatedNoResult: return null; case EvalState.EvaluatedNoResult: throw new DebuggerException("Evaluation did not return any value.");
case EvalState.EvaluatedTimeOut: throw new GetValueException("Timeout"); case EvalState.EvaluatedTimeOut: throw new GetValueException("Timeout");
default: throw new DebuggerException("Unknown state"); default: throw new DebuggerException("Unknown state");
} }

5
src/AddIns/Debugger/Debugger.Core/StackFrame.cs

@ -232,7 +232,7 @@ namespace Debugger
if (loc.IsThis) if (loc.IsThis)
return loc.GetValue(this); return loc.GetValue(this);
} }
return null; throw new GetValueException("The current method does not have 'this'.");
} else { } else {
return new Value(this.AppDomain, GetThisCorValue()); return new Value(this.AppDomain, GetThisCorValue());
} }
@ -240,7 +240,8 @@ namespace Debugger
ICorDebugValue GetThisCorValue() ICorDebugValue GetThisCorValue()
{ {
if (this.MethodInfo.IsStatic) throw new GetValueException("Static method does not have 'this'."); if (this.MethodInfo.IsStatic)
throw new GetValueException("Static method does not have 'this'.");
ICorDebugValue corValue; ICorDebugValue corValue;
try { try {
corValue = CorILFrame.GetArgument(0); corValue = CorILFrame.GetArgument(0);

22
src/AddIns/Debugger/Debugger.Core/Value.cs

@ -14,6 +14,10 @@ namespace Debugger
{ {
public delegate Value ValueGetter(StackFrame context); public delegate Value ValueGetter(StackFrame context);
/// <summary>
/// Thrown when Value can not be obtained.
/// Methods should throw this exception instead of returning null.
/// </summary>
public class GetValueException: DebuggerException public class GetValueException: DebuggerException
{ {
public GetValueException(string error) : base(error) {} public GetValueException(string error) : base(error) {}
@ -240,13 +244,13 @@ namespace Debugger
} }
/// <summary> Dereferences a pointer type </summary> /// <summary> Dereferences a pointer type </summary>
/// <returns> Returns null for a null pointer </returns>
public Value Dereference() public Value Dereference()
{ {
if (this.Type.Kind != TypeKind.Pointer) throw new DebuggerException("Not a pointer"); if (this.Type.Kind != TypeKind.Pointer)
throw new DebuggerException("Not a pointer");
ICorDebugReferenceValue corRef = (ICorDebugReferenceValue)this.CorValue; ICorDebugReferenceValue corRef = (ICorDebugReferenceValue)this.CorValue;
if (corRef.GetValue() == 0 || corRef.Dereference() == null) { if (corRef.GetValue() == 0 || corRef.Dereference() == null) {
return null; throw new GetValueException("Null pointer");
} else { } else {
return new Value(this.AppDomain, corRef.Dereference()); return new Value(this.AppDomain, corRef.Dereference());
} }
@ -394,18 +398,6 @@ namespace Debugger
} }
} }
/*
/// <summary> Get a field or property of an object with a given name. </summary>
/// <returns> Null if not found </returns>
public Value GetMemberValue(Thread evalThread, string name)
{
MemberInfo memberInfo = this.Type.GetMembers(m => m.Name == name && (m.IsFieldOrNonIndexedProperty), GetMemberOptions.None);
if (memberInfo == null)
return null;
return GetMemberValue(evalThread, memberInfo);
}
*/
/// <summary> Get the value of given member. </summary> /// <summary> Get the value of given member. </summary>
public Value GetMemberValue(Thread evalThread, IMember memberInfo, params Value[] arguments) public Value GetMemberValue(Thread evalThread, IMember memberInfo, params Value[] arguments)
{ {

Loading…
Cancel
Save