blob: 0c4eba43e56f8fb9c2cdf792c5ee8a84d65ac27f [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"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000020using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000021
22
23SBModule::SBModule () :
Greg Clayton63094e02010-06-23 01:19:29 +000024 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000025{
26}
27
28SBModule::SBModule (const lldb::ModuleSP& module_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000029 m_opaque_sp (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000030{
31}
32
Greg Clayton538eb822010-11-05 23:17:00 +000033SBModule::SBModule(const SBModule &rhs) :
34 m_opaque_sp (rhs.m_opaque_sp)
35{
36}
37
38const SBModule &
39SBModule::operator = (const SBModule &rhs)
40{
41 if (this != &rhs)
42 m_opaque_sp = rhs.m_opaque_sp;
43 return *this;
44}
45
Chris Lattner24943d22010-06-08 16:52:24 +000046SBModule::~SBModule ()
47{
48}
49
50bool
51SBModule::IsValid () const
52{
Greg Clayton63094e02010-06-23 01:19:29 +000053 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000054}
55
56SBFileSpec
57SBModule::GetFileSpec () const
58{
Greg Claytone005f2c2010-11-06 01:53:30 +000059 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000060
Chris Lattner24943d22010-06-08 16:52:24 +000061 SBFileSpec file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +000062 if (m_opaque_sp)
63 file_spec.SetFileSpec(m_opaque_sp->GetFileSpec());
Caroline Tice7826c882010-10-26 03:11:13 +000064
65 if (log)
66 {
Greg Clayton49ce6822010-10-31 03:01:06 +000067 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
68 m_opaque_sp.get(), file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +000069 }
70
Chris Lattner24943d22010-06-08 16:52:24 +000071 return file_spec;
72}
73
Greg Clayton180546b2011-04-30 01:09:13 +000074lldb::SBFileSpec
75SBModule::GetPlatformFileSpec () const
76{
77 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
78
79 SBFileSpec file_spec;
80 if (m_opaque_sp)
81 file_spec.SetFileSpec(m_opaque_sp->GetPlatformFileSpec());
82
83 if (log)
84 {
85 log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
86 m_opaque_sp.get(), file_spec.get());
87 }
88
89 return file_spec;
90
91}
92
93bool
94SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file)
95{
96 bool result = false;
97 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
98
99 if (m_opaque_sp)
100 {
101 m_opaque_sp->SetPlatformFileSpec(*platform_file);
102 result = true;
103 }
104
105 if (log)
106 {
107 log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i",
108 m_opaque_sp.get(),
109 platform_file.get(),
110 platform_file->GetDirectory().GetCString(),
111 platform_file->GetDirectory() ? "/" : "",
112 platform_file->GetFilename().GetCString(),
113 result);
114 }
115 return result;
116}
117
118
119
Chris Lattner24943d22010-06-08 16:52:24 +0000120const uint8_t *
121SBModule::GetUUIDBytes () const
122{
Greg Claytone005f2c2010-11-06 01:53:30 +0000123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000124
Greg Claytona66ba462010-10-30 04:51:46 +0000125 const uint8_t *uuid_bytes = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000126 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000127 uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +0000128
129 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000130 {
131 if (uuid_bytes)
132 {
133 StreamString s;
134 m_opaque_sp->GetUUID().Dump (&s);
135 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData());
136 }
137 else
138 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get());
139 }
140 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +0000141}
142
143
Johnny Chen919ee602011-04-01 00:35:55 +0000144const char *
145SBModule::GetUUIDString () const
146{
147 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
148
149 static char uuid_string[80];
150 const char * uuid_c_string = NULL;
151 if (m_opaque_sp)
152 uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
153
154 if (log)
155 {
156 if (uuid_c_string)
157 {
158 StreamString s;
159 m_opaque_sp->GetUUID().Dump (&s);
160 log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData());
161 }
162 else
163 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get());
164 }
165 return uuid_c_string;
166}
167
168
Chris Lattner24943d22010-06-08 16:52:24 +0000169bool
170SBModule::operator == (const SBModule &rhs) const
171{
Greg Clayton63094e02010-06-23 01:19:29 +0000172 if (m_opaque_sp)
173 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000174 return false;
175}
176
177bool
178SBModule::operator != (const SBModule &rhs) const
179{
Greg Clayton63094e02010-06-23 01:19:29 +0000180 if (m_opaque_sp)
181 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000182 return false;
183}
184
185lldb::ModuleSP &
186SBModule::operator *()
187{
Greg Clayton63094e02010-06-23 01:19:29 +0000188 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000189}
190
191lldb_private::Module *
192SBModule::operator ->()
193{
Greg Clayton63094e02010-06-23 01:19:29 +0000194 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000195}
196
197const lldb_private::Module *
198SBModule::operator ->() const
199{
Greg Clayton63094e02010-06-23 01:19:29 +0000200 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000201}
202
203lldb_private::Module *
204SBModule::get()
205{
Greg Clayton63094e02010-06-23 01:19:29 +0000206 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000207}
208
209const lldb_private::Module *
210SBModule::get() const
211{
Greg Clayton63094e02010-06-23 01:19:29 +0000212 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000213}
214
215
216void
217SBModule::SetModule (const lldb::ModuleSP& module_sp)
218{
Greg Clayton63094e02010-06-23 01:19:29 +0000219 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000220}
221
Greg Clayton466f6c42010-09-10 18:31:35 +0000222
223bool
224SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
225{
Johnny Chenb7a9d642011-06-28 22:32:15 +0000226 if (m_opaque_sp && addr.IsValid())
Greg Clayton466f6c42010-09-10 18:31:35 +0000227 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
228
Johnny Chenb7a9d642011-06-28 22:32:15 +0000229 if (addr.IsValid())
230 addr->Clear();
Greg Clayton466f6c42010-09-10 18:31:35 +0000231 return false;
232}
233
234SBSymbolContext
235SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
236{
237 SBSymbolContext sb_sc;
238 if (m_opaque_sp && addr.IsValid())
239 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
240 return sb_sc;
241}
242
Caroline Tice98f930f2010-09-20 05:20:02 +0000243bool
244SBModule::GetDescription (SBStream &description)
245{
246 if (m_opaque_sp)
247 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000248 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000249 m_opaque_sp->GetDescription (description.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000250 }
251 else
252 description.Printf ("No value");
253
254 return true;
255}
Greg Clayton43edca32010-12-07 05:40:31 +0000256
257size_t
258SBModule::GetNumSymbols ()
259{
260 if (m_opaque_sp)
261 {
262 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
263 if (obj_file)
264 {
265 Symtab *symtab = obj_file->GetSymtab();
266 if (symtab)
267 return symtab->GetNumSymbols();
268 }
269 }
270 return 0;
271}
272
273SBSymbol
274SBModule::GetSymbolAtIndex (size_t idx)
275{
276 SBSymbol sb_symbol;
277 if (m_opaque_sp)
278 {
279 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
280 if (obj_file)
281 {
282 Symtab *symtab = obj_file->GetSymtab();
283 if (symtab)
284 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
285 }
286 }
287 return sb_symbol;
288}
Greg Clayton4ed315f2011-06-21 01:34:41 +0000289
290uint32_t
291SBModule::FindFunctions (const char *name,
292 uint32_t name_type_mask,
293 bool append,
294 lldb::SBSymbolContextList& sc_list)
295{
296 if (!append)
297 sc_list.Clear();
298 if (m_opaque_sp)
299 {
300 const bool symbols_ok = true;
301 return m_opaque_sp->FindFunctions (ConstString(name),
302 name_type_mask,
303 symbols_ok,
304 append,
305 *sc_list);
306 }
307 return 0;
308}
309