Permalink
Browse files

2005-09-08 Martin Baulig <martin@ximian.com>

	* interfaces/ITargetObject.cs
	(ITargetObject.IsNull): New property.

	* interfaces/ILanguage.cs
	(ILanguage.CreateNullObject): New method.

	* backends/mono/MonoNullObject.cs: New file.

	* backends/mono/MonoVariable.cs (MonoVariable.GetObject): Return a
	`MonoNullObject' if the location is null.

	* frontend/CSharpExpressionParser.jay (constant): Added `NULL'.

	* frontend/Expression.cs (NullExpression): New expression.

	* test/TestNull.cs, test/mono-debugger.test/TestNull.exp: Added
	tests for `null' handling.


svn path=/trunk/debugger/; revision=49701
  • Loading branch information...
1 parent d8da200 commit 12e3a2491456d7e1a98ff0a4809f6051f4290ef9 Martin Baulig committed Sep 8, 2005
View
@@ -1,5 +1,25 @@
2005-09-08 Martin Baulig <martin@ximian.com>
+ * interfaces/ITargetObject.cs
+ (ITargetObject.IsNull): New property.
+
+ * interfaces/ILanguage.cs
+ (ILanguage.CreateNullObject): New method.
+
+ * backends/mono/MonoNullObject.cs: New file.
+
+ * backends/mono/MonoVariable.cs (MonoVariable.GetObject): Return a
+ `MonoNullObject' if the location is null.
+
+ * frontend/CSharpExpressionParser.jay (constant): Added `NULL'.
+
+ * frontend/Expression.cs (NullExpression): New expression.
+
+ * test/TestNull.cs, test/mono-debugger.test/TestNull.exp: Added
+ tests for `null' handling.
+
+2005-09-08 Martin Baulig <martin@ximian.com>
+
* interfaces/ITargetArrayObject.cs (ITargetArrayObject.this): Take
an `int[] indices' arguments (not a `params' one) and added setter.
View
@@ -641,33 +641,49 @@ public long ReadLongInteger (TargetAddress address)
public TargetAddress ReadAddress (TargetAddress address)
{
check_disposed ();
+ TargetAddress res;
switch (TargetAddressSize) {
case 4:
- return new TargetAddress (AddressDomain, (uint) ReadInteger (address));
+ res = new TargetAddress (AddressDomain, (uint) ReadInteger (address));
+ break;
case 8:
- return new TargetAddress (AddressDomain, ReadLongInteger (address));
+ res = new TargetAddress (AddressDomain, ReadLongInteger (address));
+ break;
default:
throw new TargetMemoryException (
"Unknown target address size " + TargetAddressSize);
}
+
+ if (res.Address == 0)
+ return TargetAddress.Null;
+ else
+ return res;
}
public TargetAddress ReadGlobalAddress (TargetAddress address)
{
check_disposed ();
+ TargetAddress res;
switch (TargetAddressSize) {
case 4:
- return new TargetAddress (GlobalAddressDomain, (uint) ReadInteger (address));
+ res = new TargetAddress (GlobalAddressDomain, (uint) ReadInteger (address));
+ break;
case 8:
- return new TargetAddress (GlobalAddressDomain, ReadLongInteger (address));
+ res = new TargetAddress (GlobalAddressDomain, ReadLongInteger (address));
+ break;
default:
throw new TargetMemoryException (
"Unknown target address size " + TargetAddressSize);
}
+
+ if (res.Address == 0)
+ return TargetAddress.Null;
+ else
+ return res;
}
public string ReadString (TargetAddress address)
@@ -37,8 +37,11 @@ void update ()
long contents = reg.Value;
- address = new TargetAddress (
- TargetMemoryInfo.AddressDomain, contents + regoffset);
+ if (contents == 0)
+ address = TargetAddress.Null;
+ else
+ address = new TargetAddress (
+ TargetMemoryInfo.AddressDomain, contents + regoffset);
if (is_byref && is_regoffset)
address = TargetMemoryAccess.ReadAddress (address);
@@ -116,6 +116,9 @@ public virtual TargetAddress ReadAddress ()
else
throw new InternalError ();
+ if (address == 0)
+ return TargetAddress.Null;
+
return new TargetAddress (TargetMemoryInfo.AddressDomain, address);
}
@@ -116,6 +116,9 @@ int GetArrayOffset (int[] indices)
dynamic_location.GetLocationAtOffset (
offset, type.Type.ElementType.IsByRef);
+ if (new_location.HasAddress && new_location.Address.IsNull)
+ return new MonoNullObject (type.ElementType, new_location);
+
return type.ElementType.GetObject (new_location);
}
@@ -807,7 +807,7 @@ public ITargetPointerObject CreatePointer (StackFrame frame, TargetAddress addre
public ITargetObject CreateObject (ITargetAccess target, TargetAddress address)
{
- TargetLocation location = new AbsoluteTargetLocation (null, target, address);
+ TargetLocation location = new AbsoluteTargetLocation (target, address);
MonoObjectObject obj = (MonoObjectObject)builtin_types.ObjectType.GetTypeInfo().GetObject (location);
if (obj == null)
return null;
@@ -818,6 +818,17 @@ public ITargetObject CreateObject (ITargetAccess target, TargetAddress address)
return obj;
}
+ public ITargetObject CreateNullObject (ITargetAccess target, ITargetType type)
+ {
+ TargetLocation location = new AbsoluteTargetLocation (target, TargetAddress.Null);
+
+ IMonoTypeInfo tinfo = ((MonoType) type).GetTypeInfo ();
+ if (tinfo == null)
+ tinfo = builtin_types.ObjectType;
+
+ return new MonoNullObject (tinfo, location);
+ }
+
ITargetFundamentalType ILanguage.IntegerType {
get { return builtin_types.Int32Type; }
}
@@ -0,0 +1,17 @@
+using System;
+
+namespace Mono.Debugger.Languages.Mono
+{
+ internal class MonoNullObject : MonoObject
+ {
+ public MonoNullObject (IMonoTypeInfo type, TargetLocation location)
+ : base (type, location)
+ { }
+
+ protected override long GetDynamicSize (TargetBlob blob, TargetLocation location,
+ out TargetLocation dynamic_location)
+ {
+ throw new InvalidOperationException ();
+ }
+ }
+}
@@ -41,7 +41,16 @@ public MonoObject (IMonoTypeInfo type_info, TargetLocation location)
public bool IsValid {
get {
- return is_valid && (location != null);
+ return is_valid;
+ }
+ }
+
+ public bool IsNull {
+ get {
+ if (!location.HasAddress)
+ return false;
+ else
+ return location.Address.IsNull;
}
}
@@ -42,6 +42,8 @@ protected override object GetObject (TargetBlob blob, TargetLocation location)
public override string Print ()
{
+ if (location.Address.IsNull)
+ return "null";
object obj = GetObject ();
return '"' + (string) obj + '"';
}
@@ -120,6 +120,10 @@ public ITargetObject GetObject (StackFrame frame)
if (location == null)
throw new LocationInvalidException ();
+ if (location.HasAddress && location.Address.IsNull)
+ return backend.MonoLanguage.CreateNullObject (
+ frame.TargetAccess, type);
+
IMonoTypeInfo tinfo = type.GetTypeInfo ();
if (tinfo == null)
return null;
@@ -79,7 +79,12 @@ public ITargetFundamentalObject CreateInstance (ITargetAccess target, int value)
public ITargetObject CreateObject (ITargetAccess target, TargetAddress address)
{
- return null;
+ throw new NotSupportedException ();
+ }
+
+ public ITargetObject CreateNullObject (ITargetAccess target, ITargetType type)
+ {
+ throw new NotSupportedException ();
}
private bool disposed = false;
@@ -35,7 +35,16 @@ public NativeObject (ITargetType type, TargetLocation location)
public bool IsValid {
get {
- return is_valid && (location != null);
+ return is_valid;
+ }
+ }
+
+ public bool IsNull {
+ get {
+ if (!location.HasAddress)
+ return false;
+ else
+ return location.Address.IsNull;
}
}
@@ -1,4 +1,5 @@
using System;
+using System.Runtime.Serialization;
namespace Mono.Debugger
{
@@ -21,6 +22,16 @@ public TargetMemoryException (TargetAddress address, int size)
: this (String.Format ("Cannot read {1} bytes from target memory at address {0:x}",
address, size))
{ }
+
+ protected TargetMemoryException (SerializationInfo info, StreamingContext context)
+ : base (info, context)
+ {
+ }
+
+ public override void GetObjectData (SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData (info, context);
+ }
}
[Serializable]
@@ -34,5 +45,15 @@ public TargetMemoryReadOnlyException (TargetAddress address)
: base (String.Format ("Can't write to target memory at address 0x{0:x}: {1}",
address, "the current target's memory is read-only"))
{ }
+
+ protected TargetMemoryReadOnlyException (SerializationInfo info, StreamingContext context)
+ : base (info, context)
+ {
+ }
+
+ public override void GetObjectData (SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData (info, context);
+ }
}
}
@@ -150,11 +150,15 @@ constant
{
$$ = new NumberExpression ((decimal) $1);
}
-
| STRING
{
$$ = new StringExpression ((string) $1);
}
+ | NULL
+ {
+ $$ = new NullExpression ();
+ }
+ ;
expression
: constant
@@ -71,7 +71,7 @@ static void InitTokens ()
keywords.Add ("false", Token.FALSE);
keywords.Add ("True", Token.TRUE);
keywords.Add ("False", Token.FALSE);
- keywords.Add ("null", Token.FALSE);
+ keywords.Add ("null", Token.NULL);
}
public string error {
@@ -363,6 +363,30 @@ protected override ITargetObject DoEvaluateVariable (ScriptingContext context)
}
}
+ public class NullExpression : Expression
+ {
+ public override string Name {
+ get { return "null"; }
+ }
+
+ protected override Expression DoResolve (ScriptingContext context)
+ {
+ resolved = true;
+ return this;
+ }
+
+ protected override object DoEvaluate (ScriptingContext context)
+ {
+ return null;
+ }
+
+ protected override ITargetObject DoEvaluateVariable (ScriptingContext context)
+ {
+ StackFrame frame = context.CurrentFrame.Frame;
+ return frame.Language.CreateObject (frame.TargetAccess, TargetAddress.Null);
+ }
+ }
+
public class ThisExpression : Expression
{
public override string Name {
@@ -181,8 +181,6 @@ public ITargetObject GetVariable (IVariable var)
{
if (!var.IsAlive (frame.TargetAddress))
throw new ScriptingException ("Variable out of scope.");
- if (!var.CheckValid (frame))
- throw new ScriptingException ("Variable cannot be accessed.");
return var.GetObject (frame);
}
View
@@ -413,6 +413,9 @@ protected string DoFormatObject (ITargetObject obj, bool recursed)
protected string DoFormatObjectRecursed (ITargetObject obj)
{
+ if (obj.IsNull)
+ return "null";
+
switch (obj.Kind) {
case TargetObjectKind.Class:
case TargetObjectKind.Struct:
@@ -460,6 +463,9 @@ protected string DoFormatArray (ITargetArrayObject aobj)
protected string DoFormatObject (ITargetObject obj)
{
+ if (obj.IsNull)
+ return "null";
+
switch (obj.Kind) {
case TargetObjectKind.Array:
return DoFormatArray ((ITargetArrayObject) obj);
@@ -505,22 +511,19 @@ protected string DoFormatObject (ITargetObject obj)
public override string PrintVariable (IVariable variable, StackFrame frame)
{
+ string contents;
ITargetObject obj = null;
- try {
- obj = variable.GetObject (frame);
- } catch {
- }
- string contents;
try {
+ obj = variable.GetObject (frame);
if (obj != null)
contents = DoFormatObject (obj, false);
else
contents = "<cannot display object>";
} catch {
contents = "<cannot display object>";
}
-
+
return String.Format (
"{0} = ({1}) {2}", variable.Name, variable.Type.Name, contents);
}
@@ -41,6 +41,8 @@ public interface ILanguage : IDisposable
ITargetPointerObject CreatePointer (StackFrame frame, TargetAddress address);
ITargetObject CreateObject (ITargetAccess target, TargetAddress address);
+
+ ITargetObject CreateNullObject (ITargetAccess target, ITargetType type);
}
}
@@ -25,6 +25,10 @@ public interface ITargetObject
get;
}
+ bool IsNull {
+ get;
+ }
+
// <summary>
// Returns the raw contents of this object. For objects with dynamic size,
// this returns a buffer of `Type.Size' bytes which is just enough to get
Oops, something went wrong.

0 comments on commit 12e3a24

Please sign in to comment.