Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Module.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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 12 | #include "lldb/Core/AddressResolverFileLine.h" |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Error.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 15 | #include "lldb/Core/DataBuffer.h" |
| 16 | #include "lldb/Core/DataBufferHeap.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Log.h" |
| 18 | #include "lldb/Core/ModuleList.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Section.h" |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 22 | #include "lldb/Core/StreamString.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Timer.h" |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 24 | #include "lldb/Host/Host.h" |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 25 | #include "lldb/Host/Symbols.h" |
| 26 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 27 | #include "lldb/Interpreter/ScriptInterpreter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/lldb-private-log.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 29 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Symbol/ObjectFile.h" |
| 31 | #include "lldb/Symbol/SymbolContext.h" |
| 32 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 33 | #include "lldb/Target/CPPLanguageRuntime.h" |
| 34 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 35 | #include "lldb/Target/Process.h" |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 36 | #include "lldb/Target/SectionLoadList.h" |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 37 | #include "lldb/Target/Target.h" |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 38 | #include "lldb/Symbol/SymbolFile.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 40 | #include "Plugins/ObjectFile/JIT/ObjectFileJIT.h" |
| 41 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | using namespace lldb; |
| 43 | using namespace lldb_private; |
| 44 | |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 45 | // Shared pointers to modules track module lifetimes in |
| 46 | // targets and in the global module, but this collection |
| 47 | // will track all module objects that are still alive |
| 48 | typedef std::vector<Module *> ModuleCollection; |
| 49 | |
| 50 | static ModuleCollection & |
| 51 | GetModuleCollection() |
| 52 | { |
Jim Ingham | 549f737 | 2011-10-31 23:47:10 +0000 | [diff] [blame] | 53 | // This module collection needs to live past any module, so we could either make it a |
| 54 | // shared pointer in each module or just leak is. Since it is only an empty vector by |
| 55 | // the time all the modules have gone away, we just leak it for now. If we decide this |
| 56 | // is a big problem we can introduce a Finalize method that will tear everything down in |
| 57 | // a predictable order. |
| 58 | |
| 59 | static ModuleCollection *g_module_collection = NULL; |
| 60 | if (g_module_collection == NULL) |
| 61 | g_module_collection = new ModuleCollection(); |
| 62 | |
| 63 | return *g_module_collection; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Greg Clayton | b26e6be | 2012-01-27 18:08:35 +0000 | [diff] [blame] | 66 | Mutex * |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 67 | Module::GetAllocationModuleCollectionMutex() |
| 68 | { |
Greg Clayton | b26e6be | 2012-01-27 18:08:35 +0000 | [diff] [blame] | 69 | // NOTE: The mutex below must be leaked since the global module list in |
| 70 | // the ModuleList class will get torn at some point, and we can't know |
| 71 | // if it will tear itself down before the "g_module_collection_mutex" below |
| 72 | // will. So we leak a Mutex object below to safeguard against that |
| 73 | |
| 74 | static Mutex *g_module_collection_mutex = NULL; |
| 75 | if (g_module_collection_mutex == NULL) |
| 76 | g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak |
| 77 | return g_module_collection_mutex; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | size_t |
| 81 | Module::GetNumberAllocatedModules () |
| 82 | { |
| 83 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 84 | return GetModuleCollection().size(); |
| 85 | } |
| 86 | |
| 87 | Module * |
| 88 | Module::GetAllocatedModuleAtIndex (size_t idx) |
| 89 | { |
| 90 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 91 | ModuleCollection &modules = GetModuleCollection(); |
| 92 | if (idx < modules.size()) |
| 93 | return modules[idx]; |
| 94 | return NULL; |
| 95 | } |
Greg Clayton | 29ad7b9 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 96 | #if 0 |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 97 | |
Greg Clayton | 29ad7b9 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 98 | // These functions help us to determine if modules are still loaded, yet don't require that |
| 99 | // you have a command interpreter and can easily be called from an external debugger. |
| 100 | namespace lldb { |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 101 | |
Greg Clayton | 29ad7b9 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 102 | void |
| 103 | ClearModuleInfo (void) |
| 104 | { |
Greg Clayton | 0cd7086 | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 105 | const bool mandatory = true; |
| 106 | ModuleList::RemoveOrphanSharedModules(mandatory); |
Greg Clayton | 29ad7b9 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void |
| 110 | DumpModuleInfo (void) |
| 111 | { |
| 112 | Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex()); |
| 113 | ModuleCollection &modules = GetModuleCollection(); |
| 114 | const size_t count = modules.size(); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 115 | printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count); |
Greg Clayton | 29ad7b9 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 116 | for (size_t i=0; i<count; ++i) |
| 117 | { |
| 118 | |
| 119 | StreamString strm; |
| 120 | Module *module = modules[i]; |
| 121 | const bool in_shared_module_list = ModuleList::ModuleIsInCache (module); |
| 122 | module->GetDescription(&strm, eDescriptionLevelFull); |
| 123 | printf ("%p: shared = %i, ref_count = %3u, module = %s\n", |
| 124 | module, |
| 125 | in_shared_module_list, |
| 126 | (uint32_t)module->use_count(), |
| 127 | strm.GetString().c_str()); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | #endif |
Greg Clayton | 3a18e31 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 133 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 134 | Module::Module (const ModuleSpec &module_spec) : |
| 135 | m_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 136 | m_mod_time (), |
| 137 | m_arch (), |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 138 | m_uuid (), |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 139 | m_file (), |
| 140 | m_platform_file(), |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 141 | m_remote_install_file(), |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 142 | m_symfile_spec (), |
| 143 | m_object_name (), |
| 144 | m_object_offset (), |
| 145 | m_object_mod_time (), |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 146 | m_objfile_sp (), |
| 147 | m_symfile_ap (), |
| 148 | m_ast (), |
Greg Clayton | d804d28 | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 149 | m_source_mappings (), |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 150 | m_sections_ap(), |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 151 | m_did_load_objfile (false), |
| 152 | m_did_load_symbol_vendor (false), |
| 153 | m_did_parse_uuid (false), |
| 154 | m_did_init_ast (false), |
Greg Clayton | 1d60909 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 155 | m_file_has_changed (false), |
| 156 | m_first_file_changed_log (false) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 157 | { |
| 158 | // Scope for locker below... |
| 159 | { |
| 160 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 161 | GetModuleCollection().push_back(this); |
| 162 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 163 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 164 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 165 | if (log) |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 166 | log->Printf ("%p Module::Module((%s) '%s%s%s%s')", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 167 | static_cast<void*>(this), |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 168 | module_spec.GetArchitecture().GetArchitectureName(), |
| 169 | module_spec.GetFileSpec().GetPath().c_str(), |
| 170 | module_spec.GetObjectName().IsEmpty() ? "" : "(", |
| 171 | module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""), |
| 172 | module_spec.GetObjectName().IsEmpty() ? "" : ")"); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 173 | |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 174 | // First extract all module specifications from the file using the local |
| 175 | // file path. If there are no specifications, then don't fill anything in |
| 176 | ModuleSpecList modules_specs; |
| 177 | if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0) |
| 178 | return; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 179 | |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 180 | // Now make sure that one of the module specifications matches what we just |
| 181 | // extract. We might have a module specification that specifies a file "/usr/lib/dyld" |
| 182 | // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that has |
| 183 | // UUID YYY and we don't want those to match. If they don't match, just don't |
| 184 | // fill any ivars in so we don't accidentally grab the wrong file later since |
| 185 | // they don't match... |
| 186 | ModuleSpec matching_module_spec; |
| 187 | if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0) |
| 188 | return; |
Greg Clayton | 7ab7f89 | 2014-05-29 21:33:45 +0000 | [diff] [blame] | 189 | |
| 190 | if (module_spec.GetFileSpec()) |
| 191 | m_mod_time = module_spec.GetFileSpec().GetModificationTime(); |
| 192 | else if (matching_module_spec.GetFileSpec()) |
| 193 | m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime(); |
| 194 | |
| 195 | // Copy the architecture from the actual spec if we got one back, else use the one that was specified |
| 196 | if (matching_module_spec.GetArchitecture().IsValid()) |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 197 | m_arch = matching_module_spec.GetArchitecture(); |
Greg Clayton | 7ab7f89 | 2014-05-29 21:33:45 +0000 | [diff] [blame] | 198 | else if (module_spec.GetArchitecture().IsValid()) |
| 199 | m_arch = module_spec.GetArchitecture(); |
| 200 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 201 | // Copy the file spec over and use the specified one (if there was one) so we |
Greg Clayton | 7ab7f89 | 2014-05-29 21:33:45 +0000 | [diff] [blame] | 202 | // don't use a path that might have gotten resolved a path in 'matching_module_spec' |
| 203 | if (module_spec.GetFileSpec()) |
| 204 | m_file = module_spec.GetFileSpec(); |
| 205 | else if (matching_module_spec.GetFileSpec()) |
| 206 | m_file = matching_module_spec.GetFileSpec(); |
| 207 | |
| 208 | // Copy the platform file spec over |
| 209 | if (module_spec.GetPlatformFileSpec()) |
| 210 | m_platform_file = module_spec.GetPlatformFileSpec(); |
| 211 | else if (matching_module_spec.GetPlatformFileSpec()) |
| 212 | m_platform_file = matching_module_spec.GetPlatformFileSpec(); |
| 213 | |
| 214 | // Copy the symbol file spec over |
| 215 | if (module_spec.GetSymbolFileSpec()) |
| 216 | m_symfile_spec = module_spec.GetSymbolFileSpec(); |
| 217 | else if (matching_module_spec.GetSymbolFileSpec()) |
| 218 | m_symfile_spec = matching_module_spec.GetSymbolFileSpec(); |
| 219 | |
| 220 | // Copy the object name over |
| 221 | if (matching_module_spec.GetObjectName()) |
| 222 | m_object_name = matching_module_spec.GetObjectName(); |
| 223 | else |
| 224 | m_object_name = module_spec.GetObjectName(); |
| 225 | |
| 226 | // Always trust the object offset (file offset) and object modification |
| 227 | // time (for mod time in a BSD static archive) of from the matching |
| 228 | // module specification |
Greg Clayton | 36d7c89 | 2014-05-29 17:52:46 +0000 | [diff] [blame] | 229 | m_object_offset = matching_module_spec.GetObjectOffset(); |
| 230 | m_object_mod_time = matching_module_spec.GetObjectModificationTime(); |
Greg Clayton | 34f1159 | 2014-03-04 21:20:23 +0000 | [diff] [blame] | 231 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 234 | Module::Module(const FileSpec& file_spec, |
| 235 | const ArchSpec& arch, |
| 236 | const ConstString *object_name, |
Zachary Turner | a746e8e | 2014-07-02 17:24:07 +0000 | [diff] [blame] | 237 | lldb::offset_t object_offset, |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 238 | const TimeValue *object_mod_time_ptr) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 239 | m_mutex (Mutex::eMutexTypeRecursive), |
| 240 | m_mod_time (file_spec.GetModificationTime()), |
| 241 | m_arch (arch), |
| 242 | m_uuid (), |
| 243 | m_file (file_spec), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 244 | m_platform_file(), |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 245 | m_remote_install_file (), |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 246 | m_symfile_spec (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 247 | m_object_name (), |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 248 | m_object_offset (object_offset), |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 249 | m_object_mod_time (), |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 250 | m_objfile_sp (), |
Greg Clayton | e83e731 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 251 | m_symfile_ap (), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 252 | m_ast (), |
Greg Clayton | d804d28 | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 253 | m_source_mappings (), |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 254 | m_sections_ap(), |
Greg Clayton | e83e731 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 255 | m_did_load_objfile (false), |
| 256 | m_did_load_symbol_vendor (false), |
| 257 | m_did_parse_uuid (false), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 258 | m_did_init_ast (false), |
Greg Clayton | 1d60909 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 259 | m_file_has_changed (false), |
| 260 | m_first_file_changed_log (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | { |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 262 | // Scope for locker below... |
| 263 | { |
| 264 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 265 | GetModuleCollection().push_back(this); |
| 266 | } |
| 267 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | if (object_name) |
| 269 | m_object_name = *object_name; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 270 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 271 | if (object_mod_time_ptr) |
| 272 | m_object_mod_time = *object_mod_time_ptr; |
| 273 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 274 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | if (log) |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 276 | log->Printf ("%p Module::Module((%s) '%s%s%s%s')", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 277 | static_cast<void*>(this), m_arch.GetArchitectureName(), |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 278 | m_file.GetPath().c_str(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | m_object_name.IsEmpty() ? "" : "(", |
| 280 | m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), |
| 281 | m_object_name.IsEmpty() ? "" : ")"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 284 | Module::Module () : |
| 285 | m_mutex (Mutex::eMutexTypeRecursive), |
| 286 | m_mod_time (), |
| 287 | m_arch (), |
| 288 | m_uuid (), |
| 289 | m_file (), |
| 290 | m_platform_file(), |
| 291 | m_remote_install_file (), |
| 292 | m_symfile_spec (), |
| 293 | m_object_name (), |
| 294 | m_object_offset (0), |
| 295 | m_object_mod_time (), |
| 296 | m_objfile_sp (), |
| 297 | m_symfile_ap (), |
| 298 | m_ast (), |
| 299 | m_source_mappings (), |
| 300 | m_sections_ap(), |
| 301 | m_did_load_objfile (false), |
| 302 | m_did_load_symbol_vendor (false), |
| 303 | m_did_parse_uuid (false), |
| 304 | m_did_init_ast (false), |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 305 | m_file_has_changed (false), |
| 306 | m_first_file_changed_log (false) |
| 307 | { |
| 308 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 309 | GetModuleCollection().push_back(this); |
| 310 | } |
| 311 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 312 | Module::~Module() |
| 313 | { |
Greg Clayton | 217b28b | 2013-05-22 20:13:22 +0000 | [diff] [blame] | 314 | // Lock our module down while we tear everything down to make sure |
| 315 | // we don't get any access to the module while it is being destroyed |
| 316 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 317 | // Scope for locker below... |
| 318 | { |
| 319 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 320 | ModuleCollection &modules = GetModuleCollection(); |
| 321 | ModuleCollection::iterator end = modules.end(); |
| 322 | ModuleCollection::iterator pos = std::find(modules.begin(), end, this); |
Greg Clayton | 3a18e31 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 323 | assert (pos != end); |
| 324 | modules.erase(pos); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 325 | } |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 326 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | if (log) |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 328 | log->Printf ("%p Module::~Module((%s) '%s%s%s%s')", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 329 | static_cast<void*>(this), |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 330 | m_arch.GetArchitectureName(), |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 331 | m_file.GetPath().c_str(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | m_object_name.IsEmpty() ? "" : "(", |
| 333 | m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), |
| 334 | m_object_name.IsEmpty() ? "" : ")"); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 335 | // Release any auto pointers before we start tearing down our member |
| 336 | // variables since the object file and symbol files might need to make |
| 337 | // function calls back into this module object. The ordering is important |
| 338 | // here because symbol files can require the module object file. So we tear |
| 339 | // down the symbol file first, then the object file. |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 340 | m_sections_ap.reset(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 341 | m_symfile_ap.reset(); |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 342 | m_objfile_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 345 | ObjectFile * |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 346 | Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error, size_t size_to_read) |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 347 | { |
| 348 | if (m_objfile_sp) |
| 349 | { |
| 350 | error.SetErrorString ("object file already exists"); |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | Mutex::Locker locker (m_mutex); |
| 355 | if (process_sp) |
| 356 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 357 | m_did_load_objfile = true; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 358 | std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0)); |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 359 | Error readmem_error; |
| 360 | const size_t bytes_read = process_sp->ReadMemory (header_addr, |
| 361 | data_ap->GetBytes(), |
| 362 | data_ap->GetByteSize(), |
| 363 | readmem_error); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 364 | if (bytes_read == size_to_read) |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 365 | { |
| 366 | DataBufferSP data_sp(data_ap.release()); |
| 367 | m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp); |
| 368 | if (m_objfile_sp) |
| 369 | { |
Greg Clayton | 3e10cf3 | 2012-04-20 19:50:20 +0000 | [diff] [blame] | 370 | StreamString s; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 371 | s.Printf("0x%16.16" PRIx64, header_addr); |
Greg Clayton | 3e10cf3 | 2012-04-20 19:50:20 +0000 | [diff] [blame] | 372 | m_object_name.SetCString (s.GetData()); |
| 373 | |
| 374 | // Once we get the object file, update our module with the object file's |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 375 | // architecture since it might differ in vendor/os if some parts were |
| 376 | // unknown. |
| 377 | m_objfile_sp->GetArchitecture (m_arch); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | error.SetErrorString ("unable to find suitable object file plug-in"); |
| 382 | } |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString()); |
| 387 | } |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | error.SetErrorString ("invalid process"); |
| 392 | } |
| 393 | } |
| 394 | return m_objfile_sp.get(); |
| 395 | } |
| 396 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | |
Greg Clayton | 6083026 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 398 | const lldb_private::UUID& |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 399 | Module::GetUUID() |
| 400 | { |
| 401 | Mutex::Locker locker (m_mutex); |
Greg Clayton | e83e731 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 402 | if (m_did_parse_uuid == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | { |
| 404 | ObjectFile * obj_file = GetObjectFile (); |
| 405 | |
| 406 | if (obj_file != NULL) |
| 407 | { |
| 408 | obj_file->GetUUID(&m_uuid); |
Greg Clayton | e83e731 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 409 | m_did_parse_uuid = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | return m_uuid; |
| 413 | } |
| 414 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 415 | ClangASTContext & |
| 416 | Module::GetClangASTContext () |
| 417 | { |
| 418 | Mutex::Locker locker (m_mutex); |
| 419 | if (m_did_init_ast == false) |
| 420 | { |
| 421 | ObjectFile * objfile = GetObjectFile(); |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 422 | ArchSpec object_arch; |
| 423 | if (objfile && objfile->GetArchitecture(object_arch)) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 424 | { |
| 425 | m_did_init_ast = true; |
Jason Molenda | 981d4df | 2012-10-16 20:45:49 +0000 | [diff] [blame] | 426 | |
| 427 | // LLVM wants this to be set to iOS or MacOSX; if we're working on |
| 428 | // a bare-boards type image, change the triple for llvm's benefit. |
| 429 | if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple |
| 430 | && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) |
| 431 | { |
| 432 | if (object_arch.GetTriple().getArch() == llvm::Triple::arm || |
Todd Fiala | d8eaa17 | 2014-07-23 14:37:35 +0000 | [diff] [blame] | 433 | object_arch.GetTriple().getArch() == llvm::Triple::aarch64 || |
Jason Molenda | 981d4df | 2012-10-16 20:45:49 +0000 | [diff] [blame] | 434 | object_arch.GetTriple().getArch() == llvm::Triple::thumb) |
| 435 | { |
| 436 | object_arch.GetTriple().setOS(llvm::Triple::IOS); |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | object_arch.GetTriple().setOS(llvm::Triple::MacOSX); |
| 441 | } |
| 442 | } |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 443 | m_ast.SetArchitecture (object_arch); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | return m_ast; |
| 447 | } |
| 448 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 449 | void |
| 450 | Module::ParseAllDebugSymbols() |
| 451 | { |
| 452 | Mutex::Locker locker (m_mutex); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 453 | size_t num_comp_units = GetNumCompileUnits(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | if (num_comp_units == 0) |
| 455 | return; |
| 456 | |
Greg Clayton | a2eee18 | 2011-09-17 07:23:18 +0000 | [diff] [blame] | 457 | SymbolContext sc; |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 458 | sc.module_sp = shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | SymbolVendor *symbols = GetSymbolVendor (); |
| 460 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 461 | for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 462 | { |
| 463 | sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get(); |
| 464 | if (sc.comp_unit) |
| 465 | { |
| 466 | sc.function = NULL; |
| 467 | symbols->ParseVariablesForContext(sc); |
| 468 | |
| 469 | symbols->ParseCompileUnitFunctions(sc); |
| 470 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 471 | for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | { |
| 473 | symbols->ParseFunctionBlocks(sc); |
| 474 | |
| 475 | // Parse the variables for this function and all its blocks |
| 476 | symbols->ParseVariablesForContext(sc); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | // Parse all types for this compile unit |
| 481 | sc.function = NULL; |
| 482 | symbols->ParseTypes(sc); |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | void |
| 488 | Module::CalculateSymbolContext(SymbolContext* sc) |
| 489 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 490 | sc->module_sp = shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 493 | ModuleSP |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 494 | Module::CalculateSymbolContextModule () |
| 495 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 496 | return shared_from_this(); |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 499 | void |
| 500 | Module::DumpSymbolContext(Stream *s) |
| 501 | { |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 502 | s->Printf(", Module{%p}", static_cast<void*>(this)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 505 | size_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | Module::GetNumCompileUnits() |
| 507 | { |
| 508 | Mutex::Locker locker (m_mutex); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 509 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 510 | "Module::GetNumCompileUnits (module = %p)", |
| 511 | static_cast<void*>(this)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 512 | SymbolVendor *symbols = GetSymbolVendor (); |
| 513 | if (symbols) |
| 514 | return symbols->GetNumCompileUnits(); |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | CompUnitSP |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 519 | Module::GetCompileUnitAtIndex (size_t index) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 520 | { |
| 521 | Mutex::Locker locker (m_mutex); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 522 | size_t num_comp_units = GetNumCompileUnits (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 523 | CompUnitSP cu_sp; |
| 524 | |
| 525 | if (index < num_comp_units) |
| 526 | { |
| 527 | SymbolVendor *symbols = GetSymbolVendor (); |
| 528 | if (symbols) |
| 529 | cu_sp = symbols->GetCompileUnitAtIndex(index); |
| 530 | } |
| 531 | return cu_sp; |
| 532 | } |
| 533 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | bool |
| 535 | Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) |
| 536 | { |
| 537 | Mutex::Locker locker (m_mutex); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 538 | Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr); |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 539 | SectionList *section_list = GetSectionList(); |
| 540 | if (section_list) |
| 541 | return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 542 | return false; |
| 543 | } |
| 544 | |
| 545 | uint32_t |
Ashok Thirumurthi | 35729bb | 2013-09-24 15:34:13 +0000 | [diff] [blame] | 546 | Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc, |
| 547 | bool resolve_tail_call_address) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 548 | { |
| 549 | Mutex::Locker locker (m_mutex); |
| 550 | uint32_t resolved_flags = 0; |
| 551 | |
Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 552 | // Clear the result symbol context in case we don't find anything, but don't clear the target |
| 553 | sc.Clear(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 554 | |
| 555 | // Get the section from the section/offset address. |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 556 | SectionSP section_sp (so_addr.GetSection()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | |
| 558 | // Make sure the section matches this module before we try and match anything |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 559 | if (section_sp && section_sp->GetModule().get() == this) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 560 | { |
| 561 | // If the section offset based address resolved itself, then this |
| 562 | // is the right module. |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 563 | sc.module_sp = shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 564 | resolved_flags |= eSymbolContextModule; |
| 565 | |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 566 | SymbolVendor* sym_vendor = GetSymbolVendor(); |
| 567 | if (!sym_vendor) |
| 568 | return resolved_flags; |
| 569 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 570 | // Resolve the compile unit, function, block, line table or line |
| 571 | // entry if requested. |
| 572 | if (resolve_scope & eSymbolContextCompUnit || |
| 573 | resolve_scope & eSymbolContextFunction || |
| 574 | resolve_scope & eSymbolContextBlock || |
| 575 | resolve_scope & eSymbolContextLineEntry ) |
| 576 | { |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 577 | resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Jim Ingham | 680e177 | 2010-08-31 23:51:36 +0000 | [diff] [blame] | 580 | // Resolve the symbol if requested, but don't re-look it up if we've already found it. |
| 581 | if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | { |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 583 | Symtab *symtab = sym_vendor->GetSymtab(); |
| 584 | if (symtab && so_addr.IsSectionOffset()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 585 | { |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 586 | sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress()); |
Ashok Thirumurthi | 35729bb | 2013-09-24 15:34:13 +0000 | [diff] [blame] | 587 | if (!sc.symbol && |
| 588 | resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction)) |
| 589 | { |
| 590 | bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address. |
| 591 | if (ObjectFile *obj_file = sc.module_sp->GetObjectFile()) |
| 592 | sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique); |
| 593 | } |
| 594 | |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 595 | if (sc.symbol) |
Greg Clayton | 93e2861 | 2013-10-11 22:03:48 +0000 | [diff] [blame] | 596 | { |
| 597 | if (sc.symbol->IsSynthetic()) |
| 598 | { |
| 599 | // We have a synthetic symbol so lets check if the object file |
| 600 | // from the symbol file in the symbol vendor is different than |
| 601 | // the object file for the module, and if so search its symbol |
| 602 | // table to see if we can come up with a better symbol. For example |
| 603 | // dSYM files on MacOSX have an unstripped symbol table inside of |
| 604 | // them. |
| 605 | ObjectFile *symtab_objfile = symtab->GetObjectFile(); |
| 606 | if (symtab_objfile && symtab_objfile->IsStripped()) |
| 607 | { |
| 608 | SymbolFile *symfile = sym_vendor->GetSymbolFile(); |
| 609 | if (symfile) |
| 610 | { |
| 611 | ObjectFile *symfile_objfile = symfile->GetObjectFile(); |
| 612 | if (symfile_objfile != symtab_objfile) |
| 613 | { |
| 614 | Symtab *symfile_symtab = symfile_objfile->GetSymtab(); |
| 615 | if (symfile_symtab) |
| 616 | { |
| 617 | Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress()); |
| 618 | if (symbol && !symbol->IsSynthetic()) |
| 619 | { |
| 620 | sc.symbol = symbol; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | } |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 627 | resolved_flags |= eSymbolContextSymbol; |
Greg Clayton | 93e2861 | 2013-10-11 22:03:48 +0000 | [diff] [blame] | 628 | } |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
| 632 | // For function symbols, so_addr may be off by one. This is a convention consistent |
| 633 | // with FDE row indices in eh_frame sections, but requires extra logic here to permit |
| 634 | // symbol lookup for disassembly and unwind. |
| 635 | if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) && |
Ashok Thirumurthi | 35729bb | 2013-09-24 15:34:13 +0000 | [diff] [blame] | 636 | resolve_tail_call_address && so_addr.IsSectionOffset()) |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 637 | { |
| 638 | Address previous_addr = so_addr; |
Greg Clayton | edfaae3 | 2013-09-18 20:03:31 +0000 | [diff] [blame] | 639 | previous_addr.Slide(-1); |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 640 | |
Ashok Thirumurthi | 35729bb | 2013-09-24 15:34:13 +0000 | [diff] [blame] | 641 | bool do_resolve_tail_call_address = false; // prevent recursion |
| 642 | const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc, |
| 643 | do_resolve_tail_call_address); |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 644 | if (flags & eSymbolContextSymbol) |
| 645 | { |
| 646 | AddressRange addr_range; |
| 647 | if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 648 | { |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 649 | if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | { |
Ashok Thirumurthi | 3880714 | 2013-09-16 22:00:17 +0000 | [diff] [blame] | 651 | // If the requested address is one past the address range of a function (i.e. a tail call), |
| 652 | // or the decremented address is the start of a function (i.e. some forms of trampoline), |
| 653 | // indicate that the symbol has been resolved. |
| 654 | if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() || |
| 655 | so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize()) |
| 656 | { |
| 657 | resolved_flags |= flags; |
| 658 | } |
| 659 | } |
| 660 | else |
| 661 | { |
| 662 | sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | return resolved_flags; |
| 669 | } |
| 670 | |
| 671 | uint32_t |
Greg Clayton | 274060b | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 672 | Module::ResolveSymbolContextForFilePath |
| 673 | ( |
| 674 | const char *file_path, |
| 675 | uint32_t line, |
| 676 | bool check_inlines, |
| 677 | uint32_t resolve_scope, |
| 678 | SymbolContextList& sc_list |
| 679 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | { |
Greg Clayton | 274060b | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 681 | FileSpec file_spec(file_path, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 682 | return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); |
| 683 | } |
| 684 | |
| 685 | uint32_t |
| 686 | Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 687 | { |
| 688 | Mutex::Locker locker (m_mutex); |
| 689 | Timer scoped_timer(__PRETTY_FUNCTION__, |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 690 | "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)", |
| 691 | file_spec.GetPath().c_str(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 692 | line, |
| 693 | check_inlines ? "yes" : "no", |
| 694 | resolve_scope); |
| 695 | |
| 696 | const uint32_t initial_count = sc_list.GetSize(); |
| 697 | |
| 698 | SymbolVendor *symbols = GetSymbolVendor (); |
| 699 | if (symbols) |
| 700 | symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list); |
| 701 | |
| 702 | return sc_list.GetSize() - initial_count; |
| 703 | } |
| 704 | |
| 705 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 706 | size_t |
| 707 | Module::FindGlobalVariables (const ConstString &name, |
| 708 | const ClangNamespaceDecl *namespace_decl, |
| 709 | bool append, |
| 710 | size_t max_matches, |
| 711 | VariableList& variables) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 712 | { |
| 713 | SymbolVendor *symbols = GetSymbolVendor (); |
| 714 | if (symbols) |
Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 715 | return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 716 | return 0; |
| 717 | } |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 718 | |
| 719 | size_t |
| 720 | Module::FindGlobalVariables (const RegularExpression& regex, |
| 721 | bool append, |
| 722 | size_t max_matches, |
| 723 | VariableList& variables) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 724 | { |
| 725 | SymbolVendor *symbols = GetSymbolVendor (); |
| 726 | if (symbols) |
| 727 | return symbols->FindGlobalVariables(regex, append, max_matches, variables); |
| 728 | return 0; |
| 729 | } |
| 730 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 731 | size_t |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 732 | Module::FindCompileUnits (const FileSpec &path, |
| 733 | bool append, |
| 734 | SymbolContextList &sc_list) |
| 735 | { |
| 736 | if (!append) |
| 737 | sc_list.Clear(); |
| 738 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 739 | const size_t start_size = sc_list.GetSize(); |
| 740 | const size_t num_compile_units = GetNumCompileUnits(); |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 741 | SymbolContext sc; |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 742 | sc.module_sp = shared_from_this(); |
Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 743 | const bool compare_directory = (bool)path.GetDirectory(); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 744 | for (size_t i=0; i<num_compile_units; ++i) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 745 | { |
| 746 | sc.comp_unit = GetCompileUnitAtIndex(i).get(); |
Greg Clayton | 2dafd8e | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 747 | if (sc.comp_unit) |
| 748 | { |
| 749 | if (FileSpec::Equal (*sc.comp_unit, path, compare_directory)) |
| 750 | sc_list.Append(sc); |
| 751 | } |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 752 | } |
| 753 | return sc_list.GetSize() - start_size; |
| 754 | } |
| 755 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 756 | size_t |
Sean Callanan | b6d70eb | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 757 | Module::FindFunctions (const ConstString &name, |
| 758 | const ClangNamespaceDecl *namespace_decl, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 759 | uint32_t name_type_mask, |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 760 | bool include_symbols, |
| 761 | bool include_inlines, |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 762 | bool append, |
| 763 | SymbolContextList& sc_list) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 764 | { |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 765 | if (!append) |
| 766 | sc_list.Clear(); |
| 767 | |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 768 | const size_t old_size = sc_list.GetSize(); |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 769 | |
| 770 | // Find all the functions (not symbols, but debug information functions... |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 771 | SymbolVendor *symbols = GetSymbolVendor (); |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 772 | |
| 773 | if (name_type_mask & eFunctionNameTypeAuto) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 774 | { |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 775 | ConstString lookup_name; |
| 776 | uint32_t lookup_name_type_mask = 0; |
| 777 | bool match_name_after_lookup = false; |
| 778 | Module::PrepareForFunctionNameLookup (name, |
| 779 | name_type_mask, |
| 780 | lookup_name, |
| 781 | lookup_name_type_mask, |
| 782 | match_name_after_lookup); |
| 783 | |
| 784 | if (symbols) |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 785 | { |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 786 | symbols->FindFunctions(lookup_name, |
| 787 | namespace_decl, |
| 788 | lookup_name_type_mask, |
| 789 | include_inlines, |
| 790 | append, |
| 791 | sc_list); |
| 792 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 793 | // Now check our symbol table for symbols that are code symbols if requested |
| 794 | if (include_symbols) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 795 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 796 | Symtab *symtab = symbols->GetSymtab(); |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 797 | if (symtab) |
| 798 | symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | if (match_name_after_lookup) |
| 803 | { |
| 804 | SymbolContext sc; |
| 805 | size_t i = old_size; |
| 806 | while (i<sc_list.GetSize()) |
| 807 | { |
| 808 | if (sc_list.GetContextAtIndex(i, sc)) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 809 | { |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 810 | const char *func_name = sc.GetFunctionName().GetCString(); |
| 811 | if (func_name && strstr (func_name, name.GetCString()) == NULL) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 812 | { |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 813 | // Remove the current context |
| 814 | sc_list.RemoveContextAtIndex(i); |
| 815 | // Don't increment i and continue in the loop |
| 816 | continue; |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 817 | } |
| 818 | } |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 819 | ++i; |
| 820 | } |
| 821 | } |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 822 | } |
| 823 | else |
| 824 | { |
| 825 | if (symbols) |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 826 | { |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 827 | symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list); |
| 828 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 829 | // Now check our symbol table for symbols that are code symbols if requested |
| 830 | if (include_symbols) |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 831 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 832 | Symtab *symtab = symbols->GetSymtab(); |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 833 | if (symtab) |
| 834 | symtab->FindFunctionSymbols(name, name_type_mask, sc_list); |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | } |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 838 | |
| 839 | return sc_list.GetSize() - old_size; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 842 | size_t |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 843 | Module::FindFunctions (const RegularExpression& regex, |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 844 | bool include_symbols, |
| 845 | bool include_inlines, |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 846 | bool append, |
| 847 | SymbolContextList& sc_list) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 848 | { |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 849 | if (!append) |
| 850 | sc_list.Clear(); |
| 851 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 852 | const size_t start_size = sc_list.GetSize(); |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 853 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 854 | SymbolVendor *symbols = GetSymbolVendor (); |
| 855 | if (symbols) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 856 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 857 | symbols->FindFunctions(regex, include_inlines, append, sc_list); |
| 858 | |
| 859 | // Now check our symbol table for symbols that are code symbols if requested |
| 860 | if (include_symbols) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 861 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 862 | Symtab *symtab = symbols->GetSymtab(); |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 863 | if (symtab) |
| 864 | { |
| 865 | std::vector<uint32_t> symbol_indexes; |
Matt Kopec | 00049b8 | 2013-02-27 20:13:38 +0000 | [diff] [blame] | 866 | symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 867 | const size_t num_matches = symbol_indexes.size(); |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 868 | if (num_matches) |
| 869 | { |
| 870 | SymbolContext sc(this); |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 871 | const size_t end_functions_added_index = sc_list.GetSize(); |
| 872 | size_t num_functions_added_to_sc_list = end_functions_added_index - start_size; |
| 873 | if (num_functions_added_to_sc_list == 0) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 874 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 875 | // No functions were added, just symbols, so we can just append them |
| 876 | for (size_t i=0; i<num_matches; ++i) |
| 877 | { |
| 878 | sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); |
| 879 | SymbolType sym_type = sc.symbol->GetType(); |
| 880 | if (sc.symbol && (sym_type == eSymbolTypeCode || |
| 881 | sym_type == eSymbolTypeResolver)) |
| 882 | sc_list.Append(sc); |
| 883 | } |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap; |
| 888 | FileAddrToIndexMap file_addr_to_index; |
| 889 | for (size_t i=start_size; i<end_functions_added_index; ++i) |
| 890 | { |
| 891 | const SymbolContext &sc = sc_list[i]; |
| 892 | if (sc.block) |
| 893 | continue; |
| 894 | file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i; |
| 895 | } |
| 896 | |
| 897 | FileAddrToIndexMap::const_iterator end = file_addr_to_index.end(); |
| 898 | // Functions were added so we need to merge symbols into any |
| 899 | // existing function symbol contexts |
| 900 | for (size_t i=start_size; i<num_matches; ++i) |
| 901 | { |
| 902 | sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); |
| 903 | SymbolType sym_type = sc.symbol->GetType(); |
| 904 | if (sc.symbol && (sym_type == eSymbolTypeCode || |
| 905 | sym_type == eSymbolTypeResolver)) |
| 906 | { |
| 907 | FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddress().GetFileAddress()); |
| 908 | if (pos == end) |
| 909 | sc_list.Append(sc); |
| 910 | else |
| 911 | sc_list[pos->second].symbol = sc.symbol; |
| 912 | } |
| 913 | } |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | return sc_list.GetSize() - start_size; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 922 | void |
| 923 | Module::FindAddressesForLine (const lldb::TargetSP target_sp, |
| 924 | const FileSpec &file, uint32_t line, |
| 925 | Function *function, |
| 926 | std::vector<Address> &output_local, std::vector<Address> &output_extern) |
| 927 | { |
| 928 | SearchFilterByModule filter(target_sp, m_file); |
| 929 | AddressResolverFileLine resolver(file, line, true); |
| 930 | resolver.ResolveAddress (filter); |
| 931 | |
| 932 | for (size_t n=0;n<resolver.GetNumberOfAddresses();n++) |
| 933 | { |
| 934 | Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress(); |
| 935 | Function *f = addr.CalculateSymbolContextFunction(); |
| 936 | if (f && f == function) |
| 937 | output_local.push_back (addr); |
| 938 | else |
| 939 | output_extern.push_back (addr); |
| 940 | } |
| 941 | } |
| 942 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 943 | size_t |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 944 | Module::FindTypes_Impl (const SymbolContext& sc, |
| 945 | const ConstString &name, |
| 946 | const ClangNamespaceDecl *namespace_decl, |
| 947 | bool append, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 948 | size_t max_matches, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 949 | TypeList& types) |
Greg Clayton | 3504eee | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 950 | { |
| 951 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 952 | if (sc.module_sp.get() == NULL || sc.module_sp.get() == this) |
| 953 | { |
| 954 | SymbolVendor *symbols = GetSymbolVendor (); |
| 955 | if (symbols) |
Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 956 | return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types); |
Greg Clayton | 3504eee | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 957 | } |
| 958 | return 0; |
| 959 | } |
| 960 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 961 | size_t |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 962 | Module::FindTypesInNamespace (const SymbolContext& sc, |
| 963 | const ConstString &type_name, |
| 964 | const ClangNamespaceDecl *namespace_decl, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 965 | size_t max_matches, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 966 | TypeList& type_list) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 967 | { |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 968 | const bool append = true; |
| 969 | return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 972 | lldb::TypeSP |
| 973 | Module::FindFirstType (const SymbolContext& sc, |
| 974 | const ConstString &name, |
| 975 | bool exact_match) |
| 976 | { |
| 977 | TypeList type_list; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 978 | const size_t num_matches = FindTypes (sc, name, exact_match, 1, type_list); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 979 | if (num_matches) |
| 980 | return type_list.GetTypeAtIndex(0); |
| 981 | return TypeSP(); |
| 982 | } |
| 983 | |
| 984 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 985 | size_t |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 986 | Module::FindTypes (const SymbolContext& sc, |
| 987 | const ConstString &name, |
| 988 | bool exact_match, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 989 | size_t max_matches, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 990 | TypeList& types) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 991 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 992 | size_t num_matches = 0; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 993 | const char *type_name_cstr = name.GetCString(); |
| 994 | std::string type_scope; |
| 995 | std::string type_basename; |
| 996 | const bool append = true; |
Greg Clayton | 7bc3133 | 2012-10-22 16:19:56 +0000 | [diff] [blame] | 997 | TypeClass type_class = eTypeClassAny; |
| 998 | if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class)) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 999 | { |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1000 | // Check if "name" starts with "::" which means the qualified type starts |
| 1001 | // from the root namespace and implies and exact match. The typenames we |
| 1002 | // get back from clang do not start with "::" so we need to strip this off |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1003 | // in order to get the qualified names to match |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1004 | |
| 1005 | if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':') |
| 1006 | { |
| 1007 | type_scope.erase(0,2); |
| 1008 | exact_match = true; |
| 1009 | } |
| 1010 | ConstString type_basename_const_str (type_basename.c_str()); |
| 1011 | if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types)) |
| 1012 | { |
Greg Clayton | 7bc3133 | 2012-10-22 16:19:56 +0000 | [diff] [blame] | 1013 | types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1014 | num_matches = types.GetSize(); |
| 1015 | } |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1016 | } |
| 1017 | else |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1018 | { |
| 1019 | // The type is not in a namespace/class scope, just search for it by basename |
Greg Clayton | 7bc3133 | 2012-10-22 16:19:56 +0000 | [diff] [blame] | 1020 | if (type_class != eTypeClassAny) |
| 1021 | { |
| 1022 | // The "type_name_cstr" will have been modified if we have a valid type class |
| 1023 | // prefix (like "struct", "class", "union", "typedef" etc). |
Arnaud A. de Grandmaison | 62e5f4d | 2014-03-22 20:23:26 +0000 | [diff] [blame] | 1024 | FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types); |
Greg Clayton | 7bc3133 | 2012-10-22 16:19:56 +0000 | [diff] [blame] | 1025 | types.RemoveMismatchedTypes (type_class); |
| 1026 | num_matches = types.GetSize(); |
| 1027 | } |
| 1028 | else |
| 1029 | { |
| 1030 | num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types); |
| 1031 | } |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | return num_matches; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1035 | |
| 1036 | } |
| 1037 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | SymbolVendor* |
Greg Clayton | 136dff8 | 2012-12-14 02:15:00 +0000 | [diff] [blame] | 1039 | Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1040 | { |
| 1041 | Mutex::Locker locker (m_mutex); |
Greg Clayton | e83e731 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 1042 | if (m_did_load_symbol_vendor == false && can_create) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1043 | { |
| 1044 | ObjectFile *obj_file = GetObjectFile (); |
| 1045 | if (obj_file != NULL) |
| 1046 | { |
| 1047 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
Greg Clayton | 136dff8 | 2012-12-14 02:15:00 +0000 | [diff] [blame] | 1048 | m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm)); |
Greg Clayton | e83e731 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 1049 | m_did_load_symbol_vendor = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | return m_symfile_ap.get(); |
| 1053 | } |
| 1054 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1055 | void |
| 1056 | Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name) |
| 1057 | { |
| 1058 | // Container objects whose paths do not specify a file directly can call |
| 1059 | // this function to correct the file and object names. |
| 1060 | m_file = file; |
| 1061 | m_mod_time = file.GetModificationTime(); |
| 1062 | m_object_name = object_name; |
| 1063 | } |
| 1064 | |
| 1065 | const ArchSpec& |
| 1066 | Module::GetArchitecture () const |
| 1067 | { |
| 1068 | return m_arch; |
| 1069 | } |
| 1070 | |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 1071 | std::string |
| 1072 | Module::GetSpecificationDescription () const |
| 1073 | { |
| 1074 | std::string spec(GetFileSpec().GetPath()); |
| 1075 | if (m_object_name) |
| 1076 | { |
| 1077 | spec += '('; |
| 1078 | spec += m_object_name.GetCString(); |
| 1079 | spec += ')'; |
| 1080 | } |
| 1081 | return spec; |
| 1082 | } |
| 1083 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1084 | void |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1085 | Module::GetDescription (Stream *s, lldb::DescriptionLevel level) |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1086 | { |
| 1087 | Mutex::Locker locker (m_mutex); |
| 1088 | |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1089 | if (level >= eDescriptionLevelFull) |
| 1090 | { |
| 1091 | if (m_arch.IsValid()) |
| 1092 | s->Printf("(%s) ", m_arch.GetArchitectureName()); |
| 1093 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1094 | |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1095 | if (level == eDescriptionLevelBrief) |
| 1096 | { |
| 1097 | const char *filename = m_file.GetFilename().GetCString(); |
| 1098 | if (filename) |
| 1099 | s->PutCString (filename); |
| 1100 | } |
| 1101 | else |
| 1102 | { |
| 1103 | char path[PATH_MAX]; |
| 1104 | if (m_file.GetPath(path, sizeof(path))) |
| 1105 | s->PutCString(path); |
| 1106 | } |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1107 | |
| 1108 | const char *object_name = m_object_name.GetCString(); |
| 1109 | if (object_name) |
| 1110 | s->Printf("(%s)", object_name); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | void |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1114 | Module::ReportError (const char *format, ...) |
| 1115 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1116 | if (format && format[0]) |
| 1117 | { |
| 1118 | StreamString strm; |
| 1119 | strm.PutCString("error: "); |
| 1120 | GetDescription(&strm, lldb::eDescriptionLevelBrief); |
Greg Clayton | 8b35334 | 2012-01-11 01:59:18 +0000 | [diff] [blame] | 1121 | strm.PutChar (' '); |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1122 | va_list args; |
| 1123 | va_start (args, format); |
| 1124 | strm.PrintfVarArg(format, args); |
| 1125 | va_end (args); |
| 1126 | |
| 1127 | const int format_len = strlen(format); |
| 1128 | if (format_len > 0) |
| 1129 | { |
| 1130 | const char last_char = format[format_len-1]; |
| 1131 | if (last_char != '\n' || last_char != '\r') |
| 1132 | strm.EOL(); |
| 1133 | } |
| 1134 | Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); |
| 1135 | |
| 1136 | } |
| 1137 | } |
| 1138 | |
Greg Clayton | 1d60909 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 1139 | bool |
| 1140 | Module::FileHasChanged () const |
| 1141 | { |
| 1142 | if (m_file_has_changed == false) |
| 1143 | m_file_has_changed = (m_file.GetModificationTime() != m_mod_time); |
| 1144 | return m_file_has_changed; |
| 1145 | } |
| 1146 | |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1147 | void |
| 1148 | Module::ReportErrorIfModifyDetected (const char *format, ...) |
| 1149 | { |
Greg Clayton | 1d60909 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 1150 | if (m_first_file_changed_log == false) |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1151 | { |
Greg Clayton | 1d60909 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 1152 | if (FileHasChanged ()) |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1153 | { |
Greg Clayton | 1d60909 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 1154 | m_first_file_changed_log = true; |
| 1155 | if (format) |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1156 | { |
Greg Clayton | 1d60909 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 1157 | StreamString strm; |
| 1158 | strm.PutCString("error: the object file "); |
| 1159 | GetDescription(&strm, lldb::eDescriptionLevelFull); |
| 1160 | strm.PutCString (" has been modified\n"); |
| 1161 | |
| 1162 | va_list args; |
| 1163 | va_start (args, format); |
| 1164 | strm.PrintfVarArg(format, args); |
| 1165 | va_end (args); |
| 1166 | |
| 1167 | const int format_len = strlen(format); |
| 1168 | if (format_len > 0) |
| 1169 | { |
| 1170 | const char last_char = format[format_len-1]; |
| 1171 | if (last_char != '\n' || last_char != '\r') |
| 1172 | strm.EOL(); |
| 1173 | } |
| 1174 | strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n"); |
| 1175 | Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1176 | } |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1177 | } |
| 1178 | } |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | void |
| 1182 | Module::ReportWarning (const char *format, ...) |
| 1183 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1184 | if (format && format[0]) |
| 1185 | { |
| 1186 | StreamString strm; |
| 1187 | strm.PutCString("warning: "); |
Greg Clayton | 8b35334 | 2012-01-11 01:59:18 +0000 | [diff] [blame] | 1188 | GetDescription(&strm, lldb::eDescriptionLevelFull); |
| 1189 | strm.PutChar (' '); |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1190 | |
| 1191 | va_list args; |
| 1192 | va_start (args, format); |
| 1193 | strm.PrintfVarArg(format, args); |
| 1194 | va_end (args); |
| 1195 | |
| 1196 | const int format_len = strlen(format); |
| 1197 | if (format_len > 0) |
| 1198 | { |
| 1199 | const char last_char = format[format_len-1]; |
| 1200 | if (last_char != '\n' || last_char != '\r') |
| 1201 | strm.EOL(); |
| 1202 | } |
| 1203 | Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str()); |
| 1204 | } |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | void |
| 1208 | Module::LogMessage (Log *log, const char *format, ...) |
| 1209 | { |
| 1210 | if (log) |
| 1211 | { |
| 1212 | StreamString log_message; |
Greg Clayton | 8b35334 | 2012-01-11 01:59:18 +0000 | [diff] [blame] | 1213 | GetDescription(&log_message, lldb::eDescriptionLevelFull); |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1214 | log_message.PutCString (": "); |
| 1215 | va_list args; |
| 1216 | va_start (args, format); |
| 1217 | log_message.PrintfVarArg (format, args); |
| 1218 | va_end (args); |
| 1219 | log->PutCString(log_message.GetString().c_str()); |
| 1220 | } |
| 1221 | } |
| 1222 | |
Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 1223 | void |
| 1224 | Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...) |
| 1225 | { |
| 1226 | if (log) |
| 1227 | { |
| 1228 | StreamString log_message; |
| 1229 | GetDescription(&log_message, lldb::eDescriptionLevelFull); |
| 1230 | log_message.PutCString (": "); |
| 1231 | va_list args; |
| 1232 | va_start (args, format); |
| 1233 | log_message.PrintfVarArg (format, args); |
| 1234 | va_end (args); |
| 1235 | if (log->GetVerbose()) |
| 1236 | Host::Backtrace (log_message, 1024); |
| 1237 | log->PutCString(log_message.GetString().c_str()); |
| 1238 | } |
| 1239 | } |
| 1240 | |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 1241 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1242 | Module::Dump(Stream *s) |
| 1243 | { |
| 1244 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 8941142 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 1245 | //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1246 | s->Indent(); |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 1247 | s->Printf("Module %s%s%s%s\n", |
| 1248 | m_file.GetPath().c_str(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1249 | m_object_name ? "(" : "", |
| 1250 | m_object_name ? m_object_name.GetCString() : "", |
| 1251 | m_object_name ? ")" : ""); |
| 1252 | |
| 1253 | s->IndentMore(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1254 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | ObjectFile *objfile = GetObjectFile (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1256 | if (objfile) |
| 1257 | objfile->Dump(s); |
| 1258 | |
| 1259 | SymbolVendor *symbols = GetSymbolVendor (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1260 | if (symbols) |
| 1261 | symbols->Dump(s); |
| 1262 | |
| 1263 | s->IndentLess(); |
| 1264 | } |
| 1265 | |
| 1266 | |
| 1267 | TypeList* |
| 1268 | Module::GetTypeList () |
| 1269 | { |
| 1270 | SymbolVendor *symbols = GetSymbolVendor (); |
| 1271 | if (symbols) |
| 1272 | return &symbols->GetTypeList(); |
| 1273 | return NULL; |
| 1274 | } |
| 1275 | |
| 1276 | const ConstString & |
| 1277 | Module::GetObjectName() const |
| 1278 | { |
| 1279 | return m_object_name; |
| 1280 | } |
| 1281 | |
| 1282 | ObjectFile * |
| 1283 | Module::GetObjectFile() |
| 1284 | { |
| 1285 | Mutex::Locker locker (m_mutex); |
Greg Clayton | e83e731 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 1286 | if (m_did_load_objfile == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1288 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1289 | "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); |
Greg Clayton | 5ce9c56 | 2013-02-06 17:22:03 +0000 | [diff] [blame] | 1290 | DataBufferSP data_sp; |
| 1291 | lldb::offset_t data_offset = 0; |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 1292 | const lldb::offset_t file_size = m_file.GetByteSize(); |
| 1293 | if (file_size > m_object_offset) |
Greg Clayton | 593577a | 2011-09-21 03:57:31 +0000 | [diff] [blame] | 1294 | { |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 1295 | m_did_load_objfile = true; |
| 1296 | m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(), |
| 1297 | &m_file, |
| 1298 | m_object_offset, |
| 1299 | file_size - m_object_offset, |
| 1300 | data_sp, |
| 1301 | data_offset); |
| 1302 | if (m_objfile_sp) |
| 1303 | { |
Zachary Turner | 5e6f452 | 2015-01-22 18:59:05 +0000 | [diff] [blame] | 1304 | // Once we get the object file, update our module with the object file's |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 1305 | // architecture since it might differ in vendor/os if some parts were |
Zachary Turner | 5e6f452 | 2015-01-22 18:59:05 +0000 | [diff] [blame] | 1306 | // unknown. But since the matching arch might already be more specific |
| 1307 | // than the generic COFF architecture, only merge in those values that |
| 1308 | // overwrite unspecified unknown values. |
| 1309 | ArchSpec new_arch; |
| 1310 | m_objfile_sp->GetArchitecture(new_arch); |
| 1311 | m_arch.MergeFrom(new_arch); |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 1312 | } |
Todd Fiala | 0ee56ce | 2014-09-05 14:48:49 +0000 | [diff] [blame] | 1313 | else |
| 1314 | { |
| 1315 | ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str()); |
| 1316 | } |
Greg Clayton | 593577a | 2011-09-21 03:57:31 +0000 | [diff] [blame] | 1317 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1318 | } |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 1319 | return m_objfile_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1322 | SectionList * |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1323 | Module::GetSectionList() |
| 1324 | { |
| 1325 | // Populate m_unified_sections_ap with sections from objfile. |
| 1326 | if (m_sections_ap.get() == NULL) |
| 1327 | { |
| 1328 | ObjectFile *obj_file = GetObjectFile(); |
| 1329 | if (obj_file) |
| 1330 | obj_file->CreateSections(*GetUnifiedSectionList()); |
| 1331 | } |
| 1332 | return m_sections_ap.get(); |
| 1333 | } |
| 1334 | |
Jason Molenda | 05a09c6 | 2014-08-22 02:46:46 +0000 | [diff] [blame] | 1335 | void |
| 1336 | Module::SectionFileAddressesChanged () |
| 1337 | { |
| 1338 | ObjectFile *obj_file = GetObjectFile (); |
| 1339 | if (obj_file) |
| 1340 | obj_file->SectionFileAddressesChanged (); |
| 1341 | SymbolVendor* sym_vendor = GetSymbolVendor(); |
| 1342 | if (sym_vendor) |
| 1343 | sym_vendor->SectionFileAddressesChanged (); |
| 1344 | } |
| 1345 | |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1346 | SectionList * |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1347 | Module::GetUnifiedSectionList() |
| 1348 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1349 | // Populate m_unified_sections_ap with sections from objfile. |
| 1350 | if (m_sections_ap.get() == NULL) |
| 1351 | m_sections_ap.reset(new SectionList()); |
| 1352 | return m_sections_ap.get(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1353 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | |
| 1355 | const Symbol * |
| 1356 | Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type) |
| 1357 | { |
| 1358 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1359 | "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", |
| 1360 | name.AsCString(), |
| 1361 | symbol_type); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1362 | SymbolVendor* sym_vendor = GetSymbolVendor(); |
| 1363 | if (sym_vendor) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1364 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1365 | Symtab *symtab = sym_vendor->GetSymtab(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1366 | if (symtab) |
Greg Clayton | bcf2cfb | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 1367 | return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1368 | } |
| 1369 | return NULL; |
| 1370 | } |
| 1371 | void |
| 1372 | Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list) |
| 1373 | { |
| 1374 | // No need to protect this call using m_mutex all other method calls are |
| 1375 | // already thread safe. |
| 1376 | |
| 1377 | size_t num_indices = symbol_indexes.size(); |
| 1378 | if (num_indices > 0) |
| 1379 | { |
| 1380 | SymbolContext sc; |
| 1381 | CalculateSymbolContext (&sc); |
| 1382 | for (size_t i = 0; i < num_indices; i++) |
| 1383 | { |
| 1384 | sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]); |
| 1385 | if (sc.symbol) |
| 1386 | sc_list.Append (sc); |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | size_t |
Greg Clayton | c1b2ccf | 2013-01-08 00:01:36 +0000 | [diff] [blame] | 1392 | Module::FindFunctionSymbols (const ConstString &name, |
| 1393 | uint32_t name_type_mask, |
| 1394 | SymbolContextList& sc_list) |
| 1395 | { |
| 1396 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1397 | "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)", |
| 1398 | name.AsCString(), |
| 1399 | name_type_mask); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1400 | SymbolVendor* sym_vendor = GetSymbolVendor(); |
| 1401 | if (sym_vendor) |
Greg Clayton | c1b2ccf | 2013-01-08 00:01:36 +0000 | [diff] [blame] | 1402 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1403 | Symtab *symtab = sym_vendor->GetSymtab(); |
Greg Clayton | c1b2ccf | 2013-01-08 00:01:36 +0000 | [diff] [blame] | 1404 | if (symtab) |
| 1405 | return symtab->FindFunctionSymbols (name, name_type_mask, sc_list); |
| 1406 | } |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
| 1410 | size_t |
Sean Callanan | b96ff33 | 2011-10-13 16:49:47 +0000 | [diff] [blame] | 1411 | Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1412 | { |
| 1413 | // No need to protect this call using m_mutex all other method calls are |
| 1414 | // already thread safe. |
| 1415 | |
| 1416 | |
| 1417 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1418 | "Module::FindSymbolsWithNameAndType (name = %s, type = %i)", |
| 1419 | name.AsCString(), |
| 1420 | symbol_type); |
| 1421 | const size_t initial_size = sc_list.GetSize(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1422 | SymbolVendor* sym_vendor = GetSymbolVendor(); |
| 1423 | if (sym_vendor) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1424 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1425 | Symtab *symtab = sym_vendor->GetSymtab(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1426 | if (symtab) |
| 1427 | { |
| 1428 | std::vector<uint32_t> symbol_indexes; |
| 1429 | symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes); |
| 1430 | SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); |
| 1431 | } |
| 1432 | } |
| 1433 | return sc_list.GetSize() - initial_size; |
| 1434 | } |
| 1435 | |
| 1436 | size_t |
| 1437 | Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list) |
| 1438 | { |
| 1439 | // No need to protect this call using m_mutex all other method calls are |
| 1440 | // already thread safe. |
| 1441 | |
| 1442 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1443 | "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)", |
| 1444 | regex.GetText(), |
| 1445 | symbol_type); |
| 1446 | const size_t initial_size = sc_list.GetSize(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1447 | SymbolVendor* sym_vendor = GetSymbolVendor(); |
| 1448 | if (sym_vendor) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1449 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1450 | Symtab *symtab = sym_vendor->GetSymtab(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1451 | if (symtab) |
| 1452 | { |
| 1453 | std::vector<uint32_t> symbol_indexes; |
Greg Clayton | bcf2cfb | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 1454 | symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1455 | SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); |
| 1456 | } |
| 1457 | } |
| 1458 | return sc_list.GetSize() - initial_size; |
| 1459 | } |
| 1460 | |
Greg Clayton | e01e07b | 2013-04-18 18:10:51 +0000 | [diff] [blame] | 1461 | void |
| 1462 | Module::SetSymbolFileFileSpec (const FileSpec &file) |
| 1463 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1464 | // Remove any sections in the unified section list that come from the current symbol vendor. |
| 1465 | if (m_symfile_ap) |
| 1466 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1467 | SectionList *section_list = GetSectionList(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1468 | SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile(); |
| 1469 | if (section_list && symbol_file) |
| 1470 | { |
| 1471 | ObjectFile *obj_file = symbol_file->GetObjectFile(); |
Greg Clayton | 540fbbf | 2013-08-13 16:46:35 +0000 | [diff] [blame] | 1472 | // Make sure we have an object file and that the symbol vendor's objfile isn't |
| 1473 | // the same as the module's objfile before we remove any sections for it... |
| 1474 | if (obj_file && obj_file != m_objfile_sp.get()) |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1475 | { |
| 1476 | size_t num_sections = section_list->GetNumSections (0); |
| 1477 | for (size_t idx = num_sections; idx > 0; --idx) |
| 1478 | { |
| 1479 | lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1)); |
| 1480 | if (section_sp->GetObjectFile() == obj_file) |
| 1481 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1482 | section_list->DeleteSection (idx - 1); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1483 | } |
| 1484 | } |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1485 | } |
| 1486 | } |
| 1487 | } |
| 1488 | |
Greg Clayton | e01e07b | 2013-04-18 18:10:51 +0000 | [diff] [blame] | 1489 | m_symfile_spec = file; |
| 1490 | m_symfile_ap.reset(); |
| 1491 | m_did_load_symbol_vendor = false; |
| 1492 | } |
| 1493 | |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1494 | bool |
| 1495 | Module::IsExecutable () |
| 1496 | { |
| 1497 | if (GetObjectFile() == NULL) |
| 1498 | return false; |
| 1499 | else |
| 1500 | return GetObjectFile()->IsExecutable(); |
| 1501 | } |
| 1502 | |
Jim Ingham | b53cb27 | 2011-08-03 01:03:17 +0000 | [diff] [blame] | 1503 | bool |
| 1504 | Module::IsLoadedInTarget (Target *target) |
| 1505 | { |
| 1506 | ObjectFile *obj_file = GetObjectFile(); |
| 1507 | if (obj_file) |
| 1508 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1509 | SectionList *sections = GetSectionList(); |
Jim Ingham | b53cb27 | 2011-08-03 01:03:17 +0000 | [diff] [blame] | 1510 | if (sections != NULL) |
| 1511 | { |
| 1512 | size_t num_sections = sections->GetSize(); |
Jim Ingham | b53cb27 | 2011-08-03 01:03:17 +0000 | [diff] [blame] | 1513 | for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) |
| 1514 | { |
| 1515 | SectionSP section_sp = sections->GetSectionAtIndex(sect_idx); |
| 1516 | if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) |
| 1517 | { |
| 1518 | return true; |
| 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | return false; |
| 1524 | } |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1525 | |
| 1526 | bool |
Enrico Granata | 9730339 | 2013-05-21 00:00:30 +0000 | [diff] [blame] | 1527 | Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream) |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1528 | { |
| 1529 | if (!target) |
| 1530 | { |
| 1531 | error.SetErrorString("invalid destination Target"); |
| 1532 | return false; |
| 1533 | } |
| 1534 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1535 | LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile(); |
Enrico Granata | 2ea43cd | 2013-05-13 17:03:52 +0000 | [diff] [blame] | 1536 | |
Greg Clayton | 994740f | 2014-08-18 21:08:44 +0000 | [diff] [blame] | 1537 | if (should_load == eLoadScriptFromSymFileFalse) |
| 1538 | return false; |
| 1539 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 1540 | Debugger &debugger = target->GetDebugger(); |
| 1541 | const ScriptLanguage script_language = debugger.GetScriptLanguage(); |
| 1542 | if (script_language != eScriptLanguageNone) |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1543 | { |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 1544 | |
| 1545 | PlatformSP platform_sp(target->GetPlatform()); |
| 1546 | |
| 1547 | if (!platform_sp) |
| 1548 | { |
| 1549 | error.SetErrorString("invalid Platform"); |
| 1550 | return false; |
| 1551 | } |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1552 | |
Greg Clayton | b9d8890 | 2013-03-23 00:50:58 +0000 | [diff] [blame] | 1553 | FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target, |
Enrico Granata | fe7295d | 2014-08-16 00:32:58 +0000 | [diff] [blame] | 1554 | *this, |
| 1555 | feedback_stream); |
Greg Clayton | b9d8890 | 2013-03-23 00:50:58 +0000 | [diff] [blame] | 1556 | |
| 1557 | |
| 1558 | const uint32_t num_specs = file_specs.GetSize(); |
| 1559 | if (num_specs) |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1560 | { |
Greg Clayton | b9d8890 | 2013-03-23 00:50:58 +0000 | [diff] [blame] | 1561 | ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter(); |
| 1562 | if (script_interpreter) |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 1563 | { |
| 1564 | for (uint32_t i=0; i<num_specs; ++i) |
| 1565 | { |
| 1566 | FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i)); |
| 1567 | if (scripting_fspec && scripting_fspec.Exists()) |
| 1568 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1569 | if (should_load == eLoadScriptFromSymFileWarn) |
Enrico Granata | 2ea43cd | 2013-05-13 17:03:52 +0000 | [diff] [blame] | 1570 | { |
Enrico Granata | 397ddd5 | 2013-05-21 20:13:34 +0000 | [diff] [blame] | 1571 | if (feedback_stream) |
Jim Ingham | d516deb | 2013-07-01 18:49:43 +0000 | [diff] [blame] | 1572 | feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in " |
| 1573 | "this debug session:\n\n command script import \"%s\"\n\n" |
| 1574 | "To run all discovered debug scripts in this session:\n\n" |
| 1575 | " settings set target.load-script-from-symbol-file true\n", |
| 1576 | GetFileSpec().GetFileNameStrippingExtension().GetCString(), |
| 1577 | scripting_fspec.GetPath().c_str()); |
Enrico Granata | 2ea43cd | 2013-05-13 17:03:52 +0000 | [diff] [blame] | 1578 | return false; |
| 1579 | } |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 1580 | StreamString scripting_stream; |
| 1581 | scripting_fspec.Dump(&scripting_stream); |
Enrico Granata | e0c70f1 | 2013-05-31 01:03:09 +0000 | [diff] [blame] | 1582 | const bool can_reload = true; |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 1583 | const bool init_lldb_globals = false; |
Jim Ingham | d516deb | 2013-07-01 18:49:43 +0000 | [diff] [blame] | 1584 | bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), |
| 1585 | can_reload, |
| 1586 | init_lldb_globals, |
| 1587 | error); |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 1588 | if (!did_load) |
| 1589 | return false; |
| 1590 | } |
| 1591 | } |
| 1592 | } |
Greg Clayton | b9d8890 | 2013-03-23 00:50:58 +0000 | [diff] [blame] | 1593 | else |
| 1594 | { |
| 1595 | error.SetErrorString("invalid ScriptInterpreter"); |
| 1596 | return false; |
| 1597 | } |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | return true; |
| 1601 | } |
| 1602 | |
| 1603 | bool |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1604 | Module::SetArchitecture (const ArchSpec &new_arch) |
| 1605 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1606 | if (!m_arch.IsValid()) |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1607 | { |
| 1608 | m_arch = new_arch; |
| 1609 | return true; |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1610 | } |
Sean Callanan | bf4b7be | 2012-12-13 22:07:14 +0000 | [diff] [blame] | 1611 | return m_arch.IsExactMatch(new_arch); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1614 | bool |
Greg Clayton | 751caf6 | 2014-02-07 22:54:47 +0000 | [diff] [blame] | 1615 | Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed) |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1616 | { |
Steve Pucci | 9e02dac | 2014-02-06 19:02:19 +0000 | [diff] [blame] | 1617 | ObjectFile *object_file = GetObjectFile(); |
| 1618 | if (object_file) |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1619 | { |
Greg Clayton | 751caf6 | 2014-02-07 22:54:47 +0000 | [diff] [blame] | 1620 | changed = object_file->SetLoadAddress(target, value, value_is_offset); |
Greg Clayton | 7524e09 | 2014-02-06 20:10:16 +0000 | [diff] [blame] | 1621 | return true; |
| 1622 | } |
| 1623 | else |
| 1624 | { |
| 1625 | changed = false; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1626 | } |
Steve Pucci | 9e02dac | 2014-02-06 19:02:19 +0000 | [diff] [blame] | 1627 | return false; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1630 | |
| 1631 | bool |
| 1632 | Module::MatchesModuleSpec (const ModuleSpec &module_ref) |
| 1633 | { |
| 1634 | const UUID &uuid = module_ref.GetUUID(); |
| 1635 | |
| 1636 | if (uuid.IsValid()) |
| 1637 | { |
| 1638 | // If the UUID matches, then nothing more needs to match... |
| 1639 | if (uuid == GetUUID()) |
| 1640 | return true; |
| 1641 | else |
| 1642 | return false; |
| 1643 | } |
| 1644 | |
| 1645 | const FileSpec &file_spec = module_ref.GetFileSpec(); |
| 1646 | if (file_spec) |
| 1647 | { |
Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 1648 | if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory())) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1649 | return false; |
| 1650 | } |
| 1651 | |
| 1652 | const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec(); |
| 1653 | if (platform_file_spec) |
| 1654 | { |
Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 1655 | if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory())) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1656 | return false; |
| 1657 | } |
| 1658 | |
| 1659 | const ArchSpec &arch = module_ref.GetArchitecture(); |
| 1660 | if (arch.IsValid()) |
| 1661 | { |
Sean Callanan | bf4b7be | 2012-12-13 22:07:14 +0000 | [diff] [blame] | 1662 | if (!m_arch.IsCompatibleMatch(arch)) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1663 | return false; |
| 1664 | } |
| 1665 | |
| 1666 | const ConstString &object_name = module_ref.GetObjectName(); |
| 1667 | if (object_name) |
| 1668 | { |
| 1669 | if (object_name != GetObjectName()) |
| 1670 | return false; |
| 1671 | } |
| 1672 | return true; |
| 1673 | } |
| 1674 | |
Greg Clayton | d804d28 | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 1675 | bool |
| 1676 | Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const |
| 1677 | { |
| 1678 | Mutex::Locker locker (m_mutex); |
| 1679 | return m_source_mappings.FindFile (orig_spec, new_spec); |
| 1680 | } |
| 1681 | |
Greg Clayton | f9be693 | 2012-03-19 22:22:41 +0000 | [diff] [blame] | 1682 | bool |
| 1683 | Module::RemapSourceFile (const char *path, std::string &new_path) const |
| 1684 | { |
| 1685 | Mutex::Locker locker (m_mutex); |
| 1686 | return m_source_mappings.RemapPath(path, new_path); |
| 1687 | } |
| 1688 | |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 1689 | uint32_t |
| 1690 | Module::GetVersion (uint32_t *versions, uint32_t num_versions) |
| 1691 | { |
| 1692 | ObjectFile *obj_file = GetObjectFile(); |
| 1693 | if (obj_file) |
| 1694 | return obj_file->GetVersion (versions, num_versions); |
| 1695 | |
| 1696 | if (versions && num_versions) |
| 1697 | { |
| 1698 | for (uint32_t i=0; i<num_versions; ++i) |
Enrico Granata | afcbdb1 | 2014-03-25 20:53:33 +0000 | [diff] [blame] | 1699 | versions[i] = LLDB_INVALID_MODULE_VERSION; |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 1700 | } |
| 1701 | return 0; |
| 1702 | } |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1703 | |
| 1704 | void |
| 1705 | Module::PrepareForFunctionNameLookup (const ConstString &name, |
| 1706 | uint32_t name_type_mask, |
| 1707 | ConstString &lookup_name, |
| 1708 | uint32_t &lookup_name_type_mask, |
| 1709 | bool &match_name_after_lookup) |
| 1710 | { |
| 1711 | const char *name_cstr = name.GetCString(); |
| 1712 | lookup_name_type_mask = eFunctionNameTypeNone; |
| 1713 | match_name_after_lookup = false; |
Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 1714 | |
| 1715 | llvm::StringRef basename; |
| 1716 | llvm::StringRef context; |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1717 | |
| 1718 | if (name_type_mask & eFunctionNameTypeAuto) |
| 1719 | { |
| 1720 | if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) |
| 1721 | lookup_name_type_mask = eFunctionNameTypeFull; |
| 1722 | else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) |
| 1723 | lookup_name_type_mask = eFunctionNameTypeFull; |
| 1724 | else |
| 1725 | { |
| 1726 | if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 1727 | lookup_name_type_mask |= eFunctionNameTypeSelector; |
| 1728 | |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1729 | CPPLanguageRuntime::MethodName cpp_method (name); |
Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 1730 | basename = cpp_method.GetBasename(); |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1731 | if (basename.empty()) |
| 1732 | { |
Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 1733 | if (CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename)) |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1734 | lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); |
Greg Clayton | c379540 | 2014-10-22 21:47:13 +0000 | [diff] [blame] | 1735 | else |
Greg Clayton | 65b0e76 | 2015-01-28 01:08:39 +0000 | [diff] [blame] | 1736 | lookup_name_type_mask |= eFunctionNameTypeFull; |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1737 | } |
| 1738 | else |
| 1739 | { |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1740 | lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1741 | } |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | else |
| 1745 | { |
| 1746 | lookup_name_type_mask = name_type_mask; |
| 1747 | if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) |
| 1748 | { |
| 1749 | // If they've asked for a CPP method or function name and it can't be that, we don't |
| 1750 | // even need to search for CPP methods or names. |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1751 | CPPLanguageRuntime::MethodName cpp_method (name); |
| 1752 | if (cpp_method.IsValid()) |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1753 | { |
Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 1754 | basename = cpp_method.GetBasename(); |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1755 | |
| 1756 | if (!cpp_method.GetQualifiers().empty()) |
| 1757 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1758 | // There is a "const" or other qualifier following the end of the function parens, |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1759 | // this can't be a eFunctionNameTypeBase |
| 1760 | lookup_name_type_mask &= ~(eFunctionNameTypeBase); |
| 1761 | if (lookup_name_type_mask == eFunctionNameTypeNone) |
| 1762 | return; |
| 1763 | } |
| 1764 | } |
| 1765 | else |
| 1766 | { |
Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 1767 | // If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can. |
| 1768 | // If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later. |
| 1769 | CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename); |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | if (lookup_name_type_mask & eFunctionNameTypeSelector) |
| 1774 | { |
| 1775 | if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) |
| 1776 | { |
| 1777 | lookup_name_type_mask &= ~(eFunctionNameTypeSelector); |
| 1778 | if (lookup_name_type_mask == eFunctionNameTypeNone) |
| 1779 | return; |
| 1780 | } |
| 1781 | } |
| 1782 | } |
| 1783 | |
Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 1784 | if (!basename.empty()) |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1785 | { |
| 1786 | // The name supplied was a partial C++ path like "a::count". In this case we want to do a |
| 1787 | // lookup on the basename "count" and then make sure any matching results contain "a::count" |
| 1788 | // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup" |
| 1789 | // to true |
Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 1790 | lookup_name.SetString(basename); |
Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 1791 | match_name_after_lookup = true; |
| 1792 | } |
| 1793 | else |
| 1794 | { |
| 1795 | // The name is already correct, just use the exact name as supplied, and we won't need |
| 1796 | // to check if any matches contain "name" |
| 1797 | lookup_name = name; |
| 1798 | match_name_after_lookup = false; |
| 1799 | } |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1800 | } |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 1801 | |
| 1802 | ModuleSP |
| 1803 | Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp) |
| 1804 | { |
| 1805 | if (delegate_sp) |
| 1806 | { |
| 1807 | // Must create a module and place it into a shared pointer before |
| 1808 | // we can create an object file since it has a std::weak_ptr back |
| 1809 | // to the module, so we need to control the creation carefully in |
| 1810 | // this static function |
| 1811 | ModuleSP module_sp(new Module()); |
| 1812 | module_sp->m_objfile_sp.reset (new ObjectFileJIT (module_sp, delegate_sp)); |
| 1813 | if (module_sp->m_objfile_sp) |
| 1814 | { |
| 1815 | // Once we get the object file, update our module with the object file's |
| 1816 | // architecture since it might differ in vendor/os if some parts were |
| 1817 | // unknown. |
| 1818 | module_sp->m_objfile_sp->GetArchitecture (module_sp->m_arch); |
| 1819 | } |
| 1820 | return module_sp; |
| 1821 | } |
| 1822 | return ModuleSP(); |
| 1823 | } |
| 1824 | |
Greg Clayton | 08928f3 | 2015-02-05 02:01:34 +0000 | [diff] [blame^] | 1825 | bool |
| 1826 | Module::GetIsDynamicLinkEditor() |
| 1827 | { |
| 1828 | ObjectFile * obj_file = GetObjectFile (); |
| 1829 | |
| 1830 | if (obj_file) |
| 1831 | return obj_file->GetIsDynamicLinkEditor(); |
| 1832 | |
| 1833 | return false; |
| 1834 | } |