1 //===-- 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"
11 #include "lldb/API/SBAddress.h"
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBFileSpec.h"
14 #include "lldb/API/SBStream.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/Log.h"
17 #include "lldb/Core/STreamString.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 
23 SBModule::SBModule () :
24     m_opaque_sp ()
25 {
26     Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
27 
28     if (log)
29         log->Printf ("SBModule::SBModule () ==> this = %p", this);
30 }
31 
32 SBModule::SBModule (const lldb::ModuleSP& module_sp) :
33     m_opaque_sp (module_sp)
34 {
35     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);
40 }
41 
42 SBModule::~SBModule ()
43 {
44 }
45 
46 bool
47 SBModule::IsValid () const
48 {
49     return m_opaque_sp.get() != NULL;
50 }
51 
52 SBFileSpec
53 SBModule::GetFileSpec () const
54 {
55     Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
56 
57     if (log)
58         log->Printf ("SBModule::GetFileSpec ()");
59 
60     SBFileSpec file_spec;
61     if (m_opaque_sp)
62         file_spec.SetFileSpec(m_opaque_sp->GetFileSpec());
63 
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 
71     return file_spec;
72 }
73 
74 const uint8_t *
75 SBModule::GetUUIDBytes () const
76 {
77     Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
78 
79     if (log)
80         log->Printf ("SBModule::GetUUIDBytes ()");
81 
82     if (m_opaque_sp)
83     {
84         if (log)
85         {
86             StreamString sstr;
87             m_opaque_sp->GetUUID().Dump (&sstr);
88             log->Printf ("SBModule::GetUUIDBytes ==> '%s'", sstr.GetData());
89         }
90         return (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
91     }
92 
93     if (log)
94         log->Printf ("SBModule::GetUUIDBytes ==> NULL");
95     return NULL;
96 }
97 
98 
99 bool
100 SBModule::operator == (const SBModule &rhs) const
101 {
102     if (m_opaque_sp)
103         return m_opaque_sp.get() == rhs.m_opaque_sp.get();
104     return false;
105 }
106 
107 bool
108 SBModule::operator != (const SBModule &rhs) const
109 {
110     if (m_opaque_sp)
111         return m_opaque_sp.get() != rhs.m_opaque_sp.get();
112     return false;
113 }
114 
115 lldb::ModuleSP &
116 SBModule::operator *()
117 {
118     return m_opaque_sp;
119 }
120 
121 lldb_private::Module *
122 SBModule::operator ->()
123 {
124     return m_opaque_sp.get();
125 }
126 
127 const lldb_private::Module *
128 SBModule::operator ->() const
129 {
130     return m_opaque_sp.get();
131 }
132 
133 lldb_private::Module *
134 SBModule::get()
135 {
136     return m_opaque_sp.get();
137 }
138 
139 const lldb_private::Module *
140 SBModule::get() const
141 {
142     return m_opaque_sp.get();
143 }
144 
145 
146 void
147 SBModule::SetModule (const lldb::ModuleSP& module_sp)
148 {
149     m_opaque_sp = module_sp;
150 }
151 
152 
153 bool
154 SBModule::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 
163 SBSymbolContext
164 SBModule::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 
172 bool
173 SBModule::GetDescription (SBStream &description)
174 {
175     if (m_opaque_sp)
176     {
177         description.ref();
178         m_opaque_sp->GetDescription (description.get());
179     }
180     else
181         description.Printf ("No value");
182 
183     return true;
184 }
185