This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
SourceAddress.cs
117 lines (103 loc) · 2.58 KB
/
SourceAddress.cs
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
using System;
using System.Text;
namespace Mono.Debugger
{
// <summary>
// Holds the location in the source code corresponding to an actual machine address.
//
// Note that the difference between an "address" and a "location" is that a location
// is basically just a name for a specific source code location while an address contains
// some additional information which are only valid while the corresponding method is
// actually loaded in memory.
//
// This means that you can easily transform a SourceAddress in a SourceLocation, but
// not the other way around. If you insert a breakpoint on a location, the debugger will
// automatically compute the actual address once the corresponding method has been loaded.
// </summary>
public class SourceAddress : MarshalByRefObject
{
MethodSource source;
int row;
int source_offset;
int source_range;
public static SourceAddress Null = new SourceAddress (null, 0);
public SourceAddress (MethodSource source, int row)
: this (source, row, 0, 0)
{ }
public SourceAddress (MethodSource source, int row, int offset, int range)
{
this.source = source;
this.row = row;
this.source_offset = offset;
this.source_range = range;
if ((source != null) && (row == 0))
throw new InvalidOperationException ();
}
public SourceLocation Location {
get {
if (source.IsDynamic)
return new SourceLocation (
source.Module, source.SourceBuffer, row);
else
return new SourceLocation (
source.SourceMethod, row);
}
}
public MethodSource MethodSource {
get {
return source;
}
}
public int Row {
get {
return row;
}
}
public int Column {
get {
return 0;
}
}
public int SourceRange {
get {
return source_range;
}
}
public int SourceOffset {
get {
return source_offset;
}
}
public string Name {
get {
if (!source.IsDynamic)
return String.Format ("{0}:{1}",
source.SourceFile.FileName, Row);
else
return String.Format ("{0}", Row);
}
}
public override string ToString ()
{
StringBuilder builder = new StringBuilder ();
builder.Append (source.Name);
if (Row > 0) {
builder.Append (" line ");
builder.Append (Row);
}
if (SourceOffset > 0) {
builder.Append (" (");
builder.Append ("offset ");
builder.Append (SourceOffset);
builder.Append (")");
}
if (SourceRange > 0) {
builder.Append (" (");
builder.Append ("range ");
builder.Append (SourceRange);
builder.Append (")");
}
return builder.ToString ();
}
}
}