Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ModuleList.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/Core/ModuleList.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Module.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/Core/ModuleSpec.h" |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 19 | #include "lldb/Host/Host.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Host/Symbols.h" |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/ClangNamespaceDecl.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/ObjectFile.h" |
| 23 | #include "lldb/Symbol/VariableList.h" |
| 24 | |
| 25 | using namespace lldb; |
| 26 | using namespace lldb_private; |
| 27 | |
| 28 | //---------------------------------------------------------------------- |
| 29 | // ModuleList constructor |
| 30 | //---------------------------------------------------------------------- |
| 31 | ModuleList::ModuleList() : |
| 32 | m_modules(), |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 33 | m_modules_mutex (Mutex::eMutexTypeRecursive), |
| 34 | m_notifier(NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
| 38 | //---------------------------------------------------------------------- |
| 39 | // Copy constructor |
| 40 | //---------------------------------------------------------------------- |
| 41 | ModuleList::ModuleList(const ModuleList& rhs) : |
Greg Clayton | e8fc036 | 2012-06-27 19:59:26 +0000 | [diff] [blame] | 42 | m_modules(), |
| 43 | m_modules_mutex (Mutex::eMutexTypeRecursive) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | { |
Greg Clayton | e8fc036 | 2012-06-27 19:59:26 +0000 | [diff] [blame] | 45 | Mutex::Locker lhs_locker(m_modules_mutex); |
| 46 | Mutex::Locker rhs_locker(rhs.m_modules_mutex); |
| 47 | m_modules = rhs.m_modules; |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | ModuleList::ModuleList (ModuleList::Notifier* notifier) : |
| 51 | m_modules(), |
| 52 | m_modules_mutex (Mutex::eMutexTypeRecursive), |
| 53 | m_notifier(notifier) |
| 54 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | //---------------------------------------------------------------------- |
| 58 | // Assignment operator |
| 59 | //---------------------------------------------------------------------- |
| 60 | const ModuleList& |
| 61 | ModuleList::operator= (const ModuleList& rhs) |
| 62 | { |
| 63 | if (this != &rhs) |
| 64 | { |
Greg Clayton | e8fc036 | 2012-06-27 19:59:26 +0000 | [diff] [blame] | 65 | Mutex::Locker lhs_locker(m_modules_mutex); |
| 66 | Mutex::Locker rhs_locker(rhs.m_modules_mutex); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | m_modules = rhs.m_modules; |
| 68 | } |
| 69 | return *this; |
| 70 | } |
| 71 | |
| 72 | //---------------------------------------------------------------------- |
| 73 | // Destructor |
| 74 | //---------------------------------------------------------------------- |
| 75 | ModuleList::~ModuleList() |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | void |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 80 | ModuleList::AppendImpl (const ModuleSP &module_sp, bool use_notifier) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 82 | if (module_sp) |
| 83 | { |
| 84 | Mutex::Locker locker(m_modules_mutex); |
| 85 | m_modules.push_back(module_sp); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 86 | if (use_notifier && m_notifier) |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 87 | m_notifier->ModuleAdded(*this, module_sp); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 88 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 91 | void |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 92 | ModuleList::Append (const ModuleSP &module_sp) |
| 93 | { |
| 94 | AppendImpl (module_sp); |
| 95 | } |
| 96 | |
| 97 | void |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 98 | ModuleList::ReplaceEquivalent (const ModuleSP &module_sp) |
| 99 | { |
| 100 | if (module_sp) |
| 101 | { |
| 102 | Mutex::Locker locker(m_modules_mutex); |
| 103 | |
| 104 | // First remove any equivalent modules. Equivalent modules are modules |
| 105 | // whose path, platform path and architecture match. |
| 106 | ModuleSpec equivalent_module_spec (module_sp->GetFileSpec(), module_sp->GetArchitecture()); |
| 107 | equivalent_module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec(); |
| 108 | |
| 109 | size_t idx = 0; |
| 110 | while (idx < m_modules.size()) |
| 111 | { |
| 112 | ModuleSP module_sp (m_modules[idx]); |
| 113 | if (module_sp->MatchesModuleSpec (equivalent_module_spec)) |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 114 | RemoveImpl(m_modules.begin() + idx); |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 115 | else |
| 116 | ++idx; |
| 117 | } |
| 118 | // Now add the new module to the list |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 119 | Append(module_sp); |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | bool |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 124 | ModuleList::AppendIfNeeded (const ModuleSP &module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 126 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 128 | Mutex::Locker locker(m_modules_mutex); |
| 129 | collection::iterator pos, end = m_modules.end(); |
| 130 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 131 | { |
| 132 | if (pos->get() == module_sp.get()) |
| 133 | return false; // Already in the list |
| 134 | } |
| 135 | // Only push module_sp on the list if it wasn't already in there. |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 136 | Append(module_sp); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 137 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 138 | } |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 139 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 142 | void |
| 143 | ModuleList::Append (const ModuleList& module_list) |
| 144 | { |
| 145 | for (auto pos : module_list.m_modules) |
| 146 | Append(pos); |
| 147 | } |
| 148 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 149 | bool |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 150 | ModuleList::AppendIfNeeded (const ModuleList& module_list) |
| 151 | { |
| 152 | bool any_in = false; |
| 153 | for (auto pos : module_list.m_modules) |
| 154 | any_in = AppendIfNeeded(pos) | any_in; |
| 155 | return any_in; |
| 156 | } |
| 157 | |
| 158 | bool |
| 159 | ModuleList::RemoveImpl (const ModuleSP &module_sp, bool use_notifier) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 161 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 163 | Mutex::Locker locker(m_modules_mutex); |
| 164 | collection::iterator pos, end = m_modules.end(); |
| 165 | for (pos = m_modules.begin(); pos != end; ++pos) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 167 | if (pos->get() == module_sp.get()) |
| 168 | { |
| 169 | m_modules.erase (pos); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 170 | if (use_notifier && m_notifier) |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 171 | m_notifier->ModuleRemoved(*this, module_sp); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 172 | return true; |
| 173 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | return false; |
| 177 | } |
| 178 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 179 | ModuleList::collection::iterator |
| 180 | ModuleList::RemoveImpl (ModuleList::collection::iterator pos, bool use_notifier) |
| 181 | { |
| 182 | ModuleSP module_sp(*pos); |
| 183 | collection::iterator retval = m_modules.erase(pos); |
| 184 | if (use_notifier && m_notifier) |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 185 | m_notifier->ModuleRemoved(*this, module_sp); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 186 | return retval; |
| 187 | } |
| 188 | |
| 189 | bool |
| 190 | ModuleList::Remove (const ModuleSP &module_sp) |
| 191 | { |
| 192 | return RemoveImpl (module_sp); |
| 193 | } |
| 194 | |
| 195 | bool |
| 196 | ModuleList::ReplaceModule (const lldb::ModuleSP &old_module_sp, const lldb::ModuleSP &new_module_sp) |
| 197 | { |
| 198 | if (!RemoveImpl(old_module_sp, false)) |
| 199 | return false; |
| 200 | AppendImpl (new_module_sp, false); |
| 201 | if (m_notifier) |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 202 | m_notifier->ModuleUpdated(*this, old_module_sp,new_module_sp); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 203 | return true; |
| 204 | } |
| 205 | |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 206 | bool |
| 207 | ModuleList::RemoveIfOrphaned (const Module *module_ptr) |
| 208 | { |
| 209 | if (module_ptr) |
| 210 | { |
| 211 | Mutex::Locker locker(m_modules_mutex); |
| 212 | collection::iterator pos, end = m_modules.end(); |
| 213 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 214 | { |
| 215 | if (pos->get() == module_ptr) |
| 216 | { |
| 217 | if (pos->unique()) |
| 218 | { |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 219 | pos = RemoveImpl(pos); |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 220 | return true; |
| 221 | } |
| 222 | else |
| 223 | return false; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | return false; |
| 228 | } |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 229 | |
| 230 | size_t |
Greg Clayton | 860b9ea | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 231 | ModuleList::RemoveOrphans (bool mandatory) |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 232 | { |
Greg Clayton | 860b9ea | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 233 | Mutex::Locker locker; |
| 234 | |
| 235 | if (mandatory) |
| 236 | { |
Jim Ingham | 1b584eb | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 237 | locker.Lock (m_modules_mutex); |
Greg Clayton | 860b9ea | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 238 | } |
| 239 | else |
| 240 | { |
| 241 | // Not mandatory, remove orphans if we can get the mutex |
Jim Ingham | 1b584eb | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 242 | if (!locker.TryLock(m_modules_mutex)) |
Greg Clayton | 860b9ea | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 243 | return 0; |
| 244 | } |
Greg Clayton | b01760c | 2011-08-11 04:30:39 +0000 | [diff] [blame] | 245 | collection::iterator pos = m_modules.begin(); |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 246 | size_t remove_count = 0; |
Greg Clayton | b01760c | 2011-08-11 04:30:39 +0000 | [diff] [blame] | 247 | while (pos != m_modules.end()) |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 248 | { |
| 249 | if (pos->unique()) |
| 250 | { |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 251 | pos = RemoveImpl(pos); |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 252 | ++remove_count; |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | ++pos; |
| 257 | } |
| 258 | } |
| 259 | return remove_count; |
| 260 | } |
| 261 | |
Greg Clayton | 7b9fcc0 | 2010-12-06 23:51:26 +0000 | [diff] [blame] | 262 | size_t |
| 263 | ModuleList::Remove (ModuleList &module_list) |
| 264 | { |
| 265 | Mutex::Locker locker(m_modules_mutex); |
| 266 | size_t num_removed = 0; |
| 267 | collection::iterator pos, end = module_list.m_modules.end(); |
| 268 | for (pos = module_list.m_modules.begin(); pos != end; ++pos) |
| 269 | { |
| 270 | if (Remove (*pos)) |
| 271 | ++num_removed; |
| 272 | } |
| 273 | return num_removed; |
| 274 | } |
| 275 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 276 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 277 | void |
| 278 | ModuleList::Clear() |
| 279 | { |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 280 | ClearImpl(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 283 | void |
| 284 | ModuleList::Destroy() |
| 285 | { |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 286 | ClearImpl(); |
| 287 | } |
| 288 | |
| 289 | void |
| 290 | ModuleList::ClearImpl (bool use_notifier) |
| 291 | { |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 292 | Mutex::Locker locker(m_modules_mutex); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 293 | if (use_notifier && m_notifier) |
Enrico Granata | 0b2f5cc | 2012-11-08 19:16:03 +0000 | [diff] [blame] | 294 | m_notifier->WillClearList(*this); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 295 | m_modules.clear(); |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | Module* |
| 299 | ModuleList::GetModulePointerAtIndex (uint32_t idx) const |
| 300 | { |
| 301 | Mutex::Locker locker(m_modules_mutex); |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 302 | return GetModulePointerAtIndexUnlocked(idx); |
| 303 | } |
| 304 | |
| 305 | Module* |
| 306 | ModuleList::GetModulePointerAtIndexUnlocked (uint32_t idx) const |
| 307 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 308 | if (idx < m_modules.size()) |
| 309 | return m_modules[idx].get(); |
| 310 | return NULL; |
| 311 | } |
| 312 | |
| 313 | ModuleSP |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 314 | ModuleList::GetModuleAtIndex(uint32_t idx) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 315 | { |
| 316 | Mutex::Locker locker(m_modules_mutex); |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 317 | return GetModuleAtIndexUnlocked(idx); |
| 318 | } |
| 319 | |
| 320 | ModuleSP |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 321 | ModuleList::GetModuleAtIndexUnlocked(uint32_t idx) const |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 322 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 323 | ModuleSP module_sp; |
| 324 | if (idx < m_modules.size()) |
| 325 | module_sp = m_modules[idx]; |
| 326 | return module_sp; |
| 327 | } |
| 328 | |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 329 | uint32_t |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 330 | ModuleList::FindFunctions (const ConstString &name, |
| 331 | uint32_t name_type_mask, |
| 332 | bool include_symbols, |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 333 | bool include_inlines, |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 334 | bool append, |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 335 | SymbolContextList &sc_list) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 336 | { |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 337 | if (!append) |
| 338 | sc_list.Clear(); |
| 339 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | Mutex::Locker locker(m_modules_mutex); |
| 341 | collection::const_iterator pos, end = m_modules.end(); |
| 342 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 343 | { |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 344 | (*pos)->FindFunctions (name, NULL, name_type_mask, include_symbols, include_inlines, true, sc_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | } |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 346 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 347 | return sc_list.GetSize(); |
| 348 | } |
| 349 | |
| 350 | uint32_t |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 351 | ModuleList::FindCompileUnits (const FileSpec &path, |
| 352 | bool append, |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 353 | SymbolContextList &sc_list) const |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 354 | { |
| 355 | if (!append) |
| 356 | sc_list.Clear(); |
| 357 | |
| 358 | Mutex::Locker locker(m_modules_mutex); |
| 359 | collection::const_iterator pos, end = m_modules.end(); |
| 360 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 361 | { |
| 362 | (*pos)->FindCompileUnits (path, true, sc_list); |
| 363 | } |
| 364 | |
| 365 | return sc_list.GetSize(); |
| 366 | } |
| 367 | |
| 368 | uint32_t |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 369 | ModuleList::FindGlobalVariables (const ConstString &name, |
| 370 | bool append, |
| 371 | uint32_t max_matches, |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 372 | VariableList& variable_list) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | { |
| 374 | size_t initial_size = variable_list.GetSize(); |
| 375 | Mutex::Locker locker(m_modules_mutex); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 376 | collection::const_iterator pos, end = m_modules.end(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 377 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 378 | { |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 379 | (*pos)->FindGlobalVariables (name, NULL, append, max_matches, variable_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 380 | } |
| 381 | return variable_list.GetSize() - initial_size; |
| 382 | } |
| 383 | |
| 384 | |
| 385 | uint32_t |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 386 | ModuleList::FindGlobalVariables (const RegularExpression& regex, |
| 387 | bool append, |
| 388 | uint32_t max_matches, |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 389 | VariableList& variable_list) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 390 | { |
| 391 | size_t initial_size = variable_list.GetSize(); |
| 392 | Mutex::Locker locker(m_modules_mutex); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 393 | collection::const_iterator pos, end = m_modules.end(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 394 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 395 | { |
| 396 | (*pos)->FindGlobalVariables (regex, append, max_matches, variable_list); |
| 397 | } |
| 398 | return variable_list.GetSize() - initial_size; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | size_t |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 403 | ModuleList::FindSymbolsWithNameAndType (const ConstString &name, |
| 404 | SymbolType symbol_type, |
Jim Ingham | 323ce42 | 2011-11-19 00:19:25 +0000 | [diff] [blame] | 405 | SymbolContextList &sc_list, |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 406 | bool append) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | { |
| 408 | Mutex::Locker locker(m_modules_mutex); |
Jim Ingham | 323ce42 | 2011-11-19 00:19:25 +0000 | [diff] [blame] | 409 | if (!append) |
| 410 | sc_list.Clear(); |
| 411 | size_t initial_size = sc_list.GetSize(); |
| 412 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 413 | collection::const_iterator pos, end = m_modules.end(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | for (pos = m_modules.begin(); pos != end; ++pos) |
Sean Callanan | aa4a553 | 2011-10-13 16:49:47 +0000 | [diff] [blame] | 415 | (*pos)->FindSymbolsWithNameAndType (name, symbol_type, sc_list); |
Jim Ingham | 323ce42 | 2011-11-19 00:19:25 +0000 | [diff] [blame] | 416 | return sc_list.GetSize() - initial_size; |
| 417 | } |
| 418 | |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 419 | size_t |
Jim Ingham | 323ce42 | 2011-11-19 00:19:25 +0000 | [diff] [blame] | 420 | ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, |
| 421 | lldb::SymbolType symbol_type, |
| 422 | SymbolContextList &sc_list, |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 423 | bool append) const |
Jim Ingham | 323ce42 | 2011-11-19 00:19:25 +0000 | [diff] [blame] | 424 | { |
| 425 | Mutex::Locker locker(m_modules_mutex); |
| 426 | if (!append) |
| 427 | sc_list.Clear(); |
| 428 | size_t initial_size = sc_list.GetSize(); |
| 429 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 430 | collection::const_iterator pos, end = m_modules.end(); |
Jim Ingham | 323ce42 | 2011-11-19 00:19:25 +0000 | [diff] [blame] | 431 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 432 | (*pos)->FindSymbolsMatchingRegExAndType (regex, symbol_type, sc_list); |
| 433 | return sc_list.GetSize() - initial_size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | size_t |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 437 | ModuleList::FindModules (const ModuleSpec &module_spec, ModuleList& matching_module_list) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | { |
| 439 | size_t existing_matches = matching_module_list.GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | |
| 441 | Mutex::Locker locker(m_modules_mutex); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 442 | collection::const_iterator pos, end = m_modules.end(); |
| 443 | for (pos = m_modules.begin(); pos != end; ++pos) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 444 | { |
| 445 | ModuleSP module_sp(*pos); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 446 | if (module_sp->MatchesModuleSpec (module_spec)) |
| 447 | matching_module_list.Append(module_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 448 | } |
| 449 | return matching_module_list.GetSize() - existing_matches; |
| 450 | } |
| 451 | |
| 452 | ModuleSP |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 453 | ModuleList::FindModule (const Module *module_ptr) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | { |
| 455 | ModuleSP module_sp; |
| 456 | |
| 457 | // Scope for "locker" |
| 458 | { |
| 459 | Mutex::Locker locker(m_modules_mutex); |
| 460 | collection::const_iterator pos, end = m_modules.end(); |
| 461 | |
| 462 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 463 | { |
| 464 | if ((*pos).get() == module_ptr) |
| 465 | { |
| 466 | module_sp = (*pos); |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | return module_sp; |
| 472 | |
| 473 | } |
| 474 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 475 | ModuleSP |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 476 | ModuleList::FindModule (const UUID &uuid) const |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 477 | { |
| 478 | ModuleSP module_sp; |
| 479 | |
| 480 | if (uuid.IsValid()) |
| 481 | { |
| 482 | Mutex::Locker locker(m_modules_mutex); |
| 483 | collection::const_iterator pos, end = m_modules.end(); |
| 484 | |
| 485 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 486 | { |
| 487 | if ((*pos)->GetUUID() == uuid) |
| 488 | { |
| 489 | module_sp = (*pos); |
| 490 | break; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | return module_sp; |
| 495 | } |
| 496 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 498 | uint32_t |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 499 | ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool name_is_fully_qualified, uint32_t max_matches, TypeList& types) const |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 500 | { |
| 501 | Mutex::Locker locker(m_modules_mutex); |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 502 | |
| 503 | uint32_t total_matches = 0; |
| 504 | collection::const_iterator pos, end = m_modules.end(); |
Greg Clayton | 72c17bf | 2012-04-06 18:09:43 +0000 | [diff] [blame] | 505 | if (sc.module_sp) |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 506 | { |
Greg Clayton | 72c17bf | 2012-04-06 18:09:43 +0000 | [diff] [blame] | 507 | // The symbol context "sc" contains a module so we want to search that |
| 508 | // one first if it is in our list... |
| 509 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 510 | { |
| 511 | if (sc.module_sp.get() == (*pos).get()) |
| 512 | { |
| 513 | total_matches += (*pos)->FindTypes (sc, name, name_is_fully_qualified, max_matches, types); |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 514 | |
Greg Clayton | 72c17bf | 2012-04-06 18:09:43 +0000 | [diff] [blame] | 515 | if (total_matches >= max_matches) |
| 516 | break; |
| 517 | } |
| 518 | } |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 519 | } |
Greg Clayton | 72c17bf | 2012-04-06 18:09:43 +0000 | [diff] [blame] | 520 | |
| 521 | if (total_matches < max_matches) |
| 522 | { |
Enrico Granata | d9c3769 | 2012-10-03 21:31:35 +0000 | [diff] [blame] | 523 | SymbolContext world_sc; |
Greg Clayton | 72c17bf | 2012-04-06 18:09:43 +0000 | [diff] [blame] | 524 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 525 | { |
| 526 | // Search the module if the module is not equal to the one in the symbol |
| 527 | // context "sc". If "sc" contains a empty module shared pointer, then |
| 528 | // the comparisong will always be true (valid_module_ptr != NULL). |
| 529 | if (sc.module_sp.get() != (*pos).get()) |
Enrico Granata | d9c3769 | 2012-10-03 21:31:35 +0000 | [diff] [blame] | 530 | total_matches += (*pos)->FindTypes (world_sc, name, name_is_fully_qualified, max_matches, types); |
Greg Clayton | 72c17bf | 2012-04-06 18:09:43 +0000 | [diff] [blame] | 531 | |
| 532 | if (total_matches >= max_matches) |
| 533 | break; |
| 534 | } |
| 535 | } |
| 536 | |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 537 | return total_matches; |
| 538 | } |
| 539 | |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 540 | bool |
| 541 | ModuleList::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const |
| 542 | { |
| 543 | Mutex::Locker locker(m_modules_mutex); |
| 544 | collection::const_iterator pos, end = m_modules.end(); |
| 545 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 546 | { |
| 547 | if ((*pos)->FindSourceFile (orig_spec, new_spec)) |
| 548 | return true; |
| 549 | } |
| 550 | return false; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | ModuleSP |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 556 | ModuleList::FindFirstModule (const ModuleSpec &module_spec) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | { |
| 558 | ModuleSP module_sp; |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 559 | Mutex::Locker locker(m_modules_mutex); |
| 560 | collection::const_iterator pos, end = m_modules.end(); |
| 561 | for (pos = m_modules.begin(); pos != end; ++pos) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 562 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 563 | ModuleSP module_sp(*pos); |
| 564 | if (module_sp->MatchesModuleSpec (module_spec)) |
| 565 | return module_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | } |
| 567 | return module_sp; |
| 568 | |
| 569 | } |
| 570 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 571 | size_t |
| 572 | ModuleList::GetSize() const |
| 573 | { |
| 574 | size_t size = 0; |
| 575 | { |
| 576 | Mutex::Locker locker(m_modules_mutex); |
| 577 | size = m_modules.size(); |
| 578 | } |
| 579 | return size; |
| 580 | } |
| 581 | |
| 582 | |
| 583 | void |
| 584 | ModuleList::Dump(Stream *s) const |
| 585 | { |
| 586 | // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
| 587 | // s.Indent(); |
| 588 | // s << "ModuleList\n"; |
| 589 | |
| 590 | Mutex::Locker locker(m_modules_mutex); |
| 591 | collection::const_iterator pos, end = m_modules.end(); |
| 592 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 593 | { |
| 594 | (*pos)->Dump(s); |
| 595 | } |
| 596 | } |
| 597 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 598 | void |
| 599 | ModuleList::LogUUIDAndPaths (LogSP &log_sp, const char *prefix_cstr) |
| 600 | { |
| 601 | if (log_sp) |
| 602 | { |
| 603 | Mutex::Locker locker(m_modules_mutex); |
| 604 | char uuid_cstr[256]; |
| 605 | collection::const_iterator pos, begin = m_modules.begin(), end = m_modules.end(); |
| 606 | for (pos = begin; pos != end; ++pos) |
| 607 | { |
| 608 | Module *module = pos->get(); |
| 609 | module->GetUUID().GetAsCString (uuid_cstr, sizeof(uuid_cstr)); |
| 610 | const FileSpec &module_file_spec = module->GetFileSpec(); |
| 611 | log_sp->Printf ("%s[%u] %s (%s) \"%s/%s\"", |
| 612 | prefix_cstr ? prefix_cstr : "", |
| 613 | (uint32_t)std::distance (begin, pos), |
| 614 | uuid_cstr, |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 615 | module->GetArchitecture().GetArchitectureName(), |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 616 | module_file_spec.GetDirectory().GetCString(), |
| 617 | module_file_spec.GetFilename().GetCString()); |
| 618 | } |
| 619 | } |
| 620 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | |
| 622 | bool |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 623 | ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 624 | { |
| 625 | Mutex::Locker locker(m_modules_mutex); |
| 626 | collection::const_iterator pos, end = m_modules.end(); |
| 627 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 628 | { |
| 629 | if ((*pos)->ResolveFileAddress (vm_addr, so_addr)) |
| 630 | return true; |
| 631 | } |
| 632 | |
| 633 | return false; |
| 634 | } |
| 635 | |
| 636 | uint32_t |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 637 | ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | { |
| 639 | // The address is already section offset so it has a module |
| 640 | uint32_t resolved_flags = 0; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 641 | ModuleSP module_sp (so_addr.GetModule()); |
| 642 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 643 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 644 | resolved_flags = module_sp->ResolveSymbolContextForAddress (so_addr, |
| 645 | resolve_scope, |
| 646 | sc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 647 | } |
| 648 | else |
| 649 | { |
| 650 | Mutex::Locker locker(m_modules_mutex); |
| 651 | collection::const_iterator pos, end = m_modules.end(); |
| 652 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 653 | { |
| 654 | resolved_flags = (*pos)->ResolveSymbolContextForAddress (so_addr, |
| 655 | resolve_scope, |
| 656 | sc); |
| 657 | if (resolved_flags != 0) |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | return resolved_flags; |
| 663 | } |
| 664 | |
| 665 | uint32_t |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 666 | ModuleList::ResolveSymbolContextForFilePath |
| 667 | ( |
| 668 | const char *file_path, |
| 669 | uint32_t line, |
| 670 | bool check_inlines, |
| 671 | uint32_t resolve_scope, |
| 672 | SymbolContextList& sc_list |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 673 | ) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 674 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 675 | FileSpec file_spec(file_path, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 676 | return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); |
| 677 | } |
| 678 | |
| 679 | uint32_t |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 680 | ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 681 | { |
| 682 | Mutex::Locker locker(m_modules_mutex); |
| 683 | collection::const_iterator pos, end = m_modules.end(); |
| 684 | for (pos = m_modules.begin(); pos != end; ++pos) |
| 685 | { |
| 686 | (*pos)->ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); |
| 687 | } |
| 688 | |
| 689 | return sc_list.GetSize(); |
| 690 | } |
| 691 | |
| 692 | uint32_t |
| 693 | ModuleList::GetIndexForModule (const Module *module) const |
| 694 | { |
| 695 | if (module) |
| 696 | { |
| 697 | Mutex::Locker locker(m_modules_mutex); |
| 698 | collection::const_iterator pos; |
| 699 | collection::const_iterator begin = m_modules.begin(); |
| 700 | collection::const_iterator end = m_modules.end(); |
| 701 | for (pos = begin; pos != end; ++pos) |
| 702 | { |
| 703 | if ((*pos).get() == module) |
| 704 | return std::distance (begin, pos); |
| 705 | } |
| 706 | } |
| 707 | return LLDB_INVALID_INDEX32; |
| 708 | } |
| 709 | |
| 710 | static ModuleList & |
| 711 | GetSharedModuleList () |
| 712 | { |
Greg Clayton | af05972 | 2012-09-18 23:50:22 +0000 | [diff] [blame] | 713 | // NOTE: Intentionally leak the module list so a program doesn't have to |
| 714 | // cleanup all modules and object files as it exits. This just wastes time |
| 715 | // doing a bunch of cleanup that isn't required. |
| 716 | static ModuleList *g_shared_module_list = NULL; |
| 717 | if (g_shared_module_list == NULL) |
| 718 | g_shared_module_list = new ModuleList(); // <--- Intentional leak!!! |
| 719 | |
| 720 | return *g_shared_module_list; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 723 | bool |
| 724 | ModuleList::ModuleIsInCache (const Module *module_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 726 | if (module_ptr) |
| 727 | { |
| 728 | ModuleList &shared_module_list = GetSharedModuleList (); |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 729 | return shared_module_list.FindModule (module_ptr).get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 730 | } |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 731 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 734 | size_t |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 735 | ModuleList::FindSharedModules (const ModuleSpec &module_spec, ModuleList &matching_module_list) |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 736 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 737 | return GetSharedModuleList ().FindModules (module_spec, matching_module_list); |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 738 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 740 | uint32_t |
Greg Clayton | 860b9ea | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 741 | ModuleList::RemoveOrphanSharedModules (bool mandatory) |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 742 | { |
Greg Clayton | 860b9ea | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 743 | return GetSharedModuleList ().RemoveOrphans(mandatory); |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 746 | Error |
| 747 | ModuleList::GetSharedModule |
| 748 | ( |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 749 | const ModuleSpec &module_spec, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | ModuleSP &module_sp, |
Greg Clayton | 9ce9538 | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 751 | const FileSpecList *module_search_paths_ptr, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 752 | ModuleSP *old_module_sp_ptr, |
Greg Clayton | dd506e1 | 2011-03-15 03:56:33 +0000 | [diff] [blame] | 753 | bool *did_create_ptr, |
| 754 | bool always_create |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 755 | ) |
| 756 | { |
| 757 | ModuleList &shared_module_list = GetSharedModuleList (); |
Greg Clayton | dd506e1 | 2011-03-15 03:56:33 +0000 | [diff] [blame] | 758 | Mutex::Locker locker(shared_module_list.m_modules_mutex); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | char path[PATH_MAX]; |
| 760 | char uuid_cstr[64]; |
| 761 | |
| 762 | Error error; |
| 763 | |
| 764 | module_sp.reset(); |
| 765 | |
| 766 | if (did_create_ptr) |
| 767 | *did_create_ptr = false; |
| 768 | if (old_module_sp_ptr) |
| 769 | old_module_sp_ptr->reset(); |
| 770 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 771 | const UUID *uuid_ptr = module_spec.GetUUIDPtr(); |
| 772 | const FileSpec &module_file_spec = module_spec.GetFileSpec(); |
| 773 | const ArchSpec &arch = module_spec.GetArchitecture(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 774 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 775 | // Make sure no one else can try and get or create a module while this |
| 776 | // function is actively working on it by doing an extra lock on the |
| 777 | // global mutex list. |
| 778 | if (always_create == false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 779 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 780 | ModuleList matching_module_list; |
| 781 | const size_t num_matching_modules = shared_module_list.FindModules (module_spec, matching_module_list); |
| 782 | if (num_matching_modules > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 784 | for (uint32_t module_idx = 0; module_idx < num_matching_modules; ++module_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 785 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 786 | module_sp = matching_module_list.GetModuleAtIndex(module_idx); |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 787 | |
| 788 | // Make sure the file for the module hasn't been modified |
| 789 | if (module_sp->FileHasChanged()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | { |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 791 | if (old_module_sp_ptr && !old_module_sp_ptr->get()) |
| 792 | *old_module_sp_ptr = module_sp; |
Greg Clayton | f737d37 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 793 | |
| 794 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_MODULES)); |
| 795 | if (log) |
| 796 | log->Printf("module changed: %p, removing from global module list", module_sp.get()); |
| 797 | |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 798 | shared_module_list.Remove (module_sp); |
| 799 | module_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 800 | } |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 801 | else |
| 802 | { |
| 803 | // The module matches and the module was not modified from |
| 804 | // when it was last loaded. |
| 805 | return error; |
| 806 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 807 | } |
| 808 | } |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 809 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 811 | if (module_sp) |
| 812 | return error; |
| 813 | else |
| 814 | { |
| 815 | module_sp.reset (new Module (module_spec)); |
| 816 | // Make sure there are a module and an object file since we can specify |
| 817 | // a valid file path with an architecture that might not be in that file. |
| 818 | // By getting the object file we can guarantee that the architecture matches |
Greg Clayton | dd506e1 | 2011-03-15 03:56:33 +0000 | [diff] [blame] | 819 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 820 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 821 | if (module_sp->GetObjectFile()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 822 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 823 | // If we get in here we got the correct arch, now we just need |
| 824 | // to verify the UUID if one was given |
| 825 | if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 826 | module_sp.reset(); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 827 | else |
| 828 | { |
| 829 | if (did_create_ptr) |
| 830 | *did_create_ptr = true; |
| 831 | |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 832 | shared_module_list.ReplaceEquivalent(module_sp); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 833 | return error; |
| 834 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 835 | } |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 836 | else |
| 837 | module_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
| 841 | // Either the file didn't exist where at the path, or no path was given, so |
| 842 | // we now have to use more extreme measures to try and find the appropriate |
| 843 | // module. |
| 844 | |
| 845 | // Fixup the incoming path in case the path points to a valid file, yet |
| 846 | // the arch or UUID (if one was passed in) don't match. |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 847 | FileSpec file_spec = Symbols::LocateExecutableObjectFile (module_spec); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 848 | |
| 849 | // Don't look for the file if it appears to be the same one we already |
| 850 | // checked for above... |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 851 | if (file_spec != module_file_spec) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 852 | { |
| 853 | if (!file_spec.Exists()) |
| 854 | { |
| 855 | file_spec.GetPath(path, sizeof(path)); |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 856 | if (path[0] == '\0') |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 857 | module_file_spec.GetPath(path, sizeof(path)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 858 | if (file_spec.Exists()) |
| 859 | { |
| 860 | if (uuid_ptr && uuid_ptr->IsValid()) |
| 861 | uuid_ptr->GetAsCString(uuid_cstr, sizeof (uuid_cstr)); |
| 862 | else |
| 863 | uuid_cstr[0] = '\0'; |
| 864 | |
| 865 | |
| 866 | if (arch.IsValid()) |
| 867 | { |
| 868 | if (uuid_cstr[0]) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 869 | error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s", path, arch.GetArchitectureName(), uuid_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 870 | else |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 871 | error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.", path, arch.GetArchitectureName()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | else |
| 875 | { |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 876 | error.SetErrorStringWithFormat("'%s' does not exist", path); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 877 | } |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 878 | if (error.Fail()) |
| 879 | module_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 880 | return error; |
| 881 | } |
| 882 | |
| 883 | |
| 884 | // Make sure no one else can try and get or create a module while this |
| 885 | // function is actively working on it by doing an extra lock on the |
| 886 | // global mutex list. |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 887 | ModuleSpec platform_module_spec(module_spec); |
| 888 | platform_module_spec.GetFileSpec() = file_spec; |
| 889 | platform_module_spec.GetPlatformFileSpec() = file_spec; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 890 | ModuleList matching_module_list; |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 891 | if (shared_module_list.FindModules (platform_module_spec, matching_module_list) > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 892 | { |
| 893 | module_sp = matching_module_list.GetModuleAtIndex(0); |
| 894 | |
| 895 | // If we didn't have a UUID in mind when looking for the object file, |
| 896 | // then we should make sure the modification time hasn't changed! |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 897 | if (platform_module_spec.GetUUIDPtr() == NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 898 | { |
| 899 | TimeValue file_spec_mod_time(file_spec.GetModificationTime()); |
| 900 | if (file_spec_mod_time.IsValid()) |
| 901 | { |
| 902 | if (file_spec_mod_time != module_sp->GetModificationTime()) |
| 903 | { |
| 904 | if (old_module_sp_ptr) |
| 905 | *old_module_sp_ptr = module_sp; |
| 906 | shared_module_list.Remove (module_sp); |
| 907 | module_sp.reset(); |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | if (module_sp.get() == NULL) |
| 914 | { |
Greg Clayton | aa20630 | 2012-03-21 04:25:00 +0000 | [diff] [blame] | 915 | module_sp.reset (new Module (platform_module_spec)); |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 916 | // Make sure there are a module and an object file since we can specify |
| 917 | // a valid file path with an architecture that might not be in that file. |
| 918 | // By getting the object file we can guarantee that the architecture matches |
| 919 | if (module_sp && module_sp->GetObjectFile()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 920 | { |
| 921 | if (did_create_ptr) |
| 922 | *did_create_ptr = true; |
| 923 | |
Greg Clayton | bcaf99a | 2012-07-12 20:32:19 +0000 | [diff] [blame] | 924 | shared_module_list.ReplaceEquivalent(module_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 925 | } |
| 926 | else |
| 927 | { |
| 928 | file_spec.GetPath(path, sizeof(path)); |
| 929 | |
| 930 | if (file_spec) |
| 931 | { |
| 932 | if (arch.IsValid()) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 933 | error.SetErrorStringWithFormat("unable to open %s architecture in '%s'", arch.GetArchitectureName(), path); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 934 | else |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 935 | error.SetErrorStringWithFormat("unable to open '%s'", path); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 936 | } |
| 937 | else |
| 938 | { |
| 939 | if (uuid_ptr && uuid_ptr->IsValid()) |
| 940 | uuid_ptr->GetAsCString(uuid_cstr, sizeof (uuid_cstr)); |
| 941 | else |
| 942 | uuid_cstr[0] = '\0'; |
| 943 | |
| 944 | if (uuid_cstr[0]) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 945 | error.SetErrorStringWithFormat("cannot locate a module for UUID '%s'", uuid_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | else |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 947 | error.SetErrorStringWithFormat("cannot locate a module"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | return error; |
| 954 | } |
| 955 | |
Greg Clayton | dd506e1 | 2011-03-15 03:56:33 +0000 | [diff] [blame] | 956 | bool |
| 957 | ModuleList::RemoveSharedModule (lldb::ModuleSP &module_sp) |
| 958 | { |
| 959 | return GetSharedModuleList ().Remove (module_sp); |
| 960 | } |
| 961 | |
Jim Ingham | 03e5e51 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 962 | bool |
| 963 | ModuleList::RemoveSharedModuleIfOrphaned (const Module *module_ptr) |
| 964 | { |
| 965 | return GetSharedModuleList ().RemoveIfOrphaned (module_ptr); |
| 966 | } |
| 967 | |
Greg Clayton | dd506e1 | 2011-03-15 03:56:33 +0000 | [diff] [blame] | 968 | |