blob: 390ca64e6c16b5f5e26c1d3b91caae7d2654a21e [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;
72 m_opaque_sp->SetLoadAddress(target, 0, changed);
73 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
165
166
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167const uint8_t *
168SBModule::GetUUIDBytes () const
169{
Greg Clayton5160ce52013-03-27 23:08:40 +0000170 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000171
Greg Clayton48381312010-10-30 04:51:46 +0000172 const uint8_t *uuid_bytes = NULL;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000173 ModuleSP module_sp (GetSP ());
174 if (module_sp)
175 uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000176
177 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000178 {
179 if (uuid_bytes)
180 {
181 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000182 module_sp->GetUUID().Dump (&s);
183 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData());
Greg Clayton48381312010-10-30 04:51:46 +0000184 }
185 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000186 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get());
Greg Clayton48381312010-10-30 04:51:46 +0000187 }
188 return uuid_bytes;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
191
Johnny Chendf2963e2011-04-01 00:35:55 +0000192const char *
193SBModule::GetUUIDString () const
194{
Greg Clayton5160ce52013-03-27 23:08:40 +0000195 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chendf2963e2011-04-01 00:35:55 +0000196
Jason Molendac16b4af2013-05-03 23:56:12 +0000197 static char uuid_string_buffer[80];
198 const char *uuid_c_string = NULL;
199 std::string uuid_string;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000200 ModuleSP module_sp (GetSP ());
201 if (module_sp)
Jason Molendac16b4af2013-05-03 23:56:12 +0000202 uuid_string = module_sp->GetUUID().GetAsString();
203
204 if (!uuid_string.empty())
205 {
206 strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer));
207 uuid_c_string = uuid_string_buffer;
208 }
Johnny Chendf2963e2011-04-01 00:35:55 +0000209
210 if (log)
211 {
Jason Molendac16b4af2013-05-03 23:56:12 +0000212 if (!uuid_string.empty())
Johnny Chendf2963e2011-04-01 00:35:55 +0000213 {
214 StreamString s;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000215 module_sp->GetUUID().Dump (&s);
216 log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData());
Johnny Chendf2963e2011-04-01 00:35:55 +0000217 }
218 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000219 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get());
Johnny Chendf2963e2011-04-01 00:35:55 +0000220 }
221 return uuid_c_string;
222}
223
224
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225bool
226SBModule::operator == (const SBModule &rhs) const
227{
Greg Clayton66111032010-06-23 01:19:29 +0000228 if (m_opaque_sp)
229 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230 return false;
231}
232
233bool
234SBModule::operator != (const SBModule &rhs) const
235{
Greg Clayton66111032010-06-23 01:19:29 +0000236 if (m_opaque_sp)
237 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238 return false;
239}
240
Greg Claytonacdbe812012-01-30 09:04:36 +0000241ModuleSP
242SBModule::GetSP () const
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000243{
244 return m_opaque_sp;
245}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246
247void
Greg Claytonacdbe812012-01-30 09:04:36 +0000248SBModule::SetSP (const ModuleSP &module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249{
Greg Clayton66111032010-06-23 01:19:29 +0000250 m_opaque_sp = module_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251}
252
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000253SBAddress
254SBModule::ResolveFileAddress (lldb::addr_t vm_addr)
Greg Clayton09960032010-09-10 18:31:35 +0000255{
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000256 lldb::SBAddress sb_addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000257 ModuleSP module_sp (GetSP ());
258 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000259 {
260 Address addr;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000261 if (module_sp->ResolveFileAddress (vm_addr, addr))
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000262 sb_addr.ref() = addr;
263 }
264 return sb_addr;
Greg Clayton09960032010-09-10 18:31:35 +0000265}
266
267SBSymbolContext
268SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
269{
270 SBSymbolContext sb_sc;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000271 ModuleSP module_sp (GetSP ());
272 if (module_sp && addr.IsValid())
273 module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc);
Greg Clayton09960032010-09-10 18:31:35 +0000274 return sb_sc;
275}
276
Caroline Ticedde9cff2010-09-20 05:20:02 +0000277bool
278SBModule::GetDescription (SBStream &description)
279{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000280 Stream &strm = description.ref();
281
Greg Claytonc2ff9312012-02-22 19:41:02 +0000282 ModuleSP module_sp (GetSP ());
283 if (module_sp)
Caroline Ticedde9cff2010-09-20 05:20:02 +0000284 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000285 module_sp->GetDescription (&strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +0000286 }
287 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000288 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000289
290 return true;
291}
Greg Claytonbbdabce2010-12-07 05:40:31 +0000292
Johnny Chen873a7a42012-03-16 20:46:10 +0000293uint32_t
294SBModule::GetNumCompileUnits()
295{
296 ModuleSP module_sp (GetSP ());
297 if (module_sp)
298 {
299 return module_sp->GetNumCompileUnits ();
300 }
301 return 0;
302}
303
304SBCompileUnit
305SBModule::GetCompileUnitAtIndex (uint32_t index)
306{
307 SBCompileUnit sb_cu;
308 ModuleSP module_sp (GetSP ());
309 if (module_sp)
310 {
311 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index);
312 sb_cu.reset(cu_sp.get());
313 }
314 return sb_cu;
315}
316
Michael Sartaina7499c92013-07-01 19:45:50 +0000317static Symtab *
318GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp)
319{
320 if (module_sp)
321 {
322 SymbolVendor *symbols = module_sp->GetSymbolVendor();
323 if (symbols)
324 return symbols->GetSymtab();
325 }
326 return NULL;
327}
328
Greg Claytonbbdabce2010-12-07 05:40:31 +0000329size_t
330SBModule::GetNumSymbols ()
331{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000332 ModuleSP module_sp (GetSP ());
333 if (module_sp)
Greg Claytonbbdabce2010-12-07 05:40:31 +0000334 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000335 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
336 if (symtab)
337 return symtab->GetNumSymbols();
Greg Claytonbbdabce2010-12-07 05:40:31 +0000338 }
339 return 0;
340}
341
342SBSymbol
343SBModule::GetSymbolAtIndex (size_t idx)
344{
345 SBSymbol sb_symbol;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000346 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000347 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
348 if (symtab)
349 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
Greg Claytonbbdabce2010-12-07 05:40:31 +0000350 return sb_symbol;
351}
Greg Claytonfe356d32011-06-21 01:34:41 +0000352
Greg Claytone14e1922012-12-04 02:22:16 +0000353lldb::SBSymbol
354SBModule::FindSymbol (const char *name,
355 lldb::SymbolType symbol_type)
356{
357 SBSymbol sb_symbol;
358 if (name && name[0])
359 {
360 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000361 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
362 if (symtab)
363 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
Greg Claytone14e1922012-12-04 02:22:16 +0000364 }
365 return sb_symbol;
366}
367
368
369lldb::SBSymbolContextList
370SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
371{
372 SBSymbolContextList sb_sc_list;
373 if (name && name[0])
374 {
375 ModuleSP module_sp (GetSP ());
Michael Sartaina7499c92013-07-01 19:45:50 +0000376 Symtab *symtab = GetUnifiedSymbolTable (module_sp);
377 if (symtab)
Greg Claytone14e1922012-12-04 02:22:16 +0000378 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000379 std::vector<uint32_t> matching_symbol_indexes;
380 const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
381 if (num_matches)
Greg Claytone14e1922012-12-04 02:22:16 +0000382 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000383 SymbolContext sc;
384 sc.module_sp = module_sp;
385 SymbolContextList &sc_list = *sb_sc_list;
386 for (size_t i=0; i<num_matches; ++i)
Greg Claytone14e1922012-12-04 02:22:16 +0000387 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000388 sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
389 if (sc.symbol)
390 sc_list.Append(sc);
Greg Claytone14e1922012-12-04 02:22:16 +0000391 }
392 }
393 }
394 }
395 return sb_sc_list;
396
397}
398
399
400
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000401size_t
402SBModule::GetNumSections ()
403{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000404 ModuleSP module_sp (GetSP ());
405 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000406 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000407 // Give the symbol vendor a chance to add to the unified section list.
408 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000409 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000410 if (section_list)
411 return section_list->GetSize();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000412 }
413 return 0;
414}
415
416SBSection
417SBModule::GetSectionAtIndex (size_t idx)
418{
419 SBSection sb_section;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000420 ModuleSP module_sp (GetSP ());
421 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000422 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000423 // Give the symbol vendor a chance to add to the unified section list.
424 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000425 SectionList *section_list = module_sp->GetSectionList ();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000426
Michael Sartaina7499c92013-07-01 19:45:50 +0000427 if (section_list)
428 sb_section.SetSP(section_list->GetSectionAtIndex (idx));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000429 }
430 return sb_section;
431}
432
Greg Clayton5569e642012-02-06 01:44:54 +0000433lldb::SBSymbolContextList
Greg Claytonfe356d32011-06-21 01:34:41 +0000434SBModule::FindFunctions (const char *name,
Greg Clayton5569e642012-02-06 01:44:54 +0000435 uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +0000436{
Greg Clayton5569e642012-02-06 01:44:54 +0000437 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000438 ModuleSP module_sp (GetSP ());
439 if (name && module_sp)
Greg Claytonfe356d32011-06-21 01:34:41 +0000440 {
Greg Clayton5569e642012-02-06 01:44:54 +0000441 const bool append = true;
Greg Claytonfe356d32011-06-21 01:34:41 +0000442 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +0000443 const bool inlines_ok = true;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000444 module_sp->FindFunctions (ConstString(name),
445 NULL,
446 name_type_mask,
447 symbols_ok,
448 inlines_ok,
449 append,
450 *sb_sc_list);
Greg Claytonfe356d32011-06-21 01:34:41 +0000451 }
Greg Clayton5569e642012-02-06 01:44:54 +0000452 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +0000453}
454
Greg Claytondea8cb42011-06-29 22:09:02 +0000455
456SBValueList
457SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
458{
459 SBValueList sb_value_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000460 ModuleSP module_sp (GetSP ());
461 if (name && module_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +0000462 {
463 VariableList variable_list;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000464 const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name),
465 NULL,
466 false,
467 max_matches,
468 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +0000469
470 if (match_count > 0)
471 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000472 for (uint32_t i=0; i<match_count; ++i)
473 {
474 lldb::ValueObjectSP valobj_sp;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000475 TargetSP target_sp (target.GetSP());
476 valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
Greg Claytondea8cb42011-06-29 22:09:02 +0000477 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +0000478 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +0000479 }
480 }
481 }
482
483 return sb_value_list;
484}
Enrico Granata6f3533f2011-07-29 19:53:35 +0000485
Enrico Granatabcd80b42013-01-16 18:53:52 +0000486lldb::SBValue
487SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name)
488{
489 SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
490 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
491 return sb_value_list.GetValueAtIndex(0);
492 return SBValue();
493}
494
Enrico Granata6f3533f2011-07-29 19:53:35 +0000495lldb::SBType
Johnny Chen4efffd92011-12-19 20:16:22 +0000496SBModule::FindFirstType (const char *name_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000497{
Greg Claytonfe42ac42011-08-03 22:57:10 +0000498 SBType sb_type;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000499 ModuleSP module_sp (GetSP ());
500 if (name_cstr && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000501 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000502 SymbolContext sc;
Greg Clayton84db9102012-03-26 23:03:23 +0000503 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000504 ConstString name(name_cstr);
505
Greg Claytonb43165b2012-12-05 21:24:42 +0000506 sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match));
Greg Claytonfe42ac42011-08-03 22:57:10 +0000507
Greg Claytonb43165b2012-12-05 21:24:42 +0000508 if (!sb_type.IsValid())
509 sb_type = SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000510 }
Greg Claytonfe42ac42011-08-03 22:57:10 +0000511 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000512}
513
Greg Claytonb43165b2012-12-05 21:24:42 +0000514lldb::SBType
515SBModule::GetBasicType(lldb::BasicType type)
516{
517 ModuleSP module_sp (GetSP ());
518 if (module_sp)
519 return SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type));
520 return SBType();
521}
522
Enrico Granata6f3533f2011-07-29 19:53:35 +0000523lldb::SBTypeList
Johnny Chen4efffd92011-12-19 20:16:22 +0000524SBModule::FindTypes (const char *type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000525{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000526 SBTypeList retval;
527
Greg Claytonc2ff9312012-02-22 19:41:02 +0000528 ModuleSP module_sp (GetSP ());
529 if (type && module_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000530 {
Greg Claytonfe42ac42011-08-03 22:57:10 +0000531 SymbolContext sc;
532 TypeList type_list;
Greg Clayton84db9102012-03-26 23:03:23 +0000533 const bool exact_match = false;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000534 ConstString name(type);
Greg Claytonb43165b2012-12-05 21:24:42 +0000535 const uint32_t num_matches = module_sp->FindTypes (sc,
536 name,
537 exact_match,
538 UINT32_MAX,
539 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000540
Greg Claytonb43165b2012-12-05 21:24:42 +0000541 if (num_matches > 0)
Greg Claytonfe42ac42011-08-03 22:57:10 +0000542 {
Greg Claytonb43165b2012-12-05 21:24:42 +0000543 for (size_t idx = 0; idx < num_matches; idx++)
544 {
545 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
546 if (type_sp)
547 retval.Append(SBType(type_sp));
548 }
549 }
550 else
551 {
552 SBType sb_type(ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
553 if (sb_type.IsValid())
554 retval.Append(sb_type);
Greg Claytonfe42ac42011-08-03 22:57:10 +0000555 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000556 }
557
558 return retval;
Greg Clayton3418c852011-08-10 02:10:13 +0000559}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000560
Greg Claytonf02500c2013-06-18 22:51:05 +0000561lldb::SBTypeList
562SBModule::GetTypes (uint32_t type_mask)
563{
564 SBTypeList sb_type_list;
565
566 ModuleSP module_sp (GetSP ());
567 if (module_sp)
568 {
569 SymbolVendor* vendor = module_sp->GetSymbolVendor();
570 if (vendor)
571 {
572 TypeList type_list;
573 vendor->GetTypes (NULL, type_mask, type_list);
574 sb_type_list.m_opaque_ap->Append(type_list);
575 }
576 }
577 return sb_type_list;
578}
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000579
580SBSection
581SBModule::FindSection (const char *sect_name)
582{
583 SBSection sb_section;
584
Greg Claytonc2ff9312012-02-22 19:41:02 +0000585 ModuleSP module_sp (GetSP ());
586 if (sect_name && module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000587 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000588 // Give the symbol vendor a chance to add to the unified section list.
589 module_sp->GetSymbolVendor();
Greg Clayton3046e662013-07-10 01:23:25 +0000590 SectionList *section_list = module_sp->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +0000591 if (section_list)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000592 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000593 ConstString const_sect_name(sect_name);
594 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
595 if (section_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000596 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000597 sb_section.SetSP (section_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000598 }
599 }
600 }
601 return sb_section;
602}
603
Greg Clayton13d19502012-01-29 06:07:39 +0000604lldb::ByteOrder
605SBModule::GetByteOrder ()
606{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000607 ModuleSP module_sp (GetSP ());
608 if (module_sp)
609 return module_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +0000610 return eByteOrderInvalid;
611}
612
613const char *
614SBModule::GetTriple ()
615{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000616 ModuleSP module_sp (GetSP ());
617 if (module_sp)
Greg Clayton13d19502012-01-29 06:07:39 +0000618 {
Greg Claytonc2ff9312012-02-22 19:41:02 +0000619 std::string triple (module_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +0000620 // Unique the string so we don't run into ownership issues since
621 // the const strings put the string into the string pool once and
622 // the strings never comes out
623 ConstString const_triple (triple.c_str());
624 return const_triple.GetCString();
625 }
626 return NULL;
627}
628
629uint32_t
630SBModule::GetAddressByteSize()
631{
Greg Claytonc2ff9312012-02-22 19:41:02 +0000632 ModuleSP module_sp (GetSP ());
633 if (module_sp)
634 return module_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +0000635 return sizeof(void*);
636}
637
Greg Claytonc2ff9312012-02-22 19:41:02 +0000638
639uint32_t
640SBModule::GetVersion (uint32_t *versions, uint32_t num_versions)
641{
642 ModuleSP module_sp (GetSP ());
643 if (module_sp)
Enrico Granata3467d802012-09-04 18:47:54 +0000644 return module_sp->GetVersion(versions, num_versions);
645 else
Greg Claytonc2ff9312012-02-22 19:41:02 +0000646 {
Enrico Granata3467d802012-09-04 18:47:54 +0000647 if (versions && num_versions)
648 {
649 for (uint32_t i=0; i<num_versions; ++i)
650 versions[i] = UINT32_MAX;
651 }
652 return 0;
Greg Claytonc2ff9312012-02-22 19:41:02 +0000653 }
Greg Claytonc2ff9312012-02-22 19:41:02 +0000654}
655