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