1cfca06d7SDimitry Andric //===-- CompileUnit.cpp ---------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/Symbol/CompileUnit.h"
10f034231aSEd Maste #include "lldb/Core/Module.h"
11f034231aSEd Maste #include "lldb/Symbol/LineTable.h"
12ead24645SDimitry Andric #include "lldb/Symbol/SymbolFile.h"
13f034231aSEd Maste #include "lldb/Symbol/VariableList.h"
14e81d9d49SDimitry Andric #include "lldb/Target/Language.h"
15706b4fc4SDimitry Andric #include "lldb/Utility/Timer.h"
16e3b55780SDimitry Andric #include <optional>
17f034231aSEd Maste
18f034231aSEd Maste using namespace lldb;
19f034231aSEd Maste using namespace lldb_private;
20f034231aSEd Maste
CompileUnit(const lldb::ModuleSP & module_sp,void * user_data,const char * pathname,const lldb::user_id_t cu_sym_id,lldb::LanguageType language,lldb_private::LazyBool is_optimized)2114f1b3e8SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
2214f1b3e8SDimitry Andric const char *pathname, const lldb::user_id_t cu_sym_id,
2314f1b3e8SDimitry Andric lldb::LanguageType language,
24f3fbd1c0SDimitry Andric lldb_private::LazyBool is_optimized)
254df029ccSDimitry Andric : CompileUnit(module_sp, user_data,
264df029ccSDimitry Andric std::make_shared<SupportFile>(FileSpec(pathname)), cu_sym_id,
274df029ccSDimitry Andric language, is_optimized) {}
28f034231aSEd Maste
CompileUnit(const lldb::ModuleSP & module_sp,void * user_data,lldb::SupportFileSP support_file_sp,const lldb::user_id_t cu_sym_id,lldb::LanguageType language,lldb_private::LazyBool is_optimized,SupportFileList && support_files)2914f1b3e8SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
304df029ccSDimitry Andric lldb::SupportFileSP support_file_sp,
314df029ccSDimitry Andric const lldb::user_id_t cu_sym_id,
3214f1b3e8SDimitry Andric lldb::LanguageType language,
33aca2e42cSDimitry Andric lldb_private::LazyBool is_optimized,
34aca2e42cSDimitry Andric SupportFileList &&support_files)
35706b4fc4SDimitry Andric : ModuleChild(module_sp), UserID(cu_sym_id), m_user_data(user_data),
364df029ccSDimitry Andric m_language(language), m_flags(0),
374df029ccSDimitry Andric m_primary_support_file_sp(support_file_sp),
38aca2e42cSDimitry Andric m_support_files(std::move(support_files)), m_is_optimized(is_optimized) {
39f034231aSEd Maste if (language != eLanguageTypeUnknown)
40f034231aSEd Maste m_flags.Set(flagsParsedLanguage);
41f034231aSEd Maste assert(module_sp);
42f034231aSEd Maste }
43f034231aSEd Maste
CalculateSymbolContext(SymbolContext * sc)4414f1b3e8SDimitry Andric void CompileUnit::CalculateSymbolContext(SymbolContext *sc) {
45f034231aSEd Maste sc->comp_unit = this;
46f034231aSEd Maste GetModule()->CalculateSymbolContext(sc);
47f034231aSEd Maste }
48f034231aSEd Maste
CalculateSymbolContextModule()4914f1b3e8SDimitry Andric ModuleSP CompileUnit::CalculateSymbolContextModule() { return GetModule(); }
50f034231aSEd Maste
CalculateSymbolContextCompileUnit()5114f1b3e8SDimitry Andric CompileUnit *CompileUnit::CalculateSymbolContextCompileUnit() { return this; }
52f034231aSEd Maste
DumpSymbolContext(Stream * s)5314f1b3e8SDimitry Andric void CompileUnit::DumpSymbolContext(Stream *s) {
54f034231aSEd Maste GetModule()->DumpSymbolContext(s);
55f034231aSEd Maste s->Printf(", CompileUnit{0x%8.8" PRIx64 "}", GetID());
56f034231aSEd Maste }
57f034231aSEd Maste
GetDescription(Stream * s,lldb::DescriptionLevel level) const5814f1b3e8SDimitry Andric void CompileUnit::GetDescription(Stream *s,
5914f1b3e8SDimitry Andric lldb::DescriptionLevel level) const {
60c0981da4SDimitry Andric const char *language = GetCachedLanguage();
6114f1b3e8SDimitry Andric *s << "id = " << (const UserID &)*this << ", file = \""
62706b4fc4SDimitry Andric << this->GetPrimaryFile() << "\", language = \"" << language << '"';
63f034231aSEd Maste }
64f034231aSEd Maste
ForeachFunction(llvm::function_ref<bool (const FunctionSP &)> lambda) const6594994d37SDimitry Andric void CompileUnit::ForeachFunction(
6694994d37SDimitry Andric llvm::function_ref<bool(const FunctionSP &)> lambda) const {
6794994d37SDimitry Andric std::vector<lldb::FunctionSP> sorted_functions;
6894994d37SDimitry Andric sorted_functions.reserve(m_functions_by_uid.size());
6994994d37SDimitry Andric for (auto &p : m_functions_by_uid)
7094994d37SDimitry Andric sorted_functions.push_back(p.second);
714b4fe385SDimitry Andric llvm::sort(sorted_functions,
7294994d37SDimitry Andric [](const lldb::FunctionSP &a, const lldb::FunctionSP &b) {
7394994d37SDimitry Andric return a->GetID() < b->GetID();
7494994d37SDimitry Andric });
7594994d37SDimitry Andric
7694994d37SDimitry Andric for (auto &f : sorted_functions)
7794994d37SDimitry Andric if (lambda(f))
7894994d37SDimitry Andric return;
7994994d37SDimitry Andric }
8094994d37SDimitry Andric
FindFunction(llvm::function_ref<bool (const FunctionSP &)> matching_lambda)81706b4fc4SDimitry Andric lldb::FunctionSP CompileUnit::FindFunction(
82706b4fc4SDimitry Andric llvm::function_ref<bool(const FunctionSP &)> matching_lambda) {
83b60736ecSDimitry Andric LLDB_SCOPED_TIMER();
84706b4fc4SDimitry Andric
85706b4fc4SDimitry Andric lldb::ModuleSP module = CalculateSymbolContextModule();
86706b4fc4SDimitry Andric
87706b4fc4SDimitry Andric if (!module)
88706b4fc4SDimitry Andric return {};
89706b4fc4SDimitry Andric
90706b4fc4SDimitry Andric SymbolFile *symbol_file = module->GetSymbolFile();
91706b4fc4SDimitry Andric
92706b4fc4SDimitry Andric if (!symbol_file)
93706b4fc4SDimitry Andric return {};
94706b4fc4SDimitry Andric
95706b4fc4SDimitry Andric // m_functions_by_uid is filled in lazily but we need all the entries.
96706b4fc4SDimitry Andric symbol_file->ParseFunctions(*this);
97706b4fc4SDimitry Andric
98706b4fc4SDimitry Andric for (auto &p : m_functions_by_uid) {
99706b4fc4SDimitry Andric if (matching_lambda(p.second))
100706b4fc4SDimitry Andric return p.second;
101706b4fc4SDimitry Andric }
102706b4fc4SDimitry Andric return {};
103706b4fc4SDimitry Andric }
104706b4fc4SDimitry Andric
GetCachedLanguage() const105c0981da4SDimitry Andric const char *CompileUnit::GetCachedLanguage() const {
106c0981da4SDimitry Andric if (m_flags.IsClear(flagsParsedLanguage))
107c0981da4SDimitry Andric return "<not loaded>";
108c0981da4SDimitry Andric return Language::GetNameForLanguageType(m_language);
109c0981da4SDimitry Andric }
110c0981da4SDimitry Andric
111f73363f1SDimitry Andric // Dump the current contents of this object. No functions that cause on demand
112f73363f1SDimitry Andric // parsing of functions, globals, statics are called, so this is a good
113f73363f1SDimitry Andric // function to call to get an idea of the current contents of the CompileUnit
114f73363f1SDimitry Andric // object.
Dump(Stream * s,bool show_context) const11514f1b3e8SDimitry Andric void CompileUnit::Dump(Stream *s, bool show_context) const {
116c0981da4SDimitry Andric const char *language = GetCachedLanguage();
117e81d9d49SDimitry Andric
1180cac4ca3SEd Maste s->Printf("%p: ", static_cast<const void *>(this));
119f034231aSEd Maste s->Indent();
12014f1b3e8SDimitry Andric *s << "CompileUnit" << static_cast<const UserID &>(*this) << ", language = \""
121706b4fc4SDimitry Andric << language << "\", file = '" << GetPrimaryFile() << "'\n";
122f034231aSEd Maste
123f034231aSEd Maste // m_types.Dump(s);
124f034231aSEd Maste
12514f1b3e8SDimitry Andric if (m_variables.get()) {
126f034231aSEd Maste s->IndentMore();
127f034231aSEd Maste m_variables->Dump(s, show_context);
128f034231aSEd Maste s->IndentLess();
129f034231aSEd Maste }
130f034231aSEd Maste
13194994d37SDimitry Andric if (!m_functions_by_uid.empty()) {
132f034231aSEd Maste s->IndentMore();
13394994d37SDimitry Andric ForeachFunction([&s, show_context](const FunctionSP &f) {
13494994d37SDimitry Andric f->Dump(s, show_context);
13594994d37SDimitry Andric return false;
13694994d37SDimitry Andric });
137f034231aSEd Maste
138f034231aSEd Maste s->IndentLess();
139f034231aSEd Maste s->EOL();
140f034231aSEd Maste }
141f034231aSEd Maste }
142f034231aSEd Maste
143f034231aSEd Maste // Add a function to this compile unit
AddFunction(FunctionSP & funcSP)14414f1b3e8SDimitry Andric void CompileUnit::AddFunction(FunctionSP &funcSP) {
14594994d37SDimitry Andric m_functions_by_uid[funcSP->GetID()] = funcSP;
146f034231aSEd Maste }
147f034231aSEd Maste
FindFunctionByUID(lldb::user_id_t func_uid)14814f1b3e8SDimitry Andric FunctionSP CompileUnit::FindFunctionByUID(lldb::user_id_t func_uid) {
14994994d37SDimitry Andric auto it = m_functions_by_uid.find(func_uid);
15094994d37SDimitry Andric if (it == m_functions_by_uid.end())
15194994d37SDimitry Andric return FunctionSP();
15294994d37SDimitry Andric return it->second;
153f034231aSEd Maste }
154f034231aSEd Maste
GetLanguage()15514f1b3e8SDimitry Andric lldb::LanguageType CompileUnit::GetLanguage() {
15614f1b3e8SDimitry Andric if (m_language == eLanguageTypeUnknown) {
15714f1b3e8SDimitry Andric if (m_flags.IsClear(flagsParsedLanguage)) {
158f034231aSEd Maste m_flags.Set(flagsParsedLanguage);
159ead24645SDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile())
160ead24645SDimitry Andric m_language = symfile->ParseLanguage(*this);
161f034231aSEd Maste }
162f034231aSEd Maste }
163f034231aSEd Maste return m_language;
164f034231aSEd Maste }
165f034231aSEd Maste
GetLineTable()16614f1b3e8SDimitry Andric LineTable *CompileUnit::GetLineTable() {
1675f29bb8aSDimitry Andric if (m_line_table_up == nullptr) {
16814f1b3e8SDimitry Andric if (m_flags.IsClear(flagsParsedLineTable)) {
169f034231aSEd Maste m_flags.Set(flagsParsedLineTable);
170ead24645SDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile())
171ead24645SDimitry Andric symfile->ParseLineTable(*this);
172f034231aSEd Maste }
173f034231aSEd Maste }
1745f29bb8aSDimitry Andric return m_line_table_up.get();
175f034231aSEd Maste }
176f034231aSEd Maste
SetLineTable(LineTable * line_table)17714f1b3e8SDimitry Andric void CompileUnit::SetLineTable(LineTable *line_table) {
1780cac4ca3SEd Maste if (line_table == nullptr)
179f034231aSEd Maste m_flags.Clear(flagsParsedLineTable);
180f034231aSEd Maste else
181f034231aSEd Maste m_flags.Set(flagsParsedLineTable);
1825f29bb8aSDimitry Andric m_line_table_up.reset(line_table);
183f034231aSEd Maste }
184f034231aSEd Maste
GetDebugMacros()18514f1b3e8SDimitry Andric DebugMacros *CompileUnit::GetDebugMacros() {
18614f1b3e8SDimitry Andric if (m_debug_macros_sp.get() == nullptr) {
18714f1b3e8SDimitry Andric if (m_flags.IsClear(flagsParsedDebugMacros)) {
188e81d9d49SDimitry Andric m_flags.Set(flagsParsedDebugMacros);
189ead24645SDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile())
190ead24645SDimitry Andric symfile->ParseDebugMacros(*this);
191e81d9d49SDimitry Andric }
192e81d9d49SDimitry Andric }
193e81d9d49SDimitry Andric
194e81d9d49SDimitry Andric return m_debug_macros_sp.get();
195e81d9d49SDimitry Andric }
196e81d9d49SDimitry Andric
SetDebugMacros(const DebugMacrosSP & debug_macros_sp)19714f1b3e8SDimitry Andric void CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp) {
198e81d9d49SDimitry Andric if (debug_macros_sp.get() == nullptr)
199e81d9d49SDimitry Andric m_flags.Clear(flagsParsedDebugMacros);
200e81d9d49SDimitry Andric else
201e81d9d49SDimitry Andric m_flags.Set(flagsParsedDebugMacros);
202e81d9d49SDimitry Andric m_debug_macros_sp = debug_macros_sp;
203e81d9d49SDimitry Andric }
204e81d9d49SDimitry Andric
GetVariableList(bool can_create)20514f1b3e8SDimitry Andric VariableListSP CompileUnit::GetVariableList(bool can_create) {
20614f1b3e8SDimitry Andric if (m_variables.get() == nullptr && can_create) {
207f034231aSEd Maste SymbolContext sc;
208f034231aSEd Maste CalculateSymbolContext(&sc);
209f034231aSEd Maste assert(sc.module_sp);
210ead24645SDimitry Andric sc.module_sp->GetSymbolFile()->ParseVariablesForContext(sc);
211f034231aSEd Maste }
212f034231aSEd Maste
213f034231aSEd Maste return m_variables;
214f034231aSEd Maste }
215f034231aSEd Maste
FindFileIndexes(const SupportFileList & files,const FileSpec & file)216aca2e42cSDimitry Andric std::vector<uint32_t> FindFileIndexes(const SupportFileList &files,
217e3b55780SDimitry Andric const FileSpec &file) {
218706b4fc4SDimitry Andric std::vector<uint32_t> result;
219706b4fc4SDimitry Andric uint32_t idx = -1;
220e3b55780SDimitry Andric while ((idx = files.FindCompatibleIndex(idx + 1, file)) !=
221706b4fc4SDimitry Andric UINT32_MAX)
222706b4fc4SDimitry Andric result.push_back(idx);
223706b4fc4SDimitry Andric return result;
224706b4fc4SDimitry Andric }
225706b4fc4SDimitry Andric
FindLineEntry(uint32_t start_idx,uint32_t line,const FileSpec * file_spec_ptr,bool exact,LineEntry * line_entry_ptr)22614f1b3e8SDimitry Andric uint32_t CompileUnit::FindLineEntry(uint32_t start_idx, uint32_t line,
22714f1b3e8SDimitry Andric const FileSpec *file_spec_ptr, bool exact,
22814f1b3e8SDimitry Andric LineEntry *line_entry_ptr) {
229706b4fc4SDimitry Andric if (!file_spec_ptr)
230706b4fc4SDimitry Andric file_spec_ptr = &GetPrimaryFile();
231e3b55780SDimitry Andric std::vector<uint32_t> file_indexes = FindFileIndexes(GetSupportFiles(),
232e3b55780SDimitry Andric *file_spec_ptr);
233706b4fc4SDimitry Andric if (file_indexes.empty())
234f034231aSEd Maste return UINT32_MAX;
235706b4fc4SDimitry Andric
236344a3780SDimitry Andric // TODO: Handle SourceLocationSpec column information
237e3b55780SDimitry Andric SourceLocationSpec location_spec(*file_spec_ptr, line,
238e3b55780SDimitry Andric /*column=*/std::nullopt,
239344a3780SDimitry Andric /*check_inlines=*/false, exact);
240344a3780SDimitry Andric
241f034231aSEd Maste LineTable *line_table = GetLineTable();
242f034231aSEd Maste if (line_table)
243706b4fc4SDimitry Andric return line_table->FindLineEntryIndexByFileIndex(
244344a3780SDimitry Andric start_idx, file_indexes, location_spec, line_entry_ptr);
245f034231aSEd Maste return UINT32_MAX;
246f034231aSEd Maste }
247f034231aSEd Maste
ResolveSymbolContext(const SourceLocationSpec & src_location_spec,SymbolContextItem resolve_scope,SymbolContextList & sc_list)248344a3780SDimitry Andric void CompileUnit::ResolveSymbolContext(
249344a3780SDimitry Andric const SourceLocationSpec &src_location_spec,
250344a3780SDimitry Andric SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
251344a3780SDimitry Andric const FileSpec file_spec = src_location_spec.GetFileSpec();
252145449b1SDimitry Andric const uint32_t line = src_location_spec.GetLine().value_or(0);
253344a3780SDimitry Andric const bool check_inlines = src_location_spec.GetCheckInlines();
254344a3780SDimitry Andric
255f034231aSEd Maste // First find all of the file indexes that match our "file_spec". If
256f73363f1SDimitry Andric // "file_spec" has an empty directory, then only compare the basenames when
257f73363f1SDimitry Andric // finding file indexes
25814f1b3e8SDimitry Andric bool file_spec_matches_cu_file_spec =
259706b4fc4SDimitry Andric FileSpec::Match(file_spec, this->GetPrimaryFile());
260f034231aSEd Maste
261f034231aSEd Maste // If we are not looking for inlined functions and our file spec doesn't
262f034231aSEd Maste // match then we are done...
26394994d37SDimitry Andric if (!file_spec_matches_cu_file_spec && !check_inlines)
264706b4fc4SDimitry Andric return;
265f034231aSEd Maste
266f034231aSEd Maste SymbolContext sc(GetModule());
267f034231aSEd Maste sc.comp_unit = this;
268f034231aSEd Maste
269706b4fc4SDimitry Andric if (line == 0) {
270706b4fc4SDimitry Andric if (file_spec_matches_cu_file_spec && !check_inlines) {
271706b4fc4SDimitry Andric // only append the context if we aren't looking for inline call sites by
272706b4fc4SDimitry Andric // file and line and if the file spec matches that of the compile unit
273706b4fc4SDimitry Andric sc_list.Append(sc);
274706b4fc4SDimitry Andric }
275706b4fc4SDimitry Andric return;
276706b4fc4SDimitry Andric }
277706b4fc4SDimitry Andric
278e3b55780SDimitry Andric std::vector<uint32_t> file_indexes = FindFileIndexes(GetSupportFiles(),
279e3b55780SDimitry Andric file_spec);
280344a3780SDimitry Andric const size_t num_file_indexes = file_indexes.size();
281344a3780SDimitry Andric if (num_file_indexes == 0)
282344a3780SDimitry Andric return;
283344a3780SDimitry Andric
284145449b1SDimitry Andric // Found a matching source file in this compile unit load its debug info.
285145449b1SDimitry Andric GetModule()->GetSymbolFile()->SetLoadDebugInfoEnabled();
286145449b1SDimitry Andric
287f034231aSEd Maste LineTable *line_table = sc.comp_unit->GetLineTable();
288f034231aSEd Maste
289344a3780SDimitry Andric if (line_table == nullptr) {
290344a3780SDimitry Andric if (file_spec_matches_cu_file_spec && !check_inlines) {
291344a3780SDimitry Andric sc_list.Append(sc);
292344a3780SDimitry Andric }
293706b4fc4SDimitry Andric return;
294344a3780SDimitry Andric }
295706b4fc4SDimitry Andric
296f034231aSEd Maste uint32_t line_idx;
297706b4fc4SDimitry Andric LineEntry line_entry;
298f034231aSEd Maste
29914f1b3e8SDimitry Andric if (num_file_indexes == 1) {
300f73363f1SDimitry Andric // We only have a single support file that matches, so use the line
301f73363f1SDimitry Andric // table function that searches for a line entries that match a single
302f73363f1SDimitry Andric // support file index
30314f1b3e8SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex(
304344a3780SDimitry Andric 0, file_indexes.front(), src_location_spec, &line_entry);
305706b4fc4SDimitry Andric } else {
306706b4fc4SDimitry Andric // We found multiple support files that match "file_spec" so use the
307706b4fc4SDimitry Andric // line table function that searches for a line entries that match a
308706b4fc4SDimitry Andric // multiple support file indexes.
309344a3780SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex(
310344a3780SDimitry Andric 0, file_indexes, src_location_spec, &line_entry);
311706b4fc4SDimitry Andric }
312f034231aSEd Maste
313f73363f1SDimitry Andric // If "exact == true", then "found_line" will be the same as "line". If
314f73363f1SDimitry Andric // "exact == false", the "found_line" will be the closest line entry
315f73363f1SDimitry Andric // with a line number greater than "line" and we will use this for our
316f73363f1SDimitry Andric // subsequent line exact matches below.
317344a3780SDimitry Andric const bool inlines = false;
318344a3780SDimitry Andric const bool exact = true;
319e3b55780SDimitry Andric const std::optional<uint16_t> column =
320e3b55780SDimitry Andric src_location_spec.GetColumn() ? std::optional<uint16_t>(line_entry.column)
321e3b55780SDimitry Andric : std::nullopt;
322c0981da4SDimitry Andric
323ac9a064cSDimitry Andric SourceLocationSpec found_entry(line_entry.GetFile(), line_entry.line, column,
324c0981da4SDimitry Andric inlines, exact);
325f034231aSEd Maste
32614f1b3e8SDimitry Andric while (line_idx != UINT32_MAX) {
327f73363f1SDimitry Andric // If they only asked for the line entry, then we're done, we can
328f73363f1SDimitry Andric // just copy that over. But if they wanted more than just the line
329f73363f1SDimitry Andric // number, fill it in.
330e3b55780SDimitry Andric SymbolContext resolved_sc;
331f034231aSEd Maste sc.line_entry = line_entry;
332e3b55780SDimitry Andric if (resolve_scope == eSymbolContextLineEntry) {
333e3b55780SDimitry Andric sc_list.Append(sc);
33414f1b3e8SDimitry Andric } else {
335e3b55780SDimitry Andric line_entry.range.GetBaseAddress().CalculateSymbolContext(&resolved_sc,
336706b4fc4SDimitry Andric resolve_scope);
337e3b55780SDimitry Andric // Sometimes debug info is bad and isn't able to resolve the line entry's
338e3b55780SDimitry Andric // address back to the same compile unit and/or line entry. If the compile
339e3b55780SDimitry Andric // unit changed, then revert back to just the compile unit and line entry.
340e3b55780SDimitry Andric // Prior to this fix, the above code might end up not being able to lookup
341e3b55780SDimitry Andric // the address, and then it would clear compile unit and the line entry in
342e3b55780SDimitry Andric // the symbol context and the breakpoint would fail to get set even though
343e3b55780SDimitry Andric // we have a valid line table entry in this compile unit. The address
344e3b55780SDimitry Andric // lookup can also end up finding another function in another compiler
345e3b55780SDimitry Andric // unit if the DWARF has overlappging address ranges. So if we end up with
346e3b55780SDimitry Andric // no compile unit or a different one after the above function call,
347e3b55780SDimitry Andric // revert back to the same results as if resolve_scope was set exactly to
348e3b55780SDimitry Andric // eSymbolContextLineEntry.
349e3b55780SDimitry Andric if (resolved_sc.comp_unit == this) {
350e3b55780SDimitry Andric sc_list.Append(resolved_sc);
351e3b55780SDimitry Andric } else {
352e3b55780SDimitry Andric if (resolved_sc.comp_unit == nullptr && resolved_sc.module_sp) {
353e3b55780SDimitry Andric // Only report an error if we don't map back to any compile unit. With
354e3b55780SDimitry Andric // link time optimizations, the debug info might have many compile
355e3b55780SDimitry Andric // units that have the same address range due to function outlining
356e3b55780SDimitry Andric // or other link time optimizations. If the compile unit is NULL, then
357e3b55780SDimitry Andric // address resolving is completely failing and more deserving of an
358e3b55780SDimitry Andric // error message the user can see.
359e3b55780SDimitry Andric resolved_sc.module_sp->ReportError(
360e3b55780SDimitry Andric "unable to resolve a line table file address {0:x16} back "
361e3b55780SDimitry Andric "to a compile unit, please file a bug and attach the address "
362e3b55780SDimitry Andric "and file.",
363e3b55780SDimitry Andric line_entry.range.GetBaseAddress().GetFileAddress());
364e3b55780SDimitry Andric }
365e3b55780SDimitry Andric sc_list.Append(sc);
366e3b55780SDimitry Andric }
367f034231aSEd Maste }
368f034231aSEd Maste
369706b4fc4SDimitry Andric if (num_file_indexes == 1)
37014f1b3e8SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex(
371344a3780SDimitry Andric line_idx + 1, file_indexes.front(), found_entry, &line_entry);
372706b4fc4SDimitry Andric else
37314f1b3e8SDimitry Andric line_idx = line_table->FindLineEntryIndexByFileIndex(
374344a3780SDimitry Andric line_idx + 1, file_indexes, found_entry, &line_entry);
375f034231aSEd Maste }
376f034231aSEd Maste }
377f034231aSEd Maste
GetIsOptimized()37814f1b3e8SDimitry Andric bool CompileUnit::GetIsOptimized() {
37914f1b3e8SDimitry Andric if (m_is_optimized == eLazyBoolCalculate) {
380f3fbd1c0SDimitry Andric m_is_optimized = eLazyBoolNo;
381ead24645SDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
382ead24645SDimitry Andric if (symfile->ParseIsOptimized(*this))
383f3fbd1c0SDimitry Andric m_is_optimized = eLazyBoolYes;
384f3fbd1c0SDimitry Andric }
385f3fbd1c0SDimitry Andric }
386e81d9d49SDimitry Andric return m_is_optimized;
387e81d9d49SDimitry Andric }
388e81d9d49SDimitry Andric
SetVariableList(VariableListSP & variables)38914f1b3e8SDimitry Andric void CompileUnit::SetVariableList(VariableListSP &variables) {
390f034231aSEd Maste m_variables = variables;
391f034231aSEd Maste }
392f034231aSEd Maste
GetImportedModules()3935f29bb8aSDimitry Andric const std::vector<SourceModule> &CompileUnit::GetImportedModules() {
3945e95aa85SEd Maste if (m_imported_modules.empty() &&
39514f1b3e8SDimitry Andric m_flags.IsClear(flagsParsedImportedModules)) {
3965e95aa85SEd Maste m_flags.Set(flagsParsedImportedModules);
397ead24645SDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
3985e95aa85SEd Maste SymbolContext sc;
3995e95aa85SEd Maste CalculateSymbolContext(&sc);
400ead24645SDimitry Andric symfile->ParseImportedModules(sc, m_imported_modules);
4015e95aa85SEd Maste }
4025e95aa85SEd Maste }
4035e95aa85SEd Maste return m_imported_modules;
4045e95aa85SEd Maste }
4055e95aa85SEd Maste
ForEachExternalModule(llvm::DenseSet<SymbolFile * > & visited_symbol_files,llvm::function_ref<bool (Module &)> lambda)406706b4fc4SDimitry Andric bool CompileUnit::ForEachExternalModule(
407706b4fc4SDimitry Andric llvm::DenseSet<SymbolFile *> &visited_symbol_files,
408706b4fc4SDimitry Andric llvm::function_ref<bool(Module &)> lambda) {
409ead24645SDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile())
410706b4fc4SDimitry Andric return symfile->ForEachExternalModule(*this, visited_symbol_files, lambda);
411706b4fc4SDimitry Andric return false;
412ead24645SDimitry Andric }
413ead24645SDimitry Andric
GetSupportFiles()414aca2e42cSDimitry Andric const SupportFileList &CompileUnit::GetSupportFiles() {
41514f1b3e8SDimitry Andric if (m_support_files.GetSize() == 0) {
41614f1b3e8SDimitry Andric if (m_flags.IsClear(flagsParsedSupportFiles)) {
417f034231aSEd Maste m_flags.Set(flagsParsedSupportFiles);
418ead24645SDimitry Andric if (SymbolFile *symfile = GetModule()->GetSymbolFile())
419ead24645SDimitry Andric symfile->ParseSupportFiles(*this, m_support_files);
420f034231aSEd Maste }
421f034231aSEd Maste }
422f034231aSEd Maste return m_support_files;
423f034231aSEd Maste }
424f034231aSEd Maste
GetUserData() const42514f1b3e8SDimitry Andric void *CompileUnit::GetUserData() const { return m_user_data; }
426