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