blob: 53172f349cabd7c8ec24b683890b0f28c3cdb70c [file] [log] [blame]
Chris Lattner24943d22010-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 Clayton466f6c42010-09-10 18:31:35 +000011#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000014#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/Module.h"
Caroline Tice7826c882010-10-26 03:11:13 +000016#include "lldb/Core/Log.h"
Greg Clayton135adf22010-10-31 19:57:43 +000017#include "lldb/Core/StreamString.h"
Greg Clayton917c0002011-06-29 22:09:02 +000018#include "lldb/Core/ValueObjectList.h"
19#include "lldb/Core/ValueObjectVariable.h"
20#include "lldb/Symbol/VariableList.h"
21#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022
23using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000024using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000025
26
27SBModule::SBModule () :
Greg Clayton63094e02010-06-23 01:19:29 +000028 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000029{
30}
31
32SBModule::SBModule (const lldb::ModuleSP& module_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000033 m_opaque_sp (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000034{
35}
36
Greg Clayton538eb822010-11-05 23:17:00 +000037SBModule::SBModule(const SBModule &rhs) :
38 m_opaque_sp (rhs.m_opaque_sp)
39{
40}
41
42const SBModule &
43SBModule::operator = (const SBModule &rhs)
44{
45 if (this != &rhs)
46 m_opaque_sp = rhs.m_opaque_sp;
47 return *this;
48}
49
Chris Lattner24943d22010-06-08 16:52:24 +000050SBModule::~SBModule ()
51{
52}
53
54bool
55SBModule::IsValid () const
56{
Greg Clayton63094e02010-06-23 01:19:29 +000057 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
60SBFileSpec
61SBModule::GetFileSpec () const
62{
Greg Claytone005f2c2010-11-06 01:53:30 +000063 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000064
Chris Lattner24943d22010-06-08 16:52:24 +000065 SBFileSpec file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +000066 if (m_opaque_sp)
67 file_spec.SetFileSpec(m_opaque_sp->GetFileSpec());
Caroline Tice7826c882010-10-26 03:11:13 +000068
69 if (log)
70 {
Greg Clayton49ce6822010-10-31 03:01:06 +000071 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
72 m_opaque_sp.get(), file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +000073 }
74
Chris Lattner24943d22010-06-08 16:52:24 +000075 return file_spec;
76}
77
Greg Clayton180546b2011-04-30 01:09:13 +000078lldb::SBFileSpec
79SBModule::GetPlatformFileSpec () const
80{
81 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
82
83 SBFileSpec file_spec;
84 if (m_opaque_sp)
85 file_spec.SetFileSpec(m_opaque_sp->GetPlatformFileSpec());
86
87 if (log)
88 {
89 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
90 m_opaque_sp.get(), file_spec.get());
91 }
92
93 return file_spec;
94
95}
96
97bool
98SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
99{
100 bool result = false;
101 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
102
103 if (m_opaque_sp)
104 {
105 m_opaque_sp->SetPlatformFileSpec(*platform_file);
106 result = true;
107 }
108
109 if (log)
110 {
111 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i",
112 m_opaque_sp.get(),
113 platform_file.get(),
114 platform_file->GetDirectory().GetCString(),
115 platform_file->GetDirectory() ? "/" : "",
116 platform_file->GetFilename().GetCString(),
117 result);
118 }
119 return result;
120}
121
122
123
Chris Lattner24943d22010-06-08 16:52:24 +0000124const uint8_t *
125SBModule::GetUUIDBytes () const
126{
Greg Claytone005f2c2010-11-06 01:53:30 +0000127 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000128
Greg Claytona66ba462010-10-30 04:51:46 +0000129 const uint8_t *uuid_bytes = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000130 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000131 uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +0000132
133 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000134 {
135 if (uuid_bytes)
136 {
137 StreamString s;
138 m_opaque_sp->GetUUID().Dump (&s);
139 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData());
140 }
141 else
142 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get());
143 }
144 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +0000145}
146
147
Johnny Chen919ee602011-04-01 00:35:55 +0000148const char *
149SBModule::GetUUIDString () const
150{
151 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
152
153 static char uuid_string[80];
154 const char * uuid_c_string = NULL;
155 if (m_opaque_sp)
156 uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
157
158 if (log)
159 {
160 if (uuid_c_string)
161 {
162 StreamString s;
163 m_opaque_sp->GetUUID().Dump (&s);
164 log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData());
165 }
166 else
167 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get());
168 }
169 return uuid_c_string;
170}
171
172
Chris Lattner24943d22010-06-08 16:52:24 +0000173bool
174SBModule::operator == (const SBModule &rhs) const
175{
Greg Clayton63094e02010-06-23 01:19:29 +0000176 if (m_opaque_sp)
177 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000178 return false;
179}
180
181bool
182SBModule::operator != (const SBModule &rhs) const
183{
Greg Clayton63094e02010-06-23 01:19:29 +0000184 if (m_opaque_sp)
185 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000186 return false;
187}
188
189lldb::ModuleSP &
190SBModule::operator *()
191{
Greg Clayton63094e02010-06-23 01:19:29 +0000192 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000193}
194
195lldb_private::Module *
196SBModule::operator ->()
197{
Greg Clayton63094e02010-06-23 01:19:29 +0000198 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000199}
200
201const lldb_private::Module *
202SBModule::operator ->() const
203{
Greg Clayton63094e02010-06-23 01:19:29 +0000204 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000205}
206
207lldb_private::Module *
208SBModule::get()
209{
Greg Clayton63094e02010-06-23 01:19:29 +0000210 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000211}
212
213const lldb_private::Module *
214SBModule::get() const
215{
Greg Clayton63094e02010-06-23 01:19:29 +0000216 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000217}
218
219
220void
221SBModule::SetModule (const lldb::ModuleSP& module_sp)
222{
Greg Clayton63094e02010-06-23 01:19:29 +0000223 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000224}
225
Greg Clayton466f6c42010-09-10 18:31:35 +0000226
227bool
228SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
229{
Johnny Chenb7a9d642011-06-28 22:32:15 +0000230 if (m_opaque_sp && addr.IsValid())
Greg Clayton466f6c42010-09-10 18:31:35 +0000231 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
232
Johnny Chenb7a9d642011-06-28 22:32:15 +0000233 if (addr.IsValid())
234 addr->Clear();
Greg Clayton466f6c42010-09-10 18:31:35 +0000235 return false;
236}
237
238SBSymbolContext
239SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
240{
241 SBSymbolContext sb_sc;
242 if (m_opaque_sp && addr.IsValid())
243 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
244 return sb_sc;
245}
246
Caroline Tice98f930f2010-09-20 05:20:02 +0000247bool
248SBModule::GetDescription (SBStream &description)
249{
250 if (m_opaque_sp)
251 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000252 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000253 m_opaque_sp->GetDescription (description.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000254 }
255 else
256 description.Printf ("No value");
257
258 return true;
259}
Greg Clayton43edca32010-12-07 05:40:31 +0000260
261size_t
262SBModule::GetNumSymbols ()
263{
264 if (m_opaque_sp)
265 {
266 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
267 if (obj_file)
268 {
269 Symtab *symtab = obj_file->GetSymtab();
270 if (symtab)
271 return symtab->GetNumSymbols();
272 }
273 }
274 return 0;
275}
276
277SBSymbol
278SBModule::GetSymbolAtIndex (size_t idx)
279{
280 SBSymbol sb_symbol;
281 if (m_opaque_sp)
282 {
283 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
284 if (obj_file)
285 {
286 Symtab *symtab = obj_file->GetSymtab();
287 if (symtab)
288 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
289 }
290 }
291 return sb_symbol;
292}
Greg Clayton4ed315f2011-06-21 01:34:41 +0000293
294uint32_t
295SBModule::FindFunctions (const char *name,
296 uint32_t name_type_mask,
297 bool append,
298 lldb::SBSymbolContextList& sc_list)
299{
300 if (!append)
301 sc_list.Clear();
302 if (m_opaque_sp)
303 {
304 const bool symbols_ok = true;
305 return m_opaque_sp->FindFunctions (ConstString(name),
306 name_type_mask,
307 symbols_ok,
308 append,
309 *sc_list);
310 }
311 return 0;
312}
313
Greg Clayton917c0002011-06-29 22:09:02 +0000314
315SBValueList
316SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
317{
318 SBValueList sb_value_list;
319 if (m_opaque_sp)
320 {
321 VariableList variable_list;
322 const uint32_t match_count = m_opaque_sp->FindGlobalVariables (ConstString (name),
323 false,
324 max_matches,
325 variable_list);
326
327 if (match_count > 0)
328 {
329 ValueObjectList &value_object_list = sb_value_list.ref();
330 for (uint32_t i=0; i<match_count; ++i)
331 {
332 lldb::ValueObjectSP valobj_sp;
333 if (target.IsValid())
334 valobj_sp = ValueObjectVariable::Create (target.get(), variable_list.GetVariableAtIndex(i));
335 else
336 valobj_sp = ValueObjectVariable::Create (NULL, variable_list.GetVariableAtIndex(i));
337 if (valobj_sp)
338 value_object_list.Append(valobj_sp);
339 }
340 }
341 }
342
343 return sb_value_list;
344}