File: Module.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 (497 lines) | stat: -rw-r--r-- 11,722 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.XPath;

using Mono.Debugger.Languages;
using Mono.Debugger.Backend;

namespace Mono.Debugger
{
	public delegate void ModuleEventHandler (Module module);

	internal interface ILoadHandler
	{
		object UserData {
			get;
		}

		void Remove ();
	}

	internal abstract class SymbolFile : DebuggerMarshalByRefObject, IDisposable
	{
		public abstract Module Module {
			get;
		}

		public abstract bool IsNative {
			get;
		}

		public abstract string FullName {
			get;
		}

		public abstract Language Language {
			get;
		}

		public abstract bool SymbolsLoaded {
			get;
		}

		public abstract bool HasDebuggingInfo {
			get;
		}

		public abstract SourceFile[] Sources {
			get;
		}

		public abstract MethodSource[] GetMethods (SourceFile file);

		// public abstract Method GetMethod (int domain, long handle);

		public abstract MethodSource FindMethod (string name);

		public abstract Symbol SimpleLookup (TargetAddress address, bool exact_match);

		public abstract ISymbolTable SymbolTable {
			get;
		}

		internal abstract StackFrame UnwindStack (StackFrame last_frame,
							  TargetMemoryAccess memory);

		internal abstract void OnModuleChanged ();

		//
		// IDisposable
		//

		private bool disposed = false;

		protected virtual void DoDispose ()
		{
			Module.UnLoadModule ();
		}

		private void Dispose (bool disposing)
		{
			// Check to see if Dispose has already been called.
			lock (this) {
				if (disposed)
					return;

				disposed = true;
			}

			// If this is a call to Dispose, dispose all managed resources.
			if (disposing)
				DoDispose ();
		}

		public void Dispose ()
		{
			Dispose (true);
			// Take yourself off the Finalization queue
			GC.SuppressFinalize (this);
		}

		~SymbolFile ()
		{
			Dispose (false);
		}
	}

	public abstract class ModuleBase : DebuggerMarshalByRefObject
	{
		protected string name;
		protected int id;
		private static int next_id;

		protected ModuleBase (string name)
		{
			this.name = name;
			this.id = ++next_id;
		}

		public int ID {
			get { return id; }
		}

		public string Name {
			get { return name; }
		}

		public abstract bool HideFromUser {
			get; set;
		}

		public abstract bool LoadSymbols {
			get; set;
		}

		public abstract bool StepInto {
			get; set;
		}

		internal void GetSessionData (XmlElement root)
		{
			XmlElement element = root.OwnerDocument.CreateElement (GetType ().Name);
			root.AppendChild (element);

			if (this is Module)
				element.SetAttribute ("group", ((Module) this).ModuleGroup.Name);
			element.SetAttribute ("name", Name);

			XmlElement hide = root.OwnerDocument.CreateElement ("HideFromUser");
			hide.InnerText = HideFromUser ? "true" : "false";
			element.AppendChild (hide);

			XmlElement step = root.OwnerDocument.CreateElement ("StepInto");
			step.InnerText = StepInto ? "true" : "false";
			element.AppendChild (step);

			XmlElement load = root.OwnerDocument.CreateElement ("LoadSymbols");
			load.InnerText = LoadSymbols ? "true" : "false";
			element.AppendChild (load);
		}

		internal void SetSessionData (XPathNodeIterator iter)
		{
			XPathNodeIterator children = iter.Current.SelectChildren (XPathNodeType.Element);
			while (children.MoveNext ()) {
				if (children.Current.Name == "HideFromUser")
					HideFromUser = Boolean.Parse (children.Current.Value);
				else if (children.Current.Name == "LoadSymbols")
					LoadSymbols = Boolean.Parse (children.Current.Value);
				else if (children.Current.Name == "StepInto")
					StepInto = Boolean.Parse (children.Current.Value);
				else
					throw new InternalError ();
			}
		}

		protected virtual string MyToString ()
		{
			return "";
		}

