blob: c8543d4de298c63766752ea4b7d37c76b32cce40 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBModule.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/API/SBModule.h"
Greg Clayton09960032010-09-10 18:31:35 +000011#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBFileSpec.h"
Greg Clayton226cce22013-07-08 22:22:41 +000013#include "lldb/API/SBModuleSpec.h"
Greg Claytonc9660542012-02-05 02:38:54 +000014#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000015#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000016#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/Module.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000018#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000019#include "lldb/Core/Section.h"
Greg Clayton38adbbb2010-10-31 19:57:43 +000020#include "lldb/Core/StreamString.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000021#include "lldb/Core/ValueObjectList.h"
22#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton1f746072012-08-29 21:13:06 +000023#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Symbol/Symtab.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000026#include "lldb/Symbol/VariableList.h"
27#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
29using namespace lldb;
Caroline Ticeceb6b132010-10-26 03:11:13 +000030using namespace lldb_private;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
32
33SBModule::SBModule () :
Greg Clayton66111032010-06-23 01:19:29 +000034 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035{
36}
37
38SBModule::SBModule (const lldb::ModuleSP& module_sp) :
Greg Clayton66111032010-06-23 01:19:29 +000039 m_opaque_sp (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040{
41}
42
Greg Clayton226cce22013-07-08 22:22:41 +000043SBModule::SBModule(const SBModuleSpec &module_spec) :
44 m_opaque_sp ()
45{
46 ModuleSP module_sp;
47 Error error = ModuleList::GetSharedModule (*module_spec.m_opaque_ap,
48 module_sp,
49 NULL,
50 NULL,
51 NULL);
52 if (module_sp)
53 SetSP(module_sp);
54}
55
Greg Claytonefabb122010-11-05 23:17:00 +000056SBModule::SBModule(const SBModule &rhs) :
57 m_opaque_sp (rhs.m_opaque_sp)
58{
59}
60
Greg Claytonc9660542012-02-05 02:38:54 +000061SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) :
62 m_opaque_sp ()
63{
64 ProcessSP process_sp (process.GetSP());
65 if (process_sp)
Greg Claytonc859e2d2012-02-13 23:10:39 +000066 {
Greg Clayton39f7ee82013-02-01 21:38:35 +000067 m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr);
68 if (m_opaque_sp)
69 {
70 Target &target = process_sp->GetTarget();
71 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +000072 m_opaque_sp->SetLoadAddress(target, 0, true, changed);
Greg Clayton39f7ee82013-02-01 21:38:35 +000073 target.GetImages().Append(m_opaque_sp);
74 }
Greg Claytonc859e2d2012-02-13 23:10:39 +000075 }
Greg Claytonc9660542012-02-05 02:38:54 +000076}
77
Greg Claytonefabb122010-11-05 23:17:00 +000078const SBModule &
79SBModule::operator = (const SBModule &rhs)
80{
81 if (this != &rhs)
82 m_opaque_sp = rhs.m_opaque_sp;
83 return *this;
84}
85
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086SBModule::~SBModule ()
87{
88}
89
90bool
91SBModule::IsValid () const
92{
Greg Clayton66111032010-06-23 01:19:29 +000093 return m_opaque_sp.get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094}
95
Jim Ingham5d3bca42011-12-19 20:39:44 +000096void
97SBModule::Clear()
98{
99 m_opaque_sp.reset();
100}
101
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102SBFileSpec
103SBModule::GetFileSpec () const
104{
Greg Clayton5160ce52013-03-27 23:08:40 +0000105 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000106
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107 SBFileSpec file_spec;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000108 ModuleSP module_sp (GetSP ());
109 if (module_sp)
110 file_spec.SetFileSpec(module_sp->GetFileSpec());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000111
112 if (log)
113 {
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000114 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
Greg Claytonc2ff9312012-02-22 19:41:02 +0000115 module_sp.get(), file_spec.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000116 }
117
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 return file_spec;
119}
120
Greg Clayton2289fa42011-04-30 01:09:13 +0000121lldb::SBFileSpec
122SBModule::GetPlatformFileSpec () const
123{
Greg Clayton5160ce52013-03-27 23:08:40 +0000124 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton2289fa42011-04-30 01:09:13 +0000125
126 SBFileSpec file_spec;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000127 ModuleSP module_sp (GetSP ());
128 if (module_sp)
129 file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
Greg Clayton2289fa42011-04-30 01:09:13 +0000130
131 if (log)
132 {
133 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
Greg Claytonc2ff9312012-02-22 19:41:02 +0000134 module_sp.get(), file_spec.get());
Greg Clayton2289fa42011-04-30 01:09:13 +0000135 }
136
137 return file_spec;
138
139}
140
141bool
142SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
143{
144 bool result = false;
Greg Clayton5160ce52013-03-27 23:08:40 +0000145 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton2289fa42011-04-30 01:09:13 +0000146
Greg Claytonc2ff9312012-02-22 19:41:02 +0000147 ModuleSP module_sp (GetSP ());
148 if (module_sp)
Greg Clayton2289fa42011-04-30 01:09:13 +0000149 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000150 module_sp->SetPlatformFileSpec(*platform_file);
Greg Clayton2289fa42011-04-30 01:09:13 +0000151 result = true;
152 }
153
154 if (log)
155 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000156 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i",
Greg Claytonc2ff9312012-02-22 19:41:02 +0000157 module_sp.get(),
Greg Clayton2289fa42011-04-30 01:09:13 +0000158 platform_file.get(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000159 platform_file->GetPath().c_str(),
Greg Clayton2289fa42011-04-30 01:09:13 +0000160 result);
161 }
162 return result;
163}
164
Greg Claytonfbb76342013-11-20 21:07:01 +0000165lldb::SBFileSpec
166SBModule::GetRemoteInstallFileSpec ()
167{
168 SBFileSpec sb_file_spec;
169 ModuleSP module_sp (GetSP ());
170 if (module_sp)
171 sb_file_spec.SetFileSpec (module_sp->GetRemoteInstallFileSpec());
172 return sb_file_spec;
173}
174
175bool
176SBModule::SetRemoteInstallFileSpec (lldb::SBFileSpec &file)
177{
178 ModuleSP module_sp (GetSP ());
179 if (module_sp)
180 {
181 module_sp->SetRemoteInstallFileSpec(file.ref());
182 return true;
183 }
184 return false;
185}
Greg Clayton2289fa42011-04-30 01:09:13 +0000186
187
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188const uint8_t *
189SBModule::GetUUIDBytes () const
190{
Greg Clayton5160ce52013-03-27 23:08:40 +0000191 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000192
Greg Clayton48381312010-10-30 04:51:46 +0000193 const uint8_t *uuid_bytes = NULL;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000194 ModuleSP module_sp (GetSP ());
195 if (module_sp)
196 uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000197
198 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000199 {
200 if (uuid_bytes)
201 {
202 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000203 module_sp->GetUUID().Dump (&s);
204 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData());
Greg Clayton48381312010-10-30 04:51:46 +0000205 }
206 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000207 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get());
Greg Clayton48381312010-10-30 04:51:46 +0000208 }
209 return uuid_bytes;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000210}
211
212
Johnny Chendf2963e2011-04-01 00:35:55 +0000213const char *
214SBModule::GetUUIDString () const
215{
Greg Clayton5160ce52013-03-27 23:08:40 +0000216 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chendf2963e2011-04-01 00:35:55 +0000217
Jason Molendac16b4af2013-05-03 23:56:12 +0000218 static char uuid_string_buffer[80];
219 const char *uuid_c_string = NULL;
220 std::string uuid_string;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000221 ModuleSP module_sp (GetSP ());
222 if (module_sp)
Jason Molendac16b4af2013-05-03 23:56:12 +0000223 uuid_string = module_sp->GetUUID().GetAsString();
224
225 if (!uuid_string.empty())
226 {
227 strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer));
228 uuid_c_string = uuid_string_buffer;
229 }
Johnny Chendf2963e2011-04-01 00:35:55 +0000230
231 if (log)
232 {
Jason Molendac16b4af2013-05-03 23:56:12 +0000233 if (!uuid_string.empty())
Johnny Chendf2963e2011-04-01 00:35:55 +0000234 {
235 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000236 module_sp->GetUUID().Dump (&s);
237 log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData());
Johnny Chendf2963e2011-04-01 00:35:55 +0000238 }
239 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000240 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get());
Johnny Chendf2963e2011-04-01 00:35:55 +0000241 }
242 return uuid_c_string;
243}
244
245
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246bool
247SBModule::operator == (const SBModule &rhs) const
248{
Greg Clayton66111032010-06-23 01:19:29 +0000249 if (m_opaque_sp)
250 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251 return false;
252}
253
254bool
255SBModule::operator != (const SBModule &rhs) const
256{
Greg Clayton66111032010-06-23 01:19:29 +0000257 if (m_opaque_sp)
258 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 return false;
260}
261
Greg Claytonacdbe812012-01-30 09:04:36 +0000262ModuleSP
263SBModule::GetSP () const
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000264{
265 return m_opaque_sp;
266}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267
268void
Greg Claytonacdbe812012-01-30 09:04:36 +0000269SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270{
Greg Clayton66111032010-06-23 01:19:29 +0000271 m_opaque_sp = module_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272}
273
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000274SBAddress
275SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton09960032010-09-10 18:31:35 +0000276{
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000277 lldb::SBAddress sb_addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000278 ModuleSP module_sp (GetSP ());
279 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000280 {
281 Address addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000282 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000283 sb_addr.ref() = addr;
284 }
285 return sb_addr;
Greg Clayton09960032010-09-10 18:31:35 +0000286}
287
288SBSymbolContext
289SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
290{
291 SBSymbolContext sb_sc;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000292 ModuleSP module_sp (GetSP ());
293 if (module_sp && addr.IsValid())
294 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton09960032010-09-10 18:31:35 +0000295 return sb_sc;
296}
297
Caroline Ticedde9cff2010-09-20 05:20:02 +0000298bool
299SBModule::GetDescription (SBStream &description)
300{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000301 Stream &strm = description.ref();
302
Greg Claytonc2ff9312012-02-22 19:41:02 +0000303 ModuleSP module_sp (GetSP ());
304 if (module_sp)
Caroline Ticedde9cff2010-09-20 05:20:02 +0000305 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000306 module_sp->GetDescription (&strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +0000307 }
308 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000309 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000310
311 return true;
312}
Greg Claytonbbdabce2010-12-07 05:40:31 +0000313
Johnny Chen873a7a42012-03-16 20:46:10 +0000314uint32_t
315SBModule::GetNumCompileUnits()
316{
317 ModuleSP module_sp (GetSP ());
318 if (module_sp)
319 {
320 return module_sp->GetNumCompileUnits ();
321 }
322 return 0;
323}
324
325SBCompileUnit
326SBModule::GetCompileUnitAtIndex (uint32_t index)
327{
328 SBCompileUnit sb_cu;
329 ModuleSP module_sp (GetSP ());
330 if (module_sp)
331 {
332 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
333 sb_cu.reset(cu_sp.get());
334 }
335 return sb_cu;
336}
337
Michael Sartaina7499c92013-07-01 19:45:50 +0000338static Symtab *
339GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp)
340{
341 if (module_sp)
342 {
343 SymbolVendor *symbols = module_sp->GetSymbolVendor();
344 if (symbols)
345 return symbols->GetSymtab();
346 }
347 return NULL;
348}
349
Greg Claytonbbdabce2010-12-07 05:40:31 +0000350size_t
351SBModule::GetNumSymbols ()
352{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000353 ModuleSP module_sp (GetSP ());
354 if (module_sp)
Greg Claytonbbdabce2010-12-07 05:40:31 +0000355 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000356 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
357 if (symtab)
358 return symtab->GetNumSymbols();
Greg Claytonbbdabce2010-12-07 05:40:31 +0000359 }
360 return 0;
361}
362
363SBSymbol
364SBModule::GetSymbolAtIndex (size_t idx)
365{
366 SBSymbol sb_symbol;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000367 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000368 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
369 if (symtab)
370 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
Greg Claytonbbdabce2010-12-07 05:40:31 +0000371 return sb_symbol;
372}
Greg Claytonfe356d32011-06-21 01:34:41 +0000373
Greg Claytone14e1922012-12-04 02:22:16 +0000374lldb::SBSymbol
375SBModule::FindSymbol (const char *name,
376 lldb::SymbolType symbol_type)
377{
378 SBSymbol sb_symbol;
379 if (name && name[0])
380 {
381 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000382 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
383 if (symtab)
384 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
Greg Claytone14e1922012-12-04 02:22:16 +0000385 }
386 return sb_symbol;
387}
388
389
390lldb::SBSymbolContextList
391SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
392{
393 SBSymbolContextList sb_sc_list;
394 if (name && name[0])
395 {
396 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000397 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
398 if (symtab)
Greg Claytone14e1922012-12-04 02:22:16 +0000399 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000400 std::vector<uint32_t> matching_symbol_indexes;
401 const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
402 if (num_matches)
Greg Claytone14e1922012-12-04 02:22:16 +0000403 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000404 SymbolContext sc;
405 sc.module_sp = module_sp;
406 SymbolContextList &sc_list = *sb_sc_list;
407 for (size_t i=0; i<num_matches; ++i)
Greg Claytone14e1922012-12-04 02:22:16 +0000408 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000409 sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
410 if (sc.symbol)
411 sc_list.Append(sc);
Greg Claytone14e1922012-12-04 02:22:16 +0000412 }
413 }
414 }
415 }
416 return sb_sc_list;
417
418}
419
420
421
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000422size_t
423SBModule::GetNumSections ()
424{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000425 ModuleSP module_sp (GetSP ());
426 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000427 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000428 // Give the symbol vendor a chance to add to the unified section list.
429 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000430 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000431 if (section_list)
432 return section_list->GetSize();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000433 }
434 return 0;
435}
436
437SBSection
438SBModule::GetSectionAtIndex (size_t idx)
439{
440 SBSection sb_section;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000441 ModuleSP module_sp (GetSP ());
442 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000443 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000444 // Give the symbol vendor a chance to add to the unified section list.
445 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000446 SectionList *section_list = module_sp->GetSectionList ();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000447
Michael Sartaina7499c92013-07-01 19:45:50 +0000448 if (section_list)
449 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000450 }
451 return sb_section;
452}
453
Greg Clayton5569e642012-02-06 01:44:54 +0000454lldb::SBSymbolContextList
Greg Claytonfe356d32011-06-21 01:34:41 +0000455SBModule::FindFunctions (const char *name,
Greg Clayton5569e642012-02-06 01:44:54 +0000456 uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +0000457{
Greg Clayton5569e642012-02-06 01:44:54 +0000458 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000459 ModuleSP module_sp (GetSP ());
460 if (name && module_sp)
Greg Claytonfe356d32011-06-21 01:34:41 +0000461 {
Greg Clayton5569e642012-02-06 01:44:54 +0000462 const bool append = true;
Greg Claytonfe356d32011-06-21 01:34:41 +0000463 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +0000464 const bool inlines_ok = true;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000465 module_sp->FindFunctions (ConstString(name),
466 NULL,
467 name_type_mask,
468 symbols_ok,
469 inlines_ok,
470 append,
471 *sb_sc_list);
Greg Claytonfe356d32011-06-21 01:34:41 +0000472 }
Greg Clayton5569e642012-02-06 01:44:54 +0000473 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +0000474}
475
Greg Claytondea8cb42011-06-29 22:09:02 +0000476
477SBValueList
478SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
479{
480 SBValueList sb_value_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000481 ModuleSP module_sp (GetSP ());
482 if (name && module_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +0000483 {
484 VariableList variable_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000485 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
486 NULL,
487 false,
488 max_matches,
489 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +0000490
491 if (match_count > 0)
492 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000493 for (uint32_t i=0; i<match_count; ++i)
494 {
495 lldb::ValueObjectSP valobj_sp;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000496 TargetSP target_sp (target.GetSP());
497 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Claytondea8cb42011-06-29 22:09:02 +0000498 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +0000499 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +0000500 }
501 }
502 }
503
504 return sb_value_list;
505}
Enrico Granata6f3533f2011-07-29 19:53:35 +0000506
Enrico Granatabcd80b42013-01-16 18:53:52 +0000507lldb::SBValue
508SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name)
509{
510 SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
511 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
512 return sb_value_list.GetValueAtIndex(0);
513 return SBValue();
514}
515
Enrico Granata6f3533f2011-07-29 19:53:35 +0000516lldb::SBType
Johnny Chen4efffd92011-12-19 20:16:22 +0000517SBModule::FindFirstType (const char *name_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000518{
Greg Claytonfe42ac42011-08-03 22:57:10 +0000519 SBType sb_type;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000520 ModuleSP module_sp (GetSP ());
521 if (name_cstr && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000522 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000523 SymbolContext sc;
Greg Clayton84db9102012-03-26 23:03:23 +0000524 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000525 ConstString name(name_cstr);
526
Greg Claytonb43165b2012-12-05 21:24:42 +0000527 sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match));
Greg Claytonfe42ac42011-08-03 22:57:10 +0000528
Greg Claytonb43165b2012-12-05 21:24:42 +0000529 if (!sb_type.IsValid())
Greg Clayton57ee3062013-07-11 22:46:58 +0000530 sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000531 }
Greg Claytonfe42ac42011-08-03 22:57:10 +0000532 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000533}
534
Greg Claytonb43165b2012-12-05 21:24:42 +0000535lldb::SBType
536SBModule::GetBasicType(lldb::BasicType type)
537{
538 ModuleSP module_sp (GetSP ());
539 if (module_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +0000540 return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +0000541 return SBType();
542}
543
Enrico Granata6f3533f2011-07-29 19:53:35 +0000544lldb::SBTypeList
Johnny Chen4efffd92011-12-19 20:16:22 +0000545SBModule::FindTypes (const char *type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000546{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000547 SBTypeList retval;
548
Greg Claytonc2ff9312012-02-22 19:41:02 +0000549 ModuleSP module_sp (GetSP ());
550 if (type && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000551 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000552 SymbolContext sc;
553 TypeList type_list;
Greg Clayton84db9102012-03-26 23:03:23 +0000554 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000555 ConstString name(type);
Greg Claytonb43165b2012-12-05 21:24:42 +0000556 const uint32_t num_matches = module_sp->FindTypes (sc,
557 name,
558 exact_match,
559 UINT32_MAX,
560 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000561
Greg Claytonb43165b2012-12-05 21:24:42 +0000562 if (num_matches > 0)
Greg Claytonfe42ac42011-08-03 22:57:10 +0000563 {
Greg Claytonb43165b2012-12-05 21:24:42 +0000564 for (size_t idx = 0; idx < num_matches; idx++)
565 {
566 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
567 if (type_sp)
568 retval.Append(SBType(type_sp));
569 }
570 }
571 else
572 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000573 SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Greg Claytonb43165b2012-12-05 21:24:42 +0000574 if (sb_type.IsValid())
575 retval.Append(sb_type);
Greg Claytonfe42ac42011-08-03 22:57:10 +0000576 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000577 }
578
579 return retval;
Greg Clayton3418c852011-08-10 02:10:13 +0000580}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000581
Greg Clayton1f4db7d2014-01-23 21:38:34 +0000582lldb::SBType
583SBModule::GetTypeByID (lldb::user_id_t uid)
584{
585 ModuleSP module_sp (GetSP ());
586 if (module_sp)
587 {
588 SymbolVendor* vendor = module_sp->GetSymbolVendor();
589 if (vendor)
590 {
591 Type *type_ptr = vendor->ResolveTypeUID(uid);
592 if (type_ptr)
593 return SBType(type_ptr->shared_from_this());
594 }
595 }
596 return SBType();
597}
598
Greg Claytonf02500c2013-06-18 22:51:05 +0000599lldb::SBTypeList
600SBModule::GetTypes (uint32_t type_mask)
601{
602 SBTypeList sb_type_list;
603
604 ModuleSP module_sp (GetSP ());
605 if (module_sp)
606 {
607 SymbolVendor* vendor = module_sp->GetSymbolVendor();
608 if (vendor)
609 {
610 TypeList type_list;
611 vendor->GetTypes (NULL, type_mask, type_list);
612 sb_type_list.m_opaque_ap->Append(type_list);
613 }
614 }
615 return sb_type_list;
616}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000617
618SBSection
619SBModule::FindSection (const char *sect_name)
620{
621 SBSection sb_section;
622
Greg Claytonc2ff9312012-02-22 19:41:02 +0000623 ModuleSP module_sp (GetSP ());
624 if (sect_name && module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000625 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000626 // Give the symbol vendor a chance to add to the unified section list.
627 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000628 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000629 if (section_list)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000630 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000631 ConstString const_sect_name(sect_name);
632 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
633 if (section_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000634 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000635 sb_section.SetSP (section_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000636 }
637 }
638 }
639 return sb_section;
640}
641
Greg Clayton13d19502012-01-29 06:07:39 +0000642lldb::ByteOrder
643SBModule::GetByteOrder ()
644{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000645 ModuleSP module_sp (GetSP ());
646 if (module_sp)
647 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +0000648 return eByteOrderInvalid;
649}
650
651const char *
652SBModule::GetTriple ()
653{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000654 ModuleSP module_sp (GetSP ());
655 if (module_sp)
Greg Clayton13d19502012-01-29 06:07:39 +0000656 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000657 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +0000658 // Unique the string so we don't run into ownership issues since
659 // the const strings put the string into the string pool once and
660 // the strings never comes out
661 ConstString const_triple (triple.c_str());
662 return const_triple.GetCString();
663 }
664 return NULL;
665}
666
667uint32_t
668SBModule::GetAddressByteSize()
669{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000670 ModuleSP module_sp (GetSP ());
671 if (module_sp)
672 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +0000673 return sizeof(void*);
674}
675
Greg Claytonc2ff9312012-02-22 19:41:02 +0000676
677uint32_t
678SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
679{
680 ModuleSP module_sp (GetSP ());
681 if (module_sp)
Enrico Granata3467d802012-09-04 18:47:54 +0000682 return module_sp->GetVersion(versions, num_versions);
683 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000684 {
Enrico Granata3467d802012-09-04 18:47:54 +0000685 if (versions && num_versions)
686 {
687 for (uint32_t i=0; i<num_versions; ++i)
688 versions[i] = UINT32_MAX;
689 }
690 return 0;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000691 }
Greg Claytonc2ff9312012-02-22 19:41:02 +0000692}
693