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