		public override string ToString ()
		{
			return String.Format ("{0} ({1}:{2}:{3}:{4}{5})", GetType (), name,
					      HideFromUser ? "hide" : "nohide",
					      LoadSymbols ? "load" : "noload",
					      StepInto ? "step" : "nostep", MyToString ());
		}
	}

	public class ModuleGroup : ModuleBase
	{
		string regexp;
		bool hide_from_user;
		bool load_symbols;
		bool step_into;

		public string Regexp {
			get { return regexp; }
			set { regexp = value; }
		}

		public override bool HideFromUser {
			get { return hide_from_user; }
			set { hide_from_user = value; }
		}

		public override bool LoadSymbols {
			get { return load_symbols; }
			set { load_symbols = value; }
		}

		public override bool StepInto {
			get { return step_into; }
			set { step_into = value; }
		}

		internal ModuleGroup (string name)
			: this (name, false, false, false)
		{
		}

		internal ModuleGroup (string name, bool hide_from_user, bool load_symbols,
				      bool step_into)
			: base (name)
		{
			this.hide_from_user = hide_from_user;
			this.load_symbols = load_symbols;
			this.step_into = step_into;
		}
	}

	// <summary>
	//   A module is either a shared library (containing unmanaged code) or a dll
	//   (containing managed code).
	//
	//   A module maintains all the breakpoints and controls whether to enter methods
	//   while single-stepping.
	// </summary>
	public sealed class Module : ModuleBase
	{
		ModuleGroup group;
		[NonSerialized]
		SymbolFile symfile;
		bool has_hide_from_user, hide_from_user;
		bool has_load_symbols, load_symbols;
		bool has_step_into, step_into;

		internal Module (ModuleGroup group, string name, SymbolFile symfile)
			: base (name)
		{
			this.group = group;
			this.symfile = symfile;
		}

		internal void LoadModule (SymbolFile symfile)
		{
			this.symfile = symfile;
			OnModuleChanged ();
			if (ModuleLoadedEvent != null)
				ModuleLoadedEvent (this);
		}

		internal void UnLoadModule ()
		{
			if (ModuleUnloadedEvent != null)
				ModuleUnloadedEvent (this);
			this.symfile = null;
		}

		public event ModuleEventHandler ModuleLoadedEvent;
		public event ModuleEventHandler ModuleUnloadedEvent;

		public Language Language {
			get { return SymbolFile.Language; }
		}

		internal SymbolFile SymbolFile {
			get {
				if (symfile != null)
					return symfile;

				throw new InvalidOperationException ();
			}
		}

		public ModuleGroup ModuleGroup {
			get { return group; }
		}

		// <summary>
		//   The full pathname where this module was loaded from.
		//   May only be used while @IsLoaded is true.
		//
		//   Throws:
		//     InvalidOperationException - if IsLoaded was false.
		// </summary>
		public string FullName {
			get { return SymbolFile.FullName; }
		}

		// <summary>
		//   Whether the module is currently loaded in memory.
		// </summary>
		public bool IsLoaded {
			get { return symfile != null; }
		}

		// <summary>
		//   Whether the module's symbol tables are currently loaded.
		// </summary>
		public bool SymbolsLoaded {
			get { return IsLoaded && SymbolFile.SymbolsLoaded; }
		}

		// <summary>
		//   Whether to load the module's symbol tables when the module is loaded
		//   into memory.  You may set this to false to completely "ignore" a
		//   module the next time you restart the target; the debugger will
		//   neither step into any of the module's methods nor will you get any
		//   method names or source locations in a backtrace.
		//
		//   Note that setting this to false does not disable any breakpoints -
		//   the debugger will still stop if it its a breakpoint inside this
		//   module, but you'll see nothing but an address in the backtrace and
		//   you won't see any source code.
		// </summary>
		public override bool LoadSymbols {
			get {
				return has_load_symbols ? load_symbols : group.LoadSymbols;
			}

			set {
				if (has_load_symbols && (load_symbols == value))
					return;

				has_load_symbols = true;
				load_symbols = value;
				OnModuleChanged ();
			}
		}

