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