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