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