blob: b1e39ff9e7598284cea433c6fbd18b2ebe5589e4 [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));
224 uuid_c_string = uuid_string_buffer;
225 }
Johnny Chendf2963e2011-04-01 00:35:55 +0000226
227 if (log)
228 {
Jason Molendac16b4af2013-05-03 23:56:12 +0000229 if (!uuid_string.empty())
Johnny Chendf2963e2011-04-01 00:35:55 +0000230 {
231 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000232 module_sp->GetUUID().Dump (&s);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000233 log->Printf ("SBModule(%p)::GetUUIDString () => %s",
234 static_cast<void*>(module_sp.get()), s.GetData());
Johnny Chendf2963e2011-04-01 00:35:55 +0000235 }
236 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000237 log->Printf ("SBModule(%p)::GetUUIDString () => NULL",
238 static_cast<void*>(module_sp.get()));
Johnny Chendf2963e2011-04-01 00:35:55 +0000239 }
240 return uuid_c_string;
241}
242
243
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244bool
245SBModule::operator == (const SBModule &rhs) const
246{
Greg Clayton66111032010-06-23 01:19:29 +0000247 if (m_opaque_sp)
248 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249 return false;
250}
251
252bool
253SBModule::operator != (const SBModule &rhs) const
254{
Greg Clayton66111032010-06-23 01:19:29 +0000255 if (m_opaque_sp)
256 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257 return false;
258}
259
Greg Claytonacdbe812012-01-30 09:04:36 +0000260ModuleSP
261SBModule::GetSP () const
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000262{
263 return m_opaque_sp;
264}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265
266void
Greg Claytonacdbe812012-01-30 09:04:36 +0000267SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268{
Greg Clayton66111032010-06-23 01:19:29 +0000269 m_opaque_sp = module_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270}
271
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000272SBAddress
273SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton09960032010-09-10 18:31:35 +0000274{
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000275 lldb::SBAddress sb_addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000276 ModuleSP module_sp (GetSP ());
277 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000278 {
279 Address addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000280 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000281 sb_addr.ref() = addr;
282 }
283 return sb_addr;
Greg Clayton09960032010-09-10 18:31:35 +0000284}
285
286SBSymbolContext
287SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
288{
289 SBSymbolContext sb_sc;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000290 ModuleSP module_sp (GetSP ());
291 if (module_sp && addr.IsValid())
292 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton09960032010-09-10 18:31:35 +0000293 return sb_sc;
294}
295
Caroline Ticedde9cff2010-09-20 05:20:02 +0000296bool
297SBModule::GetDescription (SBStream &description)
298{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000299 Stream &strm = description.ref();
300
Greg Claytonc2ff9312012-02-22 19:41:02 +0000301 ModuleSP module_sp (GetSP ());
302 if (module_sp)
Caroline Ticedde9cff2010-09-20 05:20:02 +0000303 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000304 module_sp->GetDescription (&strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +0000305 }
306 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000307 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000308
309 return true;
310}
Greg Claytonbbdabce2010-12-07 05:40:31 +0000311
Johnny Chen873a7a42012-03-16 20:46:10 +0000312uint32_t
313SBModule::GetNumCompileUnits()
314{
315 ModuleSP module_sp (GetSP ());
316 if (module_sp)
317 {
318 return module_sp->GetNumCompileUnits ();
319 }
320 return 0;
321}
322
323SBCompileUnit
324SBModule::GetCompileUnitAtIndex (uint32_t index)
325{
326 SBCompileUnit sb_cu;
327 ModuleSP module_sp (GetSP ());
328 if (module_sp)
329 {
330 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
331 sb_cu.reset(cu_sp.get());
332 }
333 return sb_cu;
334}
335
Michael Sartaina7499c92013-07-01 19:45:50 +0000336static Symtab *
337GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp)
338{
339 if (module_sp)
340 {
341 SymbolVendor *symbols = module_sp->GetSymbolVendor();
342 if (symbols)
343 return symbols->GetSymtab();
344 }
345 return NULL;
346}
347
Greg Claytonbbdabce2010-12-07 05:40:31 +0000348size_t
349SBModule::GetNumSymbols ()
350{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000351 ModuleSP module_sp (GetSP ());
352 if (module_sp)
Greg Claytonbbdabce2010-12-07 05:40:31 +0000353 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000354 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
355 if (symtab)
356 return symtab->GetNumSymbols();
Greg Claytonbbdabce2010-12-07 05:40:31 +0000357 }
358 return 0;
359}
360
361SBSymbol
362SBModule::GetSymbolAtIndex (size_t idx)
363{
364 SBSymbol sb_symbol;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000365 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000366 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
367 if (symtab)
368 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
Greg Claytonbbdabce2010-12-07 05:40:31 +0000369 return sb_symbol;
370}
Greg Claytonfe356d32011-06-21 01:34:41 +0000371
Greg Claytone14e1922012-12-04 02:22:16 +0000372lldb::SBSymbol
373SBModule::FindSymbol (const char *name,
374 lldb::SymbolType symbol_type)
375{
376 SBSymbol sb_symbol;
377 if (name && name[0])
378 {
379 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000380 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
381 if (symtab)
382 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
Greg Claytone14e1922012-12-04 02:22:16 +0000383 }
384 return sb_symbol;
385}
386
387
388lldb::SBSymbolContextList
389SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
390{
391 SBSymbolContextList sb_sc_list;
392 if (name && name[0])
393 {
394 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000395 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
396 if (symtab)
Greg Claytone14e1922012-12-04 02:22:16 +0000397 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000398 std::vector<uint32_t> matching_symbol_indexes;
399 const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
400 if (num_matches)
Greg Claytone14e1922012-12-04 02:22:16 +0000401 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000402 SymbolContext sc;
403 sc.module_sp = module_sp;
404 SymbolContextList &sc_list = *sb_sc_list;
405 for (size_t i=0; i<num_matches; ++i)
Greg Claytone14e1922012-12-04 02:22:16 +0000406 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000407 sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
408 if (sc.symbol)
409 sc_list.Append(sc);
Greg Claytone14e1922012-12-04 02:22:16 +0000410 }
411 }
412 }
413 }
414 return sb_sc_list;
415
416}
417
418
419
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000420size_t
421SBModule::GetNumSections ()
422{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000423 ModuleSP module_sp (GetSP ());
424 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000425 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000426 // Give the symbol vendor a chance to add to the unified section list.
427 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000428 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000429 if (section_list)
430 return section_list->GetSize();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000431 }
432 return 0;
433}
434
435SBSection
436SBModule::GetSectionAtIndex (size_t idx)
437{
438 SBSection sb_section;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000439 ModuleSP module_sp (GetSP ());
440 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000441 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000442 // Give the symbol vendor a chance to add to the unified section list.
443 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000444 SectionList *section_list = module_sp->GetSectionList ();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000445
Michael Sartaina7499c92013-07-01 19:45:50 +0000446 if (section_list)
447 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000448 }
449 return sb_section;
450}
451
Greg Clayton5569e642012-02-06 01:44:54 +0000452lldb::SBSymbolContextList
Greg Claytonfe356d32011-06-21 01:34:41 +0000453SBModule::FindFunctions (const char *name,
Greg Clayton5569e642012-02-06 01:44:54 +0000454 uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +0000455{
Greg Clayton5569e642012-02-06 01:44:54 +0000456 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000457 ModuleSP module_sp (GetSP ());
458 if (name && module_sp)
Greg Claytonfe356d32011-06-21 01:34:41 +0000459 {
Greg Clayton5569e642012-02-06 01:44:54 +0000460 const bool append = true;
Greg Claytonfe356d32011-06-21 01:34:41 +0000461 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +0000462 const bool inlines_ok = true;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000463 module_sp->FindFunctions (ConstString(name),
464 NULL,
465 name_type_mask,
466 symbols_ok,
467 inlines_ok,
468 append,
469 *sb_sc_list);
Greg Claytonfe356d32011-06-21 01:34:41 +0000470 }
Greg Clayton5569e642012-02-06 01:44:54 +0000471 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +0000472}
473
Greg Claytondea8cb42011-06-29 22:09:02 +0000474
475SBValueList
476SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
477{
478 SBValueList sb_value_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000479 ModuleSP module_sp (GetSP ());
480 if (name && module_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +0000481 {
482 VariableList variable_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000483 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
484 NULL,
485 false,
486 max_matches,
487 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +0000488
489 if (match_count > 0)
490 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000491 for (uint32_t i=0; i<match_count; ++i)
492 {
493 lldb::ValueObjectSP valobj_sp;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000494 TargetSP target_sp (target.GetSP());
495 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Claytondea8cb42011-06-29 22:09:02 +0000496 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +0000497 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +0000498 }
499 }
500 }
501
502 return sb_value_list;
503}
Enrico Granata6f3533f2011-07-29 19:53:35 +0000504
Enrico Granatabcd80b42013-01-16 18:53:52 +0000505lldb::SBValue
506SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name)
507{
508 SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
509 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
510 return sb_value_list.GetValueAtIndex(0);
511 return SBValue();
512}
513
Enrico Granata6f3533f2011-07-29 19:53:35 +0000514lldb::SBType
Johnny Chen4efffd92011-12-19 20:16:22 +0000515SBModule::FindFirstType (const char *name_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000516{
Greg Claytonfe42ac42011-08-03 22:57:10 +0000517 SBType sb_type;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000518 ModuleSP module_sp (GetSP ());
519 if (name_cstr && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000520 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000521 SymbolContext sc;
Greg Clayton84db9102012-03-26 23:03:23 +0000522 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000523 ConstString name(name_cstr);
524
Greg Claytonb43165b2012-12-05 21:24:42 +0000525 sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match));
Greg Claytonfe42ac42011-08-03 22:57:10 +0000526
Greg Claytonb43165b2012-12-05 21:24:42 +0000527 if (!sb_type.IsValid())
Greg Clayton57ee3062013-07-11 22:46:58 +0000528 sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000529 }
Greg Claytonfe42ac42011-08-03 22:57:10 +0000530 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000531}
532
Greg Claytonb43165b2012-12-05 21:24:42 +0000533lldb::SBType
534SBModule::GetBasicType(lldb::BasicType type)
535{
536 ModuleSP module_sp (GetSP ());
537 if (module_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +0000538 return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +0000539 return SBType();
540}
541
Enrico Granata6f3533f2011-07-29 19:53:35 +0000542lldb::SBTypeList
Johnny Chen4efffd92011-12-19 20:16:22 +0000543SBModule::FindTypes (const char *type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000544{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000545 SBTypeList retval;
546
Greg Claytonc2ff9312012-02-22 19:41:02 +0000547 ModuleSP module_sp (GetSP ());
548 if (type && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000549 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000550 SymbolContext sc;
551 TypeList type_list;
Greg Clayton84db9102012-03-26 23:03:23 +0000552 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000553 ConstString name(type);
Greg Claytonb43165b2012-12-05 21:24:42 +0000554 const uint32_t num_matches = module_sp->FindTypes (sc,
555 name,
556 exact_match,
557 UINT32_MAX,
558 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000559
Greg Claytonb43165b2012-12-05 21:24:42 +0000560 if (num_matches > 0)
Greg Claytonfe42ac42011-08-03 22:57:10 +0000561 {
Greg Claytonb43165b2012-12-05 21:24:42 +0000562 for (size_t idx = 0; idx < num_matches; idx++)
563 {
564 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
565 if (type_sp)
566 retval.Append(SBType(type_sp));
567 }
568 }
569 else
570 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000571 SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Greg Claytonb43165b2012-12-05 21:24:42 +0000572 if (sb_type.IsValid())
573 retval.Append(sb_type);
Greg Claytonfe42ac42011-08-03 22:57:10 +0000574 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000575 }
576
577 return retval;
Greg Clayton3418c852011-08-10 02:10:13 +0000578}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000579
Greg Clayton1f4db7d2014-01-23 21:38:34 +0000580lldb::SBType
581SBModule::GetTypeByID (lldb::user_id_t uid)
582{
583 ModuleSP module_sp (GetSP ());
584 if (module_sp)
585 {
586 SymbolVendor* vendor = module_sp->GetSymbolVendor();
587 if (vendor)
588 {
589 Type *type_ptr = vendor->ResolveTypeUID(uid);
590 if (type_ptr)
591 return SBType(type_ptr->shared_from_this());
592 }
593 }
594 return SBType();
595}
596
Greg Claytonf02500c2013-06-18 22:51:05 +0000597lldb::SBTypeList
598SBModule::GetTypes (uint32_t type_mask)
599{
600 SBTypeList sb_type_list;
601
602 ModuleSP module_sp (GetSP ());
603 if (module_sp)
604 {
605 SymbolVendor* vendor = module_sp->GetSymbolVendor();
606 if (vendor)
607 {
608 TypeList type_list;
609 vendor->GetTypes (NULL, type_mask, type_list);
610 sb_type_list.m_opaque_ap->Append(type_list);
611 }
612 }
613 return sb_type_list;
614}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000615
616SBSection
617SBModule::FindSection (const char *sect_name)
618{
619 SBSection sb_section;
620
Greg Claytonc2ff9312012-02-22 19:41:02 +0000621 ModuleSP module_sp (GetSP ());
622 if (sect_name && module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000623 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000624 // Give the symbol vendor a chance to add to the unified section list.
625 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000626 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000627 if (section_list)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000628 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000629 ConstString const_sect_name(sect_name);
630 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
631 if (section_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000632 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000633 sb_section.SetSP (section_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000634 }
635 }
636 }
637 return sb_section;
638}
639
Greg Clayton13d19502012-01-29 06:07:39 +0000640lldb::ByteOrder
641SBModule::GetByteOrder ()
642{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000643 ModuleSP module_sp (GetSP ());
644 if (module_sp)
645 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +0000646 return eByteOrderInvalid;
647}
648
649const char *
650SBModule::GetTriple ()
651{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000652 ModuleSP module_sp (GetSP ());
653 if (module_sp)
Greg Clayton13d19502012-01-29 06:07:39 +0000654 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000655 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +0000656 // Unique the string so we don't run into ownership issues since
657 // the const strings put the string into the string pool once and
658 // the strings never comes out
659 ConstString const_triple (triple.c_str());
660 return const_triple.GetCString();
661 }
662 return NULL;
663}
664
665uint32_t
666SBModule::GetAddressByteSize()
667{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000668 ModuleSP module_sp (GetSP ());
669 if (module_sp)
670 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +0000671 return sizeof(void*);
672}
673
Greg Claytonc2ff9312012-02-22 19:41:02 +0000674
675uint32_t
676SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
677{
678 ModuleSP module_sp (GetSP ());
679 if (module_sp)
Enrico Granata3467d802012-09-04 18:47:54 +0000680 return module_sp->GetVersion(versions, num_versions);
681 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000682 {
Enrico Granata3467d802012-09-04 18:47:54 +0000683 if (versions && num_versions)
684 {
685 for (uint32_t i=0; i<num_versions; ++i)
686 versions[i] = UINT32_MAX;
687 }
688 return 0;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000689 }
Greg Claytonc2ff9312012-02-22 19:41:02 +0000690}
691