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