| Eugene Zelenko | 0af149a | 2015-10-19 18:52:10 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARFDebugMap.cpp -----------------------------*- C++ -*-===// |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
| 10 | #include "SymbolFileDWARFDebugMap.h" |
| 11 | |
| Enrico Granata | c76e60b | 2013-06-27 01:43:09 +0000 | [diff] [blame] | 12 | #include "DWARFDebugAranges.h" |
| 13 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
| 15 | #include "lldb/Core/ModuleList.h" |
| 16 | #include "lldb/Core/PluginManager.h" |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 17 | #include "lldb/Core/RangeMap.h" |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Section.h" |
| Pavel Labath | 1408bf7 | 2016-11-01 16:11:14 +0000 | [diff] [blame] | 19 | #include "lldb/Host/FileSystem.h" |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 20 | #include "lldb/Utility/RegularExpression.h" |
| Pavel Labath | 38d0632 | 2017-06-29 14:32:17 +0000 | [diff] [blame] | 21 | #include "lldb/Utility/Timer.h" |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 22 | |
| 23 | //#define DEBUG_OSO_DMAP // DO NOT CHECKIN WITH THIS NOT COMMENTED OUT |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 24 | #if defined(DEBUG_OSO_DMAP) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StreamFile.h" |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 26 | #endif |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 27 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 28 | #include "lldb/Symbol/CompileUnit.h" |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 29 | #include "lldb/Symbol/LineTable.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Symbol/ObjectFile.h" |
| 31 | #include "lldb/Symbol/SymbolVendor.h" |
| Ravitheja Addepally | 4069730 | 2015-10-08 09:45:41 +0000 | [diff] [blame] | 32 | #include "lldb/Symbol/TypeMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Symbol/VariableList.h" |
| Pavel Labath | 7e2cfbf | 2016-11-09 09:59:18 +0000 | [diff] [blame] | 34 | #include "llvm/Support/ScopedPrinter.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 36 | #include "LogChannelDWARF.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | #include "SymbolFileDWARF.h" |
| 38 | |
| 39 | using namespace lldb; |
| 40 | using namespace lldb_private; |
| 41 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | // Subclass lldb_private::Module so we can intercept the |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 43 | // "Module::GetObjectFile()" (so we can fixup the object file sections) and |
| 44 | // also for "Module::GetSymbolVendor()" (so we can fixup the symbol file id. |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 45 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 46 | const SymbolFileDWARFDebugMap::FileRangeMap & |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap( |
| 48 | SymbolFileDWARFDebugMap *exe_symfile) { |
| 49 | if (file_range_map_valid) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 50 | return file_range_map; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | |
| 52 | file_range_map_valid = true; |
| 53 | |
| 54 | Module *oso_module = exe_symfile->GetModuleByCompUnitInfo(this); |
| 55 | if (!oso_module) |
| 56 | return file_range_map; |
| 57 | |
| 58 | ObjectFile *oso_objfile = oso_module->GetObjectFile(); |
| 59 | if (!oso_objfile) |
| 60 | return file_range_map; |
| 61 | |
| 62 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_MAP)); |
| 63 | if (log) { |
| 64 | ConstString object_name(oso_module->GetObjectName()); |
| 65 | log->Printf( |
| 66 | "%p: SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap ('%s')", |
| 67 | static_cast<void *>(this), |
| 68 | oso_module->GetSpecificationDescription().c_str()); |
| 69 | } |
| 70 | |
| 71 | std::vector<SymbolFileDWARFDebugMap::CompileUnitInfo *> cu_infos; |
| 72 | if (exe_symfile->GetCompUnitInfosForModule(oso_module, cu_infos)) { |
| 73 | for (auto comp_unit_info : cu_infos) { |
| 74 | Symtab *exe_symtab = exe_symfile->GetObjectFile()->GetSymtab(); |
| 75 | ModuleSP oso_module_sp(oso_objfile->GetModule()); |
| 76 | Symtab *oso_symtab = oso_objfile->GetSymtab(); |
| 77 | |
| 78 | /// const uint32_t fun_resolve_flags = SymbolContext::Module | |
| 79 | /// eSymbolContextCompUnit | eSymbolContextFunction; |
| 80 | // SectionList *oso_sections = oso_objfile->Sections(); |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 81 | // Now we need to make sections that map from zero based object file |
| 82 | // addresses to where things ended up in the main executable. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 83 | |
| 84 | assert(comp_unit_info->first_symbol_index != UINT32_MAX); |
| 85 | // End index is one past the last valid symbol index |
| 86 | const uint32_t oso_end_idx = comp_unit_info->last_symbol_index + 1; |
| 87 | for (uint32_t idx = comp_unit_info->first_symbol_index + |
| 88 | 2; // Skip the N_SO and N_OSO |
| Jonas Devlieghere | 010b56b | 2018-11-27 15:25:58 +0000 | [diff] [blame^] | 89 | idx < oso_end_idx; ++idx) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | Symbol *exe_symbol = exe_symtab->SymbolAtIndex(idx); |
| 91 | if (exe_symbol) { |
| 92 | if (exe_symbol->IsDebug() == false) |
| 93 | continue; |
| 94 | |
| 95 | switch (exe_symbol->GetType()) { |
| 96 | default: |
| 97 | break; |
| 98 | |
| 99 | case eSymbolTypeCode: { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 100 | // For each N_FUN, or function that we run into in the debug map we |
| 101 | // make a new section that we add to the sections found in the .o |
| 102 | // file. This new section has the file address set to what the |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | // addresses are in the .o file, and the load address is adjusted |
| 104 | // to match where it ended up in the final executable! We do this |
| 105 | // before we parse any dwarf info so that when it goes get parsed |
| 106 | // all section/offset addresses that get registered will resolve |
| 107 | // correctly to the new addresses in the main executable. |
| 108 | |
| 109 | // First we find the original symbol in the .o file's symbol table |
| 110 | Symbol *oso_fun_symbol = oso_symtab->FindFirstSymbolWithNameAndType( |
| 111 | exe_symbol->GetMangled().GetName(lldb::eLanguageTypeUnknown, |
| 112 | Mangled::ePreferMangled), |
| 113 | eSymbolTypeCode, Symtab::eDebugNo, Symtab::eVisibilityAny); |
| 114 | if (oso_fun_symbol) { |
| 115 | // Add the inverse OSO file address to debug map entry mapping |
| 116 | exe_symfile->AddOSOFileRange( |
| 117 | this, exe_symbol->GetAddressRef().GetFileAddress(), |
| 118 | exe_symbol->GetByteSize(), |
| 119 | oso_fun_symbol->GetAddressRef().GetFileAddress(), |
| 120 | oso_fun_symbol->GetByteSize()); |
| 121 | } |
| 122 | } break; |
| 123 | |
| 124 | case eSymbolTypeData: { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 125 | // For each N_GSYM we remap the address for the global by making a |
| 126 | // new section that we add to the sections found in the .o file. |
| 127 | // This new section has the file address set to what the addresses |
| 128 | // are in the .o file, and the load address is adjusted to match |
| 129 | // where it ended up in the final executable! We do this before we |
| 130 | // parse any dwarf info so that when it goes get parsed all |
| 131 | // section/offset addresses that get registered will resolve |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | // correctly to the new addresses in the main executable. We |
| 133 | // initially set the section size to be 1 byte, but will need to |
| 134 | // fix up these addresses further after all globals have been |
| 135 | // parsed to span the gaps, or we can find the global variable |
| 136 | // sizes from the DWARF info as we are parsing. |
| 137 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 138 | // Next we find the non-stab entry that corresponds to the N_GSYM |
| 139 | // in the .o file |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 140 | Symbol *oso_gsym_symbol = |
| 141 | oso_symtab->FindFirstSymbolWithNameAndType( |
| 142 | exe_symbol->GetMangled().GetName(lldb::eLanguageTypeUnknown, |
| 143 | Mangled::ePreferMangled), |
| 144 | eSymbolTypeData, Symtab::eDebugNo, Symtab::eVisibilityAny); |
| 145 | if (exe_symbol && oso_gsym_symbol && exe_symbol->ValueIsAddress() && |
| 146 | oso_gsym_symbol->ValueIsAddress()) { |
| 147 | // Add the inverse OSO file address to debug map entry mapping |
| 148 | exe_symfile->AddOSOFileRange( |
| 149 | this, exe_symbol->GetAddressRef().GetFileAddress(), |
| 150 | exe_symbol->GetByteSize(), |
| 151 | oso_gsym_symbol->GetAddressRef().GetFileAddress(), |
| 152 | oso_gsym_symbol->GetByteSize()); |
| 153 | } |
| 154 | } break; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | exe_symfile->FinalizeOSOFileRanges(this); |
| 160 | // We don't need the symbols anymore for the .o files |
| 161 | oso_objfile->ClearSymtab(); |
| 162 | } |
| 163 | } |
| 164 | return file_range_map; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 167 | class DebugMapModule : public Module { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 168 | public: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | DebugMapModule(const ModuleSP &exe_module_sp, uint32_t cu_idx, |
| 170 | const FileSpec &file_spec, const ArchSpec &arch, |
| 171 | const ConstString *object_name, off_t object_offset, |
| Pavel Labath | 7e2cfbf | 2016-11-09 09:59:18 +0000 | [diff] [blame] | 172 | const llvm::sys::TimePoint<> object_mod_time) |
| 173 | : Module(file_spec, arch, object_name, object_offset, object_mod_time), |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | m_exe_module_wp(exe_module_sp), m_cu_idx(cu_idx) {} |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 175 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 176 | ~DebugMapModule() override = default; |
| Greg Clayton | 9ba42d1 | 2012-10-08 22:48:57 +0000 | [diff] [blame] | 177 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | SymbolVendor * |
| 179 | GetSymbolVendor(bool can_create = true, |
| 180 | lldb_private::Stream *feedback_strm = NULL) override { |
| 181 | // Scope for locker |
| 182 | if (m_symfile_ap.get() || can_create == false) |
| 183 | return m_symfile_ap.get(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 184 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 185 | ModuleSP exe_module_sp(m_exe_module_wp.lock()); |
| 186 | if (exe_module_sp) { |
| 187 | // Now get the object file outside of a locking scope |
| 188 | ObjectFile *oso_objfile = GetObjectFile(); |
| 189 | if (oso_objfile) { |
| 190 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 191 | SymbolVendor *symbol_vendor = |
| 192 | Module::GetSymbolVendor(can_create, feedback_strm); |
| 193 | if (symbol_vendor) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 194 | // Set a pointer to this class to set our OSO DWARF file know that |
| 195 | // the DWARF is being used along with a debug map and that it will |
| 196 | // have the remapped sections that we do below. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 197 | SymbolFileDWARF *oso_symfile = |
| 198 | SymbolFileDWARFDebugMap::GetSymbolFileAsSymbolFileDWARF( |
| 199 | symbol_vendor->GetSymbolFile()); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 200 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | if (!oso_symfile) |
| 202 | return NULL; |
| 203 | |
| 204 | ObjectFile *exe_objfile = exe_module_sp->GetObjectFile(); |
| 205 | SymbolVendor *exe_sym_vendor = exe_module_sp->GetSymbolVendor(); |
| 206 | |
| 207 | if (exe_objfile && exe_sym_vendor) { |
| 208 | oso_symfile->SetDebugMapModule(exe_module_sp); |
| 209 | // Set the ID of the symbol file DWARF to the index of the OSO |
| 210 | // shifted left by 32 bits to provide a unique prefix for any |
| 211 | // UserID's that get created in the symbol file. |
| 212 | oso_symfile->SetID(((uint64_t)m_cu_idx + 1ull) << 32ull); |
| 213 | } |
| 214 | return symbol_vendor; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 215 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 216 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 217 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 218 | return NULL; |
| 219 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 220 | |
| 221 | protected: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 222 | ModuleWP m_exe_module_wp; |
| 223 | const uint32_t m_cu_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 226 | void SymbolFileDWARFDebugMap::Initialize() { |
| 227 | PluginManager::RegisterPlugin(GetPluginNameStatic(), |
| 228 | GetPluginDescriptionStatic(), CreateInstance); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 231 | void SymbolFileDWARFDebugMap::Terminate() { |
| 232 | PluginManager::UnregisterPlugin(CreateInstance); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 235 | lldb_private::ConstString SymbolFileDWARFDebugMap::GetPluginNameStatic() { |
| 236 | static ConstString g_name("dwarf-debugmap"); |
| 237 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 240 | const char *SymbolFileDWARFDebugMap::GetPluginDescriptionStatic() { |
| 241 | return "DWARF and DWARF3 debug symbol file reader (debug map)."; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | SymbolFile *SymbolFileDWARFDebugMap::CreateInstance(ObjectFile *obj_file) { |
| 245 | return new SymbolFileDWARFDebugMap(obj_file); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap(ObjectFile *ofile) |
| 249 | : SymbolFile(ofile), m_flags(), m_compile_unit_infos(), m_func_indexes(), |
| 250 | m_glob_indexes(), |
| 251 | m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate) {} |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 253 | SymbolFileDWARFDebugMap::~SymbolFileDWARFDebugMap() {} |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 255 | void SymbolFileDWARFDebugMap::InitializeObject() {} |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 256 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 257 | void SymbolFileDWARFDebugMap::InitOSO() { |
| 258 | if (m_flags.test(kHaveInitializedOSOs)) |
| 259 | return; |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 260 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 | m_flags.set(kHaveInitializedOSOs); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 262 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 263 | // If the object file has been stripped, there is no sense in looking further |
| 264 | // as all of the debug symbols for the debug map will not be available |
| 265 | if (m_obj_file->IsStripped()) |
| 266 | return; |
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 267 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | // Also make sure the file type is some sort of executable. Core files, debug |
| 269 | // info files (dSYM), object files (.o files), and stub libraries all can |
| 270 | switch (m_obj_file->GetType()) { |
| 271 | case ObjectFile::eTypeInvalid: |
| 272 | case ObjectFile::eTypeCoreFile: |
| 273 | case ObjectFile::eTypeDebugInfo: |
| 274 | case ObjectFile::eTypeObjectFile: |
| 275 | case ObjectFile::eTypeStubLibrary: |
| 276 | case ObjectFile::eTypeUnknown: |
| 277 | case ObjectFile::eTypeJIT: |
| 278 | return; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | case ObjectFile::eTypeExecutable: |
| 281 | case ObjectFile::eTypeDynamicLinker: |
| 282 | case ObjectFile::eTypeSharedLibrary: |
| 283 | break; |
| 284 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 286 | // In order to get the abilities of this plug-in, we look at the list of |
| 287 | // N_OSO entries (object files) from the symbol table and make sure that |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 288 | // these files exist and also contain valid DWARF. If we get any of that then |
| 289 | // we return the abilities of the first N_OSO's DWARF. |
| Greg Clayton | 16b2d2b | 2011-01-20 06:08:59 +0000 | [diff] [blame] | 290 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 291 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 292 | if (symtab) { |
| 293 | Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_MAP)); |
| Greg Clayton | 16b2d2b | 2011-01-20 06:08:59 +0000 | [diff] [blame] | 294 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 295 | std::vector<uint32_t> oso_indexes; |
| 296 | // When a mach-o symbol is encoded, the n_type field is encoded in bits |
| 297 | // 23:16, and the n_desc field is encoded in bits 15:0. |
| 298 | // |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 299 | // To find all N_OSO entries that are part of the DWARF + debug map we find |
| 300 | // only object file symbols with the flags value as follows: bits 23:16 == |
| 301 | // 0x66 (N_OSO) bits 15: 0 == 0x0001 (specifies this is a debug map object |
| 302 | // file) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 303 | const uint32_t k_oso_symbol_flags_value = 0x660001u; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 304 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 305 | const uint32_t oso_index_count = |
| 306 | symtab->AppendSymbolIndexesWithTypeAndFlagsValue( |
| 307 | eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 308 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 309 | if (oso_index_count > 0) { |
| 310 | symtab->AppendSymbolIndexesWithType(eSymbolTypeCode, Symtab::eDebugYes, |
| 311 | Symtab::eVisibilityAny, |
| 312 | m_func_indexes); |
| 313 | symtab->AppendSymbolIndexesWithType(eSymbolTypeData, Symtab::eDebugYes, |
| 314 | Symtab::eVisibilityAny, |
| 315 | m_glob_indexes); |
| 316 | |
| 317 | symtab->SortSymbolIndexesByValue(m_func_indexes, true); |
| 318 | symtab->SortSymbolIndexesByValue(m_glob_indexes, true); |
| 319 | |
| 320 | for (uint32_t sym_idx : m_func_indexes) { |
| 321 | const Symbol *symbol = symtab->SymbolAtIndex(sym_idx); |
| 322 | lldb::addr_t file_addr = symbol->GetAddressRef().GetFileAddress(); |
| 323 | lldb::addr_t byte_size = symbol->GetByteSize(); |
| 324 | DebugMap::Entry debug_map_entry( |
| 325 | file_addr, byte_size, OSOEntry(sym_idx, LLDB_INVALID_ADDRESS)); |
| 326 | m_debug_map.Append(debug_map_entry); |
| 327 | } |
| 328 | for (uint32_t sym_idx : m_glob_indexes) { |
| 329 | const Symbol *symbol = symtab->SymbolAtIndex(sym_idx); |
| 330 | lldb::addr_t file_addr = symbol->GetAddressRef().GetFileAddress(); |
| 331 | lldb::addr_t byte_size = symbol->GetByteSize(); |
| 332 | DebugMap::Entry debug_map_entry( |
| 333 | file_addr, byte_size, OSOEntry(sym_idx, LLDB_INVALID_ADDRESS)); |
| 334 | m_debug_map.Append(debug_map_entry); |
| 335 | } |
| 336 | m_debug_map.Sort(); |
| 337 | |
| 338 | m_compile_unit_infos.resize(oso_index_count); |
| 339 | |
| 340 | for (uint32_t i = 0; i < oso_index_count; ++i) { |
| 341 | const uint32_t so_idx = oso_indexes[i] - 1; |
| 342 | const uint32_t oso_idx = oso_indexes[i]; |
| 343 | const Symbol *so_symbol = symtab->SymbolAtIndex(so_idx); |
| 344 | const Symbol *oso_symbol = symtab->SymbolAtIndex(oso_idx); |
| 345 | if (so_symbol && oso_symbol && |
| 346 | so_symbol->GetType() == eSymbolTypeSourceFile && |
| 347 | oso_symbol->GetType() == eSymbolTypeObjectFile) { |
| 348 | m_compile_unit_infos[i].so_file.SetFile( |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 349 | so_symbol->GetName().AsCString(), FileSpec::Style::native); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | m_compile_unit_infos[i].oso_path = oso_symbol->GetName(); |
| Pavel Labath | 7e2cfbf | 2016-11-09 09:59:18 +0000 | [diff] [blame] | 351 | m_compile_unit_infos[i].oso_mod_time = |
| 352 | llvm::sys::toTimePoint(oso_symbol->GetIntegerValue(0)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 353 | uint32_t sibling_idx = so_symbol->GetSiblingIndex(); |
| 354 | // The sibling index can't be less that or equal to the current index |
| 355 | // "i" |
| 356 | if (sibling_idx == UINT32_MAX) { |
| 357 | m_obj_file->GetModule()->ReportError( |
| 358 | "N_SO in symbol with UID %u has invalid sibling in debug map, " |
| 359 | "please file a bug and attach the binary listed in this error", |
| 360 | so_symbol->GetID()); |
| 361 | } else { |
| 362 | const Symbol *last_symbol = symtab->SymbolAtIndex(sibling_idx - 1); |
| 363 | m_compile_unit_infos[i].first_symbol_index = so_idx; |
| 364 | m_compile_unit_infos[i].last_symbol_index = sibling_idx - 1; |
| 365 | m_compile_unit_infos[i].first_symbol_id = so_symbol->GetID(); |
| 366 | m_compile_unit_infos[i].last_symbol_id = last_symbol->GetID(); |
| 367 | |
| 368 | if (log) |
| 369 | log->Printf("Initialized OSO 0x%8.8x: file=%s", i, |
| 370 | oso_symbol->GetName().GetCString()); |
| 371 | } |
| 372 | } else { |
| 373 | if (oso_symbol == NULL) |
| 374 | m_obj_file->GetModule()->ReportError( |
| 375 | "N_OSO symbol[%u] can't be found, please file a bug and attach " |
| 376 | "the binary listed in this error", |
| 377 | oso_idx); |
| 378 | else if (so_symbol == NULL) |
| 379 | m_obj_file->GetModule()->ReportError( |
| 380 | "N_SO not found for N_OSO symbol[%u], please file a bug and " |
| 381 | "attach the binary listed in this error", |
| 382 | oso_idx); |
| 383 | else if (so_symbol->GetType() != eSymbolTypeSourceFile) |
| 384 | m_obj_file->GetModule()->ReportError( |
| 385 | "N_SO has incorrect symbol type (%u) for N_OSO symbol[%u], " |
| 386 | "please file a bug and attach the binary listed in this error", |
| 387 | so_symbol->GetType(), oso_idx); |
| 388 | else if (oso_symbol->GetType() != eSymbolTypeSourceFile) |
| 389 | m_obj_file->GetModule()->ReportError( |
| 390 | "N_OSO has incorrect symbol type (%u) for N_OSO symbol[%u], " |
| 391 | "please file a bug and attach the binary listed in this error", |
| 392 | oso_symbol->GetType(), oso_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 394 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 395 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 396 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 399 | Module *SymbolFileDWARFDebugMap::GetModuleByOSOIndex(uint32_t oso_idx) { |
| 400 | const uint32_t cu_count = GetNumCompileUnits(); |
| 401 | if (oso_idx < cu_count) |
| 402 | return GetModuleByCompUnitInfo(&m_compile_unit_infos[oso_idx]); |
| 403 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 406 | Module *SymbolFileDWARFDebugMap::GetModuleByCompUnitInfo( |
| 407 | CompileUnitInfo *comp_unit_info) { |
| 408 | if (!comp_unit_info->oso_sp) { |
| James Y Knight | 9c2d520 | 2018-06-02 02:44:10 +0000 | [diff] [blame] | 409 | auto pos = m_oso_map.find( |
| 410 | {comp_unit_info->oso_path, comp_unit_info->oso_mod_time}); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 411 | if (pos != m_oso_map.end()) { |
| 412 | comp_unit_info->oso_sp = pos->second; |
| 413 | } else { |
| 414 | ObjectFile *obj_file = GetObjectFile(); |
| 415 | comp_unit_info->oso_sp.reset(new OSOInfo()); |
| James Y Knight | 9c2d520 | 2018-06-02 02:44:10 +0000 | [diff] [blame] | 416 | m_oso_map[{comp_unit_info->oso_path, comp_unit_info->oso_mod_time}] = |
| 417 | comp_unit_info->oso_sp; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | const char *oso_path = comp_unit_info->oso_path.GetCString(); |
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 419 | FileSpec oso_file(oso_path); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 420 | ConstString oso_object; |
| Jonas Devlieghere | dbd7fab | 2018-11-01 17:09:25 +0000 | [diff] [blame] | 421 | if (FileSystem::Instance().Exists(oso_file)) { |
| Jonas Devlieghere | 010b56b | 2018-11-27 15:25:58 +0000 | [diff] [blame^] | 422 | // The modification time returned by the FS can have a higher precision |
| 423 | // than the one from the CU. |
| 424 | auto oso_mod_time = std::chrono::time_point_cast<std::chrono::seconds>( |
| 425 | FileSystem::Instance().GetModificationTime(oso_file)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 426 | if (oso_mod_time != comp_unit_info->oso_mod_time) { |
| 427 | obj_file->GetModule()->ReportError( |
| 428 | "debug map object file '%s' has changed (actual time is " |
| Pavel Labath | 7e2cfbf | 2016-11-09 09:59:18 +0000 | [diff] [blame] | 429 | "%s, debug map time is %s" |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 430 | ") since this executable was linked, file will be ignored", |
| Pavel Labath | 7e2cfbf | 2016-11-09 09:59:18 +0000 | [diff] [blame] | 431 | oso_file.GetPath().c_str(), llvm::to_string(oso_mod_time).c_str(), |
| 432 | llvm::to_string(comp_unit_info->oso_mod_time).c_str()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | } |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 435 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 436 | } else { |
| 437 | const bool must_exist = true; |
| Greg Clayton | 906ba47 | 2013-02-06 00:38:25 +0000 | [diff] [blame] | 438 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 439 | if (!ObjectFile::SplitArchivePathWithObject(oso_path, oso_file, |
| 440 | oso_object, must_exist)) { |
| 441 | return NULL; |
| Greg Clayton | 906ba47 | 2013-02-06 00:38:25 +0000 | [diff] [blame] | 442 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | } |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 444 | // Always create a new module for .o files. Why? Because we use the debug |
| 445 | // map, to add new sections to each .o file and even though a .o file |
| 446 | // might not have changed, the sections that get added to the .o file can |
| 447 | // change. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 448 | ArchSpec oso_arch; |
| 449 | // Only adopt the architecture from the module (not the vendor or OS) |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 450 | // since .o files for "i386-apple-ios" will historically show up as "i386 |
| 451 | // -apple-macosx" due to the lack of a LC_VERSION_MIN_MACOSX or |
| 452 | // LC_VERSION_MIN_IPHONEOS load command... |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 453 | oso_arch.SetTriple(m_obj_file->GetModule() |
| 454 | ->GetArchitecture() |
| 455 | .GetTriple() |
| 456 | .getArchName() |
| 457 | .str() |
| 458 | .c_str()); |
| 459 | comp_unit_info->oso_sp->module_sp.reset(new DebugMapModule( |
| 460 | obj_file->GetModule(), GetCompUnitInfoIndex(comp_unit_info), oso_file, |
| 461 | oso_arch, oso_object ? &oso_object : NULL, 0, |
| Pavel Labath | 7e2cfbf | 2016-11-09 09:59:18 +0000 | [diff] [blame] | 462 | oso_object ? comp_unit_info->oso_mod_time |
| 463 | : llvm::sys::TimePoint<>())); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 465 | } |
| 466 | if (comp_unit_info->oso_sp) |
| 467 | return comp_unit_info->oso_sp->module_sp.get(); |
| 468 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | bool SymbolFileDWARFDebugMap::GetFileSpecForSO(uint32_t oso_idx, |
| 472 | FileSpec &file_spec) { |
| 473 | if (oso_idx < m_compile_unit_infos.size()) { |
| 474 | if (m_compile_unit_infos[oso_idx].so_file) { |
| 475 | file_spec = m_compile_unit_infos[oso_idx].so_file; |
| 476 | return true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 477 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 478 | } |
| 479 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 482 | ObjectFile *SymbolFileDWARFDebugMap::GetObjectFileByOSOIndex(uint32_t oso_idx) { |
| 483 | Module *oso_module = GetModuleByOSOIndex(oso_idx); |
| 484 | if (oso_module) |
| 485 | return oso_module->GetObjectFile(); |
| 486 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | SymbolFileDWARF * |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | SymbolFileDWARFDebugMap::GetSymbolFile(const SymbolContext &sc) { |
| 491 | CompileUnitInfo *comp_unit_info = GetCompUnitInfo(sc); |
| 492 | if (comp_unit_info) |
| 493 | return GetSymbolFileByCompUnitInfo(comp_unit_info); |
| 494 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | ObjectFile *SymbolFileDWARFDebugMap::GetObjectFileByCompUnitInfo( |
| 498 | CompileUnitInfo *comp_unit_info) { |
| 499 | Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info); |
| 500 | if (oso_module) |
| 501 | return oso_module->GetObjectFile(); |
| 502 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 505 | uint32_t SymbolFileDWARFDebugMap::GetCompUnitInfoIndex( |
| 506 | const CompileUnitInfo *comp_unit_info) { |
| 507 | if (!m_compile_unit_infos.empty()) { |
| 508 | const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front(); |
| 509 | const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back(); |
| 510 | if (first_comp_unit_info <= comp_unit_info && |
| 511 | comp_unit_info <= last_comp_unit_info) |
| 512 | return comp_unit_info - first_comp_unit_info; |
| 513 | } |
| 514 | return UINT32_MAX; |
| 515 | } |
| 516 | |
| 517 | SymbolFileDWARF * |
| 518 | SymbolFileDWARFDebugMap::GetSymbolFileByOSOIndex(uint32_t oso_idx) { |
| Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 519 | unsigned size = m_compile_unit_infos.size(); |
| 520 | if (oso_idx < size) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 521 | return GetSymbolFileByCompUnitInfo(&m_compile_unit_infos[oso_idx]); |
| 522 | return NULL; |
| 523 | } |
| 524 | |
| 525 | SymbolFileDWARF * |
| 526 | SymbolFileDWARFDebugMap::GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file) { |
| 527 | if (sym_file && |
| 528 | sym_file->GetPluginName() == SymbolFileDWARF::GetPluginNameStatic()) |
| 529 | return (SymbolFileDWARF *)sym_file; |
| 530 | return NULL; |
| 531 | } |
| 532 | |
| 533 | SymbolFileDWARF *SymbolFileDWARFDebugMap::GetSymbolFileByCompUnitInfo( |
| 534 | CompileUnitInfo *comp_unit_info) { |
| 535 | Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info); |
| 536 | if (oso_module) { |
| 537 | SymbolVendor *sym_vendor = oso_module->GetSymbolVendor(); |
| 538 | if (sym_vendor) |
| 539 | return GetSymbolFileAsSymbolFileDWARF(sym_vendor->GetSymbolFile()); |
| 540 | } |
| 541 | return NULL; |
| 542 | } |
| 543 | |
| 544 | uint32_t SymbolFileDWARFDebugMap::CalculateAbilities() { |
| 545 | // In order to get the abilities of this plug-in, we look at the list of |
| 546 | // N_OSO entries (object files) from the symbol table and make sure that |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 547 | // these files exist and also contain valid DWARF. If we get any of that then |
| 548 | // we return the abilities of the first N_OSO's DWARF. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 549 | |
| 550 | const uint32_t oso_index_count = GetNumCompileUnits(); |
| 551 | if (oso_index_count > 0) { |
| 552 | InitOSO(); |
| 553 | if (!m_compile_unit_infos.empty()) { |
| 554 | return SymbolFile::CompileUnits | SymbolFile::Functions | |
| 555 | SymbolFile::Blocks | SymbolFile::GlobalVariables | |
| 556 | SymbolFile::LocalVariables | SymbolFile::VariableTypes | |
| 557 | SymbolFile::LineTables; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 558 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 559 | } |
| 560 | return 0; |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 563 | uint32_t SymbolFileDWARFDebugMap::GetNumCompileUnits() { |
| 564 | InitOSO(); |
| 565 | return m_compile_unit_infos.size(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 568 | CompUnitSP SymbolFileDWARFDebugMap::ParseCompileUnitAtIndex(uint32_t cu_idx) { |
| 569 | CompUnitSP comp_unit_sp; |
| 570 | const uint32_t cu_count = GetNumCompileUnits(); |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 571 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 572 | if (cu_idx < cu_count) { |
| 573 | Module *oso_module = GetModuleByCompUnitInfo(&m_compile_unit_infos[cu_idx]); |
| 574 | if (oso_module) { |
| 575 | FileSpec so_file_spec; |
| 576 | if (GetFileSpecForSO(cu_idx, so_file_spec)) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 577 | // User zero as the ID to match the compile unit at offset zero in each |
| 578 | // .o file since each .o file can only have one compile unit for now. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 579 | lldb::user_id_t cu_id = 0; |
| 580 | m_compile_unit_infos[cu_idx].compile_unit_sp.reset( |
| 581 | new CompileUnit(m_obj_file->GetModule(), NULL, so_file_spec, cu_id, |
| 582 | eLanguageTypeUnknown, eLazyBoolCalculate)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 583 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 584 | if (m_compile_unit_infos[cu_idx].compile_unit_sp) { |
| 585 | // Let our symbol vendor know about this compile unit |
| 586 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex( |
| 587 | cu_idx, m_compile_unit_infos[cu_idx].compile_unit_sp); |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 588 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 590 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 591 | comp_unit_sp = m_compile_unit_infos[cu_idx].compile_unit_sp; |
| 592 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 593 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 594 | return comp_unit_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | SymbolFileDWARFDebugMap::CompileUnitInfo * |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 598 | SymbolFileDWARFDebugMap::GetCompUnitInfo(const SymbolContext &sc) { |
| 599 | const uint32_t cu_count = GetNumCompileUnits(); |
| 600 | for (uint32_t i = 0; i < cu_count; ++i) { |
| 601 | if (sc.comp_unit == m_compile_unit_infos[i].compile_unit_sp.get()) |
| 602 | return &m_compile_unit_infos[i]; |
| 603 | } |
| 604 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 607 | size_t SymbolFileDWARFDebugMap::GetCompUnitInfosForModule( |
| 608 | const lldb_private::Module *module, |
| 609 | std::vector<CompileUnitInfo *> &cu_infos) { |
| 610 | const uint32_t cu_count = GetNumCompileUnits(); |
| 611 | for (uint32_t i = 0; i < cu_count; ++i) { |
| 612 | if (module == GetModuleByCompUnitInfo(&m_compile_unit_infos[i])) |
| 613 | cu_infos.push_back(&m_compile_unit_infos[i]); |
| 614 | } |
| 615 | return cu_infos.size(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | lldb::LanguageType |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | SymbolFileDWARFDebugMap::ParseCompileUnitLanguage(const SymbolContext &sc) { |
| 620 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 621 | if (oso_dwarf) |
| 622 | return oso_dwarf->ParseCompileUnitLanguage(sc); |
| 623 | return eLanguageTypeUnknown; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 626 | size_t |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 627 | SymbolFileDWARFDebugMap::ParseCompileUnitFunctions(const SymbolContext &sc) { |
| 628 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 629 | if (oso_dwarf) |
| 630 | return oso_dwarf->ParseCompileUnitFunctions(sc); |
| 631 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 634 | bool SymbolFileDWARFDebugMap::ParseCompileUnitLineTable( |
| 635 | const SymbolContext &sc) { |
| 636 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 637 | if (oso_dwarf) |
| 638 | return oso_dwarf->ParseCompileUnitLineTable(sc); |
| 639 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 642 | bool SymbolFileDWARFDebugMap::ParseCompileUnitDebugMacros( |
| 643 | const SymbolContext &sc) { |
| 644 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 645 | if (oso_dwarf) |
| 646 | return oso_dwarf->ParseCompileUnitDebugMacros(sc); |
| 647 | return false; |
| Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 650 | bool SymbolFileDWARFDebugMap::ParseCompileUnitSupportFiles( |
| 651 | const SymbolContext &sc, FileSpecList &support_files) { |
| 652 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 653 | if (oso_dwarf) |
| 654 | return oso_dwarf->ParseCompileUnitSupportFiles(sc, support_files); |
| 655 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 658 | bool SymbolFileDWARFDebugMap::ParseCompileUnitIsOptimized( |
| 659 | const lldb_private::SymbolContext &sc) { |
| 660 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 661 | if (oso_dwarf) |
| 662 | return oso_dwarf->ParseCompileUnitIsOptimized(sc); |
| 663 | return false; |
| Greg Clayton | ad2b63c | 2016-07-05 23:01:20 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 666 | bool SymbolFileDWARFDebugMap::ParseImportedModules( |
| 667 | const SymbolContext &sc, std::vector<ConstString> &imported_modules) { |
| 668 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 669 | if (oso_dwarf) |
| 670 | return oso_dwarf->ParseImportedModules(sc, imported_modules); |
| 671 | return false; |
| 672 | } |
| 673 | |
| 674 | size_t SymbolFileDWARFDebugMap::ParseFunctionBlocks(const SymbolContext &sc) { |
| 675 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 676 | if (oso_dwarf) |
| 677 | return oso_dwarf->ParseFunctionBlocks(sc); |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | size_t SymbolFileDWARFDebugMap::ParseTypes(const SymbolContext &sc) { |
| 682 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 683 | if (oso_dwarf) |
| 684 | return oso_dwarf->ParseTypes(sc); |
| 685 | return 0; |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 686 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | |
| 688 | size_t |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 689 | SymbolFileDWARFDebugMap::ParseVariablesForContext(const SymbolContext &sc) { |
| 690 | SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc); |
| 691 | if (oso_dwarf) |
| 692 | return oso_dwarf->ParseVariablesForContext(sc); |
| 693 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | Type *SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid) { |
| 697 | const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); |
| 698 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); |
| 699 | if (oso_dwarf) |
| 700 | return oso_dwarf->ResolveTypeUID(type_uid); |
| 701 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 704 | llvm::Optional<SymbolFile::ArrayInfo> |
| 705 | SymbolFileDWARFDebugMap::GetDynamicArrayInfoForUID( |
| 706 | lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) { |
| 707 | const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); |
| 708 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); |
| 709 | if (oso_dwarf) |
| 710 | return oso_dwarf->GetDynamicArrayInfoForUID(type_uid, exe_ctx); |
| 711 | return llvm::None; |
| 712 | } |
| 713 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 714 | bool SymbolFileDWARFDebugMap::CompleteType(CompilerType &compiler_type) { |
| 715 | bool success = false; |
| 716 | if (compiler_type) { |
| 717 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 718 | if (oso_dwarf->HasForwardDeclForClangType(compiler_type)) { |
| 719 | oso_dwarf->CompleteType(compiler_type); |
| 720 | success = true; |
| 721 | return true; |
| 722 | } |
| 723 | return false; |
| 724 | }); |
| 725 | } |
| 726 | return success; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 729 | uint32_t |
| 730 | SymbolFileDWARFDebugMap::ResolveSymbolContext(const Address &exe_so_addr, |
| 731 | SymbolContextItem resolve_scope, |
| 732 | SymbolContext &sc) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 733 | uint32_t resolved_flags = 0; |
| 734 | Symtab *symtab = m_obj_file->GetSymtab(); |
| 735 | if (symtab) { |
| 736 | const addr_t exe_file_addr = exe_so_addr.GetFileAddress(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 737 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 738 | const DebugMap::Entry *debug_map_entry = |
| 739 | m_debug_map.FindEntryThatContains(exe_file_addr); |
| 740 | if (debug_map_entry) { |
| 741 | |
| 742 | sc.symbol = |
| 743 | symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex()); |
| 744 | |
| 745 | if (sc.symbol != NULL) { |
| 746 | resolved_flags |= eSymbolContextSymbol; |
| 747 | |
| 748 | uint32_t oso_idx = 0; |
| 749 | CompileUnitInfo *comp_unit_info = |
| 750 | GetCompileUnitInfoForSymbolWithID(sc.symbol->GetID(), &oso_idx); |
| 751 | if (comp_unit_info) { |
| 752 | comp_unit_info->GetFileRangeMap(this); |
| 753 | Module *oso_module = GetModuleByCompUnitInfo(comp_unit_info); |
| 754 | if (oso_module) { |
| 755 | lldb::addr_t oso_file_addr = |
| 756 | exe_file_addr - debug_map_entry->GetRangeBase() + |
| 757 | debug_map_entry->data.GetOSOFileAddress(); |
| 758 | Address oso_so_addr; |
| 759 | if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr)) { |
| 760 | resolved_flags |= |
| 761 | oso_module->GetSymbolVendor()->ResolveSymbolContext( |
| 762 | oso_so_addr, resolve_scope, sc); |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 763 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | } |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 767 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 768 | } |
| 769 | return resolved_flags; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 770 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 771 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 772 | uint32_t SymbolFileDWARFDebugMap::ResolveSymbolContext( |
| 773 | const FileSpec &file_spec, uint32_t line, bool check_inlines, |
| Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 774 | SymbolContextItem resolve_scope, SymbolContextList &sc_list) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 775 | const uint32_t initial = sc_list.GetSize(); |
| 776 | const uint32_t cu_count = GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 777 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 778 | for (uint32_t i = 0; i < cu_count; ++i) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 779 | // If we are checking for inlines, then we need to look through all compile |
| 780 | // units no matter if "file_spec" matches. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 781 | bool resolve = check_inlines; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 782 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 783 | if (!resolve) { |
| 784 | FileSpec so_file_spec; |
| 785 | if (GetFileSpecForSO(i, so_file_spec)) { |
| 786 | // Match the full path if the incoming file_spec has a directory (not |
| 787 | // just a basename) |
| 788 | const bool full_match = (bool)file_spec.GetDirectory(); |
| 789 | resolve = FileSpec::Equal(file_spec, so_file_spec, full_match); |
| 790 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 791 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 792 | if (resolve) { |
| 793 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(i); |
| 794 | if (oso_dwarf) |
| 795 | oso_dwarf->ResolveSymbolContext(file_spec, line, check_inlines, |
| 796 | resolve_scope, sc_list); |
| 797 | } |
| 798 | } |
| 799 | return sc_list.GetSize() - initial; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 802 | uint32_t SymbolFileDWARFDebugMap::PrivateFindGlobalVariables( |
| 803 | const ConstString &name, const CompilerDeclContext *parent_decl_ctx, |
| 804 | const std::vector<uint32_t> |
| 805 | &indexes, // Indexes into the symbol table that match "name" |
| Jonas Devlieghere | 010b56b | 2018-11-27 15:25:58 +0000 | [diff] [blame^] | 806 | uint32_t max_matches, VariableList &variables) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 807 | const uint32_t original_size = variables.GetSize(); |
| 808 | const size_t match_count = indexes.size(); |
| 809 | for (size_t i = 0; i < match_count; ++i) { |
| 810 | uint32_t oso_idx; |
| 811 | CompileUnitInfo *comp_unit_info = |
| 812 | GetCompileUnitInfoForSymbolWithIndex(indexes[i], &oso_idx); |
| 813 | if (comp_unit_info) { |
| 814 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); |
| 815 | if (oso_dwarf) { |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 816 | if (oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches, |
| 817 | variables)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 818 | if (variables.GetSize() > max_matches) |
| 819 | break; |
| 820 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 821 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 822 | } |
| 823 | return variables.GetSize() - original_size; |
| 824 | } |
| 825 | |
| 826 | uint32_t SymbolFileDWARFDebugMap::FindGlobalVariables( |
| 827 | const ConstString &name, const CompilerDeclContext *parent_decl_ctx, |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 828 | uint32_t max_matches, VariableList &variables) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 829 | |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 830 | // Remember how many variables are in the list before we search. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 831 | const uint32_t original_size = variables.GetSize(); |
| 832 | |
| 833 | uint32_t total_matches = 0; |
| 834 | |
| 835 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 836 | const uint32_t oso_matches = oso_dwarf->FindGlobalVariables( |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 837 | name, parent_decl_ctx, max_matches, variables); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 838 | if (oso_matches > 0) { |
| 839 | total_matches += oso_matches; |
| 840 | |
| 841 | // Are we getting all matches? |
| 842 | if (max_matches == UINT32_MAX) |
| 843 | return false; // Yep, continue getting everything |
| 844 | |
| 845 | // If we have found enough matches, lets get out |
| 846 | if (max_matches >= total_matches) |
| 847 | return true; |
| 848 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 849 | // Update the max matches for any subsequent calls to find globals in any |
| 850 | // other object files with DWARF |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 851 | max_matches -= oso_matches; |
| 852 | } |
| 853 | |
| 854 | return false; |
| 855 | }); |
| 856 | |
| 857 | // Return the number of variable that were appended to the list |
| 858 | return variables.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | uint32_t |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 862 | SymbolFileDWARFDebugMap::FindGlobalVariables(const RegularExpression ®ex, |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 863 | uint32_t max_matches, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 864 | VariableList &variables) { |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 865 | // Remember how many variables are in the list before we search. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 866 | const uint32_t original_size = variables.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 867 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 868 | uint32_t total_matches = 0; |
| 869 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 870 | const uint32_t oso_matches = |
| Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 871 | oso_dwarf->FindGlobalVariables(regex, max_matches, variables); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 872 | if (oso_matches > 0) { |
| 873 | total_matches += oso_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 874 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 875 | // Are we getting all matches? |
| 876 | if (max_matches == UINT32_MAX) |
| 877 | return false; // Yep, continue getting everything |
| Sean Callanan | 0dc848c | 2015-04-01 20:43:23 +0000 | [diff] [blame] | 878 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 879 | // If we have found enough matches, lets get out |
| 880 | if (max_matches >= total_matches) |
| 881 | return true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 882 | |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 883 | // Update the max matches for any subsequent calls to find globals in any |
| 884 | // other object files with DWARF |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 885 | max_matches -= oso_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 888 | return false; |
| 889 | }); |
| 890 | |
| 891 | // Return the number of variable that were appended to the list |
| 892 | return variables.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 895 | int SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex( |
| 896 | uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) { |
| 897 | const uint32_t symbol_idx = *symbol_idx_ptr; |
| Greg Clayton | bcf2cfb | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 898 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 899 | if (symbol_idx < comp_unit_info->first_symbol_index) |
| 900 | return -1; |
| 901 | |
| 902 | if (symbol_idx <= comp_unit_info->last_symbol_index) |
| 903 | return 0; |
| 904 | |
| 905 | return 1; |
| Greg Clayton | bcf2cfb | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 908 | int SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID( |
| 909 | user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) { |
| 910 | const user_id_t symbol_id = *symbol_idx_ptr; |
| 911 | |
| 912 | if (symbol_id < comp_unit_info->first_symbol_id) |
| 913 | return -1; |
| 914 | |
| 915 | if (symbol_id <= comp_unit_info->last_symbol_id) |
| 916 | return 0; |
| 917 | |
| 918 | return 1; |
| Greg Clayton | 3ef3fc6 | 2010-08-17 23:16:15 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 921 | SymbolFileDWARFDebugMap::CompileUnitInfo * |
| 922 | SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithIndex( |
| 923 | uint32_t symbol_idx, uint32_t *oso_idx_ptr) { |
| 924 | const uint32_t oso_index_count = m_compile_unit_infos.size(); |
| 925 | CompileUnitInfo *comp_unit_info = NULL; |
| 926 | if (oso_index_count) { |
| 927 | comp_unit_info = (CompileUnitInfo *)bsearch( |
| 928 | &symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(), |
| 929 | sizeof(CompileUnitInfo), |
| 930 | (ComparisonFunction)SymbolContainsSymbolWithIndex); |
| 931 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 932 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 933 | if (oso_idx_ptr) { |
| 934 | if (comp_unit_info != NULL) |
| 935 | *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0]; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 936 | else |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 937 | *oso_idx_ptr = UINT32_MAX; |
| 938 | } |
| 939 | return comp_unit_info; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 942 | SymbolFileDWARFDebugMap::CompileUnitInfo * |
| 943 | SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithID( |
| 944 | user_id_t symbol_id, uint32_t *oso_idx_ptr) { |
| 945 | const uint32_t oso_index_count = m_compile_unit_infos.size(); |
| 946 | CompileUnitInfo *comp_unit_info = NULL; |
| 947 | if (oso_index_count) { |
| 948 | comp_unit_info = (CompileUnitInfo *)::bsearch( |
| 949 | &symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(), |
| 950 | sizeof(CompileUnitInfo), |
| 951 | (ComparisonFunction)SymbolContainsSymbolWithID); |
| 952 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 953 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 954 | if (oso_idx_ptr) { |
| 955 | if (comp_unit_info != NULL) |
| 956 | *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0]; |
| Greg Clayton | 57a6b99 | 2010-08-17 00:35:34 +0000 | [diff] [blame] | 957 | else |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 958 | *oso_idx_ptr = UINT32_MAX; |
| 959 | } |
| 960 | return comp_unit_info; |
| 961 | } |
| Greg Clayton | 57a6b99 | 2010-08-17 00:35:34 +0000 | [diff] [blame] | 962 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 963 | static void RemoveFunctionsWithModuleNotEqualTo(const ModuleSP &module_sp, |
| 964 | SymbolContextList &sc_list, |
| 965 | uint32_t start_idx) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 966 | // We found functions in .o files. Not all functions in the .o files will |
| 967 | // have made it into the final output file. The ones that did make it into |
| 968 | // the final output file will have a section whose module matches the module |
| 969 | // from the ObjectFile for this SymbolFile. When the modules don't match, |
| 970 | // then we have something that was in a .o file, but doesn't map to anything |
| 971 | // in the final executable. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 972 | uint32_t i = start_idx; |
| 973 | while (i < sc_list.GetSize()) { |
| 974 | SymbolContext sc; |
| 975 | sc_list.GetContextAtIndex(i, sc); |
| 976 | if (sc.function) { |
| 977 | const SectionSP section_sp( |
| 978 | sc.function->GetAddressRange().GetBaseAddress().GetSection()); |
| 979 | if (section_sp->GetModule() != module_sp) { |
| 980 | sc_list.RemoveContextAtIndex(i); |
| 981 | continue; |
| 982 | } |
| 983 | } |
| 984 | ++i; |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | uint32_t SymbolFileDWARFDebugMap::FindFunctions( |
| 989 | const ConstString &name, const CompilerDeclContext *parent_decl_ctx, |
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 990 | FunctionNameType name_type_mask, bool include_inlines, bool append, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 991 | SymbolContextList &sc_list) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 992 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 993 | Timer scoped_timer(func_cat, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 994 | "SymbolFileDWARFDebugMap::FindFunctions (name = %s)", |
| 995 | name.GetCString()); |
| 996 | |
| 997 | uint32_t initial_size = 0; |
| 998 | if (append) |
| 999 | initial_size = sc_list.GetSize(); |
| 1000 | else |
| 1001 | sc_list.Clear(); |
| 1002 | |
| 1003 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1004 | uint32_t sc_idx = sc_list.GetSize(); |
| 1005 | if (oso_dwarf->FindFunctions(name, parent_decl_ctx, name_type_mask, |
| 1006 | include_inlines, true, sc_list)) { |
| 1007 | RemoveFunctionsWithModuleNotEqualTo(m_obj_file->GetModule(), sc_list, |
| 1008 | sc_idx); |
| 1009 | } |
| 1010 | return false; |
| 1011 | }); |
| 1012 | |
| 1013 | return sc_list.GetSize() - initial_size; |
| 1014 | } |
| 1015 | |
| 1016 | uint32_t SymbolFileDWARFDebugMap::FindFunctions(const RegularExpression ®ex, |
| 1017 | bool include_inlines, |
| 1018 | bool append, |
| 1019 | SymbolContextList &sc_list) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 1020 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 1021 | Timer scoped_timer(func_cat, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1022 | "SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')", |
| Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 1023 | regex.GetText().str().c_str()); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1024 | |
| 1025 | uint32_t initial_size = 0; |
| 1026 | if (append) |
| 1027 | initial_size = sc_list.GetSize(); |
| 1028 | else |
| 1029 | sc_list.Clear(); |
| 1030 | |
| 1031 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1032 | uint32_t sc_idx = sc_list.GetSize(); |
| 1033 | |
| 1034 | if (oso_dwarf->FindFunctions(regex, include_inlines, true, sc_list)) { |
| 1035 | RemoveFunctionsWithModuleNotEqualTo(m_obj_file->GetModule(), sc_list, |
| 1036 | sc_idx); |
| 1037 | } |
| 1038 | return false; |
| 1039 | }); |
| 1040 | |
| 1041 | return sc_list.GetSize() - initial_size; |
| 1042 | } |
| 1043 | |
| 1044 | size_t SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope, |
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 1045 | lldb::TypeClass type_mask, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1046 | TypeList &type_list) { |
| Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 1047 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 1048 | Timer scoped_timer(func_cat, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1049 | "SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)", |
| 1050 | type_mask); |
| 1051 | |
| 1052 | uint32_t initial_size = type_list.GetSize(); |
| 1053 | SymbolFileDWARF *oso_dwarf = NULL; |
| 1054 | if (sc_scope) { |
| 1055 | SymbolContext sc; |
| 1056 | sc_scope->CalculateSymbolContext(&sc); |
| 1057 | |
| 1058 | CompileUnitInfo *cu_info = GetCompUnitInfo(sc); |
| 1059 | if (cu_info) { |
| 1060 | oso_dwarf = GetSymbolFileByCompUnitInfo(cu_info); |
| 1061 | if (oso_dwarf) |
| 1062 | oso_dwarf->GetTypes(sc_scope, type_mask, type_list); |
| 1063 | } |
| 1064 | } else { |
| Sean Callanan | 0dc848c | 2015-04-01 20:43:23 +0000 | [diff] [blame] | 1065 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1066 | oso_dwarf->GetTypes(sc_scope, type_mask, type_list); |
| 1067 | return false; |
| Sean Callanan | 0dc848c | 2015-04-01 20:43:23 +0000 | [diff] [blame] | 1068 | }); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1069 | } |
| 1070 | return type_list.GetSize() - initial_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| Vedant Kumar | 4b36f79 | 2018-10-05 23:23:15 +0000 | [diff] [blame] | 1073 | std::vector<lldb_private::CallEdge> |
| 1074 | SymbolFileDWARFDebugMap::ParseCallEdgesInFunction(UserID func_id) { |
| 1075 | uint32_t oso_idx = GetOSOIndexFromUserID(func_id.GetID()); |
| 1076 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); |
| 1077 | if (oso_dwarf) |
| 1078 | return oso_dwarf->ParseCallEdgesInFunction(func_id); |
| 1079 | return {}; |
| 1080 | } |
| 1081 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1082 | TypeSP SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext( |
| 1083 | const DWARFDeclContext &die_decl_ctx) { |
| 1084 | TypeSP type_sp; |
| 1085 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1086 | type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx); |
| 1087 | return ((bool)type_sp); |
| 1088 | }); |
| 1089 | return type_sp; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1092 | bool SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type( |
| 1093 | SymbolFileDWARF *skip_dwarf_oso) { |
| 1094 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) { |
| 1095 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| Sean Callanan | 0dc848c | 2015-04-01 20:43:23 +0000 | [diff] [blame] | 1096 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1097 | if (skip_dwarf_oso != oso_dwarf && |
| 1098 | oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(NULL)) { |
| 1099 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 1100 | return true; |
| 1101 | } |
| 1102 | return false; |
| Sean Callanan | 0dc848c | 2015-04-01 20:43:23 +0000 | [diff] [blame] | 1103 | }); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1104 | } |
| 1105 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 1106 | } |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1107 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1108 | TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE( |
| 1109 | const DWARFDIE &die, const ConstString &type_name, |
| 1110 | bool must_be_implementation) { |
| Adrian Prantl | 4e8be2c | 2018-06-13 16:21:24 +0000 | [diff] [blame] | 1111 | // If we have a debug map, we will have an Objective-C symbol whose name is |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1112 | // the type name and whose type is eSymbolTypeObjCClass. If we can find that |
| 1113 | // symbol and find its containing parent, we can locate the .o file that will |
| 1114 | // contain the implementation definition since it will be scoped inside the |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1115 | // N_SO and we can then locate the SymbolFileDWARF that corresponds to that |
| 1116 | // N_SO. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1117 | SymbolFileDWARF *oso_dwarf = NULL; |
| 1118 | TypeSP type_sp; |
| 1119 | ObjectFile *module_objfile = m_obj_file->GetModule()->GetObjectFile(); |
| 1120 | if (module_objfile) { |
| 1121 | Symtab *symtab = module_objfile->GetSymtab(); |
| 1122 | if (symtab) { |
| 1123 | Symbol *objc_class_symbol = symtab->FindFirstSymbolWithNameAndType( |
| 1124 | type_name, eSymbolTypeObjCClass, Symtab::eDebugAny, |
| 1125 | Symtab::eVisibilityAny); |
| 1126 | if (objc_class_symbol) { |
| 1127 | // Get the N_SO symbol that contains the objective C class symbol as |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1128 | // this should be the .o file that contains the real definition... |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1129 | const Symbol *source_file_symbol = symtab->GetParent(objc_class_symbol); |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 1130 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1131 | if (source_file_symbol && |
| 1132 | source_file_symbol->GetType() == eSymbolTypeSourceFile) { |
| 1133 | const uint32_t source_file_symbol_idx = |
| 1134 | symtab->GetIndexForSymbol(source_file_symbol); |
| 1135 | if (source_file_symbol_idx != UINT32_MAX) { |
| 1136 | CompileUnitInfo *compile_unit_info = |
| 1137 | GetCompileUnitInfoForSymbolWithIndex(source_file_symbol_idx, |
| 1138 | NULL); |
| 1139 | if (compile_unit_info) { |
| 1140 | oso_dwarf = GetSymbolFileByCompUnitInfo(compile_unit_info); |
| 1141 | if (oso_dwarf) { |
| 1142 | TypeSP type_sp(oso_dwarf->FindCompleteObjCDefinitionTypeForDIE( |
| 1143 | die, type_name, must_be_implementation)); |
| 1144 | if (type_sp) { |
| 1145 | return type_sp; |
| Greg Clayton | bc63aac | 2015-02-25 22:41:34 +0000 | [diff] [blame] | 1146 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1147 | } |
| Greg Clayton | bc63aac | 2015-02-25 22:41:34 +0000 | [diff] [blame] | 1148 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1149 | } |
| Greg Clayton | bc63aac | 2015-02-25 22:41:34 +0000 | [diff] [blame] | 1150 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1151 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 1152 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1153 | } |
| Greg Clayton | bc63aac | 2015-02-25 22:41:34 +0000 | [diff] [blame] | 1154 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1155 | // Only search all .o files for the definition if we don't need the |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1156 | // implementation because otherwise, with a valid debug map we should have |
| 1157 | // the ObjC class symbol and the code above should have found it. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1158 | if (must_be_implementation == false) { |
| 1159 | TypeSP type_sp; |
| 1160 | |
| 1161 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1162 | type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE( |
| 1163 | die, type_name, must_be_implementation); |
| 1164 | return (bool)type_sp; |
| 1165 | }); |
| 1166 | |
| 1167 | return type_sp; |
| 1168 | } |
| 1169 | return TypeSP(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1172 | uint32_t SymbolFileDWARFDebugMap::FindTypes( |
| 1173 | const SymbolContext &sc, const ConstString &name, |
| 1174 | const CompilerDeclContext *parent_decl_ctx, bool append, |
| Greg Clayton | ae088e5 | 2016-02-10 21:28:13 +0000 | [diff] [blame] | 1175 | uint32_t max_matches, |
| 1176 | llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1177 | TypeMap &types) { |
| 1178 | if (!append) |
| 1179 | types.Clear(); |
| Greg Clayton | 6dbd398 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 1180 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1181 | const uint32_t initial_types_size = types.GetSize(); |
| 1182 | SymbolFileDWARF *oso_dwarf; |
| Greg Clayton | 6dbd398 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 1183 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1184 | if (sc.comp_unit) { |
| 1185 | oso_dwarf = GetSymbolFile(sc); |
| 1186 | if (oso_dwarf) |
| 1187 | return oso_dwarf->FindTypes(sc, name, parent_decl_ctx, append, |
| 1188 | max_matches, searched_symbol_files, types); |
| 1189 | } else { |
| 1190 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1191 | oso_dwarf->FindTypes(sc, name, parent_decl_ctx, append, max_matches, |
| 1192 | searched_symbol_files, types); |
| 1193 | if (types.GetSize() >= max_matches) |
| 1194 | return true; |
| 1195 | else |
| 1196 | return false; |
| 1197 | }); |
| 1198 | } |
| Greg Clayton | 6dbd398 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 1199 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1200 | return types.GetSize() - initial_types_size; |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | // |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1204 | // uint32_t |
| 1205 | // SymbolFileDWARFDebugMap::FindTypes (const SymbolContext& sc, const |
| 1206 | // RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding |
| 1207 | // encoding, lldb::user_id_t udt_uid, TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1208 | //{ |
| 1209 | // SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 1210 | // if (oso_dwarf) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1211 | // return oso_dwarf->FindTypes (sc, regex, append, max_matches, encoding, |
| 1212 | // udt_uid, types); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1213 | // return 0; |
| 1214 | //} |
| 1215 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1216 | CompilerDeclContext SymbolFileDWARFDebugMap::FindNamespace( |
| 1217 | const lldb_private::SymbolContext &sc, |
| 1218 | const lldb_private::ConstString &name, |
| 1219 | const CompilerDeclContext *parent_decl_ctx) { |
| 1220 | CompilerDeclContext matching_namespace; |
| 1221 | SymbolFileDWARF *oso_dwarf; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1222 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1223 | if (sc.comp_unit) { |
| 1224 | oso_dwarf = GetSymbolFile(sc); |
| 1225 | if (oso_dwarf) |
| 1226 | matching_namespace = oso_dwarf->FindNamespace(sc, name, parent_decl_ctx); |
| 1227 | } else { |
| 1228 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1229 | matching_namespace = oso_dwarf->FindNamespace(sc, name, parent_decl_ctx); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1230 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1231 | return (bool)matching_namespace; |
| 1232 | }); |
| 1233 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1234 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1235 | return matching_namespace; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| Zachary Turner | 4911023 | 2018-11-05 17:40:28 +0000 | [diff] [blame] | 1238 | void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s) { |
| 1239 | ForEachSymbolFile([&s](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1240 | oso_dwarf->DumpClangAST(s); |
| 1241 | return true; |
| 1242 | }); |
| 1243 | } |
| 1244 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1245 | //------------------------------------------------------------------ |
| 1246 | // PluginInterface protocol |
| 1247 | //------------------------------------------------------------------ |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1248 | lldb_private::ConstString SymbolFileDWARFDebugMap::GetPluginName() { |
| 1249 | return GetPluginNameStatic(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1252 | uint32_t SymbolFileDWARFDebugMap::GetPluginVersion() { return 1; } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1253 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1254 | lldb::CompUnitSP |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1255 | SymbolFileDWARFDebugMap::GetCompileUnit(SymbolFileDWARF *oso_dwarf) { |
| 1256 | if (oso_dwarf) { |
| 1257 | const uint32_t cu_count = GetNumCompileUnits(); |
| 1258 | for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) { |
| 1259 | SymbolFileDWARF *oso_symfile = |
| 1260 | GetSymbolFileByCompUnitInfo(&m_compile_unit_infos[cu_idx]); |
| 1261 | if (oso_symfile == oso_dwarf) { |
| 1262 | if (!m_compile_unit_infos[cu_idx].compile_unit_sp) |
| 1263 | m_compile_unit_infos[cu_idx].compile_unit_sp = |
| 1264 | ParseCompileUnitAtIndex(cu_idx); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1265 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1266 | return m_compile_unit_infos[cu_idx].compile_unit_sp; |
| 1267 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1268 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1269 | } |
| David Blaikie | a322f36 | 2017-01-06 00:38:06 +0000 | [diff] [blame] | 1270 | llvm_unreachable("this shouldn't happen"); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1273 | SymbolFileDWARFDebugMap::CompileUnitInfo * |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1274 | SymbolFileDWARFDebugMap::GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf) { |
| 1275 | if (oso_dwarf) { |
| 1276 | const uint32_t cu_count = GetNumCompileUnits(); |
| 1277 | for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) { |
| 1278 | SymbolFileDWARF *oso_symfile = |
| 1279 | GetSymbolFileByCompUnitInfo(&m_compile_unit_infos[cu_idx]); |
| 1280 | if (oso_symfile == oso_dwarf) { |
| 1281 | return &m_compile_unit_infos[cu_idx]; |
| 1282 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1283 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1284 | } |
| 1285 | return NULL; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1288 | void SymbolFileDWARFDebugMap::SetCompileUnit(SymbolFileDWARF *oso_dwarf, |
| 1289 | const CompUnitSP &cu_sp) { |
| 1290 | if (oso_dwarf) { |
| 1291 | const uint32_t cu_count = GetNumCompileUnits(); |
| 1292 | for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) { |
| 1293 | SymbolFileDWARF *oso_symfile = |
| 1294 | GetSymbolFileByCompUnitInfo(&m_compile_unit_infos[cu_idx]); |
| 1295 | if (oso_symfile == oso_dwarf) { |
| 1296 | if (m_compile_unit_infos[cu_idx].compile_unit_sp) { |
| 1297 | assert(m_compile_unit_infos[cu_idx].compile_unit_sp.get() == |
| 1298 | cu_sp.get()); |
| 1299 | } else { |
| 1300 | m_compile_unit_infos[cu_idx].compile_unit_sp = cu_sp; |
| 1301 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex( |
| 1302 | cu_idx, cu_sp); |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1303 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1304 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1305 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1306 | } |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1309 | CompilerDeclContext |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1310 | SymbolFileDWARFDebugMap::GetDeclContextForUID(lldb::user_id_t type_uid) { |
| 1311 | const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); |
| 1312 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); |
| 1313 | if (oso_dwarf) |
| 1314 | return oso_dwarf->GetDeclContextForUID(type_uid); |
| 1315 | return CompilerDeclContext(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1318 | CompilerDeclContext |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1319 | SymbolFileDWARFDebugMap::GetDeclContextContainingUID(lldb::user_id_t type_uid) { |
| 1320 | const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); |
| 1321 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); |
| 1322 | if (oso_dwarf) |
| 1323 | return oso_dwarf->GetDeclContextContainingUID(type_uid); |
| 1324 | return CompilerDeclContext(); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1327 | void SymbolFileDWARFDebugMap::ParseDeclsForContext( |
| 1328 | lldb_private::CompilerDeclContext decl_ctx) { |
| 1329 | ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { |
| 1330 | oso_dwarf->ParseDeclsForContext(decl_ctx); |
| 1331 | return true; // Keep iterating |
| 1332 | }); |
| Greg Clayton | 2bd8e7b | 2015-10-07 22:07:33 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1335 | bool SymbolFileDWARFDebugMap::AddOSOFileRange(CompileUnitInfo *cu_info, |
| 1336 | lldb::addr_t exe_file_addr, |
| 1337 | lldb::addr_t exe_byte_size, |
| 1338 | lldb::addr_t oso_file_addr, |
| 1339 | lldb::addr_t oso_byte_size) { |
| 1340 | const uint32_t debug_map_idx = |
| 1341 | m_debug_map.FindEntryIndexThatContains(exe_file_addr); |
| 1342 | if (debug_map_idx != UINT32_MAX) { |
| 1343 | DebugMap::Entry *debug_map_entry = |
| 1344 | m_debug_map.FindEntryThatContains(exe_file_addr); |
| 1345 | debug_map_entry->data.SetOSOFileAddress(oso_file_addr); |
| 1346 | addr_t range_size = std::min<addr_t>(exe_byte_size, oso_byte_size); |
| 1347 | if (range_size == 0) { |
| 1348 | range_size = std::max<addr_t>(exe_byte_size, oso_byte_size); |
| 1349 | if (range_size == 0) |
| 1350 | range_size = 1; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1351 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1352 | cu_info->file_range_map.Append( |
| 1353 | FileRangeMap::Entry(oso_file_addr, range_size, exe_file_addr)); |
| 1354 | return true; |
| 1355 | } |
| 1356 | return false; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1359 | void SymbolFileDWARFDebugMap::FinalizeOSOFileRanges(CompileUnitInfo *cu_info) { |
| 1360 | cu_info->file_range_map.Sort(); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1361 | #if defined(DEBUG_OSO_DMAP) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1362 | const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this); |
| 1363 | const size_t n = oso_file_range_map.GetSize(); |
| 1364 | printf("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s\n", |
| 1365 | cu_info, cu_info->oso_sp->module_sp->GetFileSpec().GetPath().c_str()); |
| 1366 | for (size_t i = 0; i < n; ++i) { |
| 1367 | const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i); |
| 1368 | printf("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 |
| 1369 | ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", |
| 1370 | entry.GetRangeBase(), entry.GetRangeEnd(), entry.data, |
| 1371 | entry.data + entry.GetByteSize()); |
| 1372 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1373 | #endif |
| 1374 | } |
| 1375 | |
| 1376 | lldb::addr_t |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1377 | SymbolFileDWARFDebugMap::LinkOSOFileAddress(SymbolFileDWARF *oso_symfile, |
| 1378 | lldb::addr_t oso_file_addr) { |
| 1379 | CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_symfile); |
| 1380 | if (cu_info) { |
| 1381 | const FileRangeMap::Entry *oso_range_entry = |
| 1382 | cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr); |
| 1383 | if (oso_range_entry) { |
| 1384 | const DebugMap::Entry *debug_map_entry = |
| 1385 | m_debug_map.FindEntryThatContains(oso_range_entry->data); |
| 1386 | if (debug_map_entry) { |
| 1387 | const lldb::addr_t offset = |
| 1388 | oso_file_addr - oso_range_entry->GetRangeBase(); |
| 1389 | const lldb::addr_t exe_file_addr = |
| 1390 | debug_map_entry->GetRangeBase() + offset; |
| 1391 | return exe_file_addr; |
| 1392 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1393 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1394 | } |
| 1395 | return LLDB_INVALID_ADDRESS; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1398 | bool SymbolFileDWARFDebugMap::LinkOSOAddress(Address &addr) { |
| 1399 | // Make sure this address hasn't been fixed already |
| 1400 | Module *exe_module = GetObjectFile()->GetModule().get(); |
| 1401 | Module *addr_module = addr.GetModule().get(); |
| 1402 | if (addr_module == exe_module) |
| 1403 | return true; // Address is already in terms of the main executable module |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1404 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1405 | CompileUnitInfo *cu_info = GetCompileUnitInfo(GetSymbolFileAsSymbolFileDWARF( |
| 1406 | addr_module->GetSymbolVendor()->GetSymbolFile())); |
| 1407 | if (cu_info) { |
| 1408 | const lldb::addr_t oso_file_addr = addr.GetFileAddress(); |
| 1409 | const FileRangeMap::Entry *oso_range_entry = |
| 1410 | cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr); |
| 1411 | if (oso_range_entry) { |
| 1412 | const DebugMap::Entry *debug_map_entry = |
| 1413 | m_debug_map.FindEntryThatContains(oso_range_entry->data); |
| 1414 | if (debug_map_entry) { |
| 1415 | const lldb::addr_t offset = |
| 1416 | oso_file_addr - oso_range_entry->GetRangeBase(); |
| 1417 | const lldb::addr_t exe_file_addr = |
| 1418 | debug_map_entry->GetRangeBase() + offset; |
| 1419 | return exe_module->ResolveFileAddress(exe_file_addr, addr); |
| 1420 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1421 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1422 | } |
| 1423 | return true; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1426 | LineTable *SymbolFileDWARFDebugMap::LinkOSOLineTable(SymbolFileDWARF *oso_dwarf, |
| 1427 | LineTable *line_table) { |
| 1428 | CompileUnitInfo *cu_info = GetCompileUnitInfo(oso_dwarf); |
| 1429 | if (cu_info) |
| 1430 | return line_table->LinkLineTable(cu_info->GetFileRangeMap(this)); |
| 1431 | return NULL; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| Enrico Granata | c76e60b | 2013-06-27 01:43:09 +0000 | [diff] [blame] | 1434 | size_t |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1435 | SymbolFileDWARFDebugMap::AddOSOARanges(SymbolFileDWARF *dwarf2Data, |
| 1436 | DWARFDebugAranges *debug_aranges) { |
| 1437 | size_t num_line_entries_added = 0; |
| 1438 | if (debug_aranges && dwarf2Data) { |
| 1439 | CompileUnitInfo *compile_unit_info = GetCompileUnitInfo(dwarf2Data); |
| 1440 | if (compile_unit_info) { |
| 1441 | const FileRangeMap &file_range_map = |
| 1442 | compile_unit_info->GetFileRangeMap(this); |
| 1443 | for (size_t idx = 0; idx < file_range_map.GetSize(); idx++) { |
| 1444 | const FileRangeMap::Entry *entry = file_range_map.GetEntryAtIndex(idx); |
| 1445 | if (entry) { |
| 1446 | debug_aranges->AppendRange(dwarf2Data->GetID(), entry->GetRangeBase(), |
| 1447 | entry->GetRangeEnd()); |
| 1448 | num_line_entries_added++; |
| Enrico Granata | c76e60b | 2013-06-27 01:43:09 +0000 | [diff] [blame] | 1449 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1450 | } |
| Enrico Granata | c76e60b | 2013-06-27 01:43:09 +0000 | [diff] [blame] | 1451 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1452 | } |
| 1453 | return num_line_entries_added; |
| Enrico Granata | c76e60b | 2013-06-27 01:43:09 +0000 | [diff] [blame] | 1454 | } |