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
|
//===-- SymbolVendor.mm -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/SymbolVendor.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolFile.h"
using namespace lldb;
using namespace lldb_private;
//----------------------------------------------------------------------
// FindPlugin
//
// Platforms can register a callback to use when creating symbol
// vendors to allow for complex debug information file setups, and to
// also allow for finding separate debug information files.
//----------------------------------------------------------------------
SymbolVendor*
SymbolVendor::FindPlugin (Module* module)
{
std::auto_ptr<SymbolVendor> instance_ap;
//----------------------------------------------------------------------
// We currently only have one debug symbol parser...
//----------------------------------------------------------------------
SymbolVendorCreateInstance create_callback;
for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolVendorCreateCallbackAtIndex(idx)) != NULL; ++idx)
{
instance_ap.reset(create_callback(module));
if (instance_ap.get())
{
// TODO: make sure this symbol vendor is what we want. We
// currently are just returning the first one we find, but
// we may want to call this function only when we have our
// main executable module and then give all symbol vendor
// plug-ins a chance to compete for who wins.
return instance_ap.release();
}
}
// The default implementation just tries to create debug information using the
// file representation for the module.
instance_ap.reset(new SymbolVendor(module));
if (instance_ap.get())
instance_ap->AddSymbolFileRepresendation(module->GetObjectFile());
return instance_ap.release();
}
//----------------------------------------------------------------------
// SymbolVendor constructor
//----------------------------------------------------------------------
SymbolVendor::SymbolVendor(Module *module) :
ModuleChild(module),
m_mutex (Mutex::eMutexTypeRecursive),
m_type_list(),
m_compile_units(),
m_sym_file_ap()
{
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
SymbolVendor::~SymbolVendor()
{
}
//----------------------------------------------------------------------
// Add a represantion given an object file.
//----------------------------------------------------------------------
void
SymbolVendor::AddSymbolFileRepresendation(ObjectFile *obj_file)
{
Mutex::Locker locker(m_mutex);
if (obj_file != NULL)
m_sym_file_ap.reset(SymbolFile::FindPlugin(obj_file));
}
bool
SymbolVendor::SetCompileUnitAtIndex (CompUnitSP& cu, uint32_t idx)
{
Mutex::Locker locker(m_mutex);
const uint32_t num_compile_units = GetNumCompileUnits();
if (idx < num_compile_units)
{
// Fire off an assertion if this compile unit already exists for now.
// The partial parsing should take care of only setting the compile
// unit once, so if this assertion fails, we need to make sure that
// we don't have a race condition, or have a second parse of the same
// compile unit.
assert(m_compile_units[idx].get() == NULL);
m_compile_units[idx] = cu;
return true;
}
return false;
}
uint32_t
SymbolVendor::GetNumCompileUnits()
{
Mutex::Locker locker(m_mutex);
if (m_compile_units.empty())
{
if (m_sym_file_ap.get())
{
// Resize our array of compile unit shared pointers -- which will
// each remain NULL until someone asks for the actual compile unit
// information. When this happens, the symbol file will be asked
// to parse this compile unit information.
m_compile_units.resize(m_sym_file_ap->GetNumCompileUnits());
}
}
return m_compile_units.size();
}
size_t
SymbolVendor::ParseCompileUnitFunctions (const SymbolContext &sc)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ParseCompileUnitFunctions(sc);
return 0;
}
bool
SymbolVendor::ParseCompileUnitLineTable (const SymbolContext &sc)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ParseCompileUnitLineTable(sc);
return false;
}
bool
SymbolVendor::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ParseCompileUnitSupportFiles(sc, support_files);
return false;
}
size_t
SymbolVendor::ParseFunctionBlocks (const SymbolContext &sc)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ParseFunctionBlocks(sc);
return 0;
}
size_t
SymbolVendor::ParseTypes (const SymbolContext &sc)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ParseTypes(sc);
return 0;
}
size_t
SymbolVendor::ParseVariablesForContext (const SymbolContext& sc)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ParseVariablesForContext(sc);
return 0;
}
Type*
SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ResolveTypeUID(type_uid);
return NULL;
}
uint32_t
SymbolVendor::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ResolveSymbolContext(so_addr, resolve_scope, sc);
return 0;
}
uint32_t
SymbolVendor::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
return 0;
}
uint32_t
SymbolVendor::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->FindGlobalVariables(name, append, max_matches, variables);
return 0;
}
uint32_t
SymbolVendor::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->FindGlobalVariables(regex, append, max_matches, variables);
return 0;
}
uint32_t
SymbolVendor::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->FindFunctions(name, name_type_mask, append, sc_list);
return 0;
}
uint32_t
SymbolVendor::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->FindFunctions(regex, append, sc_list);
return 0;
}
uint32_t
SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
{
Mutex::Locker locker(m_mutex);
if (m_sym_file_ap.get())
return m_sym_file_ap->FindTypes(sc, name, append, max_matches, types);
if (!append)
types.Clear();
return 0;
}
ClangNamespaceDecl
SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name)
{
Mutex::Locker locker(m_mutex);
ClangNamespaceDecl namespace_decl;
if (m_sym_file_ap.get())
namespace_decl = m_sym_file_ap->FindNamespace (sc, name);
return namespace_decl;
}
void
SymbolVendor::Dump(Stream *s)
{
Mutex::Locker locker(m_mutex);
bool show_context = false;
s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
s->Indent();
s->PutCString("SymbolVendor");
if (m_sym_file_ap.get())
{
ObjectFile *objfile = m_sym_file_ap->GetObjectFile();
if (objfile)
{
const FileSpec &objfile_file_spec = objfile->GetFileSpec();
if (objfile_file_spec)
{
s->PutCString(" (");
objfile_file_spec.Dump(s);
s->PutChar(')');
}
}
}
s->EOL();
s->IndentMore();
m_type_list.Dump(s, show_context);
CompileUnitConstIter cu_pos, cu_end;
cu_end = m_compile_units.end();
for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos)
{
// We currently only dump the compile units that have been parsed
if (cu_pos->get())
(*cu_pos)->Dump(s, show_context);
}
s->IndentLess();
}
CompUnitSP
SymbolVendor::GetCompileUnitAtIndex(uint32_t idx)
{
Mutex::Locker locker(m_mutex);
CompUnitSP cu_sp;
const uint32_t num_compile_units = GetNumCompileUnits();
if (idx < num_compile_units)
{
cu_sp = m_compile_units[idx];
if (cu_sp.get() == NULL)
{
m_compile_units[idx] = m_sym_file_ap->ParseCompileUnitAtIndex(idx);
cu_sp = m_compile_units[idx];
}
}
return cu_sp;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
const char *
SymbolVendor::GetPluginName()
{
return "SymbolVendor";
}
const char *
SymbolVendor::GetShortPluginName()
{
return "vendor-default";
}
uint32_t
SymbolVendor::GetPluginVersion()
{
return 1;
}
|