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
|
//===-- SBModule.cpp --------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBModule.h"
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBSymbolContextList.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/ValueObjectList.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Target.h"
using namespace lldb;
using namespace lldb_private;
SBModule::SBModule () :
m_opaque_sp ()
{
}
SBModule::SBModule (const lldb::ModuleSP& module_sp) :
m_opaque_sp (module_sp)
{
}
SBModule::SBModule(const SBModule &rhs) :
m_opaque_sp (rhs.m_opaque_sp)
{
}
const SBModule &
SBModule::operator = (const SBModule &rhs)
{
if (this != &rhs)
m_opaque_sp = rhs.m_opaque_sp;
return *this;
}
SBModule::~SBModule ()
{
}
bool
SBModule::IsValid () const
{
return m_opaque_sp.get() != NULL;
}
SBFileSpec
SBModule::GetFileSpec () const
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
SBFileSpec file_spec;
if (m_opaque_sp)
file_spec.SetFileSpec(m_opaque_sp->GetFileSpec());
if (log)
{
log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
m_opaque_sp.get(), file_spec.get());
}
return file_spec;
}
lldb::SBFileSpec
SBModule::GetPlatformFileSpec () const
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
SBFileSpec file_spec;
if (m_opaque_sp)
file_spec.SetFileSpec(m_opaque_sp->GetPlatformFileSpec());
if (log)
{
log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
m_opaque_sp.get(), file_spec.get());
}
return file_spec;
}
bool
SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
{
bool result = false;
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (m_opaque_sp)
{
m_opaque_sp->SetPlatformFileSpec(*platform_file);
result = true;
}
if (log)
{
log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i",
m_opaque_sp.get(),
platform_file.get(),
platform_file->GetDirectory().GetCString(),
platform_file->GetDirectory() ? "/" : "",
platform_file->GetFilename().GetCString(),
result);
}
return result;
}
const uint8_t *
SBModule::GetUUIDBytes () const
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
const uint8_t *uuid_bytes = NULL;
if (m_opaque_sp)
uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
if (log)
{
if (uuid_bytes)
{
StreamString s;
m_opaque_sp->GetUUID().Dump (&s);
log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData());
}
else
log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get());
}
return uuid_bytes;
}
const char *
SBModule::GetUUIDString () const
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
static char uuid_string[80];
const char * uuid_c_string = NULL;
if (m_opaque_sp)
uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
if (log)
{
if (uuid_c_string)
{
StreamString s;
m_opaque_sp->GetUUID().Dump (&s);
log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData());
}
else
log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get());
}
return uuid_c_string;
}
bool
SBModule::operator == (const SBModule &rhs) const
{
if (m_opaque_sp)
return m_opaque_sp.get() == rhs.m_opaque_sp.get();
return false;
}
bool
SBModule::operator != (const SBModule &rhs) const
{
if (m_opaque_sp)
return m_opaque_sp.get() != rhs.m_opaque_sp.get();
return false;
}
lldb::ModuleSP &
SBModule::operator *()
{
return m_opaque_sp;
}
lldb_private::Module *
SBModule::operator ->()
{
return m_opaque_sp.get();
}
const lldb_private::Module *
SBModule::operator ->() const
{
return m_opaque_sp.get();
}
lldb_private::Module *
SBModule::get()
{
return m_opaque_sp.get();
}
const lldb_private::Module *
SBModule::get() const
{
return m_opaque_sp.get();
}
const lldb::ModuleSP &
SBModule::get_sp() const
{
return m_opaque_sp;
}
void
SBModule::SetModule (const lldb::ModuleSP& module_sp)
{
m_opaque_sp = module_sp;
}
SBAddress
SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
{
lldb::SBAddress sb_addr;
if (m_opaque_sp)
{
Address addr;
if (m_opaque_sp->ResolveFileAddress (vm_addr, addr))
sb_addr.ref() = addr;
}
return sb_addr;
}
SBSymbolContext
SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
{
SBSymbolContext sb_sc;
if (m_opaque_sp && addr.IsValid())
m_opaque_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
return sb_sc;
}
bool
SBModule::GetDescription (SBStream &description)
{
Stream &strm = description.ref();
if (m_opaque_sp)
{
m_opaque_sp->GetDescription (&strm);
}
else
strm.PutCString ("No value");
return true;
}
size_t
SBModule::GetNumSymbols ()
{
if (m_opaque_sp)
{
ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
if (obj_file)
{
Symtab *symtab = obj_file->GetSymtab();
if (symtab)
return symtab->GetNumSymbols();
}
}
return 0;
}
SBSymbol
SBModule::GetSymbolAtIndex (size_t idx)
{
SBSymbol sb_symbol;
if (m_opaque_sp)
{
ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
if (obj_file)
{
Symtab *symtab = obj_file->GetSymtab();
if (symtab)
sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
}
}
return sb_symbol;
}
size_t
SBModule::GetNumSections ()
{
if (m_opaque_sp)
{
ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
if (obj_file)
{
SectionList *section_list = obj_file->GetSectionList ();
if (section_list)
return section_list->GetSize();
}
}
return 0;
}
SBSection
SBModule::GetSectionAtIndex (size_t idx)
{
SBSection sb_section;
if (m_opaque_sp)
{
ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
if (obj_file)
{
SectionList *section_list = obj_file->GetSectionList ();
if (section_list)
sb_section.SetSection(section_list->GetSectionAtIndex (idx).get());
}
}
return sb_section;
}
uint32_t
SBModule::FindFunctions (const char *name,
uint32_t name_type_mask,
bool append,
lldb::SBSymbolContextList& sc_list)
{
if (!append)
sc_list.Clear();
if (m_opaque_sp)
{
const bool symbols_ok = true;
return m_opaque_sp->FindFunctions (ConstString(name),
NULL,
name_type_mask,
symbols_ok,
append,
*sc_list);
}
return 0;
}
SBValueList
SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
{
SBValueList sb_value_list;
if (m_opaque_sp)
{
VariableList variable_list;
const uint32_t match_count = m_opaque_sp->FindGlobalVariables (ConstString (name),
NULL,
false,
max_matches,
variable_list);
if (match_count > 0)
{
ValueObjectList &value_object_list = sb_value_list.ref();
for (uint32_t i=0; i<match_count; ++i)
{
lldb::ValueObjectSP valobj_sp;
if (target.IsValid())
valobj_sp = ValueObjectVariable::Create (target.get(), variable_list.GetVariableAtIndex(i));
else
valobj_sp = ValueObjectVariable::Create (NULL, variable_list.GetVariableAtIndex(i));
if (valobj_sp)
value_object_list.Append(valobj_sp);
}
}
}
return sb_value_list;
}
lldb::SBType
SBModule::FindFirstType (const char* name_cstr)
{
SBType sb_type;
if (IsValid())
{
SymbolContext sc;
TypeList type_list;
uint32_t num_matches = 0;
ConstString name(name_cstr);
num_matches = m_opaque_sp->FindTypes(sc,
name,
NULL,
false,
1,
type_list);
if (num_matches)
sb_type = lldb::SBType(type_list.GetTypeAtIndex(0));
}
return sb_type;
}
lldb::SBTypeList
SBModule::FindTypes (const char* type)
{
SBTypeList retval;
if (IsValid())
{
SymbolContext sc;
TypeList type_list;
uint32_t num_matches = 0;
ConstString name(type);
num_matches = m_opaque_sp->FindTypes(sc,
name,
NULL,
false,
UINT32_MAX,
type_list);
for (size_t idx = 0; idx < num_matches; idx++)
{
TypeSP type_sp (type_list.GetTypeAtIndex(idx));
if (type_sp)
retval.Append(SBType(type_sp));
}
}
return retval;
}
SBSection
SBModule::FindSection (const char *sect_name)
{
SBSection sb_section;
if (IsValid())
{
ObjectFile *objfile = m_opaque_sp->GetObjectFile();
if (objfile)
{
SectionList *section_list = objfile->GetSectionList();
if (section_list)
{
ConstString const_sect_name(sect_name);
SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
if (section_sp)
{
sb_section.SetSection(section_sp.get());
}
}
}
}
return sb_section;
}
|