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