File: NativePointerObject.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 (87 lines) | stat: -rw-r--r-- 2,330 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
using System;

namespace Mono.Debugger.Languages.Native
{
	internal class NativePointerObject : TargetPointerObject
	{
		public NativePointerObject (NativePointerType type, TargetLocation location)
			: base (type, location)
		{ }

		internal override TargetType GetCurrentType (TargetMemoryAccess target)
		{
			if (!Type.HasStaticType)
				throw new InvalidOperationException ();

			return Type.StaticType;
		}

		internal override TargetObject GetDereferencedObject (TargetMemoryAccess target)
		{
			if (!Type.HasStaticType)
				throw new InvalidOperationException ();

			TargetLocation new_location = Location.GetLocationAtOffset (0);
			return Type.StaticType.GetObject (target, new_location);
		}

		internal override long GetDynamicSize (TargetMemoryAccess target, TargetBlob blob,
						       TargetLocation location,
						       out TargetLocation dynamic_location)
		{
			throw new InvalidOperationException ();
		}

		internal override TargetObject GetArrayElement (TargetMemoryAccess target, int index)
		{
			if (!Type.IsArray)
				throw new InvalidOperationException ();

			int size = Type.Size;
			TargetLocation new_loc = Location.GetLocationAtOffset (index * size);

			if (Type.StaticType.IsByRef)
				new_loc = new_loc.GetDereferencedLocation ();

			return Type.StaticType.GetObject (target, new_loc);
		}

		internal override string Print (TargetMemoryAccess target)
		{
			if (Type.HasStaticType) {
				TargetFundamentalType ftype;
				NativeTypeAlias alias = Type.StaticType as NativeTypeAlias;
				if (alias != null)
					ftype = alias.TargetType as TargetFundamentalType;
				else
					ftype = Type.StaticType as TargetFundamentalType;

				if ((ftype != null) && (ftype.Name == "char")) {
					TargetObject sobj = Type.Language.StringType.GetObject (
						target, Location);
					if (sobj != null)
						return sobj.Print (target);
				}
			}

			if (HasAddress) {
				TargetAddress address = GetAddress (target);
				if (address.IsNull)
					return "0x0";
				else
					return String.Format ("{0}", address);
			} else {
				byte[] data = Location.ReadBuffer (target, type.Size);

				long address;
				if (type.Size == 4)
					address = (uint) BitConverter.ToInt32 (data, 0);
				else
					address = BitConverter.ToInt64 (data, 0);

				return String.Format ("0x{0:x}", address);
			}
		}
	}
}