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