This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
BfdContainer.cs
169 lines (134 loc) · 3.56 KB
/
BfdContainer.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
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
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using Mono.Debugger;
using Mono.Debugger.Backends;
namespace Mono.Debugger.Architecture
{
internal class BfdContainer : ISerializable, IDisposable
{
Hashtable bfd_hash;
Hashtable module_hash;
DebuggerBackend backend;
public BfdContainer (DebuggerBackend backend)
{
this.backend = backend;
this.bfd_hash = new Hashtable ();
this.module_hash = new Hashtable ();
backend.TargetExited += new TargetExitedHandler (target_exited_handler);
}
public DebuggerBackend DebuggerBackend {
get { return backend; }
}
public Module this [string filename] {
get {
check_disposed ();
return (Module) module_hash [filename];
}
}
public Bfd AddFile (ITargetMemoryAccess memory, string filename, bool step_into)
{
return AddFile (memory, filename, step_into, TargetAddress.Null, null);
}
public Bfd AddFile (ITargetMemoryAccess memory, string filename, bool step_into,
TargetAddress base_address, Bfd core_bfd)
{
bool new_module = false;
check_disposed ();
if (bfd_hash.Contains (filename))
return (Bfd) bfd_hash [filename];
Module module = (Module) module_hash [filename];
if (module == null) {
module = backend.ModuleManager.CreateModule (filename);
module.LoadSymbols = step_into;
module.StepInto = step_into;
module_hash.Add (filename, module);
new_module = true;
}
Bfd bfd = new Bfd (this, memory, filename, false, module, base_address);
bfd.CoreFileBfd = core_bfd;
bfd_hash.Add (filename, bfd);
return bfd;
}
public TargetAddress LookupSymbol (string name)
{
foreach (Module module in module_hash.Values) {
if (!module.IsLoaded)
continue;
TargetAddress symbol = module.SimpleLookup (name);
if (!symbol.IsNull)
return symbol;
}
return TargetAddress.Null;
}
public void CloseBfd (Bfd bfd)
{
if (bfd == null)
return;
bfd_hash.Remove (bfd.FileName);
bfd.Dispose ();
}
void target_exited_handler ()
{
foreach (Bfd bfd in bfd_hash.Values)
bfd.Dispose ();
bfd_hash = new Hashtable ();
foreach (Module module in module_hash.Values)
module.ModuleData = null;
}
//
// ISerializable
//
public void GetObjectData (SerializationInfo info, StreamingContext context)
{
info.AddValue ("modules", module_hash.Values, typeof (ICollection));
}
private BfdContainer (SerializationInfo info, StreamingContext context)
{
backend = context.Context as DebuggerBackend;
if (backend == null)
throw new InvalidOperationException ();
ICollection modules = (ICollection) info.GetValue ("modules", typeof (ICollection));
bfd_hash = new Hashtable ();
module_hash = new Hashtable ();
backend.TargetExited += new TargetExitedHandler (target_exited_handler);
foreach (BfdModule module in module_hash) {
module_hash.Add (module.FullName, module);
}
}
//
// IDisposable
//
private bool disposed = false;
private void check_disposed ()
{
if (disposed)
throw new ObjectDisposedException ("BfdContainer");
}
protected virtual void Dispose (bool disposing)
{
if (!this.disposed) {
if (disposing) {
if (bfd_hash != null) {
foreach (Bfd bfd in bfd_hash.Values)
bfd.Dispose ();
}
}
this.disposed = true;
}
}
public void Dispose ()
{
Dispose (true);
// Take yourself off the Finalization queue
GC.SuppressFinalize (this);
}
~BfdContainer ()
{
Dispose (false);
}
}
}