1ac7ddfbfSEd Maste //===-- CompileUnit.cpp -----------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/Symbol/CompileUnit.h"
11ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
12ac7ddfbfSEd Maste #include "lldb/Symbol/LineTable.h"
13ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolVendor.h"
14ac7ddfbfSEd Maste #include "lldb/Symbol/VariableList.h"
159f2f44ceSEd Maste #include "lldb/Target/Language.h"
16ac7ddfbfSEd Maste 
17ac7ddfbfSEd Maste using namespace lldb;
18ac7ddfbfSEd Maste using namespace lldb_private;
19ac7ddfbfSEd Maste 
209f2f44ceSEd Maste CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const char *pathname, const lldb::user_id_t cu_sym_id, lldb::LanguageType language, bool is_optimized) :
21ac7ddfbfSEd Maste     ModuleChild(module_sp),
22ac7ddfbfSEd Maste     FileSpec (pathname, false),
23ac7ddfbfSEd Maste     UserID(cu_sym_id),
24ac7ddfbfSEd Maste     m_user_data (user_data),
25ac7ddfbfSEd Maste     m_language (language),
26ac7ddfbfSEd Maste     m_flags (0),
27ac7ddfbfSEd Maste     m_functions (),
28ac7ddfbfSEd Maste     m_support_files (),
29ac7ddfbfSEd Maste     m_line_table_ap (),
309f2f44ceSEd Maste     m_variables(),
319f2f44ceSEd Maste     m_is_optimized (is_optimized)
32ac7ddfbfSEd Maste {
33ac7ddfbfSEd Maste     if (language != eLanguageTypeUnknown)
34ac7ddfbfSEd Maste         m_flags.Set(flagsParsedLanguage);
35ac7ddfbfSEd Maste     assert(module_sp);
36ac7ddfbfSEd Maste }
37ac7ddfbfSEd Maste 
389f2f44ceSEd Maste CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &fspec, const lldb::user_id_t cu_sym_id, lldb::LanguageType language, bool is_optimized) :
39ac7ddfbfSEd Maste     ModuleChild(module_sp),
40ac7ddfbfSEd Maste     FileSpec (fspec),
41ac7ddfbfSEd Maste     UserID(cu_sym_id),
42ac7ddfbfSEd Maste     m_user_data (user_data),
43ac7ddfbfSEd Maste     m_language (language),
44ac7ddfbfSEd Maste     m_flags (0),
45ac7ddfbfSEd Maste     m_functions (),
46ac7ddfbfSEd Maste     m_support_files (),
47ac7ddfbfSEd Maste     m_line_table_ap (),
489f2f44ceSEd Maste     m_variables(),
499f2f44ceSEd Maste     m_is_optimized (is_optimized)
50ac7ddfbfSEd Maste {
51ac7ddfbfSEd Maste     if (language != eLanguageTypeUnknown)
52ac7ddfbfSEd Maste         m_flags.Set(flagsParsedLanguage);
53ac7ddfbfSEd Maste     assert(module_sp);
54ac7ddfbfSEd Maste }
55ac7ddfbfSEd Maste 
56ac7ddfbfSEd Maste CompileUnit::~CompileUnit ()
57ac7ddfbfSEd Maste {
58ac7ddfbfSEd Maste }
59ac7ddfbfSEd Maste 
60ac7ddfbfSEd Maste void
61ac7ddfbfSEd Maste CompileUnit::CalculateSymbolContext(SymbolContext* sc)
62ac7ddfbfSEd Maste {
63ac7ddfbfSEd Maste     sc->comp_unit = this;
64ac7ddfbfSEd Maste     GetModule()->CalculateSymbolContext(sc);
65ac7ddfbfSEd Maste }
66ac7ddfbfSEd Maste 
67ac7ddfbfSEd Maste ModuleSP
68ac7ddfbfSEd Maste CompileUnit::CalculateSymbolContextModule ()
69ac7ddfbfSEd Maste {
70ac7ddfbfSEd Maste     return GetModule();
71ac7ddfbfSEd Maste }
72ac7ddfbfSEd Maste 
73ac7ddfbfSEd Maste CompileUnit *
74ac7ddfbfSEd Maste CompileUnit::CalculateSymbolContextCompileUnit ()
75ac7ddfbfSEd Maste {
76ac7ddfbfSEd Maste     return this;
77ac7ddfbfSEd Maste }
78ac7ddfbfSEd Maste 
79ac7ddfbfSEd Maste void
80ac7ddfbfSEd Maste CompileUnit::DumpSymbolContext(Stream *s)
81ac7ddfbfSEd Maste {
82ac7ddfbfSEd Maste     GetModule()->DumpSymbolContext(s);
83ac7ddfbfSEd Maste     s->Printf(", CompileUnit{0x%8.8" PRIx64 "}", GetID());
84ac7ddfbfSEd Maste }
85ac7ddfbfSEd Maste 
86ac7ddfbfSEd Maste 
87ac7ddfbfSEd Maste void
88ac7ddfbfSEd Maste CompileUnit::GetDescription(Stream *s, lldb::DescriptionLevel level) const
89ac7ddfbfSEd Maste {
909f2f44ceSEd Maste     const char* language = Language::GetNameForLanguageType(m_language);
91ac7ddfbfSEd Maste     *s << "id = " << (const UserID&)*this << ", file = \"" << (const FileSpec&)*this << "\", language = \"" << language << '"';
92ac7ddfbfSEd Maste }
93ac7ddfbfSEd Maste 
94ac7ddfbfSEd Maste 
95ac7ddfbfSEd Maste //----------------------------------------------------------------------
96ac7ddfbfSEd Maste // Dump the current contents of this object. No functions that cause on
97ac7ddfbfSEd Maste // demand parsing of functions, globals, statics are called, so this
98ac7ddfbfSEd Maste // is a good function to call to get an idea of the current contents of
99ac7ddfbfSEd Maste // the CompileUnit object.
100ac7ddfbfSEd Maste //----------------------------------------------------------------------
101ac7ddfbfSEd Maste void
102ac7ddfbfSEd Maste CompileUnit::Dump(Stream *s, bool show_context) const
103ac7ddfbfSEd Maste {
1049f2f44ceSEd Maste     const char* language = Language::GetNameForLanguageType(m_language);
1059f2f44ceSEd Maste 
1060127ef0fSEd Maste     s->Printf("%p: ", static_cast<const void*>(this));
107ac7ddfbfSEd Maste     s->Indent();
1080127ef0fSEd Maste     *s << "CompileUnit" << static_cast<const UserID&>(*this)
1099f2f44ceSEd Maste        << ", language = \"" << language
1100127ef0fSEd Maste        << "\", file = '" << static_cast<const FileSpec&>(*this) << "'\n";
111ac7ddfbfSEd Maste 
112ac7ddfbfSEd Maste //  m_types.Dump(s);
113ac7ddfbfSEd Maste 
114ac7ddfbfSEd Maste     if (m_variables.get())
115ac7ddfbfSEd Maste     {
116ac7ddfbfSEd Maste         s->IndentMore();
117ac7ddfbfSEd Maste         m_variables->Dump(s, show_context);
118ac7ddfbfSEd Maste         s->IndentLess();
119ac7ddfbfSEd Maste     }
120ac7ddfbfSEd Maste 
121ac7ddfbfSEd Maste     if (!m_functions.empty())
122ac7ddfbfSEd Maste     {
123ac7ddfbfSEd Maste         s->IndentMore();
124ac7ddfbfSEd Maste         std::vector<FunctionSP>::const_iterator pos;
125ac7ddfbfSEd Maste         std::vector<FunctionSP>::const_iterator end = m_functions.end();
126ac7ddfbfSEd Maste         for (pos = m_functions.begin(); pos != end; ++pos)
127ac7ddfbfSEd Maste         {
128ac7ddfbfSEd Maste             (*pos)->Dump(s, show_context);
129ac7ddfbfSEd Maste         }
130ac7ddfbfSEd Maste 
131ac7ddfbfSEd Maste         s->IndentLess();
132ac7ddfbfSEd Maste         s->EOL();
133ac7ddfbfSEd Maste     }
134ac7ddfbfSEd Maste }
135ac7ddfbfSEd Maste 
136ac7ddfbfSEd Maste //----------------------------------------------------------------------
137ac7ddfbfSEd Maste // Add a function to this compile unit
138ac7ddfbfSEd Maste //----------------------------------------------------------------------
139ac7ddfbfSEd Maste void
140ac7ddfbfSEd Maste CompileUnit::AddFunction(FunctionSP& funcSP)
141ac7ddfbfSEd Maste {
142ac7ddfbfSEd Maste     // TODO: order these by address
143ac7ddfbfSEd Maste     m_functions.push_back(funcSP);
144ac7ddfbfSEd Maste }
145ac7ddfbfSEd Maste 
146ac7ddfbfSEd Maste FunctionSP
147ac7ddfbfSEd Maste CompileUnit::GetFunctionAtIndex (size_t idx)
148ac7ddfbfSEd Maste {
149ac7ddfbfSEd Maste     FunctionSP funcSP;
150ac7ddfbfSEd Maste     if (idx < m_functions.size())
151ac7ddfbfSEd Maste         funcSP = m_functions[idx];
152ac7ddfbfSEd Maste     return funcSP;
153ac7ddfbfSEd Maste }
154ac7ddfbfSEd Maste 
155ac7ddfbfSEd Maste //----------------------------------------------------------------------
1561c3bbb01SEd Maste // Find functions using the Mangled::Tokens token list. This
1571c3bbb01SEd Maste // function currently implements an interactive approach designed to find
1581c3bbb01SEd Maste // all instances of certain functions. It isn't designed to the
159ac7ddfbfSEd Maste // quickest way to lookup functions as it will need to iterate through
160ac7ddfbfSEd Maste // all functions and see if they match, though it does provide a powerful
161ac7ddfbfSEd Maste // and context sensitive way to search for all functions with a certain
162ac7ddfbfSEd Maste // name, all functions in a namespace, or all functions of a template
163ac7ddfbfSEd Maste // type. See Mangled::Tokens::Parse() comments for more information.
164ac7ddfbfSEd Maste //
165ac7ddfbfSEd Maste // The function prototype will need to change to return a list of
166ac7ddfbfSEd Maste // results. It was originally used to help debug the Mangled class
167ac7ddfbfSEd Maste // and the Mangled::Tokens::MatchesQuery() function and it currently
168ac7ddfbfSEd Maste // will print out a list of matching results for the functions that
169ac7ddfbfSEd Maste // are currently in this compile unit.
170ac7ddfbfSEd Maste //
171ac7ddfbfSEd Maste // A FindFunctions method should be called prior to this that takes
172ac7ddfbfSEd Maste // a regular function name (const char * or ConstString as a parameter)
173ac7ddfbfSEd Maste // before resorting to this slower but more complete function. The
174ac7ddfbfSEd Maste // other FindFunctions method should be able to take advantage of any
175ac7ddfbfSEd Maste // accelerator tables available in the debug information (which is
176ac7ddfbfSEd Maste // parsed by the SymbolFile parser plug-ins and registered with each
177ac7ddfbfSEd Maste // Module).
178ac7ddfbfSEd Maste //----------------------------------------------------------------------
179ac7ddfbfSEd Maste //void
180ac7ddfbfSEd Maste //CompileUnit::FindFunctions(const Mangled::Tokens& tokens)
181ac7ddfbfSEd Maste //{
182ac7ddfbfSEd Maste //  if (!m_functions.empty())
183ac7ddfbfSEd Maste //  {
184ac7ddfbfSEd Maste //      Stream s(stdout);
185ac7ddfbfSEd Maste //      std::vector<FunctionSP>::const_iterator pos;
186ac7ddfbfSEd Maste //      std::vector<FunctionSP>::const_iterator end = m_functions.end();
187ac7ddfbfSEd Maste //      for (pos = m_functions.begin(); pos != end; ++pos)
188ac7ddfbfSEd Maste //      {
189ac7ddfbfSEd Maste //          const ConstString& demangled = (*pos)->Mangled().Demangled();
190ac7ddfbfSEd Maste //          if (demangled)
191ac7ddfbfSEd Maste //          {
192ac7ddfbfSEd Maste //              const Mangled::Tokens& func_tokens = (*pos)->Mangled().GetTokens();
193ac7ddfbfSEd Maste //              if (func_tokens.MatchesQuery (tokens))
194ac7ddfbfSEd Maste //                  s << "demangled MATCH found: " << demangled << "\n";
195ac7ddfbfSEd Maste //          }
196ac7ddfbfSEd Maste //      }
197ac7ddfbfSEd Maste //  }
198ac7ddfbfSEd Maste //}
199ac7ddfbfSEd Maste 
200ac7ddfbfSEd Maste FunctionSP
201ac7ddfbfSEd Maste CompileUnit::FindFunctionByUID (lldb::user_id_t func_uid)
202ac7ddfbfSEd Maste {
203ac7ddfbfSEd Maste     FunctionSP funcSP;
204ac7ddfbfSEd Maste     if (!m_functions.empty())
205ac7ddfbfSEd Maste     {
206ac7ddfbfSEd Maste         std::vector<FunctionSP>::const_iterator pos;
207ac7ddfbfSEd Maste         std::vector<FunctionSP>::const_iterator end = m_functions.end();
208ac7ddfbfSEd Maste         for (pos = m_functions.begin(); pos != end; ++pos)
209ac7ddfbfSEd Maste         {
210ac7ddfbfSEd Maste             if ((*pos)->GetID() == func_uid)
211ac7ddfbfSEd Maste             {
212ac7ddfbfSEd Maste                 funcSP = *pos;
213ac7ddfbfSEd Maste                 break;
214ac7ddfbfSEd Maste             }
215ac7ddfbfSEd Maste         }
216ac7ddfbfSEd Maste     }
217ac7ddfbfSEd Maste     return funcSP;
218ac7ddfbfSEd Maste }
219ac7ddfbfSEd Maste 
220ac7ddfbfSEd Maste 
221ac7ddfbfSEd Maste lldb::LanguageType
222ac7ddfbfSEd Maste CompileUnit::GetLanguage()
223ac7ddfbfSEd Maste {
224ac7ddfbfSEd Maste     if (m_language == eLanguageTypeUnknown)
225ac7ddfbfSEd Maste     {
226ac7ddfbfSEd Maste         if (m_flags.IsClear(flagsParsedLanguage))
227ac7ddfbfSEd Maste         {
228ac7ddfbfSEd Maste             m_flags.Set(flagsParsedLanguage);
229ac7ddfbfSEd Maste             SymbolVendor* symbol_vendor = GetModule()->GetSymbolVendor();
230ac7ddfbfSEd Maste             if (symbol_vendor)
231ac7ddfbfSEd Maste             {
232ac7ddfbfSEd Maste                 SymbolContext sc;
233ac7ddfbfSEd Maste                 CalculateSymbolContext(&sc);
234ac7ddfbfSEd Maste                 m_language = symbol_vendor->ParseCompileUnitLanguage(sc);
235ac7ddfbfSEd Maste             }
236ac7ddfbfSEd Maste         }
237ac7ddfbfSEd Maste     }
238ac7ddfbfSEd Maste     return m_language;
239ac7ddfbfSEd Maste }
240ac7ddfbfSEd Maste 
241ac7ddfbfSEd Maste LineTable*
242ac7ddfbfSEd Maste CompileUnit::GetLineTable()
243ac7ddfbfSEd Maste {
2440127ef0fSEd Maste     if (m_line_table_ap.get() == nullptr)
245ac7ddfbfSEd Maste     {
246ac7ddfbfSEd Maste         if (m_flags.IsClear(flagsParsedLineTable))
247ac7ddfbfSEd Maste         {
248ac7ddfbfSEd Maste             m_flags.Set(flagsParsedLineTable);
249ac7ddfbfSEd Maste             SymbolVendor* symbol_vendor = GetModule()->GetSymbolVendor();
250ac7ddfbfSEd Maste             if (symbol_vendor)
251ac7ddfbfSEd Maste             {
252ac7ddfbfSEd Maste                 SymbolContext sc;
253ac7ddfbfSEd Maste                 CalculateSymbolContext(&sc);
254ac7ddfbfSEd Maste                 symbol_vendor->ParseCompileUnitLineTable(sc);
255ac7ddfbfSEd Maste             }
256ac7ddfbfSEd Maste         }
257ac7ddfbfSEd Maste     }
258ac7ddfbfSEd Maste     return m_line_table_ap.get();
259ac7ddfbfSEd Maste }
260ac7ddfbfSEd Maste 
261ac7ddfbfSEd Maste void
262ac7ddfbfSEd Maste CompileUnit::SetLineTable(LineTable* line_table)
263ac7ddfbfSEd Maste {
2640127ef0fSEd Maste     if (line_table == nullptr)
265ac7ddfbfSEd Maste         m_flags.Clear(flagsParsedLineTable);
266ac7ddfbfSEd Maste     else
267ac7ddfbfSEd Maste         m_flags.Set(flagsParsedLineTable);
268ac7ddfbfSEd Maste     m_line_table_ap.reset(line_table);
269ac7ddfbfSEd Maste }
270ac7ddfbfSEd Maste 
2719f2f44ceSEd Maste DebugMacros*
2729f2f44ceSEd Maste CompileUnit::GetDebugMacros()
2739f2f44ceSEd Maste {
2749f2f44ceSEd Maste     if (m_debug_macros_sp.get() == nullptr)
2759f2f44ceSEd Maste     {
2769f2f44ceSEd Maste         if (m_flags.IsClear(flagsParsedDebugMacros))
2779f2f44ceSEd Maste         {
2789f2f44ceSEd Maste             m_flags.Set(flagsParsedDebugMacros);
2799f2f44ceSEd Maste             SymbolVendor* symbol_vendor = GetModule()->GetSymbolVendor();
2809f2f44ceSEd Maste             if (symbol_vendor)
2819f2f44ceSEd Maste             {
2829f2f44ceSEd Maste                 SymbolContext sc;
2839f2f44ceSEd Maste                 CalculateSymbolContext(&sc);
2849f2f44ceSEd Maste                 symbol_vendor->ParseCompileUnitDebugMacros(sc);
2859f2f44ceSEd Maste             }
2869f2f44ceSEd Maste         }
2879f2f44ceSEd Maste     }
2889f2f44ceSEd Maste 
2899f2f44ceSEd Maste     return m_debug_macros_sp.get();
2909f2f44ceSEd Maste }
2919f2f44ceSEd Maste 
2929f2f44ceSEd Maste void
2939f2f44ceSEd Maste CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp)
2949f2f44ceSEd Maste {
2959f2f44ceSEd Maste     if (debug_macros_sp.get() == nullptr)
2969f2f44ceSEd Maste         m_flags.Clear(flagsParsedDebugMacros);
2979f2f44ceSEd Maste     else
2989f2f44ceSEd Maste         m_flags.Set(flagsParsedDebugMacros);
2999f2f44ceSEd Maste     m_debug_macros_sp = debug_macros_sp;
3009f2f44ceSEd Maste }
3019f2f44ceSEd Maste 
302ac7ddfbfSEd Maste VariableListSP
303ac7ddfbfSEd Maste CompileUnit::GetVariableList(bool can_create)
304ac7ddfbfSEd Maste {
3050127ef0fSEd Maste     if (m_variables.get() == nullptr && can_create)
306ac7ddfbfSEd Maste     {
307ac7ddfbfSEd Maste         SymbolContext sc;
308ac7ddfbfSEd Maste         CalculateSymbolContext(&sc);
309ac7ddfbfSEd Maste         assert(sc.module_sp);
310ac7ddfbfSEd Maste         sc.module_sp->GetSymbolVendor()->ParseVariablesForContext(sc);
311ac7ddfbfSEd Maste     }
312ac7ddfbfSEd Maste 
313ac7ddfbfSEd Maste     return m_variables;
314ac7ddfbfSEd Maste }
315ac7ddfbfSEd Maste 
316ac7ddfbfSEd Maste uint32_t
317ac7ddfbfSEd Maste CompileUnit::FindLineEntry (uint32_t start_idx, uint32_t line, const FileSpec* file_spec_ptr, bool exact, LineEntry *line_entry_ptr)
318ac7ddfbfSEd Maste {
319ac7ddfbfSEd Maste     uint32_t file_idx = 0;
320ac7ddfbfSEd Maste 
321ac7ddfbfSEd Maste     if (file_spec_ptr)
322ac7ddfbfSEd Maste     {
323ac7ddfbfSEd Maste         file_idx = GetSupportFiles().FindFileIndex (1, *file_spec_ptr, true);
324ac7ddfbfSEd Maste         if (file_idx == UINT32_MAX)
325ac7ddfbfSEd Maste             return UINT32_MAX;
326ac7ddfbfSEd Maste     }
327ac7ddfbfSEd Maste     else
328ac7ddfbfSEd Maste     {
329ac7ddfbfSEd Maste         // All the line table entries actually point to the version of the Compile
3301c3bbb01SEd Maste         // Unit that is in the support files (the one at 0 was artificially added.)
331ac7ddfbfSEd Maste         // So prefer the one further on in the support files if it exists...
332ac7ddfbfSEd Maste         FileSpecList &support_files = GetSupportFiles();
333ac7ddfbfSEd Maste         const bool full = true;
334ac7ddfbfSEd Maste         file_idx = support_files.FindFileIndex (1, support_files.GetFileSpecAtIndex(0), full);
335ac7ddfbfSEd Maste         if (file_idx == UINT32_MAX)
336ac7ddfbfSEd Maste             file_idx = 0;
337ac7ddfbfSEd Maste     }
338ac7ddfbfSEd Maste     LineTable *line_table = GetLineTable();
339ac7ddfbfSEd Maste     if (line_table)
340ac7ddfbfSEd Maste         return line_table->FindLineEntryIndexByFileIndex (start_idx, file_idx, line, exact, line_entry_ptr);
341ac7ddfbfSEd Maste     return UINT32_MAX;
342ac7ddfbfSEd Maste }
343ac7ddfbfSEd Maste 
344ac7ddfbfSEd Maste 
345ac7ddfbfSEd Maste 
346ac7ddfbfSEd Maste 
347ac7ddfbfSEd Maste uint32_t
348ac7ddfbfSEd Maste CompileUnit::ResolveSymbolContext
349ac7ddfbfSEd Maste (
350ac7ddfbfSEd Maste     const FileSpec& file_spec,
351ac7ddfbfSEd Maste     uint32_t line,
352ac7ddfbfSEd Maste     bool check_inlines,
353ac7ddfbfSEd Maste     bool exact,
354ac7ddfbfSEd Maste     uint32_t resolve_scope,
355ac7ddfbfSEd Maste     SymbolContextList &sc_list
356ac7ddfbfSEd Maste )
357ac7ddfbfSEd Maste {
358ac7ddfbfSEd Maste     // First find all of the file indexes that match our "file_spec". If
359ac7ddfbfSEd Maste     // "file_spec" has an empty directory, then only compare the basenames
360ac7ddfbfSEd Maste     // when finding file indexes
361ac7ddfbfSEd Maste     std::vector<uint32_t> file_indexes;
36235617911SEd Maste     const bool full_match = (bool)file_spec.GetDirectory();
3637aa51b79SEd Maste     const bool remove_backup_dots = true;
3647aa51b79SEd Maste     bool file_spec_matches_cu_file_spec = FileSpec::Equal(file_spec, *this, full_match, remove_backup_dots);
365ac7ddfbfSEd Maste 
366ac7ddfbfSEd Maste     // If we are not looking for inlined functions and our file spec doesn't
367ac7ddfbfSEd Maste     // match then we are done...
368ac7ddfbfSEd Maste     if (file_spec_matches_cu_file_spec == false && check_inlines == false)
369ac7ddfbfSEd Maste         return 0;
370ac7ddfbfSEd Maste 
3717aa51b79SEd Maste     uint32_t file_idx = GetSupportFiles().FindFileIndex (1, file_spec, true, remove_backup_dots);
372ac7ddfbfSEd Maste     while (file_idx != UINT32_MAX)
373ac7ddfbfSEd Maste     {
374ac7ddfbfSEd Maste         file_indexes.push_back (file_idx);
3757aa51b79SEd Maste         file_idx = GetSupportFiles().FindFileIndex (file_idx + 1, file_spec, true, remove_backup_dots);
376ac7ddfbfSEd Maste     }
377ac7ddfbfSEd Maste 
378ac7ddfbfSEd Maste     const size_t num_file_indexes = file_indexes.size();
379ac7ddfbfSEd Maste     if (num_file_indexes == 0)
380ac7ddfbfSEd Maste         return 0;
381ac7ddfbfSEd Maste 
382ac7ddfbfSEd Maste     const uint32_t prev_size = sc_list.GetSize();
383ac7ddfbfSEd Maste 
384ac7ddfbfSEd Maste     SymbolContext sc(GetModule());
385ac7ddfbfSEd Maste     sc.comp_unit = this;
386ac7ddfbfSEd Maste 
387ac7ddfbfSEd Maste 
388ac7ddfbfSEd Maste     if (line != 0)
389ac7ddfbfSEd Maste     {
390ac7ddfbfSEd Maste         LineTable *line_table = sc.comp_unit->GetLineTable();
391ac7ddfbfSEd Maste 
3920127ef0fSEd Maste         if (line_table != nullptr)
393ac7ddfbfSEd Maste         {
394ac7ddfbfSEd Maste             uint32_t found_line;
395ac7ddfbfSEd Maste             uint32_t line_idx;
396ac7ddfbfSEd Maste 
397ac7ddfbfSEd Maste             if (num_file_indexes == 1)
398ac7ddfbfSEd Maste             {
399ac7ddfbfSEd Maste                 // We only have a single support file that matches, so use
400ac7ddfbfSEd Maste                 // the line table function that searches for a line entries
401ac7ddfbfSEd Maste                 // that match a single support file index
402ac7ddfbfSEd Maste                 LineEntry line_entry;
403ac7ddfbfSEd Maste                 line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_indexes.front(), line, exact, &line_entry);
404ac7ddfbfSEd Maste 
405ac7ddfbfSEd Maste                 // If "exact == true", then "found_line" will be the same
406ac7ddfbfSEd Maste                 // as "line". If "exact == false", the "found_line" will be the
407ac7ddfbfSEd Maste                 // closest line entry with a line number greater than "line" and
408ac7ddfbfSEd Maste                 // we will use this for our subsequent line exact matches below.
409ac7ddfbfSEd Maste                 found_line = line_entry.line;
410ac7ddfbfSEd Maste 
411ac7ddfbfSEd Maste                 while (line_idx != UINT32_MAX)
412ac7ddfbfSEd Maste                 {
413ac7ddfbfSEd Maste                     // If they only asked for the line entry, then we're done, we can just copy that over.
414ac7ddfbfSEd Maste                     // But if they wanted more than just the line number, fill it in.
415ac7ddfbfSEd Maste                     if (resolve_scope == eSymbolContextLineEntry)
416ac7ddfbfSEd Maste                     {
417ac7ddfbfSEd Maste                         sc.line_entry = line_entry;
418ac7ddfbfSEd Maste                     }
419ac7ddfbfSEd Maste                     else
420ac7ddfbfSEd Maste                     {
421ac7ddfbfSEd Maste                         line_entry.range.GetBaseAddress().CalculateSymbolContext(&sc, resolve_scope);
422ac7ddfbfSEd Maste                     }
423ac7ddfbfSEd Maste 
424ac7ddfbfSEd Maste                     sc_list.Append(sc);
425ac7ddfbfSEd Maste                     line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_indexes.front(), found_line, true, &line_entry);
426ac7ddfbfSEd Maste                 }
427ac7ddfbfSEd Maste             }
428ac7ddfbfSEd Maste             else
429ac7ddfbfSEd Maste             {
430ac7ddfbfSEd Maste                 // We found multiple support files that match "file_spec" so use
431ac7ddfbfSEd Maste                 // the line table function that searches for a line entries
432ac7ddfbfSEd Maste                 // that match a multiple support file indexes.
433ac7ddfbfSEd Maste                 LineEntry line_entry;
434ac7ddfbfSEd Maste                 line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_indexes, line, exact, &line_entry);
435ac7ddfbfSEd Maste 
436ac7ddfbfSEd Maste                 // If "exact == true", then "found_line" will be the same
437ac7ddfbfSEd Maste                 // as "line". If "exact == false", the "found_line" will be the
438ac7ddfbfSEd Maste                 // closest line entry with a line number greater than "line" and
439ac7ddfbfSEd Maste                 // we will use this for our subsequent line exact matches below.
440ac7ddfbfSEd Maste                 found_line = line_entry.line;
441ac7ddfbfSEd Maste 
442ac7ddfbfSEd Maste                 while (line_idx != UINT32_MAX)
443ac7ddfbfSEd Maste                 {
444ac7ddfbfSEd Maste                     if (resolve_scope == eSymbolContextLineEntry)
445ac7ddfbfSEd Maste                     {
446ac7ddfbfSEd Maste                         sc.line_entry = line_entry;
447ac7ddfbfSEd Maste                     }
448ac7ddfbfSEd Maste                     else
449ac7ddfbfSEd Maste                     {
450ac7ddfbfSEd Maste                         line_entry.range.GetBaseAddress().CalculateSymbolContext(&sc, resolve_scope);
451ac7ddfbfSEd Maste                     }
452ac7ddfbfSEd Maste 
453ac7ddfbfSEd Maste                     sc_list.Append(sc);
454ac7ddfbfSEd Maste                     line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_indexes, found_line, true, &line_entry);
455ac7ddfbfSEd Maste                 }
456ac7ddfbfSEd Maste             }
457ac7ddfbfSEd Maste         }
458ac7ddfbfSEd Maste     }
459ac7ddfbfSEd Maste     else if (file_spec_matches_cu_file_spec && !check_inlines)
460ac7ddfbfSEd Maste     {
461ac7ddfbfSEd Maste         // only append the context if we aren't looking for inline call sites
462ac7ddfbfSEd Maste         // by file and line and if the file spec matches that of the compile unit
463ac7ddfbfSEd Maste         sc_list.Append(sc);
464ac7ddfbfSEd Maste     }
465ac7ddfbfSEd Maste     return sc_list.GetSize() - prev_size;
466ac7ddfbfSEd Maste }
467ac7ddfbfSEd Maste 
4689f2f44ceSEd Maste bool
4699f2f44ceSEd Maste CompileUnit::GetIsOptimized ()
4709f2f44ceSEd Maste {
4719f2f44ceSEd Maste     return m_is_optimized;
4729f2f44ceSEd Maste }
4739f2f44ceSEd Maste 
474ac7ddfbfSEd Maste void
475ac7ddfbfSEd Maste CompileUnit::SetVariableList(VariableListSP &variables)
476ac7ddfbfSEd Maste {
477ac7ddfbfSEd Maste     m_variables = variables;
478ac7ddfbfSEd Maste }
479ac7ddfbfSEd Maste 
4801c3bbb01SEd Maste const std::vector<ConstString> &
4811c3bbb01SEd Maste CompileUnit::GetImportedModules ()
4821c3bbb01SEd Maste {
4831c3bbb01SEd Maste     if (m_imported_modules.empty() &&
4841c3bbb01SEd Maste         m_flags.IsClear(flagsParsedImportedModules))
4851c3bbb01SEd Maste     {
4861c3bbb01SEd Maste         m_flags.Set(flagsParsedImportedModules);
4871c3bbb01SEd Maste         if (SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor())
4881c3bbb01SEd Maste         {
4891c3bbb01SEd Maste             SymbolContext sc;
4901c3bbb01SEd Maste             CalculateSymbolContext(&sc);
4911c3bbb01SEd Maste             symbol_vendor->ParseImportedModules(sc, m_imported_modules);
4921c3bbb01SEd Maste         }
4931c3bbb01SEd Maste     }
4941c3bbb01SEd Maste     return m_imported_modules;
4951c3bbb01SEd Maste }
4961c3bbb01SEd Maste 
497ac7ddfbfSEd Maste FileSpecList&
498ac7ddfbfSEd Maste CompileUnit::GetSupportFiles ()
499ac7ddfbfSEd Maste {
500ac7ddfbfSEd Maste     if (m_support_files.GetSize() == 0)
501ac7ddfbfSEd Maste     {
502ac7ddfbfSEd Maste         if (m_flags.IsClear(flagsParsedSupportFiles))
503ac7ddfbfSEd Maste         {
504ac7ddfbfSEd Maste             m_flags.Set(flagsParsedSupportFiles);
505ac7ddfbfSEd Maste             SymbolVendor* symbol_vendor = GetModule()->GetSymbolVendor();
506ac7ddfbfSEd Maste             if (symbol_vendor)
507ac7ddfbfSEd Maste             {
508ac7ddfbfSEd Maste                 SymbolContext sc;
509ac7ddfbfSEd Maste                 CalculateSymbolContext(&sc);
510ac7ddfbfSEd Maste                 symbol_vendor->ParseCompileUnitSupportFiles(sc, m_support_files);
511ac7ddfbfSEd Maste             }
512ac7ddfbfSEd Maste         }
513ac7ddfbfSEd Maste     }
514ac7ddfbfSEd Maste     return m_support_files;
515ac7ddfbfSEd Maste }
516ac7ddfbfSEd Maste 
517ac7ddfbfSEd Maste void *
518ac7ddfbfSEd Maste CompileUnit::GetUserData () const
519ac7ddfbfSEd Maste {
520ac7ddfbfSEd Maste     return m_user_data;
521ac7ddfbfSEd Maste }
522ac7ddfbfSEd Maste 
523ac7ddfbfSEd Maste 
524