blob: 35a88b61ce855ab0e01846c665af7f5bdc070fcc [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"
17#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{
Caroline Tice7826c882010-10-26 03:11:13 +000026 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
27
28 if (log)
29 log->Printf ("SBModule::SBModule () ==> this = %p", this);
Chris Lattner24943d22010-06-08 16:52:24 +000030}
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{
Caroline Tice7826c882010-10-26 03:11:13 +000035 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
36
37 if (log)
38 log->Printf ("SBModule::SBModule (const lldb::ModuleSP &module_sp) module_sp.get() = %p ==> this = %p",
39 module_sp.get(), this);
Chris Lattner24943d22010-06-08 16:52:24 +000040}
41
42SBModule::~SBModule ()
43{
44}
45
46bool
47SBModule::IsValid () const
48{
Greg Clayton63094e02010-06-23 01:19:29 +000049 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000050}
51
52SBFileSpec
53SBModule::GetFileSpec () const
54{
Caroline Tice7826c882010-10-26 03:11:13 +000055 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
56
57 if (log)
58 log->Printf ("SBModule::GetFileSpec ()");
59
Chris Lattner24943d22010-06-08 16:52:24 +000060 SBFileSpec file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +000061 if (m_opaque_sp)
62 file_spec.SetFileSpec(m_opaque_sp->GetFileSpec());
Caroline Tice7826c882010-10-26 03:11:13 +000063
64 if (log)
65 {
66 SBStream sstr;
67 file_spec.GetDescription (sstr);
68 log->Printf ("SBModule::GetFileSpec ==> SBFileSpec (this = %p, 's')", &file_spec, sstr.GetData());
69 }
70
Chris Lattner24943d22010-06-08 16:52:24 +000071 return file_spec;
72}
73
74const uint8_t *
75SBModule::GetUUIDBytes () const
76{
Caroline Tice7826c882010-10-26 03:11:13 +000077 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
78
79 if (log)
80 log->Printf ("SBModule::GetUUIDBytes ()");
81
Greg Clayton63094e02010-06-23 01:19:29 +000082 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +000083 {
84 if (log)
85 {
86 StreamString sstr;
87 m_opaque_sp->GetUUID().Dump (&sstr);
88 log->Printf ("SBModule::GetUUIDBytes ==> '%s'", sstr.GetData());
89 }
Greg Clayton63094e02010-06-23 01:19:29 +000090 return (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +000091 }
92
93 if (log)
94 log->Printf ("SBModule::GetUUIDBytes ==> NULL");
Chris Lattner24943d22010-06-08 16:52:24 +000095 return NULL;
96}
97
98
99bool
100SBModule::operator == (const SBModule &rhs) const
101{
Greg Clayton63094e02010-06-23 01:19:29 +0000102 if (m_opaque_sp)
103 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000104 return false;
105}
106
107bool
108SBModule::operator != (const SBModule &rhs) const
109{
Greg Clayton63094e02010-06-23 01:19:29 +0000110 if (m_opaque_sp)
111 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000112 return false;
113}
114
115lldb::ModuleSP &
116SBModule::operator *()
117{
Greg Clayton63094e02010-06-23 01:19:29 +0000118 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000119}
120
121lldb_private::Module *
122SBModule::operator ->()
123{
Greg Clayton63094e02010-06-23 01:19:29 +0000124 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000125}
126
127const lldb_private::Module *
128SBModule::operator ->() const
129{
Greg Clayton63094e02010-06-23 01:19:29 +0000130 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000131}
132
133lldb_private::Module *
134SBModule::get()
135{
Greg Clayton63094e02010-06-23 01:19:29 +0000136 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000137}
138
139const lldb_private::Module *
140SBModule::get() const
141{
Greg Clayton63094e02010-06-23 01:19:29 +0000142 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000143}
144
145
146void
147SBModule::SetModule (const lldb::ModuleSP& module_sp)
148{
Greg Clayton63094e02010-06-23 01:19:29 +0000149 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000150}
151
Greg Clayton466f6c42010-09-10 18:31:35 +0000152
153bool
154SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
155{
156 if (m_opaque_sp)
157 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
158
159 addr->Clear();
160 return false;
161}
162
163SBSymbolContext
164SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
165{
166 SBSymbolContext sb_sc;
167 if (m_opaque_sp && addr.IsValid())
168 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
169 return sb_sc;
170}
171
Caroline Tice98f930f2010-09-20 05:20:02 +0000172bool
173SBModule::GetDescription (SBStream &description)
174{
175 if (m_opaque_sp)
176 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000177 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000178 m_opaque_sp->GetDescription (description.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000179 }
180 else
181 description.Printf ("No value");
182
183 return true;
184}