blob: 0d7dda1aa1f7db6e2e705cdfe6a26004564c63c3 [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)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000113 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
114 static_cast<void*>(module_sp.get()),
115 static_cast<const void*>(file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000116
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117 return file_spec;
118}
119
Greg Clayton2289fa42011-04-30 01:09:13 +0000120lldb::SBFileSpec
121SBModule::GetPlatformFileSpec () const
122{
Greg Clayton5160ce52013-03-27 23:08:40 +0000123 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000124
Greg Clayton2289fa42011-04-30 01:09:13 +0000125 SBFileSpec file_spec;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000126 ModuleSP module_sp (GetSP ());
127 if (module_sp)
128 file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000129
Greg Clayton2289fa42011-04-30 01:09:13 +0000130 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000131 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
132 static_cast<void*>(module_sp.get()),
133 static_cast<const void*>(file_spec.get()));
134
Greg Clayton2289fa42011-04-30 01:09:13 +0000135 return file_spec;
Greg Clayton2289fa42011-04-30 01:09:13 +0000136}
137
138bool
139SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
140{
141 bool result = false;
Greg Clayton5160ce52013-03-27 23:08:40 +0000142 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000143
Greg Claytonc2ff9312012-02-22 19:41:02 +0000144 ModuleSP module_sp (GetSP ());
145 if (module_sp)
Greg Clayton2289fa42011-04-30 01:09:13 +0000146 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000147 module_sp->SetPlatformFileSpec(*platform_file);
Greg Clayton2289fa42011-04-30 01:09:13 +0000148 result = true;
149 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000150
Greg Clayton2289fa42011-04-30 01:09:13 +0000151 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000152 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i",
153 static_cast<void*>(module_sp.get()),
154 static_cast<const void*>(platform_file.get()),
155 platform_file->GetPath().c_str(), result);
Greg Clayton2289fa42011-04-30 01:09:13 +0000156 return result;
157}
158
Greg Claytonfbb76342013-11-20 21:07:01 +0000159lldb::SBFileSpec
160SBModule::GetRemoteInstallFileSpec ()
161{
162 SBFileSpec sb_file_spec;
163 ModuleSP module_sp (GetSP ());
164 if (module_sp)
165 sb_file_spec.SetFileSpec (module_sp->GetRemoteInstallFileSpec());
166 return sb_file_spec;
167}
168
169bool
170SBModule::SetRemoteInstallFileSpec (lldb::SBFileSpec &file)
171{
172 ModuleSP module_sp (GetSP ());
173 if (module_sp)
174 {
175 module_sp->SetRemoteInstallFileSpec(file.ref());
176 return true;
177 }
178 return false;
179}
Greg Clayton2289fa42011-04-30 01:09:13 +0000180
181
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182const uint8_t *
183SBModule::GetUUIDBytes () const
184{
Greg Clayton5160ce52013-03-27 23:08:40 +0000185 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000186
Greg Clayton48381312010-10-30 04:51:46 +0000187 const uint8_t *uuid_bytes = NULL;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000188 ModuleSP module_sp (GetSP ());
189 if (module_sp)
190 uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000191
192 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000193 {
194 if (uuid_bytes)
195 {
196 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000197 module_sp->GetUUID().Dump (&s);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000198 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s",
199 static_cast<void*>(module_sp.get()), s.GetData());
Greg Clayton48381312010-10-30 04:51:46 +0000200 }
201 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000202 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL",
203 static_cast<void*>(module_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000204 }
205 return uuid_bytes;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206}
207
208
Johnny Chendf2963e2011-04-01 00:35:55 +0000209const char *
210SBModule::GetUUIDString () const
211{
Greg Clayton5160ce52013-03-27 23:08:40 +0000212 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chendf2963e2011-04-01 00:35:55 +0000213
Jason Molendac16b4af2013-05-03 23:56:12 +0000214 static char uuid_string_buffer[80];
215 const char *uuid_c_string = NULL;
216 std::string uuid_string;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000217 ModuleSP module_sp (GetSP ());
218 if (module_sp)
Jason Molendac16b4af2013-05-03 23:56:12 +0000219 uuid_string = module_sp->GetUUID().GetAsString();
220
221 if (!uuid_string.empty())
222 {
223 strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer));
Sylvestre Ledru802a3532014-08-19 12:13:14 +0000224 uuid_string_buffer[sizeof (uuid_string_buffer) - 1] = '\0';
Jason Molendac16b4af2013-05-03 23:56:12 +0000225 uuid_c_string = uuid_string_buffer;
226 }
Johnny Chendf2963e2011-04-01 00:35:55 +0000227
228 if (log)
229 {
Jason Molendac16b4af2013-05-03 23:56:12 +0000230 if (!uuid_string.empty())
Johnny Chendf2963e2011-04-01 00:35:55 +0000231 {
232 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000233 module_sp->GetUUID().Dump (&s);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000234 log->Printf ("SBModule(%p)::GetUUIDString () => %s",
235 static_cast<void*>(module_sp.get()), s.GetData());
Johnny Chendf2963e2011-04-01 00:35:55 +0000236 }
237 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000238 log->Printf ("SBModule(%p)::GetUUIDString () => NULL",
239 static_cast<void*>(module_sp.get()));
Johnny Chendf2963e2011-04-01 00:35:55 +0000240 }
241 return uuid_c_string;
242}
243
244
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245bool
246SBModule::operator == (const SBModule &rhs) const
247{
Greg Clayton66111032010-06-23 01:19:29 +0000248 if (m_opaque_sp)
249 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250 return false;
251}
252
253bool
254SBModule::operator != (const SBModule &rhs) const
255{
Greg Clayton66111032010-06-23 01:19:29 +0000256 if (m_opaque_sp)
257 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 return false;
259}
260
Greg Claytonacdbe812012-01-30 09:04:36 +0000261ModuleSP
262SBModule::GetSP () const
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000263{
264 return m_opaque_sp;
265}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266
267void
Greg Claytonacdbe812012-01-30 09:04:36 +0000268SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269{
Greg Clayton66111032010-06-23 01:19:29 +0000270 m_opaque_sp = module_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271}
272
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000273SBAddress
274SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton09960032010-09-10 18:31:35 +0000275{
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000276 lldb::SBAddress sb_addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000277 ModuleSP module_sp (GetSP ());
278 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000279 {
280 Address addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000281 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000282 sb_addr.ref() = addr;
283 }
284 return sb_addr;
Greg Clayton09960032010-09-10 18:31:35 +0000285}
286
287SBSymbolContext
288SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
289{
290 SBSymbolContext sb_sc;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000291 ModuleSP module_sp (GetSP ());
292 if (module_sp && addr.IsValid())
293 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton09960032010-09-10 18:31:35 +0000294 return sb_sc;
295}
296
Caroline Ticedde9cff2010-09-20 05:20:02 +0000297bool
298SBModule::GetDescription (SBStream &description)
299{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000300 Stream &strm = description.ref();
301
Greg Claytonc2ff9312012-02-22 19:41:02 +0000302 ModuleSP module_sp (GetSP ());
303 if (module_sp)
Caroline Ticedde9cff2010-09-20 05:20:02 +0000304 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000305 module_sp->GetDescription (&strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +0000306 }
307 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000308 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000309
310 return true;
311}
Greg Claytonbbdabce2010-12-07 05:40:31 +0000312
Johnny Chen873a7a42012-03-16 20:46:10 +0000313uint32_t
314SBModule::GetNumCompileUnits()
315{
316 ModuleSP module_sp (GetSP ());
317 if (module_sp)
318 {
319 return module_sp->GetNumCompileUnits ();
320 }
321 return 0;
322}
323
324SBCompileUnit
325SBModule::GetCompileUnitAtIndex (uint32_t index)
326{
327 SBCompileUnit sb_cu;
328 ModuleSP module_sp (GetSP ());
329 if (module_sp)
330 {
331 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
332 sb_cu.reset(cu_sp.get());
333 }
334 return sb_cu;
335}
336
Michael Sartaina7499c92013-07-01 19:45:50 +0000337static Symtab *
338GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp)
339{
340 if (module_sp)
341 {
342 SymbolVendor *symbols = module_sp->GetSymbolVendor();
343 if (symbols)
344 return symbols->GetSymtab();
345 }
346 return NULL;
347}
348
Greg Claytonbbdabce2010-12-07 05:40:31 +0000349size_t
350SBModule::GetNumSymbols ()
351{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000352 ModuleSP module_sp (GetSP ());
353 if (module_sp)
Greg Claytonbbdabce2010-12-07 05:40:31 +0000354 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000355 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
356 if (symtab)
357 return symtab->GetNumSymbols();
Greg Claytonbbdabce2010-12-07 05:40:31 +0000358 }
359 return 0;
360}
361
362SBSymbol
363SBModule::GetSymbolAtIndex (size_t idx)
364{
365 SBSymbol sb_symbol;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000366 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000367 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
368 if (symtab)
369 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
Greg Claytonbbdabce2010-12-07 05:40:31 +0000370 return sb_symbol;
371}
Greg Claytonfe356d32011-06-21 01:34:41 +0000372
Greg Claytone14e1922012-12-04 02:22:16 +0000373lldb::SBSymbol
374SBModule::FindSymbol (const char *name,
375 lldb::SymbolType symbol_type)
376{
377 SBSymbol sb_symbol;
378 if (name && name[0])
379 {
380 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000381 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
382 if (symtab)
383 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
Greg Claytone14e1922012-12-04 02:22:16 +0000384 }
385 return sb_symbol;
386}
387
388
389lldb::SBSymbolContextList
390SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
391{
392 SBSymbolContextList sb_sc_list;
393 if (name && name[0])
394 {
395 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000396 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
397 if (symtab)
Greg Claytone14e1922012-12-04 02:22:16 +0000398 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000399 std::vector<uint32_t> matching_symbol_indexes;
400 const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
401 if (num_matches)
Greg Claytone14e1922012-12-04 02:22:16 +0000402 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000403 SymbolContext sc;
404 sc.module_sp = module_sp;
405 SymbolContextList &sc_list = *sb_sc_list;
406 for (size_t i=0; i<num_matches; ++i)
Greg Claytone14e1922012-12-04 02:22:16 +0000407 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000408 sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
409 if (sc.symbol)
410 sc_list.Append(sc);
Greg Claytone14e1922012-12-04 02:22:16 +0000411 }
412 }
413 }
414 }
415 return sb_sc_list;
416
417}
418
419
420
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000421size_t
422SBModule::GetNumSections ()
423{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000424 ModuleSP module_sp (GetSP ());
425 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000426 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000427 // Give the symbol vendor a chance to add to the unified section list.
428 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000429 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000430 if (section_list)
431 return section_list->GetSize();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000432 }
433 return 0;
434}
435
436SBSection
437SBModule::GetSectionAtIndex (size_t idx)
438{
439 SBSection sb_section;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000440 ModuleSP module_sp (GetSP ());
441 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000442 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000443 // Give the symbol vendor a chance to add to the unified section list.
444 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000445 SectionList *section_list = module_sp->GetSectionList ();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000446
Michael Sartaina7499c92013-07-01 19:45:50 +0000447 if (section_list)
448 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000449 }
450 return sb_section;
451}
452
Greg Clayton5569e642012-02-06 01:44:54 +0000453lldb::SBSymbolContextList
Greg Claytonfe356d32011-06-21 01:34:41 +0000454SBModule::FindFunctions (const char *name,
Greg Clayton5569e642012-02-06 01:44:54 +0000455 uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +0000456{
Greg Clayton5569e642012-02-06 01:44:54 +0000457 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000458 ModuleSP module_sp (GetSP ());
459 if (name && module_sp)
Greg Claytonfe356d32011-06-21 01:34:41 +0000460 {
Greg Clayton5569e642012-02-06 01:44:54 +0000461 const bool append = true;
Greg Claytonfe356d32011-06-21 01:34:41 +0000462 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +0000463 const bool inlines_ok = true;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000464 module_sp->FindFunctions (ConstString(name),
465 NULL,
466 name_type_mask,
467 symbols_ok,
468 inlines_ok,
469 append,
470 *sb_sc_list);
Greg Claytonfe356d32011-06-21 01:34:41 +0000471 }
Greg Clayton5569e642012-02-06 01:44:54 +0000472 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +0000473}
474
Greg Claytondea8cb42011-06-29 22:09:02 +0000475
476SBValueList
477SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
478{
479 SBValueList sb_value_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000480 ModuleSP module_sp (GetSP ());
481 if (name && module_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +0000482 {
483 VariableList variable_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000484 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
485 NULL,
486 false,
487 max_matches,
488 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +0000489
490 if (match_count > 0)
491 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000492 for (uint32_t i=0; i<match_count; ++i)
493 {
494 lldb::ValueObjectSP valobj_sp;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000495 TargetSP target_sp (target.GetSP());
496 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Claytondea8cb42011-06-29 22:09:02 +0000497 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +0000498 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +0000499 }
500 }
501 }
502
503 return sb_value_list;
504}
Enrico Granata6f3533f2011-07-29 19:53:35 +0000505
Enrico Granatabcd80b42013-01-16 18:53:52 +0000506lldb::SBValue
507SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name)
508{
509 SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
510 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
511 return sb_value_list.GetValueAtIndex(0);
512 return SBValue();
513}
514
Enrico Granata6f3533f2011-07-29 19:53:35 +0000515lldb::SBType
Johnny Chen4efffd92011-12-19 20:16:22 +0000516SBModule::FindFirstType (const char *name_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000517{
Greg Claytonfe42ac42011-08-03 22:57:10 +0000518 SBType sb_type;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000519 ModuleSP module_sp (GetSP ());
520 if (name_cstr && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000521 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000522 SymbolContext sc;
Greg Clayton84db9102012-03-26 23:03:23 +0000523 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000524 ConstString name(name_cstr);
525
Greg Claytonb43165b2012-12-05 21:24:42 +0000526 sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match));
Greg Claytonfe42ac42011-08-03 22:57:10 +0000527
Greg Claytonb43165b2012-12-05 21:24:42 +0000528 if (!sb_type.IsValid())
Greg Clayton57ee3062013-07-11 22:46:58 +0000529 sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000530 }
Greg Claytonfe42ac42011-08-03 22:57:10 +0000531 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000532}
533
Greg Claytonb43165b2012-12-05 21:24:42 +0000534lldb::SBType
535SBModule::GetBasicType(lldb::BasicType type)
536{
537 ModuleSP module_sp (GetSP ());
538 if (module_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +0000539 return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +0000540 return SBType();
541}
542
Enrico Granata6f3533f2011-07-29 19:53:35 +0000543lldb::SBTypeList
Johnny Chen4efffd92011-12-19 20:16:22 +0000544SBModule::FindTypes (const char *type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000545{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000546 SBTypeList retval;
547
Greg Claytonc2ff9312012-02-22 19:41:02 +0000548 ModuleSP module_sp (GetSP ());
549 if (type && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000550 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000551 SymbolContext sc;
552 TypeList type_list;
Greg Clayton84db9102012-03-26 23:03:23 +0000553 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000554 ConstString name(type);
Greg Claytonb43165b2012-12-05 21:24:42 +0000555 const uint32_t num_matches = module_sp->FindTypes (sc,
556 name,
557 exact_match,
558 UINT32_MAX,
559 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000560
Greg Claytonb43165b2012-12-05 21:24:42 +0000561 if (num_matches > 0)
Greg Claytonfe42ac42011-08-03 22:57:10 +0000562 {
Greg Claytonb43165b2012-12-05 21:24:42 +0000563 for (size_t idx = 0; idx < num_matches; idx++)
564 {
565 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
566 if (type_sp)
567 retval.Append(SBType(type_sp));
568 }
569 }
570 else
571 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000572 SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Greg Claytonb43165b2012-12-05 21:24:42 +0000573 if (sb_type.IsValid())
574 retval.Append(sb_type);
Greg Claytonfe42ac42011-08-03 22:57:10 +0000575 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000576 }
577
578 return retval;
Greg Clayton3418c852011-08-10 02:10:13 +0000579}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000580
Greg Clayton1f4db7d2014-01-23 21:38:34 +0000581lldb::SBType
582SBModule::GetTypeByID (lldb::user_id_t uid)
583{
584 ModuleSP module_sp (GetSP ());
585 if (module_sp)
586 {
587 SymbolVendor* vendor = module_sp->GetSymbolVendor();
588 if (vendor)
589 {
590 Type *type_ptr = vendor->ResolveTypeUID(uid);
591 if (type_ptr)
592 return SBType(type_ptr->shared_from_this());
593 }
594 }
595 return SBType();
596}
597
Greg Claytonf02500c2013-06-18 22:51:05 +0000598lldb::SBTypeList
599SBModule::GetTypes (uint32_t type_mask)
600{
601 SBTypeList sb_type_list;
602
603 ModuleSP module_sp (GetSP ());
604 if (module_sp)
605 {
606 SymbolVendor* vendor = module_sp->GetSymbolVendor();
607 if (vendor)
608 {
609 TypeList type_list;
610 vendor->GetTypes (NULL, type_mask, type_list);
611 sb_type_list.m_opaque_ap->Append(type_list);
612 }
613 }
614 return sb_type_list;
615}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000616
617SBSection
618SBModule::FindSection (const char *sect_name)
619{
620 SBSection sb_section;
621
Greg Claytonc2ff9312012-02-22 19:41:02 +0000622 ModuleSP module_sp (GetSP ());
623 if (sect_name && module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000624 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000625 // Give the symbol vendor a chance to add to the unified section list.
626 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000627 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000628 if (section_list)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000629 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000630 ConstString const_sect_name(sect_name);
631 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
632 if (section_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000633 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000634 sb_section.SetSP (section_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000635 }
636 }
637 }
638 return sb_section;
639}
640
Greg Clayton13d19502012-01-29 06:07:39 +0000641lldb::ByteOrder
642SBModule::GetByteOrder ()
643{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000644 ModuleSP module_sp (GetSP ());
645 if (module_sp)
646 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +0000647 return eByteOrderInvalid;
648}
649
650const char *
651SBModule::GetTriple ()
652{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000653 ModuleSP module_sp (GetSP ());
654 if (module_sp)
Greg Clayton13d19502012-01-29 06:07:39 +0000655 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000656 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +0000657 // Unique the string so we don't run into ownership issues since
658 // the const strings put the string into the string pool once and
659 // the strings never comes out
660 ConstString const_triple (triple.c_str());
661 return const_triple.GetCString();
662 }
663 return NULL;
664}
665
666uint32_t
667SBModule::GetAddressByteSize()
668{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000669 ModuleSP module_sp (GetSP ());
670 if (module_sp)
671 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +0000672 return sizeof(void*);
673}
674
Greg Claytonc2ff9312012-02-22 19:41:02 +0000675
676uint32_t
677SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
678{
679 ModuleSP module_sp (GetSP ());
680 if (module_sp)
Enrico Granata3467d802012-09-04 18:47:54 +0000681 return module_sp->GetVersion(versions, num_versions);
682 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000683 {
Enrico Granata3467d802012-09-04 18:47:54 +0000684 if (versions && num_versions)
685 {
686 for (uint32_t i=0; i<num_versions; ++i)
687 versions[i] = UINT32_MAX;
688 }
689 return 0;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000690 }
Greg Claytonc2ff9312012-02-22 19:41:02 +0000691}
692