1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
using System;
using Mono.Debugger.Backend;
namespace Mono.Debugger.Languages
{
public abstract class TargetType : DebuggerMarshalByRefObject
{
protected readonly Language language;
protected readonly TargetObjectKind kind;
protected TargetType (Language language, TargetObjectKind kind)
{
this.language = language;
this.kind = kind;
}
public TargetObjectKind Kind {
get { return kind; }
}
public abstract string Name {
get;
}
public abstract bool IsByRef {
get;
}
public abstract bool HasFixedSize {
get;
}
public abstract bool HasClassType {
get;
}
public abstract TargetClassType ClassType {
get;
}
public Language Language {
get { return language; }
}
public abstract int Size {
get;
}
internal void SetObject (TargetMemoryAccess target, TargetLocation location,
TargetObject obj)
{
if (obj == null) {
if (IsByRef) {
location.WriteAddress (target, TargetAddress.Null);
return;
}
throw new InvalidOperationException ();
}
if (IsByRef) {
if (obj.Type.IsByRef) {
location.WriteAddress (target, obj.Location.GetAddress (target));
return;
}
throw new InvalidOperationException ();
}
if (!HasFixedSize || !obj.Type.HasFixedSize)
throw new InvalidOperationException ();
if (Size != obj.Type.Size)
throw new InvalidOperationException ();
byte[] contents = obj.Location.ReadBuffer (target, obj.Type.Size);
location.WriteBuffer (target, contents);
}
internal TargetObject GetObject (TargetMemoryAccess target, TargetLocation location)
{
return DoGetObject (target, location);
}
protected abstract TargetObject DoGetObject (TargetMemoryAccess target,
TargetLocation location);
public override string ToString ()
{
return String.Format ("{0} [{1}]", GetType (), Name);
}
}
}
|