15ffd83dbSDimitry Andric //===-- CompileUnit.cpp ---------------------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "lldb/Symbol/CompileUnit.h" 100b57cec5SDimitry Andric #include "lldb/Core/Module.h" 110b57cec5SDimitry Andric #include "lldb/Symbol/LineTable.h" 129dba64beSDimitry Andric #include "lldb/Symbol/SymbolFile.h" 130b57cec5SDimitry Andric #include "lldb/Symbol/VariableList.h" 140b57cec5SDimitry Andric #include "lldb/Target/Language.h" 15480093f4SDimitry Andric #include "lldb/Utility/Timer.h" 16bdd1243dSDimitry Andric #include <optional> 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric using namespace lldb; 190b57cec5SDimitry Andric using namespace lldb_private; 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, 220b57cec5SDimitry Andric const char *pathname, const lldb::user_id_t cu_sym_id, 230b57cec5SDimitry Andric lldb::LanguageType language, 240b57cec5SDimitry Andric lldb_private::LazyBool is_optimized) 257a6dacacSDimitry Andric : CompileUnit(module_sp, user_data, 267a6dacacSDimitry Andric std::make_shared<SupportFile>(FileSpec(pathname)), cu_sym_id, 277a6dacacSDimitry Andric language, is_optimized) {} 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, 307a6dacacSDimitry Andric lldb::SupportFileSP support_file_sp, 317a6dacacSDimitry Andric const lldb::user_id_t cu_sym_id, 320b57cec5SDimitry Andric lldb::LanguageType language, 331db9f3b2SDimitry Andric lldb_private::LazyBool is_optimized, 341db9f3b2SDimitry Andric SupportFileList &&support_files) 35480093f4SDimitry Andric : ModuleChild(module_sp), UserID(cu_sym_id), m_user_data(user_data), 367a6dacacSDimitry Andric m_language(language), m_flags(0), 377a6dacacSDimitry Andric m_primary_support_file_sp(support_file_sp), 381db9f3b2SDimitry Andric m_support_files(std::move(support_files)), m_is_optimized(is_optimized) { 390b57cec5SDimitry Andric if (language != eLanguageTypeUnknown) 400b57cec5SDimitry Andric m_flags.Set(flagsParsedLanguage); 410b57cec5SDimitry Andric assert(module_sp); 420b57cec5SDimitry Andric } 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric void CompileUnit::CalculateSymbolContext(SymbolContext *sc) { 450b57cec5SDimitry Andric sc->comp_unit = this; 460b57cec5SDimitry Andric GetModule()->CalculateSymbolContext(sc); 470b57cec5SDimitry Andric } 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric ModuleSP CompileUnit::CalculateSymbolContextModule() { return GetModule(); } 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric CompileUnit *CompileUnit::CalculateSymbolContextCompileUnit() { return this; } 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric void CompileUnit::DumpSymbolContext(Stream *s) { 540b57cec5SDimitry Andric GetModule()->DumpSymbolContext(s); 550b57cec5SDimitry Andric s->Printf(", CompileUnit{0x%8.8" PRIx64 "}", GetID()); 560b57cec5SDimitry Andric } 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric void CompileUnit::GetDescription(Stream *s, 590b57cec5SDimitry Andric lldb::DescriptionLevel level) const { 60349cc55cSDimitry Andric const char *language = GetCachedLanguage(); 610b57cec5SDimitry Andric *s << "id = " << (const UserID &)*this << ", file = \"" 62480093f4SDimitry Andric << this->GetPrimaryFile() << "\", language = \"" << language << '"'; 630b57cec5SDimitry Andric } 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric void CompileUnit::ForeachFunction( 660b57cec5SDimitry Andric llvm::function_ref<bool(const FunctionSP &)> lambda) const { 670b57cec5SDimitry Andric std::vector<lldb::FunctionSP> sorted_functions; 680b57cec5SDimitry Andric sorted_functions.reserve(m_functions_by_uid.size()); 690b57cec5SDimitry Andric for (auto &p : m_functions_by_uid) 700b57cec5SDimitry Andric sorted_functions.push_back(p.second); 71fcaf7f86SDimitry Andric llvm::sort(sorted_functions, 720b57cec5SDimitry Andric [](const lldb::FunctionSP &a, const lldb::FunctionSP &b) { 730b57cec5SDimitry Andric return a->GetID() < b->GetID(); 740b57cec5SDimitry Andric }); 750b57cec5SDimitry Andric 760b57cec5SDimitry Andric for (auto &f : sorted_functions) 770b57cec5SDimitry Andric if (lambda(f)) 780b57cec5SDimitry Andric return; 790b57cec5SDimitry Andric } 800b57cec5SDimitry Andric 81480093f4SDimitry Andric lldb::FunctionSP CompileUnit::FindFunction( 82480093f4SDimitry Andric llvm::function_ref<bool(const FunctionSP &)> matching_lambda) { 83e8d8bef9SDimitry Andric LLDB_SCOPED_TIMER(); 84480093f4SDimitry Andric 85480093f4SDimitry Andric lldb::ModuleSP module = CalculateSymbolContextModule(); 86480093f4SDimitry Andric 87480093f4SDimitry Andric if (!module) 88480093f4SDimitry Andric return {}; 89480093f4SDimitry Andric 90480093f4SDimitry Andric SymbolFile *symbol_file = module->GetSymbolFile(); 91480093f4SDimitry Andric 92480093f4SDimitry Andric if (!symbol_file) 93480093f4SDimitry Andric return {}; 94480093f4SDimitry Andric 95480093f4SDimitry Andric // m_functions_by_uid is filled in lazily but we need all the entries. 96480093f4SDimitry Andric symbol_file->ParseFunctions(*this); 97480093f4SDimitry Andric 98480093f4SDimitry Andric for (auto &p : m_functions_by_uid) { 99480093f4SDimitry Andric if (matching_lambda(p.second)) 100480093f4SDimitry Andric return p.second; 101480093f4SDimitry Andric } 102480093f4SDimitry Andric return {}; 103480093f4SDimitry Andric } 104480093f4SDimitry Andric 105349cc55cSDimitry Andric const char *CompileUnit::GetCachedLanguage() const { 106349cc55cSDimitry Andric if (m_flags.IsClear(flagsParsedLanguage)) 107349cc55cSDimitry Andric return "<not loaded>"; 108349cc55cSDimitry Andric return Language::GetNameForLanguageType(m_language); 109349cc55cSDimitry Andric } 110349cc55cSDimitry Andric 1110b57cec5SDimitry Andric // Dump the current contents of this object. No functions that cause on demand 1120b57cec5SDimitry Andric // parsing of functions, globals, statics are called, so this is a good 1130b57cec5SDimitry Andric // function to call to get an idea of the current contents of the CompileUnit 1140b57cec5SDimitry Andric // object. 1150b57cec5SDimitry Andric void CompileUnit::Dump(Stream *s, bool show_context) const { 116349cc55cSDimitry Andric const char *language = GetCachedLanguage(); 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric s->Printf("%p: ", static_cast<const void *>(this)); 1190b57cec5SDimitry Andric s->Indent(); 1200b57cec5SDimitry Andric *s << "CompileUnit" << static_cast<const UserID &>(*this) << ", language = \"" 121480093f4SDimitry Andric << language << "\", file = '" << GetPrimaryFile() << "'\n"; 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric // m_types.Dump(s); 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric if (m_variables.get()) { 1260b57cec5SDimitry Andric s->IndentMore(); 1270b57cec5SDimitry Andric m_variables->Dump(s, show_context); 1280b57cec5SDimitry Andric s->IndentLess(); 1290b57cec5SDimitry Andric } 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andric if (!m_functions_by_uid.empty()) { 1320b57cec5SDimitry Andric s->IndentMore(); 1330b57cec5SDimitry Andric ForeachFunction([&s, show_context](const FunctionSP &f) { 1340b57cec5SDimitry Andric f->Dump(s, show_context); 1350b57cec5SDimitry Andric return false; 1360b57cec5SDimitry Andric }); 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andric s->IndentLess(); 1390b57cec5SDimitry Andric s->EOL(); 1400b57cec5SDimitry Andric } 1410b57cec5SDimitry Andric } 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andric // Add a function to this compile unit 1440b57cec5SDimitry Andric void CompileUnit::AddFunction(FunctionSP &funcSP) { 1450b57cec5SDimitry Andric m_functions_by_uid[funcSP->GetID()] = funcSP; 1460b57cec5SDimitry Andric } 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andric FunctionSP CompileUnit::FindFunctionByUID(lldb::user_id_t func_uid) { 1490b57cec5SDimitry Andric auto it = m_functions_by_uid.find(func_uid); 1500b57cec5SDimitry Andric if (it == m_functions_by_uid.end()) 1510b57cec5SDimitry Andric return FunctionSP(); 1520b57cec5SDimitry Andric return it->second; 1530b57cec5SDimitry Andric } 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric lldb::LanguageType CompileUnit::GetLanguage() { 1560b57cec5SDimitry Andric if (m_language == eLanguageTypeUnknown) { 1570b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedLanguage)) { 1580b57cec5SDimitry Andric m_flags.Set(flagsParsedLanguage); 1599dba64beSDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) 1609dba64beSDimitry Andric m_language = symfile->ParseLanguage(*this); 1610b57cec5SDimitry Andric } 1620b57cec5SDimitry Andric } 1630b57cec5SDimitry Andric return m_language; 1640b57cec5SDimitry Andric } 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andric LineTable *CompileUnit::GetLineTable() { 1670b57cec5SDimitry Andric if (m_line_table_up == nullptr) { 1680b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedLineTable)) { 1690b57cec5SDimitry Andric m_flags.Set(flagsParsedLineTable); 1709dba64beSDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) 1719dba64beSDimitry Andric symfile->ParseLineTable(*this); 1720b57cec5SDimitry Andric } 1730b57cec5SDimitry Andric } 1740b57cec5SDimitry Andric return m_line_table_up.get(); 1750b57cec5SDimitry Andric } 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric void CompileUnit::SetLineTable(LineTable *line_table) { 1780b57cec5SDimitry Andric if (line_table == nullptr) 1790b57cec5SDimitry Andric m_flags.Clear(flagsParsedLineTable); 1800b57cec5SDimitry Andric else 1810b57cec5SDimitry Andric m_flags.Set(flagsParsedLineTable); 1820b57cec5SDimitry Andric m_line_table_up.reset(line_table); 1830b57cec5SDimitry Andric } 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andric DebugMacros *CompileUnit::GetDebugMacros() { 1860b57cec5SDimitry Andric if (m_debug_macros_sp.get() == nullptr) { 1870b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedDebugMacros)) { 1880b57cec5SDimitry Andric m_flags.Set(flagsParsedDebugMacros); 1899dba64beSDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) 1909dba64beSDimitry Andric symfile->ParseDebugMacros(*this); 1910b57cec5SDimitry Andric } 1920b57cec5SDimitry Andric } 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andric return m_debug_macros_sp.get(); 1950b57cec5SDimitry Andric } 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric void CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp) { 1980b57cec5SDimitry Andric if (debug_macros_sp.get() == nullptr) 1990b57cec5SDimitry Andric m_flags.Clear(flagsParsedDebugMacros); 2000b57cec5SDimitry Andric else 2010b57cec5SDimitry Andric m_flags.Set(flagsParsedDebugMacros); 2020b57cec5SDimitry Andric m_debug_macros_sp = debug_macros_sp; 2030b57cec5SDimitry Andric } 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andric VariableListSP CompileUnit::GetVariableList(bool can_create) { 2060b57cec5SDimitry Andric if (m_variables.get() == nullptr && can_create) { 2070b57cec5SDimitry Andric SymbolContext sc; 2080b57cec5SDimitry Andric CalculateSymbolContext(&sc); 2090b57cec5SDimitry Andric assert(sc.module_sp); 2109dba64beSDimitry Andric sc.module_sp->GetSymbolFile()->ParseVariablesForContext(sc); 2110b57cec5SDimitry Andric } 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andric return m_variables; 2140b57cec5SDimitry Andric } 2150b57cec5SDimitry Andric 2161db9f3b2SDimitry Andric std::vector<uint32_t> FindFileIndexes(const SupportFileList &files, 217bdd1243dSDimitry Andric const FileSpec &file) { 218480093f4SDimitry Andric std::vector<uint32_t> result; 219480093f4SDimitry Andric uint32_t idx = -1; 220bdd1243dSDimitry Andric while ((idx = files.FindCompatibleIndex(idx + 1, file)) != 221480093f4SDimitry Andric UINT32_MAX) 222480093f4SDimitry Andric result.push_back(idx); 223480093f4SDimitry Andric return result; 224480093f4SDimitry Andric } 225480093f4SDimitry Andric 2260b57cec5SDimitry Andric uint32_t CompileUnit::FindLineEntry(uint32_t start_idx, uint32_t line, 2270b57cec5SDimitry Andric const FileSpec *file_spec_ptr, bool exact, 2280b57cec5SDimitry Andric LineEntry *line_entry_ptr) { 229480093f4SDimitry Andric if (!file_spec_ptr) 230480093f4SDimitry Andric file_spec_ptr = &GetPrimaryFile(); 231bdd1243dSDimitry Andric std::vector<uint32_t> file_indexes = FindFileIndexes(GetSupportFiles(), 232bdd1243dSDimitry Andric *file_spec_ptr); 233480093f4SDimitry Andric if (file_indexes.empty()) 2340b57cec5SDimitry Andric return UINT32_MAX; 235480093f4SDimitry Andric 236fe6060f1SDimitry Andric // TODO: Handle SourceLocationSpec column information 237bdd1243dSDimitry Andric SourceLocationSpec location_spec(*file_spec_ptr, line, 238bdd1243dSDimitry Andric /*column=*/std::nullopt, 239fe6060f1SDimitry Andric /*check_inlines=*/false, exact); 240fe6060f1SDimitry Andric 2410b57cec5SDimitry Andric LineTable *line_table = GetLineTable(); 2420b57cec5SDimitry Andric if (line_table) 243480093f4SDimitry Andric return line_table->FindLineEntryIndexByFileIndex( 244fe6060f1SDimitry Andric start_idx, file_indexes, location_spec, line_entry_ptr); 2450b57cec5SDimitry Andric return UINT32_MAX; 2460b57cec5SDimitry Andric } 2470b57cec5SDimitry Andric 248fe6060f1SDimitry Andric void CompileUnit::ResolveSymbolContext( 249fe6060f1SDimitry Andric const SourceLocationSpec &src_location_spec, 250fe6060f1SDimitry Andric SymbolContextItem resolve_scope, SymbolContextList &sc_list) { 251fe6060f1SDimitry Andric const FileSpec file_spec = src_location_spec.GetFileSpec(); 25281ad6265SDimitry Andric const uint32_t line = src_location_spec.GetLine().value_or(0); 253fe6060f1SDimitry Andric const bool check_inlines = src_location_spec.GetCheckInlines(); 254fe6060f1SDimitry Andric 2550b57cec5SDimitry Andric // First find all of the file indexes that match our "file_spec". If 2560b57cec5SDimitry Andric // "file_spec" has an empty directory, then only compare the basenames when 2570b57cec5SDimitry Andric // finding file indexes 2580b57cec5SDimitry Andric bool file_spec_matches_cu_file_spec = 259480093f4SDimitry Andric FileSpec::Match(file_spec, this->GetPrimaryFile()); 2600b57cec5SDimitry Andric 2610b57cec5SDimitry Andric // If we are not looking for inlined functions and our file spec doesn't 2620b57cec5SDimitry Andric // match then we are done... 2630b57cec5SDimitry Andric if (!file_spec_matches_cu_file_spec && !check_inlines) 264480093f4SDimitry Andric return; 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andric SymbolContext sc(GetModule()); 2670b57cec5SDimitry Andric sc.comp_unit = this; 2680b57cec5SDimitry Andric 269480093f4SDimitry Andric if (line == 0) { 270480093f4SDimitry Andric if (file_spec_matches_cu_file_spec && !check_inlines) { 271480093f4SDimitry Andric // only append the context if we aren't looking for inline call sites by 272480093f4SDimitry Andric // file and line and if the file spec matches that of the compile unit 273480093f4SDimitry Andric sc_list.Append(sc); 274480093f4SDimitry Andric } 275480093f4SDimitry Andric return; 276480093f4SDimitry Andric } 277480093f4SDimitry Andric 278bdd1243dSDimitry Andric std::vector<uint32_t> file_indexes = FindFileIndexes(GetSupportFiles(), 279bdd1243dSDimitry Andric file_spec); 280fe6060f1SDimitry Andric const size_t num_file_indexes = file_indexes.size(); 281fe6060f1SDimitry Andric if (num_file_indexes == 0) 282fe6060f1SDimitry Andric return; 283fe6060f1SDimitry Andric 28481ad6265SDimitry Andric // Found a matching source file in this compile unit load its debug info. 28581ad6265SDimitry Andric GetModule()->GetSymbolFile()->SetLoadDebugInfoEnabled(); 28681ad6265SDimitry Andric 2870b57cec5SDimitry Andric LineTable *line_table = sc.comp_unit->GetLineTable(); 2880b57cec5SDimitry Andric 289fe6060f1SDimitry Andric if (line_table == nullptr) { 290fe6060f1SDimitry Andric if (file_spec_matches_cu_file_spec && !check_inlines) { 291fe6060f1SDimitry Andric sc_list.Append(sc); 292fe6060f1SDimitry Andric } 293480093f4SDimitry Andric return; 294fe6060f1SDimitry Andric } 295480093f4SDimitry Andric 2960b57cec5SDimitry Andric uint32_t line_idx; 297480093f4SDimitry Andric LineEntry line_entry; 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andric if (num_file_indexes == 1) { 3000b57cec5SDimitry Andric // We only have a single support file that matches, so use the line 3010b57cec5SDimitry Andric // table function that searches for a line entries that match a single 3020b57cec5SDimitry Andric // support file index 3030b57cec5SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 304fe6060f1SDimitry Andric 0, file_indexes.front(), src_location_spec, &line_entry); 305480093f4SDimitry Andric } else { 306480093f4SDimitry Andric // We found multiple support files that match "file_spec" so use the 307480093f4SDimitry Andric // line table function that searches for a line entries that match a 308480093f4SDimitry Andric // multiple support file indexes. 309fe6060f1SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 310fe6060f1SDimitry Andric 0, file_indexes, src_location_spec, &line_entry); 311480093f4SDimitry Andric } 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andric // If "exact == true", then "found_line" will be the same as "line". If 3140b57cec5SDimitry Andric // "exact == false", the "found_line" will be the closest line entry 3150b57cec5SDimitry Andric // with a line number greater than "line" and we will use this for our 3160b57cec5SDimitry Andric // subsequent line exact matches below. 317fe6060f1SDimitry Andric const bool inlines = false; 318fe6060f1SDimitry Andric const bool exact = true; 319bdd1243dSDimitry Andric const std::optional<uint16_t> column = 320bdd1243dSDimitry Andric src_location_spec.GetColumn() ? std::optional<uint16_t>(line_entry.column) 321bdd1243dSDimitry Andric : std::nullopt; 322349cc55cSDimitry Andric 323*0fca6ea1SDimitry Andric SourceLocationSpec found_entry(line_entry.GetFile(), line_entry.line, column, 324349cc55cSDimitry Andric inlines, exact); 3250b57cec5SDimitry Andric 3260b57cec5SDimitry Andric while (line_idx != UINT32_MAX) { 3270b57cec5SDimitry Andric // If they only asked for the line entry, then we're done, we can 3280b57cec5SDimitry Andric // just copy that over. But if they wanted more than just the line 3290b57cec5SDimitry Andric // number, fill it in. 330bdd1243dSDimitry Andric SymbolContext resolved_sc; 3310b57cec5SDimitry Andric sc.line_entry = line_entry; 332bdd1243dSDimitry Andric if (resolve_scope == eSymbolContextLineEntry) { 333bdd1243dSDimitry Andric sc_list.Append(sc); 3340b57cec5SDimitry Andric } else { 335bdd1243dSDimitry Andric line_entry.range.GetBaseAddress().CalculateSymbolContext(&resolved_sc, 336480093f4SDimitry Andric resolve_scope); 337bdd1243dSDimitry Andric // Sometimes debug info is bad and isn't able to resolve the line entry's 338bdd1243dSDimitry Andric // address back to the same compile unit and/or line entry. If the compile 339bdd1243dSDimitry Andric // unit changed, then revert back to just the compile unit and line entry. 340bdd1243dSDimitry Andric // Prior to this fix, the above code might end up not being able to lookup 341bdd1243dSDimitry Andric // the address, and then it would clear compile unit and the line entry in 342bdd1243dSDimitry Andric // the symbol context and the breakpoint would fail to get set even though 343bdd1243dSDimitry Andric // we have a valid line table entry in this compile unit. The address 344bdd1243dSDimitry Andric // lookup can also end up finding another function in another compiler 345bdd1243dSDimitry Andric // unit if the DWARF has overlappging address ranges. So if we end up with 346bdd1243dSDimitry Andric // no compile unit or a different one after the above function call, 347bdd1243dSDimitry Andric // revert back to the same results as if resolve_scope was set exactly to 348bdd1243dSDimitry Andric // eSymbolContextLineEntry. 349bdd1243dSDimitry Andric if (resolved_sc.comp_unit == this) { 350bdd1243dSDimitry Andric sc_list.Append(resolved_sc); 351bdd1243dSDimitry Andric } else { 352bdd1243dSDimitry Andric if (resolved_sc.comp_unit == nullptr && resolved_sc.module_sp) { 353bdd1243dSDimitry Andric // Only report an error if we don't map back to any compile unit. With 354bdd1243dSDimitry Andric // link time optimizations, the debug info might have many compile 355bdd1243dSDimitry Andric // units that have the same address range due to function outlining 356bdd1243dSDimitry Andric // or other link time optimizations. If the compile unit is NULL, then 357bdd1243dSDimitry Andric // address resolving is completely failing and more deserving of an 358bdd1243dSDimitry Andric // error message the user can see. 359bdd1243dSDimitry Andric resolved_sc.module_sp->ReportError( 360bdd1243dSDimitry Andric "unable to resolve a line table file address {0:x16} back " 361bdd1243dSDimitry Andric "to a compile unit, please file a bug and attach the address " 362bdd1243dSDimitry Andric "and file.", 363bdd1243dSDimitry Andric line_entry.range.GetBaseAddress().GetFileAddress()); 364bdd1243dSDimitry Andric } 365bdd1243dSDimitry Andric sc_list.Append(sc); 366bdd1243dSDimitry Andric } 3670b57cec5SDimitry Andric } 3680b57cec5SDimitry Andric 369480093f4SDimitry Andric if (num_file_indexes == 1) 3700b57cec5SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 371fe6060f1SDimitry Andric line_idx + 1, file_indexes.front(), found_entry, &line_entry); 372480093f4SDimitry Andric else 3730b57cec5SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 374fe6060f1SDimitry Andric line_idx + 1, file_indexes, found_entry, &line_entry); 3750b57cec5SDimitry Andric } 3760b57cec5SDimitry Andric } 3770b57cec5SDimitry Andric 3780b57cec5SDimitry Andric bool CompileUnit::GetIsOptimized() { 3790b57cec5SDimitry Andric if (m_is_optimized == eLazyBoolCalculate) { 3800b57cec5SDimitry Andric m_is_optimized = eLazyBoolNo; 3819dba64beSDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) { 3829dba64beSDimitry Andric if (symfile->ParseIsOptimized(*this)) 3830b57cec5SDimitry Andric m_is_optimized = eLazyBoolYes; 3840b57cec5SDimitry Andric } 3850b57cec5SDimitry Andric } 3860b57cec5SDimitry Andric return m_is_optimized; 3870b57cec5SDimitry Andric } 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andric void CompileUnit::SetVariableList(VariableListSP &variables) { 3900b57cec5SDimitry Andric m_variables = variables; 3910b57cec5SDimitry Andric } 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andric const std::vector<SourceModule> &CompileUnit::GetImportedModules() { 3940b57cec5SDimitry Andric if (m_imported_modules.empty() && 3950b57cec5SDimitry Andric m_flags.IsClear(flagsParsedImportedModules)) { 3960b57cec5SDimitry Andric m_flags.Set(flagsParsedImportedModules); 3979dba64beSDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) { 3980b57cec5SDimitry Andric SymbolContext sc; 3990b57cec5SDimitry Andric CalculateSymbolContext(&sc); 4009dba64beSDimitry Andric symfile->ParseImportedModules(sc, m_imported_modules); 4010b57cec5SDimitry Andric } 4020b57cec5SDimitry Andric } 4030b57cec5SDimitry Andric return m_imported_modules; 4040b57cec5SDimitry Andric } 4050b57cec5SDimitry Andric 406480093f4SDimitry Andric bool CompileUnit::ForEachExternalModule( 407480093f4SDimitry Andric llvm::DenseSet<SymbolFile *> &visited_symbol_files, 408480093f4SDimitry Andric llvm::function_ref<bool(Module &)> lambda) { 4099dba64beSDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) 410480093f4SDimitry Andric return symfile->ForEachExternalModule(*this, visited_symbol_files, lambda); 411480093f4SDimitry Andric return false; 4129dba64beSDimitry Andric } 4139dba64beSDimitry Andric 4141db9f3b2SDimitry Andric const SupportFileList &CompileUnit::GetSupportFiles() { 4150b57cec5SDimitry Andric if (m_support_files.GetSize() == 0) { 4160b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedSupportFiles)) { 4170b57cec5SDimitry Andric m_flags.Set(flagsParsedSupportFiles); 4189dba64beSDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) 4199dba64beSDimitry Andric symfile->ParseSupportFiles(*this, m_support_files); 4200b57cec5SDimitry Andric } 4210b57cec5SDimitry Andric } 4220b57cec5SDimitry Andric return m_support_files; 4230b57cec5SDimitry Andric } 4240b57cec5SDimitry Andric 4250b57cec5SDimitry Andric void *CompileUnit::GetUserData() const { return m_user_data; } 426