Chris Lattner | 24943d2 | 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 | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Error.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 14 | #include "lldb/Core/DataBuffer.h" |
| 15 | #include "lldb/Core/DataBufferHeap.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
| 17 | #include "lldb/Core/ModuleList.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Section.h" |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 21 | #include "lldb/Core/StreamString.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Timer.h" |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 23 | #include "lldb/Host/Host.h" |
Enrico Granata | 146d952 | 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 | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/lldb-private-log.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 28 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 24943d2 | 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 | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 32 | #include "lldb/Target/Process.h" |
| 33 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | |
| 35 | using namespace lldb; |
| 36 | using namespace lldb_private; |
| 37 | |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 38 | // Shared pointers to modules track module lifetimes in |
| 39 | // targets and in the global module, but this collection |
| 40 | // will track all module objects that are still alive |
| 41 | typedef std::vector<Module *> ModuleCollection; |
| 42 | |
| 43 | static ModuleCollection & |
| 44 | GetModuleCollection() |
| 45 | { |
Jim Ingham | b67c2a2 | 2011-10-31 23:47:10 +0000 | [diff] [blame] | 46 | // This module collection needs to live past any module, so we could either make it a |
| 47 | // shared pointer in each module or just leak is. Since it is only an empty vector by |
| 48 | // the time all the modules have gone away, we just leak it for now. If we decide this |
| 49 | // is a big problem we can introduce a Finalize method that will tear everything down in |
| 50 | // a predictable order. |
| 51 | |
| 52 | static ModuleCollection *g_module_collection = NULL; |
| 53 | if (g_module_collection == NULL) |
| 54 | g_module_collection = new ModuleCollection(); |
| 55 | |
| 56 | return *g_module_collection; |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Greg Clayton | c149c8b | 2012-01-27 18:08:35 +0000 | [diff] [blame] | 59 | Mutex * |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 60 | Module::GetAllocationModuleCollectionMutex() |
| 61 | { |
Greg Clayton | c149c8b | 2012-01-27 18:08:35 +0000 | [diff] [blame] | 62 | // NOTE: The mutex below must be leaked since the global module list in |
| 63 | // the ModuleList class will get torn at some point, and we can't know |
| 64 | // if it will tear itself down before the "g_module_collection_mutex" below |
| 65 | // will. So we leak a Mutex object below to safeguard against that |
| 66 | |
| 67 | static Mutex *g_module_collection_mutex = NULL; |
| 68 | if (g_module_collection_mutex == NULL) |
| 69 | g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak |
| 70 | return g_module_collection_mutex; |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | size_t |
| 74 | Module::GetNumberAllocatedModules () |
| 75 | { |
| 76 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 77 | return GetModuleCollection().size(); |
| 78 | } |
| 79 | |
| 80 | Module * |
| 81 | Module::GetAllocatedModuleAtIndex (size_t idx) |
| 82 | { |
| 83 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 84 | ModuleCollection &modules = GetModuleCollection(); |
| 85 | if (idx < modules.size()) |
| 86 | return modules[idx]; |
| 87 | return NULL; |
| 88 | } |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 89 | #if 0 |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 90 | |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 91 | // These functions help us to determine if modules are still loaded, yet don't require that |
| 92 | // you have a command interpreter and can easily be called from an external debugger. |
| 93 | namespace lldb { |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 94 | |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 95 | void |
| 96 | ClearModuleInfo (void) |
| 97 | { |
Greg Clayton | 860b9ea | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 98 | const bool mandatory = true; |
| 99 | ModuleList::RemoveOrphanSharedModules(mandatory); |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void |
| 103 | DumpModuleInfo (void) |
| 104 | { |
| 105 | Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex()); |
| 106 | ModuleCollection &modules = GetModuleCollection(); |
| 107 | const size_t count = modules.size(); |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 108 | printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count); |
Greg Clayton | 08205a6 | 2012-01-27 18:45:39 +0000 | [diff] [blame] | 109 | for (size_t i=0; i<count; ++i) |
| 110 | { |
| 111 | |
| 112 | StreamString strm; |
| 113 | Module *module = modules[i]; |
| 114 | const bool in_shared_module_list = ModuleList::ModuleIsInCache (module); |
| 115 | module->GetDescription(&strm, eDescriptionLevelFull); |
| 116 | printf ("%p: shared = %i, ref_count = %3u, module = %s\n", |
| 117 | module, |
| 118 | in_shared_module_list, |
| 119 | (uint32_t)module->use_count(), |
| 120 | strm.GetString().c_str()); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | #endif |
Greg Clayton | f737d37 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 126 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 127 | Module::Module (const ModuleSpec &module_spec) : |
| 128 | m_mutex (Mutex::eMutexTypeRecursive), |
| 129 | m_mod_time (module_spec.GetFileSpec().GetModificationTime()), |
| 130 | m_arch (module_spec.GetArchitecture()), |
| 131 | m_uuid (), |
| 132 | m_file (module_spec.GetFileSpec()), |
| 133 | m_platform_file(module_spec.GetPlatformFileSpec()), |
| 134 | m_symfile_spec (module_spec.GetSymbolFileSpec()), |
| 135 | m_object_name (module_spec.GetObjectName()), |
| 136 | m_object_offset (module_spec.GetObjectOffset()), |
| 137 | m_objfile_sp (), |
| 138 | m_symfile_ap (), |
| 139 | m_ast (), |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 140 | m_source_mappings (), |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 141 | m_did_load_objfile (false), |
| 142 | m_did_load_symbol_vendor (false), |
| 143 | m_did_parse_uuid (false), |
| 144 | m_did_init_ast (false), |
| 145 | m_is_dynamic_loader_module (false), |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 146 | m_file_has_changed (false), |
| 147 | m_first_file_changed_log (false) |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 148 | { |
| 149 | // Scope for locker below... |
| 150 | { |
| 151 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 152 | GetModuleCollection().push_back(this); |
| 153 | } |
| 154 | |
Greg Clayton | f737d37 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 155 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 156 | if (log) |
| 157 | log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')", |
| 158 | this, |
| 159 | m_arch.GetArchitectureName(), |
| 160 | m_file.GetDirectory().AsCString(""), |
| 161 | m_file.GetFilename().AsCString(""), |
| 162 | m_object_name.IsEmpty() ? "" : "(", |
| 163 | m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), |
| 164 | m_object_name.IsEmpty() ? "" : ")"); |
| 165 | } |
| 166 | |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 167 | Module::Module(const FileSpec& file_spec, |
| 168 | const ArchSpec& arch, |
| 169 | const ConstString *object_name, |
| 170 | off_t object_offset) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 171 | m_mutex (Mutex::eMutexTypeRecursive), |
| 172 | m_mod_time (file_spec.GetModificationTime()), |
| 173 | m_arch (arch), |
| 174 | m_uuid (), |
| 175 | m_file (file_spec), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 176 | m_platform_file(), |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 177 | m_symfile_spec (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 178 | m_object_name (), |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 179 | m_object_offset (object_offset), |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 180 | m_objfile_sp (), |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 181 | m_symfile_ap (), |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 182 | m_ast (), |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 183 | m_source_mappings (), |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 184 | m_did_load_objfile (false), |
| 185 | m_did_load_symbol_vendor (false), |
| 186 | m_did_parse_uuid (false), |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 187 | m_did_init_ast (false), |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 188 | m_is_dynamic_loader_module (false), |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 189 | m_file_has_changed (false), |
| 190 | m_first_file_changed_log (false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | { |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 192 | // Scope for locker below... |
| 193 | { |
| 194 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 195 | GetModuleCollection().push_back(this); |
| 196 | } |
| 197 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | if (object_name) |
| 199 | m_object_name = *object_name; |
Greg Clayton | f737d37 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 200 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | if (log) |
| 202 | log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')", |
| 203 | this, |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 204 | m_arch.GetArchitectureName(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | m_file.GetDirectory().AsCString(""), |
| 206 | m_file.GetFilename().AsCString(""), |
| 207 | m_object_name.IsEmpty() ? "" : "(", |
| 208 | m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), |
| 209 | m_object_name.IsEmpty() ? "" : ")"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | Module::~Module() |
| 213 | { |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 214 | // Scope for locker below... |
| 215 | { |
| 216 | Mutex::Locker locker (GetAllocationModuleCollectionMutex()); |
| 217 | ModuleCollection &modules = GetModuleCollection(); |
| 218 | ModuleCollection::iterator end = modules.end(); |
| 219 | ModuleCollection::iterator pos = std::find(modules.begin(), end, this); |
Greg Clayton | f737d37 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 220 | assert (pos != end); |
| 221 | modules.erase(pos); |
Greg Clayton | 899025f | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 222 | } |
Greg Clayton | f737d37 | 2012-10-08 22:41:53 +0000 | [diff] [blame] | 223 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | if (log) |
| 225 | log->Printf ("%p Module::~Module((%s) '%s/%s%s%s%s')", |
| 226 | this, |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 227 | m_arch.GetArchitectureName(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 228 | m_file.GetDirectory().AsCString(""), |
| 229 | m_file.GetFilename().AsCString(""), |
| 230 | m_object_name.IsEmpty() ? "" : "(", |
| 231 | m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), |
| 232 | m_object_name.IsEmpty() ? "" : ")"); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 233 | // Release any auto pointers before we start tearing down our member |
| 234 | // variables since the object file and symbol files might need to make |
| 235 | // function calls back into this module object. The ordering is important |
| 236 | // here because symbol files can require the module object file. So we tear |
| 237 | // down the symbol file first, then the object file. |
| 238 | m_symfile_ap.reset(); |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 239 | m_objfile_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Greg Clayton | 6c5438b | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 242 | ObjectFile * |
| 243 | Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error) |
| 244 | { |
| 245 | if (m_objfile_sp) |
| 246 | { |
| 247 | error.SetErrorString ("object file already exists"); |
| 248 | } |
| 249 | else |
| 250 | { |
| 251 | Mutex::Locker locker (m_mutex); |
| 252 | if (process_sp) |
| 253 | { |
Greg Clayton | 6c5438b | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 254 | m_did_load_objfile = true; |
| 255 | std::auto_ptr<DataBufferHeap> data_ap (new DataBufferHeap (512, 0)); |
| 256 | Error readmem_error; |
| 257 | const size_t bytes_read = process_sp->ReadMemory (header_addr, |
| 258 | data_ap->GetBytes(), |
| 259 | data_ap->GetByteSize(), |
| 260 | readmem_error); |
| 261 | if (bytes_read == 512) |
| 262 | { |
| 263 | DataBufferSP data_sp(data_ap.release()); |
| 264 | m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp); |
| 265 | if (m_objfile_sp) |
| 266 | { |
Greg Clayton | 808e92a | 2012-04-20 19:50:20 +0000 | [diff] [blame] | 267 | StreamString s; |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 268 | s.Printf("0x%16.16" PRIx64, header_addr); |
Greg Clayton | 808e92a | 2012-04-20 19:50:20 +0000 | [diff] [blame] | 269 | m_object_name.SetCString (s.GetData()); |
| 270 | |
| 271 | // Once we get the object file, update our module with the object file's |
Greg Clayton | 6c5438b | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 272 | // architecture since it might differ in vendor/os if some parts were |
| 273 | // unknown. |
| 274 | m_objfile_sp->GetArchitecture (m_arch); |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | error.SetErrorString ("unable to find suitable object file plug-in"); |
| 279 | } |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString()); |
| 284 | } |
| 285 | } |
| 286 | else |
| 287 | { |
| 288 | error.SetErrorString ("invalid process"); |
| 289 | } |
| 290 | } |
| 291 | return m_objfile_sp.get(); |
| 292 | } |
| 293 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 294 | |
Greg Clayton | 0467c78 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 295 | const lldb_private::UUID& |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 296 | Module::GetUUID() |
| 297 | { |
| 298 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 299 | if (m_did_parse_uuid == false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 300 | { |
| 301 | ObjectFile * obj_file = GetObjectFile (); |
| 302 | |
| 303 | if (obj_file != NULL) |
| 304 | { |
| 305 | obj_file->GetUUID(&m_uuid); |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 306 | m_did_parse_uuid = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | return m_uuid; |
| 310 | } |
| 311 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 312 | ClangASTContext & |
| 313 | Module::GetClangASTContext () |
| 314 | { |
| 315 | Mutex::Locker locker (m_mutex); |
| 316 | if (m_did_init_ast == false) |
| 317 | { |
| 318 | ObjectFile * objfile = GetObjectFile(); |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 319 | ArchSpec object_arch; |
| 320 | if (objfile && objfile->GetArchitecture(object_arch)) |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 321 | { |
| 322 | m_did_init_ast = true; |
Jason Molenda | 1b97a65 | 2012-10-16 20:45:49 +0000 | [diff] [blame] | 323 | |
| 324 | // LLVM wants this to be set to iOS or MacOSX; if we're working on |
| 325 | // a bare-boards type image, change the triple for llvm's benefit. |
| 326 | if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple |
| 327 | && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) |
| 328 | { |
| 329 | if (object_arch.GetTriple().getArch() == llvm::Triple::arm || |
| 330 | object_arch.GetTriple().getArch() == llvm::Triple::thumb) |
| 331 | { |
| 332 | object_arch.GetTriple().setOS(llvm::Triple::IOS); |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | object_arch.GetTriple().setOS(llvm::Triple::MacOSX); |
| 337 | } |
| 338 | } |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 339 | m_ast.SetArchitecture (object_arch); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | return m_ast; |
| 343 | } |
| 344 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | void |
| 346 | Module::ParseAllDebugSymbols() |
| 347 | { |
| 348 | Mutex::Locker locker (m_mutex); |
| 349 | uint32_t num_comp_units = GetNumCompileUnits(); |
| 350 | if (num_comp_units == 0) |
| 351 | return; |
| 352 | |
Greg Clayton | 02e210c | 2011-09-17 07:23:18 +0000 | [diff] [blame] | 353 | SymbolContext sc; |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 354 | sc.module_sp = shared_from_this(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 355 | uint32_t cu_idx; |
| 356 | SymbolVendor *symbols = GetSymbolVendor (); |
| 357 | |
| 358 | for (cu_idx = 0; cu_idx < num_comp_units; cu_idx++) |
| 359 | { |
| 360 | sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get(); |
| 361 | if (sc.comp_unit) |
| 362 | { |
| 363 | sc.function = NULL; |
| 364 | symbols->ParseVariablesForContext(sc); |
| 365 | |
| 366 | symbols->ParseCompileUnitFunctions(sc); |
| 367 | |
| 368 | uint32_t func_idx; |
| 369 | for (func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx) |
| 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 | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 388 | sc->module_sp = shared_from_this(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 391 | ModuleSP |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 392 | Module::CalculateSymbolContextModule () |
| 393 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 394 | return shared_from_this(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | void |
| 398 | Module::DumpSymbolContext(Stream *s) |
| 399 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 400 | s->Printf(", Module{%p}", this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | uint32_t |
| 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 |
| 415 | Module::GetCompileUnitAtIndex (uint32_t index) |
| 416 | { |
| 417 | Mutex::Locker locker (m_mutex); |
| 418 | uint32_t num_comp_units = GetNumCompileUnits (); |
| 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 | 24943d2 | 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 | 5f35a4b | 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 | 24943d2 | 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 | |
| 447 | // Clear the result symbol context in case we don't find anything |
| 448 | sc.Clear(); |
| 449 | |
| 450 | // Get the section from the section/offset address. |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 451 | SectionSP section_sp (so_addr.GetSection()); |
Chris Lattner | 24943d2 | 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 | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 454 | if (section_sp && section_sp->GetModule().get() == this) |
Chris Lattner | 24943d2 | 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 | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 458 | sc.module_sp = shared_from_this(); |
Chris Lattner | 24943d2 | 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 | bddb789 | 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 | 24943d2 | 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 | 537a7a8 | 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 | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 504 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 505 | FileSpec file_spec(file_path, false); |
Chris Lattner | 24943d2 | 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 | |
| 532 | uint32_t |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 533 | Module::FindGlobalVariables(const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | { |
| 535 | SymbolVendor *symbols = GetSymbolVendor (); |
| 536 | if (symbols) |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 537 | return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | uint32_t |
| 541 | Module::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 542 | { |
| 543 | SymbolVendor *symbols = GetSymbolVendor (); |
| 544 | if (symbols) |
| 545 | return symbols->FindGlobalVariables(regex, append, max_matches, variables); |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | uint32_t |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 550 | Module::FindCompileUnits (const FileSpec &path, |
| 551 | bool append, |
| 552 | SymbolContextList &sc_list) |
| 553 | { |
| 554 | if (!append) |
| 555 | sc_list.Clear(); |
| 556 | |
| 557 | const uint32_t start_size = sc_list.GetSize(); |
| 558 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 559 | SymbolContext sc; |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 560 | sc.module_sp = shared_from_this(); |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 561 | const bool compare_directory = path.GetDirectory(); |
| 562 | for (uint32_t i=0; i<num_compile_units; ++i) |
| 563 | { |
| 564 | sc.comp_unit = GetCompileUnitAtIndex(i).get(); |
Greg Clayton | c705730 | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 565 | if (sc.comp_unit) |
| 566 | { |
| 567 | if (FileSpec::Equal (*sc.comp_unit, path, compare_directory)) |
| 568 | sc_list.Append(sc); |
| 569 | } |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 570 | } |
| 571 | return sc_list.GetSize() - start_size; |
| 572 | } |
| 573 | |
| 574 | uint32_t |
Sean Callanan | 3e80cd9 | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 575 | Module::FindFunctions (const ConstString &name, |
| 576 | const ClangNamespaceDecl *namespace_decl, |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 577 | uint32_t name_type_mask, |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 578 | bool include_symbols, |
| 579 | bool include_inlines, |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 580 | bool append, |
| 581 | SymbolContextList& sc_list) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | { |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 583 | if (!append) |
| 584 | sc_list.Clear(); |
| 585 | |
| 586 | const uint32_t start_size = sc_list.GetSize(); |
| 587 | |
| 588 | // Find all the functions (not symbols, but debug information functions... |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 589 | SymbolVendor *symbols = GetSymbolVendor (); |
| 590 | if (symbols) |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 591 | symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list); |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 592 | |
| 593 | // Now check our symbol table for symbols that are code symbols if requested |
| 594 | if (include_symbols) |
| 595 | { |
| 596 | ObjectFile *objfile = GetObjectFile(); |
| 597 | if (objfile) |
| 598 | { |
| 599 | Symtab *symtab = objfile->GetSymtab(); |
| 600 | if (symtab) |
| 601 | { |
| 602 | std::vector<uint32_t> symbol_indexes; |
| 603 | symtab->FindAllSymbolsWithNameAndType (name, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); |
| 604 | const uint32_t num_matches = symbol_indexes.size(); |
| 605 | if (num_matches) |
| 606 | { |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 607 | const bool merge_symbol_into_function = true; |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 608 | SymbolContext sc(this); |
| 609 | for (uint32_t i=0; i<num_matches; i++) |
| 610 | { |
| 611 | sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 612 | sc_list.AppendIfUnique (sc, merge_symbol_into_function); |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | return sc_list.GetSize() - start_size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | uint32_t |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 622 | Module::FindFunctions (const RegularExpression& regex, |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 623 | bool include_symbols, |
| 624 | bool include_inlines, |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 625 | bool append, |
| 626 | SymbolContextList& sc_list) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | { |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 628 | if (!append) |
| 629 | sc_list.Clear(); |
| 630 | |
| 631 | const uint32_t start_size = sc_list.GetSize(); |
| 632 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 633 | SymbolVendor *symbols = GetSymbolVendor (); |
| 634 | if (symbols) |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 635 | symbols->FindFunctions(regex, include_inlines, append, sc_list); |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 636 | // Now check our symbol table for symbols that are code symbols if requested |
| 637 | if (include_symbols) |
| 638 | { |
| 639 | ObjectFile *objfile = GetObjectFile(); |
| 640 | if (objfile) |
| 641 | { |
| 642 | Symtab *symtab = objfile->GetSymtab(); |
| 643 | if (symtab) |
| 644 | { |
| 645 | std::vector<uint32_t> symbol_indexes; |
| 646 | symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); |
| 647 | const uint32_t num_matches = symbol_indexes.size(); |
| 648 | if (num_matches) |
| 649 | { |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 650 | const bool merge_symbol_into_function = true; |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 651 | SymbolContext sc(this); |
| 652 | for (uint32_t i=0; i<num_matches; i++) |
| 653 | { |
| 654 | sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 655 | sc_list.AppendIfUnique (sc, merge_symbol_into_function); |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | return sc_list.GetSize() - start_size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 664 | uint32_t |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 665 | Module::FindTypes_Impl (const SymbolContext& sc, |
| 666 | const ConstString &name, |
| 667 | const ClangNamespaceDecl *namespace_decl, |
| 668 | bool append, |
| 669 | uint32_t max_matches, |
| 670 | TypeList& types) |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 671 | { |
| 672 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 673 | if (sc.module_sp.get() == NULL || sc.module_sp.get() == this) |
| 674 | { |
| 675 | SymbolVendor *symbols = GetSymbolVendor (); |
| 676 | if (symbols) |
Sean Callanan | 0fcec13 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 677 | return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types); |
Greg Clayton | 7aff9ff | 2010-08-03 01:26:16 +0000 | [diff] [blame] | 678 | } |
| 679 | return 0; |
| 680 | } |
| 681 | |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 682 | uint32_t |
| 683 | Module::FindTypesInNamespace (const SymbolContext& sc, |
| 684 | const ConstString &type_name, |
| 685 | const ClangNamespaceDecl *namespace_decl, |
| 686 | uint32_t max_matches, |
| 687 | TypeList& type_list) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 688 | { |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 689 | const bool append = true; |
| 690 | return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Greg Clayton | 0b93a75 | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 693 | lldb::TypeSP |
| 694 | Module::FindFirstType (const SymbolContext& sc, |
| 695 | const ConstString &name, |
| 696 | bool exact_match) |
| 697 | { |
| 698 | TypeList type_list; |
| 699 | const uint32_t num_matches = FindTypes (sc, name, exact_match, 1, type_list); |
| 700 | if (num_matches) |
| 701 | return type_list.GetTypeAtIndex(0); |
| 702 | return TypeSP(); |
| 703 | } |
| 704 | |
| 705 | |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 706 | uint32_t |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 707 | Module::FindTypes (const SymbolContext& sc, |
| 708 | const ConstString &name, |
| 709 | bool exact_match, |
| 710 | uint32_t max_matches, |
| 711 | TypeList& types) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 712 | { |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 713 | uint32_t num_matches = 0; |
| 714 | const char *type_name_cstr = name.GetCString(); |
| 715 | std::string type_scope; |
| 716 | std::string type_basename; |
| 717 | const bool append = true; |
Greg Clayton | b9bd4ee | 2012-10-22 16:19:56 +0000 | [diff] [blame] | 718 | TypeClass type_class = eTypeClassAny; |
| 719 | if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class)) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 720 | { |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 721 | // Check if "name" starts with "::" which means the qualified type starts |
| 722 | // from the root namespace and implies and exact match. The typenames we |
| 723 | // get back from clang do not start with "::" so we need to strip this off |
| 724 | // in order to get the qualfied names to match |
| 725 | |
| 726 | if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':') |
| 727 | { |
| 728 | type_scope.erase(0,2); |
| 729 | exact_match = true; |
| 730 | } |
| 731 | ConstString type_basename_const_str (type_basename.c_str()); |
| 732 | if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types)) |
| 733 | { |
Greg Clayton | b9bd4ee | 2012-10-22 16:19:56 +0000 | [diff] [blame] | 734 | types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match); |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 735 | num_matches = types.GetSize(); |
| 736 | } |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 737 | } |
| 738 | else |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 739 | { |
| 740 | // The type is not in a namespace/class scope, just search for it by basename |
Greg Clayton | b9bd4ee | 2012-10-22 16:19:56 +0000 | [diff] [blame] | 741 | if (type_class != eTypeClassAny) |
| 742 | { |
| 743 | // The "type_name_cstr" will have been modified if we have a valid type class |
| 744 | // prefix (like "struct", "class", "union", "typedef" etc). |
| 745 | num_matches = FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types); |
| 746 | types.RemoveMismatchedTypes (type_class); |
| 747 | num_matches = types.GetSize(); |
| 748 | } |
| 749 | else |
| 750 | { |
| 751 | num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types); |
| 752 | } |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | return num_matches; |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 756 | |
| 757 | } |
| 758 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | //uint32_t |
| 760 | //Module::FindTypes(const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, const char *udt_name, TypeList& types) |
| 761 | //{ |
| 762 | // Timer scoped_timer(__PRETTY_FUNCTION__); |
| 763 | // SymbolVendor *symbols = GetSymbolVendor (); |
| 764 | // if (symbols) |
| 765 | // return symbols->FindTypes(sc, regex, append, max_matches, encoding, udt_name, types); |
| 766 | // return 0; |
| 767 | // |
| 768 | //} |
| 769 | |
| 770 | SymbolVendor* |
| 771 | Module::GetSymbolVendor (bool can_create) |
| 772 | { |
| 773 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 774 | if (m_did_load_symbol_vendor == false && can_create) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 775 | { |
| 776 | ObjectFile *obj_file = GetObjectFile (); |
| 777 | if (obj_file != NULL) |
| 778 | { |
| 779 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 780 | m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this())); |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 781 | m_did_load_symbol_vendor = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | return m_symfile_ap.get(); |
| 785 | } |
| 786 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 787 | void |
| 788 | Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name) |
| 789 | { |
| 790 | // Container objects whose paths do not specify a file directly can call |
| 791 | // this function to correct the file and object names. |
| 792 | m_file = file; |
| 793 | m_mod_time = file.GetModificationTime(); |
| 794 | m_object_name = object_name; |
| 795 | } |
| 796 | |
| 797 | const ArchSpec& |
| 798 | Module::GetArchitecture () const |
| 799 | { |
| 800 | return m_arch; |
| 801 | } |
| 802 | |
| 803 | void |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 804 | Module::GetDescription (Stream *s, lldb::DescriptionLevel level) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 805 | { |
| 806 | Mutex::Locker locker (m_mutex); |
| 807 | |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 808 | if (level >= eDescriptionLevelFull) |
| 809 | { |
| 810 | if (m_arch.IsValid()) |
| 811 | s->Printf("(%s) ", m_arch.GetArchitectureName()); |
| 812 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 813 | |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 814 | if (level == eDescriptionLevelBrief) |
| 815 | { |
| 816 | const char *filename = m_file.GetFilename().GetCString(); |
| 817 | if (filename) |
| 818 | s->PutCString (filename); |
| 819 | } |
| 820 | else |
| 821 | { |
| 822 | char path[PATH_MAX]; |
| 823 | if (m_file.GetPath(path, sizeof(path))) |
| 824 | s->PutCString(path); |
| 825 | } |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 826 | |
| 827 | const char *object_name = m_object_name.GetCString(); |
| 828 | if (object_name) |
| 829 | s->Printf("(%s)", object_name); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | void |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 833 | Module::ReportError (const char *format, ...) |
| 834 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 835 | if (format && format[0]) |
| 836 | { |
| 837 | StreamString strm; |
| 838 | strm.PutCString("error: "); |
| 839 | GetDescription(&strm, lldb::eDescriptionLevelBrief); |
Greg Clayton | 7129913 | 2012-01-11 01:59:18 +0000 | [diff] [blame] | 840 | strm.PutChar (' '); |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 841 | va_list args; |
| 842 | va_start (args, format); |
| 843 | strm.PrintfVarArg(format, args); |
| 844 | va_end (args); |
| 845 | |
| 846 | const int format_len = strlen(format); |
| 847 | if (format_len > 0) |
| 848 | { |
| 849 | const char last_char = format[format_len-1]; |
| 850 | if (last_char != '\n' || last_char != '\r') |
| 851 | strm.EOL(); |
| 852 | } |
| 853 | Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); |
| 854 | |
| 855 | } |
| 856 | } |
| 857 | |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 858 | bool |
| 859 | Module::FileHasChanged () const |
| 860 | { |
| 861 | if (m_file_has_changed == false) |
| 862 | m_file_has_changed = (m_file.GetModificationTime() != m_mod_time); |
| 863 | return m_file_has_changed; |
| 864 | } |
| 865 | |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 866 | void |
| 867 | Module::ReportErrorIfModifyDetected (const char *format, ...) |
| 868 | { |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 869 | if (m_first_file_changed_log == false) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 870 | { |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 871 | if (FileHasChanged ()) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 872 | { |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 873 | m_first_file_changed_log = true; |
| 874 | if (format) |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 875 | { |
Greg Clayton | cbacba1 | 2012-07-12 22:51:12 +0000 | [diff] [blame] | 876 | StreamString strm; |
| 877 | strm.PutCString("error: the object file "); |
| 878 | GetDescription(&strm, lldb::eDescriptionLevelFull); |
| 879 | strm.PutCString (" has been modified\n"); |
| 880 | |
| 881 | va_list args; |
| 882 | va_start (args, format); |
| 883 | strm.PrintfVarArg(format, args); |
| 884 | va_end (args); |
| 885 | |
| 886 | const int format_len = strlen(format); |
| 887 | if (format_len > 0) |
| 888 | { |
| 889 | const char last_char = format[format_len-1]; |
| 890 | if (last_char != '\n' || last_char != '\r') |
| 891 | strm.EOL(); |
| 892 | } |
| 893 | strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n"); |
| 894 | Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 895 | } |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 896 | } |
| 897 | } |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | void |
| 901 | Module::ReportWarning (const char *format, ...) |
| 902 | { |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 903 | if (format && format[0]) |
| 904 | { |
| 905 | StreamString strm; |
| 906 | strm.PutCString("warning: "); |
Greg Clayton | 7129913 | 2012-01-11 01:59:18 +0000 | [diff] [blame] | 907 | GetDescription(&strm, lldb::eDescriptionLevelFull); |
| 908 | strm.PutChar (' '); |
Greg Clayton | df6dc88 | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 909 | |
| 910 | va_list args; |
| 911 | va_start (args, format); |
| 912 | strm.PrintfVarArg(format, args); |
| 913 | va_end (args); |
| 914 | |
| 915 | const int format_len = strlen(format); |
| 916 | if (format_len > 0) |
| 917 | { |
| 918 | const char last_char = format[format_len-1]; |
| 919 | if (last_char != '\n' || last_char != '\r') |
| 920 | strm.EOL(); |
| 921 | } |
| 922 | Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str()); |
| 923 | } |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | void |
| 927 | Module::LogMessage (Log *log, const char *format, ...) |
| 928 | { |
| 929 | if (log) |
| 930 | { |
| 931 | StreamString log_message; |
Greg Clayton | 7129913 | 2012-01-11 01:59:18 +0000 | [diff] [blame] | 932 | GetDescription(&log_message, lldb::eDescriptionLevelFull); |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 933 | log_message.PutCString (": "); |
| 934 | va_list args; |
| 935 | va_start (args, format); |
| 936 | log_message.PrintfVarArg (format, args); |
| 937 | va_end (args); |
| 938 | log->PutCString(log_message.GetString().c_str()); |
| 939 | } |
| 940 | } |
| 941 | |
Greg Clayton | 73a3571 | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 942 | void |
| 943 | Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...) |
| 944 | { |
| 945 | if (log) |
| 946 | { |
| 947 | StreamString log_message; |
| 948 | GetDescription(&log_message, lldb::eDescriptionLevelFull); |
| 949 | log_message.PutCString (": "); |
| 950 | va_list args; |
| 951 | va_start (args, format); |
| 952 | log_message.PrintfVarArg (format, args); |
| 953 | va_end (args); |
| 954 | if (log->GetVerbose()) |
| 955 | Host::Backtrace (log_message, 1024); |
| 956 | log->PutCString(log_message.GetString().c_str()); |
| 957 | } |
| 958 | } |
| 959 | |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 960 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 961 | Module::Dump(Stream *s) |
| 962 | { |
| 963 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 964 | //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 965 | s->Indent(); |
| 966 | s->Printf("Module %s/%s%s%s%s\n", |
| 967 | m_file.GetDirectory().AsCString(), |
| 968 | m_file.GetFilename().AsCString(), |
| 969 | m_object_name ? "(" : "", |
| 970 | m_object_name ? m_object_name.GetCString() : "", |
| 971 | m_object_name ? ")" : ""); |
| 972 | |
| 973 | s->IndentMore(); |
| 974 | ObjectFile *objfile = GetObjectFile (); |
| 975 | |
| 976 | if (objfile) |
| 977 | objfile->Dump(s); |
| 978 | |
| 979 | SymbolVendor *symbols = GetSymbolVendor (); |
| 980 | |
| 981 | if (symbols) |
| 982 | symbols->Dump(s); |
| 983 | |
| 984 | s->IndentLess(); |
| 985 | } |
| 986 | |
| 987 | |
| 988 | TypeList* |
| 989 | Module::GetTypeList () |
| 990 | { |
| 991 | SymbolVendor *symbols = GetSymbolVendor (); |
| 992 | if (symbols) |
| 993 | return &symbols->GetTypeList(); |
| 994 | return NULL; |
| 995 | } |
| 996 | |
| 997 | const ConstString & |
| 998 | Module::GetObjectName() const |
| 999 | { |
| 1000 | return m_object_name; |
| 1001 | } |
| 1002 | |
| 1003 | ObjectFile * |
| 1004 | Module::GetObjectFile() |
| 1005 | { |
| 1006 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 1007 | if (m_did_load_objfile == false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1008 | { |
Greg Clayton | 236c1c7 | 2010-09-07 23:40:05 +0000 | [diff] [blame] | 1009 | m_did_load_objfile = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1010 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1011 | "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 1012 | DataBufferSP file_data_sp; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1013 | m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(), |
| 1014 | &m_file, |
| 1015 | m_object_offset, |
| 1016 | m_file.GetByteSize(), |
| 1017 | file_data_sp); |
Greg Clayton | 6a64bbf | 2011-09-21 03:57:31 +0000 | [diff] [blame] | 1018 | if (m_objfile_sp) |
| 1019 | { |
| 1020 | // Once we get the object file, update our module with the object file's |
| 1021 | // architecture since it might differ in vendor/os if some parts were |
| 1022 | // unknown. |
| 1023 | m_objfile_sp->GetArchitecture (m_arch); |
| 1024 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | } |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 1026 | return m_objfile_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | |
| 1030 | const Symbol * |
| 1031 | Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type) |
| 1032 | { |
| 1033 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1034 | "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", |
| 1035 | name.AsCString(), |
| 1036 | symbol_type); |
| 1037 | ObjectFile *objfile = GetObjectFile(); |
| 1038 | if (objfile) |
| 1039 | { |
| 1040 | Symtab *symtab = objfile->GetSymtab(); |
| 1041 | if (symtab) |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 1042 | return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1043 | } |
| 1044 | return NULL; |
| 1045 | } |
| 1046 | void |
| 1047 | Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list) |
| 1048 | { |
| 1049 | // No need to protect this call using m_mutex all other method calls are |
| 1050 | // already thread safe. |
| 1051 | |
| 1052 | size_t num_indices = symbol_indexes.size(); |
| 1053 | if (num_indices > 0) |
| 1054 | { |
| 1055 | SymbolContext sc; |
| 1056 | CalculateSymbolContext (&sc); |
| 1057 | for (size_t i = 0; i < num_indices; i++) |
| 1058 | { |
| 1059 | sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]); |
| 1060 | if (sc.symbol) |
| 1061 | sc_list.Append (sc); |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | size_t |
Sean Callanan | aa4a553 | 2011-10-13 16:49:47 +0000 | [diff] [blame] | 1067 | Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1068 | { |
| 1069 | // No need to protect this call using m_mutex all other method calls are |
| 1070 | // already thread safe. |
| 1071 | |
| 1072 | |
| 1073 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1074 | "Module::FindSymbolsWithNameAndType (name = %s, type = %i)", |
| 1075 | name.AsCString(), |
| 1076 | symbol_type); |
| 1077 | const size_t initial_size = sc_list.GetSize(); |
| 1078 | ObjectFile *objfile = GetObjectFile (); |
| 1079 | if (objfile) |
| 1080 | { |
| 1081 | Symtab *symtab = objfile->GetSymtab(); |
| 1082 | if (symtab) |
| 1083 | { |
| 1084 | std::vector<uint32_t> symbol_indexes; |
| 1085 | symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes); |
| 1086 | SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); |
| 1087 | } |
| 1088 | } |
| 1089 | return sc_list.GetSize() - initial_size; |
| 1090 | } |
| 1091 | |
| 1092 | size_t |
| 1093 | Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, 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 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| 1099 | "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)", |
| 1100 | regex.GetText(), |
| 1101 | symbol_type); |
| 1102 | const size_t initial_size = sc_list.GetSize(); |
| 1103 | ObjectFile *objfile = GetObjectFile (); |
| 1104 | if (objfile) |
| 1105 | { |
| 1106 | Symtab *symtab = objfile->GetSymtab(); |
| 1107 | if (symtab) |
| 1108 | { |
| 1109 | std::vector<uint32_t> symbol_indexes; |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 1110 | symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1111 | SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); |
| 1112 | } |
| 1113 | } |
| 1114 | return sc_list.GetSize() - initial_size; |
| 1115 | } |
| 1116 | |
| 1117 | const TimeValue & |
| 1118 | Module::GetModificationTime () const |
| 1119 | { |
| 1120 | return m_mod_time; |
| 1121 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1122 | |
| 1123 | bool |
| 1124 | Module::IsExecutable () |
| 1125 | { |
| 1126 | if (GetObjectFile() == NULL) |
| 1127 | return false; |
| 1128 | else |
| 1129 | return GetObjectFile()->IsExecutable(); |
| 1130 | } |
| 1131 | |
Jim Ingham | 51b11e0 | 2011-08-03 01:03:17 +0000 | [diff] [blame] | 1132 | bool |
| 1133 | Module::IsLoadedInTarget (Target *target) |
| 1134 | { |
| 1135 | ObjectFile *obj_file = GetObjectFile(); |
| 1136 | if (obj_file) |
| 1137 | { |
| 1138 | SectionList *sections = obj_file->GetSectionList(); |
| 1139 | if (sections != NULL) |
| 1140 | { |
| 1141 | size_t num_sections = sections->GetSize(); |
Jim Ingham | 51b11e0 | 2011-08-03 01:03:17 +0000 | [diff] [blame] | 1142 | for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) |
| 1143 | { |
| 1144 | SectionSP section_sp = sections->GetSectionAtIndex(sect_idx); |
| 1145 | if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) |
| 1146 | { |
| 1147 | return true; |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | return false; |
| 1153 | } |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1154 | |
| 1155 | bool |
| 1156 | Module::LoadScriptingResourceInTarget (Target *target, Error& error) |
| 1157 | { |
| 1158 | if (!target) |
| 1159 | { |
| 1160 | error.SetErrorString("invalid destination Target"); |
| 1161 | return false; |
| 1162 | } |
| 1163 | |
| 1164 | PlatformSP platform_sp(target->GetPlatform()); |
| 1165 | |
| 1166 | if (!platform_sp) |
| 1167 | { |
| 1168 | error.SetErrorString("invalid Platform"); |
| 1169 | return false; |
| 1170 | } |
| 1171 | |
| 1172 | ModuleSpec module_spec(GetFileSpec()); |
| 1173 | FileSpec scripting_fspec = platform_sp->LocateExecutableScriptingResource(module_spec); |
| 1174 | Debugger &debugger(target->GetDebugger()); |
| 1175 | if (scripting_fspec && scripting_fspec.Exists()) |
| 1176 | { |
| 1177 | ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter(); |
| 1178 | if (script_interpreter) |
| 1179 | { |
| 1180 | StreamString scripting_stream; |
| 1181 | scripting_fspec.Dump(&scripting_stream); |
Jim Ingham | 14e71ec | 2012-12-07 17:43:38 +0000 | [diff] [blame] | 1182 | const bool can_reload = false; |
| 1183 | const bool init_lldb_globals = false; |
| 1184 | bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), can_reload, init_lldb_globals, error); |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1185 | if (!did_load) |
| 1186 | return false; |
| 1187 | } |
| 1188 | else |
| 1189 | { |
| 1190 | error.SetErrorString("invalid ScriptInterpreter"); |
| 1191 | return false; |
| 1192 | } |
| 1193 | } |
| 1194 | return true; |
| 1195 | } |
| 1196 | |
| 1197 | bool |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1198 | Module::SetArchitecture (const ArchSpec &new_arch) |
| 1199 | { |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1200 | if (!m_arch.IsValid()) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1201 | { |
| 1202 | m_arch = new_arch; |
| 1203 | return true; |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1204 | } |
| 1205 | return m_arch == new_arch; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1208 | bool |
| 1209 | Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed) |
| 1210 | { |
Greg Clayton | 9ab696e | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 1211 | size_t num_loaded_sections = 0; |
| 1212 | ObjectFile *objfile = GetObjectFile(); |
| 1213 | if (objfile) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1214 | { |
Greg Clayton | 9ab696e | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 1215 | SectionList *section_list = objfile->GetSectionList (); |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1216 | if (section_list) |
| 1217 | { |
| 1218 | const size_t num_sections = section_list->GetSize(); |
| 1219 | size_t sect_idx = 0; |
| 1220 | for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 1221 | { |
| 1222 | // Iterate through the object file sections to find the |
| 1223 | // first section that starts of file offset zero and that |
| 1224 | // has bytes in the file... |
Greg Clayton | 545762f | 2012-07-07 01:24:12 +0000 | [diff] [blame] | 1225 | SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx)); |
Greg Clayton | 9ab696e | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 1226 | // Only load non-thread specific sections when given a slide |
Greg Clayton | 545762f | 2012-07-07 01:24:12 +0000 | [diff] [blame] | 1227 | if (section_sp && !section_sp->IsThreadSpecific()) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1228 | { |
Greg Clayton | 545762f | 2012-07-07 01:24:12 +0000 | [diff] [blame] | 1229 | if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + offset)) |
Greg Clayton | 9ab696e | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 1230 | ++num_loaded_sections; |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1231 | } |
| 1232 | } |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1233 | } |
| 1234 | } |
Greg Clayton | 9ab696e | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 1235 | changed = num_loaded_sections > 0; |
| 1236 | return num_loaded_sections > 0; |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1239 | |
| 1240 | bool |
| 1241 | Module::MatchesModuleSpec (const ModuleSpec &module_ref) |
| 1242 | { |
| 1243 | const UUID &uuid = module_ref.GetUUID(); |
| 1244 | |
| 1245 | if (uuid.IsValid()) |
| 1246 | { |
| 1247 | // If the UUID matches, then nothing more needs to match... |
| 1248 | if (uuid == GetUUID()) |
| 1249 | return true; |
| 1250 | else |
| 1251 | return false; |
| 1252 | } |
| 1253 | |
| 1254 | const FileSpec &file_spec = module_ref.GetFileSpec(); |
| 1255 | if (file_spec) |
| 1256 | { |
| 1257 | if (!FileSpec::Equal (file_spec, m_file, file_spec.GetDirectory())) |
| 1258 | return false; |
| 1259 | } |
| 1260 | |
| 1261 | const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec(); |
| 1262 | if (platform_file_spec) |
| 1263 | { |
Greg Clayton | 58aa715 | 2012-10-02 06:04:17 +0000 | [diff] [blame] | 1264 | if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), platform_file_spec.GetDirectory())) |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1265 | return false; |
| 1266 | } |
| 1267 | |
| 1268 | const ArchSpec &arch = module_ref.GetArchitecture(); |
| 1269 | if (arch.IsValid()) |
| 1270 | { |
| 1271 | if (m_arch != arch) |
| 1272 | return false; |
| 1273 | } |
| 1274 | |
| 1275 | const ConstString &object_name = module_ref.GetObjectName(); |
| 1276 | if (object_name) |
| 1277 | { |
| 1278 | if (object_name != GetObjectName()) |
| 1279 | return false; |
| 1280 | } |
| 1281 | return true; |
| 1282 | } |
| 1283 | |
Greg Clayton | 964deba | 2012-03-15 21:01:31 +0000 | [diff] [blame] | 1284 | bool |
| 1285 | Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const |
| 1286 | { |
| 1287 | Mutex::Locker locker (m_mutex); |
| 1288 | return m_source_mappings.FindFile (orig_spec, new_spec); |
| 1289 | } |
| 1290 | |
Greg Clayton | 2418fdd | 2012-03-19 22:22:41 +0000 | [diff] [blame] | 1291 | bool |
| 1292 | Module::RemapSourceFile (const char *path, std::string &new_path) const |
| 1293 | { |
| 1294 | Mutex::Locker locker (m_mutex); |
| 1295 | return m_source_mappings.RemapPath(path, new_path); |
| 1296 | } |
| 1297 | |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 1298 | uint32_t |
| 1299 | Module::GetVersion (uint32_t *versions, uint32_t num_versions) |
| 1300 | { |
| 1301 | ObjectFile *obj_file = GetObjectFile(); |
| 1302 | if (obj_file) |
| 1303 | return obj_file->GetVersion (versions, num_versions); |
| 1304 | |
| 1305 | if (versions && num_versions) |
| 1306 | { |
| 1307 | for (uint32_t i=0; i<num_versions; ++i) |
| 1308 | versions[i] = UINT32_MAX; |
| 1309 | } |
| 1310 | return 0; |
| 1311 | } |