File: NativeClass.cs

package info (click to toggle)
mono-debugger 0.60%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,556 kB
  • ctags: 22,787
  • sloc: ansic: 99,407; cs: 42,429; sh: 9,192; makefile: 376
file content (149 lines) | stat: -rw-r--r-- 3,847 bytes parent folder | download
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;

namespace Mono.Debugger.Languages.Native
{
	internal class NativeClass : TargetClass
	{
		NativeStructType type;
		NativeFieldInfo[] fields;

		internal NativeClass (NativeStructType type, NativeFieldInfo[] fields)
		{
			this.type = type;
			this.fields = fields != null ? fields : new NativeFieldInfo [0];
		}

		public override TargetClassType Type {
			get { return type; }
		}

		public override bool HasParent {
			get { return false; }
		}

		public override TargetClass GetParent (Thread thread)
		{
			throw new InvalidOperationException ();
		}

		public override TargetFieldInfo[] GetFields (Thread thread)
		{
			return fields;
		}

		public override TargetObject GetField (Thread thread,
						       TargetStructObject instance,
						       TargetFieldInfo field)
		{
			if (field.HasConstValue)
				return type.Language.CreateInstance (thread, field.ConstValue);

			return (TargetObject) thread.ThreadServant.DoTargetAccess (
				delegate (TargetMemoryAccess target)  {
					return GetField (target, instance, field);
			});
		}

		internal TargetObject GetField (TargetMemoryAccess target,
						TargetStructObject instance,
						TargetFieldInfo field)
		{
			TargetLocation field_loc = instance.Location.GetLocationAtOffset (field.Offset);

			if (field.Type.IsByRef)
				field_loc = field_loc.GetDereferencedLocation ();

			NativeFieldInfo nfield = (NativeFieldInfo) field;
			if (!field.Type.IsByRef && nfield.IsBitfield)
				field_loc = new BitfieldTargetLocation (
					field_loc, nfield.BitOffset, nfield.BitSize);

			return field.Type.GetObject (target, field_loc);
		}

		public override void SetField (Thread thread, TargetStructObject instance,
					       TargetFieldInfo field, TargetObject value)
		{
			TargetLocation field_loc = instance.Location.GetLocationAtOffset (field.Offset);

			if (field.Type.IsByRef)
				field_loc = field_loc.GetDereferencedLocation ();

			NativeFieldInfo nfield = (NativeFieldInfo) field;
			if (!field.Type.IsByRef && nfield.IsBitfield)
				field_loc = new BitfieldTargetLocation (
					field_loc, nfield.BitOffset, nfield.BitSize);

			// field.Type.SetObject (field_loc, value);
			throw new NotImplementedException ();
		}

#if FIXME
		public override TargetPropertyInfo[] Properties {
			get { return new TargetPropertyInfo [0]; }
		}

		public override TargetPropertyInfo[] StaticProperties {
			get { return new TargetPropertyInfo [0]; }
		}

		public override TargetEventInfo[] Events {
			get { return new TargetEventInfo [0]; }
		}

		public override TargetEventInfo[] StaticEvents {
			get { return new TargetEventInfo [0]; }
		}

		public override TargetMethodInfo[] Methods {
			get { return new TargetMethodInfo [0]; }
		}

		public override TargetMethodInfo[] StaticMethods {
			get { return new TargetMethodInfo [0]; }
		}

		public override TargetMethodInfo[] Constructors {
			get { return new TargetMethodInfo [0]; }
		}

		public override TargetMethodInfo[] StaticConstructors {
			get { return new TargetMethodInfo [0]; }
		}

		public override TargetMemberInfo FindMember (string name, bool search_static,
							     bool search_instance)
		{
			if (search_static) {
				foreach (TargetFieldInfo field in StaticFields)
					if (field.Name == name)
						return field;

				foreach (TargetPropertyInfo property in StaticProperties)
					if (property.Name == name)
						return property;

				foreach (TargetEventInfo ev in StaticEvents)
					if (ev.Name == name)
						return ev;
			}

			if (search_instance) {
				foreach (TargetFieldInfo field in Fields)
					if (field.Name == name)
						return field;

				foreach (TargetPropertyInfo property in Properties)
					if (property.Name == name)
						return property;

				foreach (TargetEventInfo ev in Events)
					if (ev.Name == name)
						return ev;
			}

			return null;
		}
#endif
	}
}