		// <summary>
		//   Whether to enter this module's methods while single-stepping.
		//   If you set this to false, you will still get full debugging support
		//   if the debugger ever stops in this module, for instance because it
		//   hit a breakpoint or received a signal.
		//
		//   When debugging managed applications, you should set this to false for
		//   `mono' and its shared libraries.  If the application ever crashes
		//   somewhere inside an unmanaged method, you'll get full debugging
		//   information in the backtrace, but the debugger will never enter
		//   unmanaged methods while single-stepping.
		// </summary>
		public override bool StepInto {
			get {
				return has_step_into ? step_into : group.StepInto;
			}

			set {
				if (has_step_into && (step_into == value))
					return;

				has_step_into = true;
				step_into = value;
				OnModuleChanged ();
			}
		}

		public override bool HideFromUser {
			get {
				return has_hide_from_user ? hide_from_user : group.HideFromUser;
			}

			set {
				if (has_hide_from_user && (hide_from_user == value))
					return;

				has_hide_from_user = true;
				hide_from_user = value;
				OnModuleChanged ();
			}
		}

		// <summary>
		//   Returns whether this module has debugging info.
		//   Note that this property is initialized when trying to read the debugging
		//   info for the first time.
		// </summary>
		public bool HasDebuggingInfo {
			get { return SymbolFile.HasDebuggingInfo; }
		}

		protected void OnModuleChanged ()
		{
			if (symfile != null)
				symfile.OnModuleChanged ();
		}

		public SourceFile[] Sources {
			get { return SymbolFile.Sources; }
		}

		public MethodSource[] GetMethods (SourceFile file)
		{
			return SymbolFile.GetMethods (file);
		}

#if FIXME
		public Method GetMethod (int domain, long handle)
		{
			return SymbolFile.GetMethod (domain, handle);
		}
#endif

		// <summary>
		//   Find method @name, which must be a full method name including the
		//   signature (System.DateTime.GetUtcOffset(System.DateTime)).
		// </summary>
		public MethodSource FindMethod (string name)
		{
			if (!SymbolsLoaded)
				return null;

			return SymbolFile.FindMethod (name);
		}

		// <summary>
		//   Find source file @filename.  If @filename is a full pathname, an exact
		//   match is required.  Otherwise, a match from any directory is ok.
		// </summary>
		public SourceFile FindFile (string filename)
		{
			if (!SymbolsLoaded)
				return null;

			if (filename.IndexOf ('/') >= 0) {
				foreach (SourceFile source in Sources) {
					if (source.FileName == filename)
						return source;
				}
			} else {
				filename = Path.GetFileName (filename);
				foreach (SourceFile source in Sources) {
					if (Path.GetFileName (source.FileName).Equals (filename))
						return source;
				}
			}

			return null;
		}

		// <summary>
		//   Find the method containing line @line in @source_file, which must be
		//   the file's full pathname.
		// </summary>
		public SourceLocation FindLocation (string source_file, int line)
		{
			SourceFile file = FindFile (source_file);
			if (file == null)
				return null;

			return file.FindLine (line);
		}

		public Symbol SimpleLookup (TargetAddress address, bool exact_match)
		{
			return SymbolFile.SimpleLookup (address, exact_match);
		}

		// <summary>
		//   Returns the module's ISymbolTable which can be used to find a method
		//   by its address.  May only be used while @SymbolsLoaded is true.
		//
		//   Throws:
		//     InvalidOperationException - if @SymbolsLoaded was false
		// </summary>
		public ISymbolTable SymbolTable {
			get { return SymbolFile.SymbolTable; }
		}

		internal StackFrame UnwindStack (StackFrame last_frame,
						 TargetMemoryAccess memory)
		{
			return SymbolFile.UnwindStack (last_frame, memory);
		}

		protected override string MyToString ()
		{
			return String.Format (":{0}:{1}", IsLoaded, SymbolsLoaded);
		}
	}
}