|
1 |
| -// FieldVariable.cs |
2 |
| -// |
3 |
| -// Author: |
4 |
| -// Lluis Sanchez Gual <[email protected]> |
5 |
| -// |
6 |
| -// Copyright (c) 2008 Novell, Inc (http://www.novell.com) |
7 |
| -// |
8 |
| -// Permission is hereby granted, free of charge, to any person obtaining a copy |
9 |
| -// of this software and associated documentation files (the "Software"), to deal |
10 |
| -// in the Software without restriction, including without limitation the rights |
11 |
| -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12 |
| -// copies of the Software, and to permit persons to whom the Software is |
13 |
| -// furnished to do so, subject to the following conditions: |
14 |
| -// |
15 |
| -// The above copyright notice and this permission notice shall be included in |
16 |
| -// all copies or substantial portions of the Software. |
17 |
| -// |
18 |
| -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 |
| -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 |
| -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21 |
| -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22 |
| -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 |
| -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24 |
| -// THE SOFTWARE. |
25 |
| -// |
26 |
| -// |
27 |
| - |
28 |
| -using System.Reflection; |
29 |
| -using System.Runtime.InteropServices; |
30 |
| -using Microsoft.Samples.Debugging.CorDebug; |
31 |
| -using Mono.Debugging.Client; |
32 |
| -using Mono.Debugging.Evaluation; |
33 |
| - |
34 |
| -namespace Mono.Debugging.Win32 |
35 |
| -{ |
36 |
| - public class FieldReference: ValueReference |
37 |
| - { |
38 |
| - readonly CorType type; |
39 |
| - readonly FieldInfo field; |
40 |
| - readonly CorValRef thisobj; |
41 |
| - readonly CorValRef.ValueLoader loader; |
42 |
| - readonly ObjectValueFlags flags; |
43 |
| - readonly string vname; |
44 |
| - |
45 |
| - public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field, string vname, ObjectValueFlags vflags) : base (ctx) |
46 |
| - { |
47 |
| - this.thisobj = thisobj; |
48 |
| - this.type = type; |
49 |
| - this.field = field; |
50 |
| - this.vname = vname; |
51 |
| - if (field.IsStatic) |
52 |
| - this.thisobj = null; |
53 |
| - |
54 |
| - flags = vflags | GetFlags (field); |
55 |
| - |
56 |
| - loader = delegate { |
57 |
| - return ((CorValRef)Value).Val; |
58 |
| - }; |
59 |
| - } |
60 |
| - |
61 |
| - public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field) |
62 |
| - : this (ctx, thisobj, type, field, null, ObjectValueFlags.Field) |
63 |
| - { |
64 |
| - } |
65 |
| - |
66 |
| - public override object Type { |
67 |
| - get { |
68 |
| - return ((CorValRef)Value).Val.ExactType; |
69 |
| - } |
70 |
| - } |
71 |
| - |
72 |
| - public override object DeclaringType { |
73 |
| - get { |
74 |
| - return type; |
75 |
| - } |
76 |
| - } |
77 |
| - |
78 |
| - public override object ObjectValue { |
79 |
| - get { |
80 |
| - if (field.IsLiteral && field.IsStatic) |
81 |
| - return field.GetValue (null); |
82 |
| - return base.ObjectValue; |
83 |
| - } |
84 |
| - } |
85 |
| - |
86 |
| - public override object Value { |
87 |
| - get { |
88 |
| - var ctx = (CorEvaluationContext) Context; |
89 |
| - CorValue val; |
90 |
| - if (thisobj != null && !field.IsStatic) { |
91 |
| - CorObjectValue cval; |
92 |
| - val = CorObjectAdaptor.GetRealObject (ctx, thisobj); |
93 |
| - if (val is CorObjectValue) { |
94 |
| - cval = (CorObjectValue)val; |
95 |
| - val = cval.GetFieldValue (type.Class, field.MetadataToken); |
96 |
| - return new CorValRef (val, loader); |
97 |
| - } |
98 |
| - if (val is CorReferenceValue) { |
99 |
| - CorReferenceValue rval = (CorReferenceValue)val; |
100 |
| - return new CorValRef (rval, loader); |
101 |
| - } |
102 |
| - } |
103 |
| - |
104 |
| - if (field.IsLiteral && field.IsStatic) { |
105 |
| - object oval = field.GetValue (null); |
106 |
| - CorObjectAdaptor ad = ctx.Adapter; |
107 |
| - // When getting enum members, convert the integer value to an enum value |
108 |
| - if (ad.IsEnum (ctx, type)) |
109 |
| - return ad.CreateEnum (ctx, type, Context.Adapter.CreateValue (ctx, oval)); |
110 |
| - |
111 |
| - return Context.Adapter.CreateValue (ctx, oval); |
112 |
| - } |
113 |
| - try { |
114 |
| - val = type.GetStaticFieldValue (field.MetadataToken, ctx.Frame); |
115 |
| - return new CorValRef (val, loader); |
116 |
| - } catch (COMException e) { |
117 |
| - if (e.ToHResult<HResult> () == HResult.CORDBG_E_STATIC_VAR_NOT_AVAILABLE) |
118 |
| - throw new EvaluatorException("A static variable is not available because it has not been initialized yet"); |
119 |
| - throw; |
120 |
| - } |
121 |
| - } |
122 |
| - set { |
123 |
| - ((CorValRef)Value).SetValue (Context, (CorValRef) value); |
124 |
| - if (thisobj != null) { |
125 |
| - CorObjectValue cob = CorObjectAdaptor.GetRealObject (Context, thisobj) as CorObjectValue; |
126 |
| - if (cob != null && cob.IsValueClass) |
127 |
| - thisobj.Invalidate (); // Required to make sure that thisobj returns an up-to-date value object |
128 |
| - } |
129 |
| - } |
130 |
| - } |
131 |
| - |
132 |
| - public override string Name { |
133 |
| - get { |
134 |
| - return vname ?? field.Name; |
135 |
| - } |
136 |
| - } |
137 |
| - |
138 |
| - public override ObjectValueFlags Flags { |
139 |
| - get { |
140 |
| - return flags; |
141 |
| - } |
142 |
| - } |
143 |
| - |
144 |
| - internal static ObjectValueFlags GetFlags (FieldInfo field) |
145 |
| - { |
146 |
| - ObjectValueFlags flags = ObjectValueFlags.Field; |
147 |
| - |
148 |
| - if (field.IsStatic) |
149 |
| - flags |= ObjectValueFlags.Global; |
150 |
| - |
151 |
| - if (field.IsFamilyOrAssembly) |
152 |
| - flags |= ObjectValueFlags.InternalProtected; |
153 |
| - else if (field.IsFamilyAndAssembly) |
154 |
| - flags |= ObjectValueFlags.Internal; |
155 |
| - else if (field.IsFamily) |
156 |
| - flags |= ObjectValueFlags.Protected; |
157 |
| - else if (field.IsPublic) |
158 |
| - flags |= ObjectValueFlags.Public; |
159 |
| - else |
160 |
| - flags |= ObjectValueFlags.Private; |
161 |
| - |
162 |
| - if (field.IsLiteral) |
163 |
| - flags |= ObjectValueFlags.ReadOnly; |
164 |
| - |
165 |
| - return flags; |
166 |
| - } |
167 |
| - } |
168 |
| -} |
| 1 | +// FieldVariable.cs |
| 2 | +// |
| 3 | +// Author: |
| 4 | +// Lluis Sanchez Gual <[email protected]> |
| 5 | +// |
| 6 | +// Copyright (c) 2008 Novell, Inc (http://www.novell.com) |
| 7 | +// |
| 8 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | +// of this software and associated documentation files (the "Software"), to deal |
| 10 | +// in the Software without restriction, including without limitation the rights |
| 11 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | +// copies of the Software, and to permit persons to whom the Software is |
| 13 | +// furnished to do so, subject to the following conditions: |
| 14 | +// |
| 15 | +// The above copyright notice and this permission notice shall be included in |
| 16 | +// all copies or substantial portions of the Software. |
| 17 | +// |
| 18 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | +// THE SOFTWARE. |
| 25 | +// |
| 26 | +// |
| 27 | + |
| 28 | +using System.Reflection; |
| 29 | +using System.Runtime.InteropServices; |
| 30 | +using Microsoft.Samples.Debugging.CorDebug; |
| 31 | +using Mono.Debugging.Client; |
| 32 | +using Mono.Debugging.Evaluation; |
| 33 | + |
| 34 | +namespace Mono.Debugging.Win32 |
| 35 | +{ |
| 36 | + public class FieldReference: ValueReference |
| 37 | + { |
| 38 | + readonly CorType type; |
| 39 | + readonly FieldInfo field; |
| 40 | + readonly CorValRef thisobj; |
| 41 | + readonly CorValRef.ValueLoader loader; |
| 42 | + readonly ObjectValueFlags flags; |
| 43 | + readonly string vname; |
| 44 | + |
| 45 | + public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field, string vname, ObjectValueFlags vflags) : base (ctx) |
| 46 | + { |
| 47 | + this.thisobj = thisobj; |
| 48 | + this.type = type; |
| 49 | + this.field = field; |
| 50 | + this.vname = vname; |
| 51 | + if (field.IsStatic) |
| 52 | + this.thisobj = null; |
| 53 | + |
| 54 | + flags = vflags | GetFlags (field); |
| 55 | + |
| 56 | + loader = delegate { |
| 57 | + return ((CorValRef)Value).Val; |
| 58 | + }; |
| 59 | + } |
| 60 | + |
| 61 | + public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field) |
| 62 | + : this (ctx, thisobj, type, field, null, ObjectValueFlags.Field) |
| 63 | + { |
| 64 | + } |
| 65 | + |
| 66 | + public override object Type { |
| 67 | + get { |
| 68 | + return ((CorValRef)Value).Val.ExactType; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + public override object DeclaringType { |
| 73 | + get { |
| 74 | + return type; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + public override object ObjectValue { |
| 79 | + get { |
| 80 | + if (field.IsLiteral && field.IsStatic) |
| 81 | + return field.GetValue (null); |
| 82 | + return base.ObjectValue; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + public override object Value { |
| 87 | + get { |
| 88 | + var ctx = (CorEvaluationContext) Context; |
| 89 | + CorValue val; |
| 90 | + if (thisobj != null && !field.IsStatic) { |
| 91 | + CorObjectValue cval; |
| 92 | + val = CorObjectAdaptor.GetRealObject (ctx, thisobj); |
| 93 | + if (val is CorObjectValue) { |
| 94 | + cval = (CorObjectValue)val; |
| 95 | + val = cval.GetFieldValue (type.Class, field.MetadataToken); |
| 96 | + return new CorValRef (val, loader); |
| 97 | + } |
| 98 | + if (val is CorReferenceValue) { |
| 99 | + CorReferenceValue rval = (CorReferenceValue)val; |
| 100 | + return new CorValRef (rval, loader); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + if (field.IsLiteral && field.IsStatic) { |
| 105 | + object oval = field.GetValue (null); |
| 106 | + CorObjectAdaptor ad = ctx.Adapter; |
| 107 | + // When getting enum members, convert the integer value to an enum value |
| 108 | + if (ad.IsEnum (ctx, type)) |
| 109 | + return ad.CreateEnum (ctx, type, Context.Adapter.CreateValue (ctx, oval)); |
| 110 | + |
| 111 | + return Context.Adapter.CreateValue (ctx, oval); |
| 112 | + } |
| 113 | + try { |
| 114 | + val = type.GetStaticFieldValue (field.MetadataToken, ctx.Frame); |
| 115 | + return new CorValRef (val, loader); |
| 116 | + } catch (COMException e) { |
| 117 | + if (e.ToHResult<HResult> () == HResult.CORDBG_E_STATIC_VAR_NOT_AVAILABLE) |
| 118 | + throw new EvaluatorException("A static variable is not available because it has not been initialized yet"); |
| 119 | + throw; |
| 120 | + } |
| 121 | + } |
| 122 | + set { |
| 123 | + ((CorValRef)Value).SetValue (Context, (CorValRef) value); |
| 124 | + if (thisobj != null) { |
| 125 | + CorObjectValue cob = CorObjectAdaptor.GetRealObject (Context, thisobj) as CorObjectValue; |
| 126 | + if (cob != null && cob.IsValueClass) |
| 127 | + thisobj.Invalidate (); // Required to make sure that thisobj returns an up-to-date value object |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + public override string Name { |
| 133 | + get { |
| 134 | + return vname ?? field.Name; |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + public override ObjectValueFlags Flags { |
| 139 | + get { |
| 140 | + return flags; |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + internal static ObjectValueFlags GetFlags (FieldInfo field) |
| 145 | + { |
| 146 | + ObjectValueFlags flags = ObjectValueFlags.Field; |
| 147 | + |
| 148 | + if (field.IsStatic) |
| 149 | + flags |= ObjectValueFlags.Global; |
| 150 | + |
| 151 | + if (field.IsFamilyOrAssembly) |
| 152 | + flags |= ObjectValueFlags.InternalProtected; |
| 153 | + else if (field.IsFamilyAndAssembly) |
| 154 | + flags |= ObjectValueFlags.Internal; |
| 155 | + else if (field.IsFamily) |
| 156 | + flags |= ObjectValueFlags.Protected; |
| 157 | + else if (field.IsPublic) |
| 158 | + flags |= ObjectValueFlags.Public; |
| 159 | + else |
| 160 | + flags |= ObjectValueFlags.Private; |
| 161 | + |
| 162 | + if (field.IsLiteral) |
| 163 | + flags |= ObjectValueFlags.ReadOnly; |
| 164 | + |
| 165 | + return flags; |
| 166 | + } |
| 167 | + } |
| 168 | +} |
0 commit comments