File: MonoStringObject.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 (59 lines) | stat: -rw-r--r-- 1,611 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
using System;

using Mono.Debugger.Backend;

namespace Mono.Debugger.Languages.Mono
{
	internal class MonoStringObject : TargetFundamentalObject
	{
		new protected readonly MonoStringType Type;

		public MonoStringObject (MonoStringType type, TargetLocation location)
			: base (type, location)
		{
			this.Type = type;
		}

		internal override long GetDynamicSize (TargetMemoryAccess target, TargetBlob blob,
						       TargetLocation location,
						       out TargetLocation dynamic_location)
		{
			TargetBinaryReader reader = blob.GetReader ();
			reader.Position = Type.ObjectSize;
			dynamic_location = location.GetLocationAtOffset (Type.ObjectSize + 4);
			return reader.ReadInteger (4) * 2;
		}

		protected override object DoGetObject (TargetMemoryAccess target)
		{
			TargetLocation dynamic_location;
			TargetBlob object_blob = Location.ReadMemory (target, type.Size);
			long size = GetDynamicSize (
				target, object_blob, Location, out dynamic_location);

			if (size > (long) MonoStringType.MaximumStringLength)
				size = MonoStringType.MaximumStringLength;

			TargetBlob blob = dynamic_location.ReadMemory (target, (int) size);

			TargetBinaryReader reader = blob.GetReader ();
			int length = (int) reader.Size / 2;

			char[] retval = new char [length];

			for (int i = 0; i < length; i++)
				retval [i] = (char) reader.ReadInt16 ();

			return new String (retval);
		}

		internal override string Print (TargetMemoryAccess target)
		{
			if (Location.GetAddress (target).IsNull)
				return "null";
			object obj = DoGetObject (target);
			return '"' + (string) obj + '"';
		}
	}
}