1*0b57cec5SDimitry Andric //===-- CompileUnit.cpp -----------------------------------------*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "lldb/Symbol/CompileUnit.h" 10*0b57cec5SDimitry Andric #include "lldb/Core/Module.h" 11*0b57cec5SDimitry Andric #include "lldb/Symbol/LineTable.h" 12*0b57cec5SDimitry Andric #include "lldb/Symbol/SymbolVendor.h" 13*0b57cec5SDimitry Andric #include "lldb/Symbol/VariableList.h" 14*0b57cec5SDimitry Andric #include "lldb/Target/Language.h" 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric using namespace lldb; 17*0b57cec5SDimitry Andric using namespace lldb_private; 18*0b57cec5SDimitry Andric 19*0b57cec5SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, 20*0b57cec5SDimitry Andric const char *pathname, const lldb::user_id_t cu_sym_id, 21*0b57cec5SDimitry Andric lldb::LanguageType language, 22*0b57cec5SDimitry Andric lldb_private::LazyBool is_optimized) 23*0b57cec5SDimitry Andric : ModuleChild(module_sp), FileSpec(pathname), UserID(cu_sym_id), 24*0b57cec5SDimitry Andric m_user_data(user_data), m_language(language), m_flags(0), 25*0b57cec5SDimitry Andric m_support_files(), m_line_table_up(), m_variables(), 26*0b57cec5SDimitry Andric m_is_optimized(is_optimized) { 27*0b57cec5SDimitry Andric if (language != eLanguageTypeUnknown) 28*0b57cec5SDimitry Andric m_flags.Set(flagsParsedLanguage); 29*0b57cec5SDimitry Andric assert(module_sp); 30*0b57cec5SDimitry Andric } 31*0b57cec5SDimitry Andric 32*0b57cec5SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, 33*0b57cec5SDimitry Andric const FileSpec &fspec, const lldb::user_id_t cu_sym_id, 34*0b57cec5SDimitry Andric lldb::LanguageType language, 35*0b57cec5SDimitry Andric lldb_private::LazyBool is_optimized) 36*0b57cec5SDimitry Andric : ModuleChild(module_sp), FileSpec(fspec), UserID(cu_sym_id), 37*0b57cec5SDimitry Andric m_user_data(user_data), m_language(language), m_flags(0), 38*0b57cec5SDimitry Andric m_support_files(), m_line_table_up(), m_variables(), 39*0b57cec5SDimitry Andric m_is_optimized(is_optimized) { 40*0b57cec5SDimitry Andric if (language != eLanguageTypeUnknown) 41*0b57cec5SDimitry Andric m_flags.Set(flagsParsedLanguage); 42*0b57cec5SDimitry Andric assert(module_sp); 43*0b57cec5SDimitry Andric } 44*0b57cec5SDimitry Andric 45*0b57cec5SDimitry Andric CompileUnit::~CompileUnit() {} 46*0b57cec5SDimitry Andric 47*0b57cec5SDimitry Andric void CompileUnit::CalculateSymbolContext(SymbolContext *sc) { 48*0b57cec5SDimitry Andric sc->comp_unit = this; 49*0b57cec5SDimitry Andric GetModule()->CalculateSymbolContext(sc); 50*0b57cec5SDimitry Andric } 51*0b57cec5SDimitry Andric 52*0b57cec5SDimitry Andric ModuleSP CompileUnit::CalculateSymbolContextModule() { return GetModule(); } 53*0b57cec5SDimitry Andric 54*0b57cec5SDimitry Andric CompileUnit *CompileUnit::CalculateSymbolContextCompileUnit() { return this; } 55*0b57cec5SDimitry Andric 56*0b57cec5SDimitry Andric void CompileUnit::DumpSymbolContext(Stream *s) { 57*0b57cec5SDimitry Andric GetModule()->DumpSymbolContext(s); 58*0b57cec5SDimitry Andric s->Printf(", CompileUnit{0x%8.8" PRIx64 "}", GetID()); 59*0b57cec5SDimitry Andric } 60*0b57cec5SDimitry Andric 61*0b57cec5SDimitry Andric void CompileUnit::GetDescription(Stream *s, 62*0b57cec5SDimitry Andric lldb::DescriptionLevel level) const { 63*0b57cec5SDimitry Andric const char *language = Language::GetNameForLanguageType(m_language); 64*0b57cec5SDimitry Andric *s << "id = " << (const UserID &)*this << ", file = \"" 65*0b57cec5SDimitry Andric << (const FileSpec &)*this << "\", language = \"" << language << '"'; 66*0b57cec5SDimitry Andric } 67*0b57cec5SDimitry Andric 68*0b57cec5SDimitry Andric void CompileUnit::ForeachFunction( 69*0b57cec5SDimitry Andric llvm::function_ref<bool(const FunctionSP &)> lambda) const { 70*0b57cec5SDimitry Andric std::vector<lldb::FunctionSP> sorted_functions; 71*0b57cec5SDimitry Andric sorted_functions.reserve(m_functions_by_uid.size()); 72*0b57cec5SDimitry Andric for (auto &p : m_functions_by_uid) 73*0b57cec5SDimitry Andric sorted_functions.push_back(p.second); 74*0b57cec5SDimitry Andric llvm::sort(sorted_functions.begin(), sorted_functions.end(), 75*0b57cec5SDimitry Andric [](const lldb::FunctionSP &a, const lldb::FunctionSP &b) { 76*0b57cec5SDimitry Andric return a->GetID() < b->GetID(); 77*0b57cec5SDimitry Andric }); 78*0b57cec5SDimitry Andric 79*0b57cec5SDimitry Andric for (auto &f : sorted_functions) 80*0b57cec5SDimitry Andric if (lambda(f)) 81*0b57cec5SDimitry Andric return; 82*0b57cec5SDimitry Andric } 83*0b57cec5SDimitry Andric 84*0b57cec5SDimitry Andric // Dump the current contents of this object. No functions that cause on demand 85*0b57cec5SDimitry Andric // parsing of functions, globals, statics are called, so this is a good 86*0b57cec5SDimitry Andric // function to call to get an idea of the current contents of the CompileUnit 87*0b57cec5SDimitry Andric // object. 88*0b57cec5SDimitry Andric void CompileUnit::Dump(Stream *s, bool show_context) const { 89*0b57cec5SDimitry Andric const char *language = Language::GetNameForLanguageType(m_language); 90*0b57cec5SDimitry Andric 91*0b57cec5SDimitry Andric s->Printf("%p: ", static_cast<const void *>(this)); 92*0b57cec5SDimitry Andric s->Indent(); 93*0b57cec5SDimitry Andric *s << "CompileUnit" << static_cast<const UserID &>(*this) << ", language = \"" 94*0b57cec5SDimitry Andric << language << "\", file = '" << static_cast<const FileSpec &>(*this) 95*0b57cec5SDimitry Andric << "'\n"; 96*0b57cec5SDimitry Andric 97*0b57cec5SDimitry Andric // m_types.Dump(s); 98*0b57cec5SDimitry Andric 99*0b57cec5SDimitry Andric if (m_variables.get()) { 100*0b57cec5SDimitry Andric s->IndentMore(); 101*0b57cec5SDimitry Andric m_variables->Dump(s, show_context); 102*0b57cec5SDimitry Andric s->IndentLess(); 103*0b57cec5SDimitry Andric } 104*0b57cec5SDimitry Andric 105*0b57cec5SDimitry Andric if (!m_functions_by_uid.empty()) { 106*0b57cec5SDimitry Andric s->IndentMore(); 107*0b57cec5SDimitry Andric ForeachFunction([&s, show_context](const FunctionSP &f) { 108*0b57cec5SDimitry Andric f->Dump(s, show_context); 109*0b57cec5SDimitry Andric return false; 110*0b57cec5SDimitry Andric }); 111*0b57cec5SDimitry Andric 112*0b57cec5SDimitry Andric s->IndentLess(); 113*0b57cec5SDimitry Andric s->EOL(); 114*0b57cec5SDimitry Andric } 115*0b57cec5SDimitry Andric } 116*0b57cec5SDimitry Andric 117*0b57cec5SDimitry Andric // Add a function to this compile unit 118*0b57cec5SDimitry Andric void CompileUnit::AddFunction(FunctionSP &funcSP) { 119*0b57cec5SDimitry Andric m_functions_by_uid[funcSP->GetID()] = funcSP; 120*0b57cec5SDimitry Andric } 121*0b57cec5SDimitry Andric 122*0b57cec5SDimitry Andric // Find functions using the Mangled::Tokens token list. This function currently 123*0b57cec5SDimitry Andric // implements an interactive approach designed to find all instances of certain 124*0b57cec5SDimitry Andric // functions. It isn't designed to the quickest way to lookup functions as it 125*0b57cec5SDimitry Andric // will need to iterate through all functions and see if they match, though it 126*0b57cec5SDimitry Andric // does provide a powerful and context sensitive way to search for all 127*0b57cec5SDimitry Andric // functions with a certain name, all functions in a namespace, or all 128*0b57cec5SDimitry Andric // functions of a template type. See Mangled::Tokens::Parse() comments for more 129*0b57cec5SDimitry Andric // information. 130*0b57cec5SDimitry Andric // 131*0b57cec5SDimitry Andric // The function prototype will need to change to return a list of results. It 132*0b57cec5SDimitry Andric // was originally used to help debug the Mangled class and the 133*0b57cec5SDimitry Andric // Mangled::Tokens::MatchesQuery() function and it currently will print out a 134*0b57cec5SDimitry Andric // list of matching results for the functions that are currently in this 135*0b57cec5SDimitry Andric // compile unit. 136*0b57cec5SDimitry Andric // 137*0b57cec5SDimitry Andric // A FindFunctions method should be called prior to this that takes 138*0b57cec5SDimitry Andric // a regular function name (const char * or ConstString as a parameter) before 139*0b57cec5SDimitry Andric // resorting to this slower but more complete function. The other FindFunctions 140*0b57cec5SDimitry Andric // method should be able to take advantage of any accelerator tables available 141*0b57cec5SDimitry Andric // in the debug information (which is parsed by the SymbolFile parser plug-ins 142*0b57cec5SDimitry Andric // and registered with each Module). 143*0b57cec5SDimitry Andric // void 144*0b57cec5SDimitry Andric // CompileUnit::FindFunctions(const Mangled::Tokens& tokens) 145*0b57cec5SDimitry Andric //{ 146*0b57cec5SDimitry Andric // if (!m_functions.empty()) 147*0b57cec5SDimitry Andric // { 148*0b57cec5SDimitry Andric // Stream s(stdout); 149*0b57cec5SDimitry Andric // std::vector<FunctionSP>::const_iterator pos; 150*0b57cec5SDimitry Andric // std::vector<FunctionSP>::const_iterator end = m_functions.end(); 151*0b57cec5SDimitry Andric // for (pos = m_functions.begin(); pos != end; ++pos) 152*0b57cec5SDimitry Andric // { 153*0b57cec5SDimitry Andric // const ConstString& demangled = (*pos)->Mangled().Demangled(); 154*0b57cec5SDimitry Andric // if (demangled) 155*0b57cec5SDimitry Andric // { 156*0b57cec5SDimitry Andric // const Mangled::Tokens& func_tokens = 157*0b57cec5SDimitry Andric // (*pos)->Mangled().GetTokens(); 158*0b57cec5SDimitry Andric // if (func_tokens.MatchesQuery (tokens)) 159*0b57cec5SDimitry Andric // s << "demangled MATCH found: " << demangled << "\n"; 160*0b57cec5SDimitry Andric // } 161*0b57cec5SDimitry Andric // } 162*0b57cec5SDimitry Andric // } 163*0b57cec5SDimitry Andric //} 164*0b57cec5SDimitry Andric 165*0b57cec5SDimitry Andric FunctionSP CompileUnit::FindFunctionByUID(lldb::user_id_t func_uid) { 166*0b57cec5SDimitry Andric auto it = m_functions_by_uid.find(func_uid); 167*0b57cec5SDimitry Andric if (it == m_functions_by_uid.end()) 168*0b57cec5SDimitry Andric return FunctionSP(); 169*0b57cec5SDimitry Andric return it->second; 170*0b57cec5SDimitry Andric } 171*0b57cec5SDimitry Andric 172*0b57cec5SDimitry Andric lldb::LanguageType CompileUnit::GetLanguage() { 173*0b57cec5SDimitry Andric if (m_language == eLanguageTypeUnknown) { 174*0b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedLanguage)) { 175*0b57cec5SDimitry Andric m_flags.Set(flagsParsedLanguage); 176*0b57cec5SDimitry Andric SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor(); 177*0b57cec5SDimitry Andric if (symbol_vendor) { 178*0b57cec5SDimitry Andric m_language = symbol_vendor->ParseLanguage(*this); 179*0b57cec5SDimitry Andric } 180*0b57cec5SDimitry Andric } 181*0b57cec5SDimitry Andric } 182*0b57cec5SDimitry Andric return m_language; 183*0b57cec5SDimitry Andric } 184*0b57cec5SDimitry Andric 185*0b57cec5SDimitry Andric LineTable *CompileUnit::GetLineTable() { 186*0b57cec5SDimitry Andric if (m_line_table_up == nullptr) { 187*0b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedLineTable)) { 188*0b57cec5SDimitry Andric m_flags.Set(flagsParsedLineTable); 189*0b57cec5SDimitry Andric SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor(); 190*0b57cec5SDimitry Andric if (symbol_vendor) 191*0b57cec5SDimitry Andric symbol_vendor->ParseLineTable(*this); 192*0b57cec5SDimitry Andric } 193*0b57cec5SDimitry Andric } 194*0b57cec5SDimitry Andric return m_line_table_up.get(); 195*0b57cec5SDimitry Andric } 196*0b57cec5SDimitry Andric 197*0b57cec5SDimitry Andric void CompileUnit::SetLineTable(LineTable *line_table) { 198*0b57cec5SDimitry Andric if (line_table == nullptr) 199*0b57cec5SDimitry Andric m_flags.Clear(flagsParsedLineTable); 200*0b57cec5SDimitry Andric else 201*0b57cec5SDimitry Andric m_flags.Set(flagsParsedLineTable); 202*0b57cec5SDimitry Andric m_line_table_up.reset(line_table); 203*0b57cec5SDimitry Andric } 204*0b57cec5SDimitry Andric 205*0b57cec5SDimitry Andric DebugMacros *CompileUnit::GetDebugMacros() { 206*0b57cec5SDimitry Andric if (m_debug_macros_sp.get() == nullptr) { 207*0b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedDebugMacros)) { 208*0b57cec5SDimitry Andric m_flags.Set(flagsParsedDebugMacros); 209*0b57cec5SDimitry Andric SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor(); 210*0b57cec5SDimitry Andric if (symbol_vendor) { 211*0b57cec5SDimitry Andric symbol_vendor->ParseDebugMacros(*this); 212*0b57cec5SDimitry Andric } 213*0b57cec5SDimitry Andric } 214*0b57cec5SDimitry Andric } 215*0b57cec5SDimitry Andric 216*0b57cec5SDimitry Andric return m_debug_macros_sp.get(); 217*0b57cec5SDimitry Andric } 218*0b57cec5SDimitry Andric 219*0b57cec5SDimitry Andric void CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp) { 220*0b57cec5SDimitry Andric if (debug_macros_sp.get() == nullptr) 221*0b57cec5SDimitry Andric m_flags.Clear(flagsParsedDebugMacros); 222*0b57cec5SDimitry Andric else 223*0b57cec5SDimitry Andric m_flags.Set(flagsParsedDebugMacros); 224*0b57cec5SDimitry Andric m_debug_macros_sp = debug_macros_sp; 225*0b57cec5SDimitry Andric } 226*0b57cec5SDimitry Andric 227*0b57cec5SDimitry Andric VariableListSP CompileUnit::GetVariableList(bool can_create) { 228*0b57cec5SDimitry Andric if (m_variables.get() == nullptr && can_create) { 229*0b57cec5SDimitry Andric SymbolContext sc; 230*0b57cec5SDimitry Andric CalculateSymbolContext(&sc); 231*0b57cec5SDimitry Andric assert(sc.module_sp); 232*0b57cec5SDimitry Andric sc.module_sp->GetSymbolVendor()->ParseVariablesForContext(sc); 233*0b57cec5SDimitry Andric } 234*0b57cec5SDimitry Andric 235*0b57cec5SDimitry Andric return m_variables; 236*0b57cec5SDimitry Andric } 237*0b57cec5SDimitry Andric 238*0b57cec5SDimitry Andric uint32_t CompileUnit::FindLineEntry(uint32_t start_idx, uint32_t line, 239*0b57cec5SDimitry Andric const FileSpec *file_spec_ptr, bool exact, 240*0b57cec5SDimitry Andric LineEntry *line_entry_ptr) { 241*0b57cec5SDimitry Andric uint32_t file_idx = 0; 242*0b57cec5SDimitry Andric 243*0b57cec5SDimitry Andric if (file_spec_ptr) { 244*0b57cec5SDimitry Andric file_idx = GetSupportFiles().FindFileIndex(1, *file_spec_ptr, true); 245*0b57cec5SDimitry Andric if (file_idx == UINT32_MAX) 246*0b57cec5SDimitry Andric return UINT32_MAX; 247*0b57cec5SDimitry Andric } else { 248*0b57cec5SDimitry Andric // All the line table entries actually point to the version of the Compile 249*0b57cec5SDimitry Andric // Unit that is in the support files (the one at 0 was artificially added.) 250*0b57cec5SDimitry Andric // So prefer the one further on in the support files if it exists... 251*0b57cec5SDimitry Andric const FileSpecList &support_files = GetSupportFiles(); 252*0b57cec5SDimitry Andric const bool full = true; 253*0b57cec5SDimitry Andric file_idx = support_files.FindFileIndex( 254*0b57cec5SDimitry Andric 1, support_files.GetFileSpecAtIndex(0), full); 255*0b57cec5SDimitry Andric if (file_idx == UINT32_MAX) 256*0b57cec5SDimitry Andric file_idx = 0; 257*0b57cec5SDimitry Andric } 258*0b57cec5SDimitry Andric LineTable *line_table = GetLineTable(); 259*0b57cec5SDimitry Andric if (line_table) 260*0b57cec5SDimitry Andric return line_table->FindLineEntryIndexByFileIndex(start_idx, file_idx, line, 261*0b57cec5SDimitry Andric exact, line_entry_ptr); 262*0b57cec5SDimitry Andric return UINT32_MAX; 263*0b57cec5SDimitry Andric } 264*0b57cec5SDimitry Andric 265*0b57cec5SDimitry Andric uint32_t CompileUnit::ResolveSymbolContext(const FileSpec &file_spec, 266*0b57cec5SDimitry Andric uint32_t line, bool check_inlines, 267*0b57cec5SDimitry Andric bool exact, 268*0b57cec5SDimitry Andric SymbolContextItem resolve_scope, 269*0b57cec5SDimitry Andric SymbolContextList &sc_list) { 270*0b57cec5SDimitry Andric // First find all of the file indexes that match our "file_spec". If 271*0b57cec5SDimitry Andric // "file_spec" has an empty directory, then only compare the basenames when 272*0b57cec5SDimitry Andric // finding file indexes 273*0b57cec5SDimitry Andric std::vector<uint32_t> file_indexes; 274*0b57cec5SDimitry Andric const bool full_match = (bool)file_spec.GetDirectory(); 275*0b57cec5SDimitry Andric bool file_spec_matches_cu_file_spec = 276*0b57cec5SDimitry Andric FileSpec::Equal(file_spec, *this, full_match); 277*0b57cec5SDimitry Andric 278*0b57cec5SDimitry Andric // If we are not looking for inlined functions and our file spec doesn't 279*0b57cec5SDimitry Andric // match then we are done... 280*0b57cec5SDimitry Andric if (!file_spec_matches_cu_file_spec && !check_inlines) 281*0b57cec5SDimitry Andric return 0; 282*0b57cec5SDimitry Andric 283*0b57cec5SDimitry Andric uint32_t file_idx = 284*0b57cec5SDimitry Andric GetSupportFiles().FindFileIndex(1, file_spec, true); 285*0b57cec5SDimitry Andric while (file_idx != UINT32_MAX) { 286*0b57cec5SDimitry Andric file_indexes.push_back(file_idx); 287*0b57cec5SDimitry Andric file_idx = GetSupportFiles().FindFileIndex(file_idx + 1, file_spec, true); 288*0b57cec5SDimitry Andric } 289*0b57cec5SDimitry Andric 290*0b57cec5SDimitry Andric const size_t num_file_indexes = file_indexes.size(); 291*0b57cec5SDimitry Andric if (num_file_indexes == 0) 292*0b57cec5SDimitry Andric return 0; 293*0b57cec5SDimitry Andric 294*0b57cec5SDimitry Andric const uint32_t prev_size = sc_list.GetSize(); 295*0b57cec5SDimitry Andric 296*0b57cec5SDimitry Andric SymbolContext sc(GetModule()); 297*0b57cec5SDimitry Andric sc.comp_unit = this; 298*0b57cec5SDimitry Andric 299*0b57cec5SDimitry Andric if (line != 0) { 300*0b57cec5SDimitry Andric LineTable *line_table = sc.comp_unit->GetLineTable(); 301*0b57cec5SDimitry Andric 302*0b57cec5SDimitry Andric if (line_table != nullptr) { 303*0b57cec5SDimitry Andric uint32_t found_line; 304*0b57cec5SDimitry Andric uint32_t line_idx; 305*0b57cec5SDimitry Andric 306*0b57cec5SDimitry Andric if (num_file_indexes == 1) { 307*0b57cec5SDimitry Andric // We only have a single support file that matches, so use the line 308*0b57cec5SDimitry Andric // table function that searches for a line entries that match a single 309*0b57cec5SDimitry Andric // support file index 310*0b57cec5SDimitry Andric LineEntry line_entry; 311*0b57cec5SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 312*0b57cec5SDimitry Andric 0, file_indexes.front(), line, exact, &line_entry); 313*0b57cec5SDimitry Andric 314*0b57cec5SDimitry Andric // If "exact == true", then "found_line" will be the same as "line". If 315*0b57cec5SDimitry Andric // "exact == false", the "found_line" will be the closest line entry 316*0b57cec5SDimitry Andric // with a line number greater than "line" and we will use this for our 317*0b57cec5SDimitry Andric // subsequent line exact matches below. 318*0b57cec5SDimitry Andric found_line = line_entry.line; 319*0b57cec5SDimitry Andric 320*0b57cec5SDimitry Andric while (line_idx != UINT32_MAX) { 321*0b57cec5SDimitry Andric // If they only asked for the line entry, then we're done, we can 322*0b57cec5SDimitry Andric // just copy that over. But if they wanted more than just the line 323*0b57cec5SDimitry Andric // number, fill it in. 324*0b57cec5SDimitry Andric if (resolve_scope == eSymbolContextLineEntry) { 325*0b57cec5SDimitry Andric sc.line_entry = line_entry; 326*0b57cec5SDimitry Andric } else { 327*0b57cec5SDimitry Andric line_entry.range.GetBaseAddress().CalculateSymbolContext( 328*0b57cec5SDimitry Andric &sc, resolve_scope); 329*0b57cec5SDimitry Andric } 330*0b57cec5SDimitry Andric 331*0b57cec5SDimitry Andric sc_list.Append(sc); 332*0b57cec5SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 333*0b57cec5SDimitry Andric line_idx + 1, file_indexes.front(), found_line, true, 334*0b57cec5SDimitry Andric &line_entry); 335*0b57cec5SDimitry Andric } 336*0b57cec5SDimitry Andric } else { 337*0b57cec5SDimitry Andric // We found multiple support files that match "file_spec" so use the 338*0b57cec5SDimitry Andric // line table function that searches for a line entries that match a 339*0b57cec5SDimitry Andric // multiple support file indexes. 340*0b57cec5SDimitry Andric LineEntry line_entry; 341*0b57cec5SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 342*0b57cec5SDimitry Andric 0, file_indexes, line, exact, &line_entry); 343*0b57cec5SDimitry Andric 344*0b57cec5SDimitry Andric // If "exact == true", then "found_line" will be the same as "line". If 345*0b57cec5SDimitry Andric // "exact == false", the "found_line" will be the closest line entry 346*0b57cec5SDimitry Andric // with a line number greater than "line" and we will use this for our 347*0b57cec5SDimitry Andric // subsequent line exact matches below. 348*0b57cec5SDimitry Andric found_line = line_entry.line; 349*0b57cec5SDimitry Andric 350*0b57cec5SDimitry Andric while (line_idx != UINT32_MAX) { 351*0b57cec5SDimitry Andric if (resolve_scope == eSymbolContextLineEntry) { 352*0b57cec5SDimitry Andric sc.line_entry = line_entry; 353*0b57cec5SDimitry Andric } else { 354*0b57cec5SDimitry Andric line_entry.range.GetBaseAddress().CalculateSymbolContext( 355*0b57cec5SDimitry Andric &sc, resolve_scope); 356*0b57cec5SDimitry Andric } 357*0b57cec5SDimitry Andric 358*0b57cec5SDimitry Andric sc_list.Append(sc); 359*0b57cec5SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex( 360*0b57cec5SDimitry Andric line_idx + 1, file_indexes, found_line, true, &line_entry); 361*0b57cec5SDimitry Andric } 362*0b57cec5SDimitry Andric } 363*0b57cec5SDimitry Andric } 364*0b57cec5SDimitry Andric } else if (file_spec_matches_cu_file_spec && !check_inlines) { 365*0b57cec5SDimitry Andric // only append the context if we aren't looking for inline call sites by 366*0b57cec5SDimitry Andric // file and line and if the file spec matches that of the compile unit 367*0b57cec5SDimitry Andric sc_list.Append(sc); 368*0b57cec5SDimitry Andric } 369*0b57cec5SDimitry Andric return sc_list.GetSize() - prev_size; 370*0b57cec5SDimitry Andric } 371*0b57cec5SDimitry Andric 372*0b57cec5SDimitry Andric bool CompileUnit::GetIsOptimized() { 373*0b57cec5SDimitry Andric if (m_is_optimized == eLazyBoolCalculate) { 374*0b57cec5SDimitry Andric m_is_optimized = eLazyBoolNo; 375*0b57cec5SDimitry Andric if (SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor()) { 376*0b57cec5SDimitry Andric if (symbol_vendor->ParseIsOptimized(*this)) 377*0b57cec5SDimitry Andric m_is_optimized = eLazyBoolYes; 378*0b57cec5SDimitry Andric } 379*0b57cec5SDimitry Andric } 380*0b57cec5SDimitry Andric return m_is_optimized; 381*0b57cec5SDimitry Andric } 382*0b57cec5SDimitry Andric 383*0b57cec5SDimitry Andric void CompileUnit::SetVariableList(VariableListSP &variables) { 384*0b57cec5SDimitry Andric m_variables = variables; 385*0b57cec5SDimitry Andric } 386*0b57cec5SDimitry Andric 387*0b57cec5SDimitry Andric const std::vector<SourceModule> &CompileUnit::GetImportedModules() { 388*0b57cec5SDimitry Andric if (m_imported_modules.empty() && 389*0b57cec5SDimitry Andric m_flags.IsClear(flagsParsedImportedModules)) { 390*0b57cec5SDimitry Andric m_flags.Set(flagsParsedImportedModules); 391*0b57cec5SDimitry Andric if (SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor()) { 392*0b57cec5SDimitry Andric SymbolContext sc; 393*0b57cec5SDimitry Andric CalculateSymbolContext(&sc); 394*0b57cec5SDimitry Andric symbol_vendor->ParseImportedModules(sc, m_imported_modules); 395*0b57cec5SDimitry Andric } 396*0b57cec5SDimitry Andric } 397*0b57cec5SDimitry Andric return m_imported_modules; 398*0b57cec5SDimitry Andric } 399*0b57cec5SDimitry Andric 400*0b57cec5SDimitry Andric const FileSpecList &CompileUnit::GetSupportFiles() { 401*0b57cec5SDimitry Andric if (m_support_files.GetSize() == 0) { 402*0b57cec5SDimitry Andric if (m_flags.IsClear(flagsParsedSupportFiles)) { 403*0b57cec5SDimitry Andric m_flags.Set(flagsParsedSupportFiles); 404*0b57cec5SDimitry Andric SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor(); 405*0b57cec5SDimitry Andric if (symbol_vendor) { 406*0b57cec5SDimitry Andric symbol_vendor->ParseSupportFiles(*this, m_support_files); 407*0b57cec5SDimitry Andric } 408*0b57cec5SDimitry Andric } 409*0b57cec5SDimitry Andric } 410*0b57cec5SDimitry Andric return m_support_files; 411*0b57cec5SDimitry Andric } 412*0b57cec5SDimitry Andric 413*0b57cec5SDimitry Andric void *CompileUnit::GetUserData() const { return m_user_data; } 414