blob: 0a5c8aaacc3a812904550906b7ea164663cb77fa [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
98bool
99SBModule::operator == (const SBModule &rhs) const
100{
Greg Clayton63094e02010-06-23 01:19:29 +0000101 if (m_opaque_sp)
102 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000103 return false;
104}
105
106bool
107SBModule::operator != (const SBModule &rhs) const
108{
Greg Clayton63094e02010-06-23 01:19:29 +0000109 if (m_opaque_sp)
110 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000111 return false;
112}
113
114lldb::ModuleSP &
115SBModule::operator *()
116{
Greg Clayton63094e02010-06-23 01:19:29 +0000117 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000118}
119
120lldb_private::Module *
121SBModule::operator ->()
122{
Greg Clayton63094e02010-06-23 01:19:29 +0000123 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000124}
125
126const lldb_private::Module *
127SBModule::operator ->() const
128{
Greg Clayton63094e02010-06-23 01:19:29 +0000129 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000130}
131
132lldb_private::Module *
133SBModule::get()
134{
Greg Clayton63094e02010-06-23 01:19:29 +0000135 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000136}
137
138const lldb_private::Module *
139SBModule::get() const
140{
Greg Clayton63094e02010-06-23 01:19:29 +0000141 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000142}
143
144
145void
146SBModule::SetModule (const lldb::ModuleSP& module_sp)
147{
Greg Clayton63094e02010-06-23 01:19:29 +0000148 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000149}
150
Greg Clayton466f6c42010-09-10 18:31:35 +0000151
152bool
153SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
154{
155 if (m_opaque_sp)
156 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
157
158 addr->Clear();
159 return false;
160}
161
162SBSymbolContext
163SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
164{
165 SBSymbolContext sb_sc;
166 if (m_opaque_sp && addr.IsValid())
167 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
168 return sb_sc;
169}
170
Caroline Tice98f930f2010-09-20 05:20:02 +0000171bool
172SBModule::GetDescription (SBStream &description)
173{
174 if (m_opaque_sp)
175 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000176 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000177 m_opaque_sp->GetDescription (description.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000178 }
179 else
180 description.Printf ("No value");
181
182 return true;
183}
Greg Clayton43edca32010-12-07 05:40:31 +0000184
185size_t
186SBModule::GetNumSymbols ()
187{
188 if (m_opaque_sp)
189 {
190 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
191 if (obj_file)
192 {
193 Symtab *symtab = obj_file->GetSymtab();
194 if (symtab)
195 return symtab->GetNumSymbols();
196 }
197 }
198 return 0;
199}
200
201SBSymbol
202SBModule::GetSymbolAtIndex (size_t idx)
203{
204 SBSymbol sb_symbol;
205 if (m_opaque_sp)
206 {
207 ObjectFile *obj_file = m_opaque_sp->GetObjectFile();
208 if (obj_file)
209 {
210 Symtab *symtab = obj_file->GetSymtab();
211 if (symtab)
212 sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx));
213 }
214 }
215 return sb_symbol;
216}