blob: e7e95be1e8bd5febf6e714a4d49f14b389c11aef [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"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.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
74const uint8_t *
75SBModule::GetUUIDBytes () const
76{
Greg Claytone005f2c2010-11-06 01:53:30 +000077 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000078
Greg Claytona66ba462010-10-30 04:51:46 +000079 const uint8_t *uuid_bytes = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000080 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +000081 uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +000082
83 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +000084 {
85 if (uuid_bytes)
86 {
87 StreamString s;
88 m_opaque_sp->GetUUID().Dump (&s);
89 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData());
90 }
91 else
92 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get());
93 }
94 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +000095}
96
97
Johnny Chen919ee602011-04-01 00:35:55 +000098const char *
99SBModule::GetUUIDString () const
100{
101 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
102
103 static char uuid_string[80];
104 const char * uuid_c_string = NULL;
105 if (m_opaque_sp)
106 uuid_c_string = (const char *)m_opaque_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
107
108 if (log)
109 {
110 if (uuid_c_string)
111 {
112 StreamString s;
113 m_opaque_sp->GetUUID().Dump (&s);
114 log->Printf ("SBModule(%p)::GetUUIDString () => %s", m_opaque_sp.get(), s.GetData());
115 }
116 else
117 log->Printf ("SBModule(%p)::GetUUIDString () => NULL", m_opaque_sp.get());
118 }
119 return uuid_c_string;
120}
121
122
Chris Lattner24943d22010-06-08 16:52:24 +0000123bool
124SBModule::operator == (const SBModule &rhs) const
125{
Greg Clayton63094e02010-06-23 01:19:29 +0000126 if (m_opaque_sp)
127 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000128 return false;
129}
130
131bool
132SBModule::operator != (const SBModule &rhs) const
133{
Greg Clayton63094e02010-06-23 01:19:29 +0000134 if (m_opaque_sp)
135 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000136 return false;
137}
138
139lldb::ModuleSP &
140SBModule::operator *()
141{
Greg Clayton63094e02010-06-23 01:19:29 +0000142 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000143}
144
145lldb_private::Module *
146SBModule::operator ->()
147{
Greg Clayton63094e02010-06-23 01:19:29 +0000148 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000149}
150
151const lldb_private::Module *
152SBModule::operator ->() const
153{
Greg Clayton63094e02010-06-23 01:19:29 +0000154 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000155}
156
157lldb_private::Module *
158SBModule::get()
159{
Greg Clayton63094e02010-06-23 01:19:29 +0000160 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000161}
162
163const lldb_private::Module *
164SBModule::get() const
165{
Greg Clayton63094e02010-06-23 01:19:29 +0000166 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000167}
168
169
170void
171SBModule::SetModule (const lldb::ModuleSP& module_sp)
172{
Greg Clayton63094e02010-06-23 01:19:29 +0000173 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000174}
175
Greg Clayton466f6c42010-09-10 18:31:35 +0000176
177bool
178SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
179{
180 if (m_opaque_sp)
181 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
182
183 addr->Clear();
184 return false;
185}
186
187SBSymbolContext
188SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
189{
190 SBSymbolContext sb_sc;
191 if (m_opaque_sp && addr.IsValid())
192 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
193 return sb_sc;
194}
195
Caroline Tice98f930f2010-09-20 05:20:02 +0000196bool
197SBModule::GetDescription (SBStream &description)
198{
199 if (m_opaque_sp)
200 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000201 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000202 m_opaque_sp->GetDescription (description.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000203 }
204 else
205 description.Printf ("No value");
206
207 return true;
208}
Greg Clayton43edca32010-12-07 05:40:31 +0000209
210size_t
211SBModule::GetNumSymbols ()
212{
213 if (m_opaque_sp)
214 {
215 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
216 if (obj_file)
217 {
218 Symtab *symtab = obj_file->GetSymtab();
219 if (symtab)
220 return symtab->GetNumSymbols();
221 }
222 }
223 return 0;
224}
225
226SBSymbol
227SBModule::GetSymbolAtIndex (size_t idx)
228{
229 SBSymbol sb_symbol;
230 if (m_opaque_sp)
231 {
232 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
233 if (obj_file)
234 {
235 Symtab *symtab = obj_file->GetSymtab();
236 if (symtab)
237 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
238 }
239 }
240 return sb_symbol;
241}