1 | //===-- SymbolFile.h --------------------------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLDB_SYMBOL_SYMBOLFILE_H |
10 | #define LLDB_SYMBOL_SYMBOLFILE_H |
11 | |
12 | #include "lldb/Core/Module.h" |
13 | #include "lldb/Core/ModuleList.h" |
14 | #include "lldb/Core/PluginInterface.h" |
15 | #include "lldb/Core/SourceLocationSpec.h" |
16 | #include "lldb/Symbol/CompilerDecl.h" |
17 | #include "lldb/Symbol/CompilerDeclContext.h" |
18 | #include "lldb/Symbol/CompilerType.h" |
19 | #include "lldb/Symbol/Function.h" |
20 | #include "lldb/Symbol/SourceModule.h" |
21 | #include "lldb/Symbol/Type.h" |
22 | #include "lldb/Symbol/TypeList.h" |
23 | #include "lldb/Symbol/TypeSystem.h" |
24 | #include "lldb/Target/Statistics.h" |
25 | #include "lldb/Utility/StructuredData.h" |
26 | #include "lldb/Utility/XcodeSDK.h" |
27 | #include "lldb/lldb-private.h" |
28 | #include "llvm/ADT/DenseSet.h" |
29 | #include "llvm/ADT/SmallSet.h" |
30 | #include "llvm/Support/Errc.h" |
31 | |
32 | #include <mutex> |
33 | #include <optional> |
34 | #include <unordered_map> |
35 | |
36 | #if defined(LLDB_CONFIGURATION_DEBUG) |
37 | #define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock()) |
38 | #else |
39 | #define ASSERT_MODULE_LOCK(expr) ((void)0) |
40 | #endif |
41 | |
42 | namespace lldb_private { |
43 | |
44 | /// Provides public interface for all SymbolFiles. Any protected |
45 | /// virtual members should go into SymbolFileCommon; most SymbolFile |
46 | /// implementations should inherit from SymbolFileCommon to override |
47 | /// the behaviors except SymbolFileOnDemand which inherits |
48 | /// public interfaces from SymbolFile and forward to underlying concrete |
49 | /// SymbolFile implementation. |
50 | class SymbolFile : public PluginInterface { |
51 | /// LLVM RTTI support. |
52 | static char ID; |
53 | |
54 | public: |
55 | /// LLVM RTTI support. |
56 | /// \{ |
57 | virtual bool isA(const void *ClassID) const { return ClassID == &ID; } |
58 | static bool classof(const SymbolFile *obj) { return obj->isA(ClassID: &ID); } |
59 | /// \} |
60 | |
61 | // Symbol file ability bits. |
62 | // |
63 | // Each symbol file can claim to support one or more symbol file abilities. |
64 | // These get returned from SymbolFile::GetAbilities(). These help us to |
65 | // determine which plug-in will be best to load the debug information found |
66 | // in files. |
67 | enum Abilities { |
68 | CompileUnits = (1u << 0), |
69 | LineTables = (1u << 1), |
70 | Functions = (1u << 2), |
71 | Blocks = (1u << 3), |
72 | GlobalVariables = (1u << 4), |
73 | LocalVariables = (1u << 5), |
74 | VariableTypes = (1u << 6), |
75 | kAllAbilities = ((1u << 7) - 1u) |
76 | }; |
77 | |
78 | static SymbolFile *FindPlugin(lldb::ObjectFileSP objfile_sp); |
79 | |
80 | // Constructors and Destructors |
81 | SymbolFile() = default; |
82 | |
83 | ~SymbolFile() override = default; |
84 | |
85 | /// SymbolFileOnDemand class overrides this to return the underlying |
86 | /// backing SymbolFile implementation that loads on-demand. |
87 | virtual SymbolFile *GetBackingSymbolFile() { return this; } |
88 | |
89 | /// Get a mask of what this symbol file supports for the object file |
90 | /// that it was constructed with. |
91 | /// |
92 | /// Each symbol file gets to respond with a mask of abilities that |
93 | /// it supports for each object file. This happens when we are |
94 | /// trying to figure out which symbol file plug-in will get used |
95 | /// for a given object file. The plug-in that responds with the |
96 | /// best mix of "SymbolFile::Abilities" bits set, will get chosen to |
97 | /// be the symbol file parser. This allows each plug-in to check for |
98 | /// sections that contain data a symbol file plug-in would need. For |
99 | /// example the DWARF plug-in requires DWARF sections in a file that |
100 | /// contain debug information. If the DWARF plug-in doesn't find |
101 | /// these sections, it won't respond with many ability bits set, and |
102 | /// we will probably fall back to the symbol table SymbolFile plug-in |
103 | /// which uses any information in the symbol table. Also, plug-ins |
104 | /// might check for some specific symbols in a symbol table in the |
105 | /// case where the symbol table contains debug information (STABS |
106 | /// and COFF). Not a lot of work should happen in these functions |
107 | /// as the plug-in might not get selected due to another plug-in |
108 | /// having more abilities. Any initialization work should be saved |
109 | /// for "void SymbolFile::InitializeObject()" which will get called |
110 | /// on the SymbolFile object with the best set of abilities. |
111 | /// |
112 | /// \return |
113 | /// A uint32_t mask containing bits from the SymbolFile::Abilities |
114 | /// enumeration. Any bits that are set represent an ability that |
115 | /// this symbol plug-in can parse from the object file. |
116 | virtual uint32_t GetAbilities() = 0; |
117 | virtual uint32_t CalculateAbilities() = 0; |
118 | |
119 | /// Symbols file subclasses should override this to return the Module that |
120 | /// owns the TypeSystem that this symbol file modifies type information in. |
121 | virtual std::recursive_mutex &GetModuleMutex() const; |
122 | |
123 | /// Initialize the SymbolFile object. |
124 | /// |
125 | /// The SymbolFile object with the best set of abilities (detected |
126 | /// in "uint32_t SymbolFile::GetAbilities()) will have this function |
127 | /// called if it is chosen to parse an object file. More complete |
128 | /// initialization can happen in this function which will get called |
129 | /// prior to any other functions in the SymbolFile protocol. |
130 | virtual void InitializeObject() {} |
131 | |
132 | /// Whether debug info will be loaded or not. |
133 | /// |
134 | /// It will be true for most implementations except SymbolFileOnDemand. |
135 | virtual bool GetLoadDebugInfoEnabled() { return true; } |
136 | |
137 | /// Specify debug info should be loaded. |
138 | /// |
139 | /// It will be no-op for most implementations except SymbolFileOnDemand. |
140 | virtual void SetLoadDebugInfoEnabled() {} |
141 | |
142 | // Compile Unit function calls |
143 | // Approach 1 - iterator |
144 | virtual uint32_t GetNumCompileUnits() = 0; |
145 | virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) = 0; |
146 | |
147 | virtual Symtab *GetSymtab() = 0; |
148 | |
149 | virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0; |
150 | /// Return the Xcode SDK comp_unit was compiled against. |
151 | virtual XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) { return {}; } |
152 | |
153 | /// This function exists because SymbolFileDWARFDebugMap may extra compile |
154 | /// units which aren't exposed as "real" compile units. In every other |
155 | /// case this function should behave identically as ParseLanguage. |
156 | virtual llvm::SmallSet<lldb::LanguageType, 4> |
157 | ParseAllLanguages(CompileUnit &comp_unit) { |
158 | llvm::SmallSet<lldb::LanguageType, 4> langs; |
159 | langs.insert(V: ParseLanguage(comp_unit)); |
160 | return langs; |
161 | } |
162 | |
163 | virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0; |
164 | virtual bool ParseLineTable(CompileUnit &comp_unit) = 0; |
165 | virtual bool ParseDebugMacros(CompileUnit &comp_unit) = 0; |
166 | |
167 | /// Apply a lambda to each external lldb::Module referenced by this |
168 | /// \p comp_unit. Recursively also descends into the referenced external |
169 | /// modules of any encountered compilation unit. |
170 | /// |
171 | /// This function can be used to traverse Clang -gmodules debug |
172 | /// information, which is stored in DWARF files separate from the |
173 | /// object files. |
174 | /// |
175 | /// \param comp_unit |
176 | /// When this SymbolFile consists of multiple auxilliary |
177 | /// SymbolFiles, for example, a Darwin debug map that references |
178 | /// multiple .o files, comp_unit helps choose the auxilliary |
179 | /// file. In most other cases comp_unit's symbol file is |
180 | /// identical with *this. |
181 | /// |
182 | /// \param[in] lambda |
183 | /// The lambda that should be applied to every function. The lambda can |
184 | /// return true if the iteration should be aborted earlier. |
185 | /// |
186 | /// \param visited_symbol_files |
187 | /// A set of SymbolFiles that were already visited to avoid |
188 | /// visiting one file more than once. |
189 | /// |
190 | /// \return |
191 | /// If the lambda early-exited, this function returns true to |
192 | /// propagate the early exit. |
193 | virtual bool ForEachExternalModule( |
194 | lldb_private::CompileUnit &comp_unit, |
195 | llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files, |
196 | llvm::function_ref<bool(Module &)> lambda) { |
197 | return false; |
198 | } |
199 | virtual bool ParseSupportFiles(CompileUnit &comp_unit, |
200 | SupportFileList &support_files) = 0; |
201 | virtual size_t ParseTypes(CompileUnit &comp_unit) = 0; |
202 | virtual bool ParseIsOptimized(CompileUnit &comp_unit) { return false; } |
203 | |
204 | virtual bool |
205 | ParseImportedModules(const SymbolContext &sc, |
206 | std::vector<SourceModule> &imported_modules) = 0; |
207 | virtual size_t ParseBlocksRecursive(Function &func) = 0; |
208 | virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0; |
209 | virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0; |
210 | |
211 | /// The characteristics of an array type. |
212 | struct ArrayInfo { |
213 | int64_t first_index = 0; |
214 | llvm::SmallVector<uint64_t, 1> element_orders; |
215 | uint32_t byte_stride = 0; |
216 | uint32_t bit_stride = 0; |
217 | }; |
218 | /// If \c type_uid points to an array type, return its characteristics. |
219 | /// To support variable-length array types, this function takes an |
220 | /// optional \p ExecutionContext. If \c exe_ctx is non-null, the |
221 | /// dynamic characteristics for that context are returned. |
222 | virtual std::optional<ArrayInfo> |
223 | GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, |
224 | const lldb_private::ExecutionContext *exe_ctx) = 0; |
225 | |
226 | virtual bool CompleteType(CompilerType &compiler_type) = 0; |
227 | virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx) {} |
228 | virtual CompilerDecl GetDeclForUID(lldb::user_id_t uid) { return {}; } |
229 | virtual CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) { |
230 | return {}; |
231 | } |
232 | virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) { |
233 | return {}; |
234 | } |
235 | virtual std::vector<CompilerContext> |
236 | GetCompilerContextForUID(lldb::user_id_t uid) { |
237 | return {}; |
238 | } |
239 | virtual uint32_t ResolveSymbolContext(const Address &so_addr, |
240 | lldb::SymbolContextItem resolve_scope, |
241 | SymbolContext &sc) = 0; |
242 | |
243 | /// Get an error that describes why variables might be missing for a given |
244 | /// symbol context. |
245 | /// |
246 | /// If there is an error in the debug information that prevents variables from |
247 | /// being fetched, this error will get filled in. If there is no debug |
248 | /// informaiton, no error should be returned. But if there is debug |
249 | /// information and something prevents the variables from being available a |
250 | /// valid error should be returned. Valid cases include: |
251 | /// - compiler option that removes variables (-gline-tables-only) |
252 | /// - missing external files |
253 | /// - .dwo files in fission are not accessible or missing |
254 | /// - .o files on darwin when not using dSYM files that are not accessible |
255 | /// or missing |
256 | /// - mismatched exteral files |
257 | /// - .dwo files in fission where the DWO ID doesn't match |
258 | /// - .o files on darwin when modification timestamp doesn't match |
259 | /// - corrupted debug info |
260 | /// |
261 | /// \param[in] frame |
262 | /// The stack frame to use as a basis for the context to check. The frame |
263 | /// address can be used if there is not debug info due to it not being able |
264 | /// to be loaded, or if there is a debug info context, like a compile unit, |
265 | /// or function, it can be used to track down more information on why |
266 | /// variables are missing. |
267 | /// |
268 | /// \returns |
269 | /// An error specifying why there should have been debug info with variable |
270 | /// information but the variables were not able to be resolved. |
271 | Status GetFrameVariableError(StackFrame &frame) { |
272 | Status err = CalculateFrameVariableError(frame); |
273 | if (err.Fail()) |
274 | SetDebugInfoHadFrameVariableErrors(); |
275 | return err; |
276 | } |
277 | |
278 | /// Subclasses will override this function to for GetFrameVariableError(). |
279 | /// |
280 | /// This allows GetFrameVariableError() to set the member variable |
281 | /// m_debug_info_had_variable_errors correctly without users having to do it |
282 | /// manually which is error prone. |
283 | virtual Status CalculateFrameVariableError(StackFrame &frame) { |
284 | return Status(); |
285 | } |
286 | virtual uint32_t |
287 | ResolveSymbolContext(const SourceLocationSpec &src_location_spec, |
288 | lldb::SymbolContextItem resolve_scope, |
289 | SymbolContextList &sc_list); |
290 | |
291 | virtual void DumpClangAST(Stream &s) {} |
292 | virtual void FindGlobalVariables(ConstString name, |
293 | const CompilerDeclContext &parent_decl_ctx, |
294 | uint32_t max_matches, |
295 | VariableList &variables); |
296 | virtual void FindGlobalVariables(const RegularExpression ®ex, |
297 | uint32_t max_matches, |
298 | VariableList &variables); |
299 | virtual void FindFunctions(const Module::LookupInfo &lookup_info, |
300 | const CompilerDeclContext &parent_decl_ctx, |
301 | bool include_inlines, SymbolContextList &sc_list); |
302 | virtual void FindFunctions(const RegularExpression ®ex, |
303 | bool include_inlines, SymbolContextList &sc_list); |
304 | |
305 | /// Find types using a type-matching object that contains all search |
306 | /// parameters. |
307 | /// |
308 | /// \see lldb_private::TypeQuery |
309 | /// |
310 | /// \param[in] query |
311 | /// A type matching object that contains all of the details of the type |
312 | /// search. |
313 | /// |
314 | /// \param[in] results |
315 | /// Any matching types will be populated into the \a results object using |
316 | /// TypeMap::InsertUnique(...). |
317 | virtual void FindTypes(const TypeQuery &query, TypeResults &results) {} |
318 | |
319 | virtual void |
320 | GetMangledNamesForFunction(const std::string &scope_qualified_name, |
321 | std::vector<ConstString> &mangled_names); |
322 | |
323 | virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope, |
324 | lldb::TypeClass type_mask, |
325 | lldb_private::TypeList &type_list) = 0; |
326 | |
327 | virtual void PreloadSymbols(); |
328 | |
329 | virtual llvm::Expected<lldb::TypeSystemSP> |
330 | GetTypeSystemForLanguage(lldb::LanguageType language) = 0; |
331 | |
332 | /// Finds a namespace of name \ref name and whose parent |
333 | /// context is \ref parent_decl_ctx. |
334 | /// |
335 | /// If \code{.cpp} !parent_decl_ctx.IsValid() \endcode |
336 | /// then this function will consider all namespaces that |
337 | /// match the name. If \ref only_root_namespaces is |
338 | /// true, only consider in the search those DIEs that |
339 | /// represent top-level namespaces. |
340 | virtual CompilerDeclContext |
341 | FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, |
342 | bool only_root_namespaces = false) { |
343 | return CompilerDeclContext(); |
344 | } |
345 | |
346 | virtual ObjectFile *GetObjectFile() = 0; |
347 | virtual const ObjectFile *GetObjectFile() const = 0; |
348 | virtual ObjectFile *GetMainObjectFile() = 0; |
349 | |
350 | virtual std::vector<std::unique_ptr<CallEdge>> |
351 | ParseCallEdgesInFunction(UserID func_id) { |
352 | return {}; |
353 | } |
354 | |
355 | virtual void AddSymbols(Symtab &symtab) {} |
356 | |
357 | /// Notify the SymbolFile that the file addresses in the Sections |
358 | /// for this module have been changed. |
359 | virtual void SectionFileAddressesChanged() = 0; |
360 | |
361 | struct RegisterInfoResolver { |
362 | virtual ~RegisterInfoResolver(); // anchor |
363 | |
364 | virtual const RegisterInfo *ResolveName(llvm::StringRef name) const = 0; |
365 | virtual const RegisterInfo *ResolveNumber(lldb::RegisterKind kind, |
366 | uint32_t number) const = 0; |
367 | }; |
368 | virtual lldb::UnwindPlanSP |
369 | GetUnwindPlan(const Address &address, const RegisterInfoResolver &resolver) { |
370 | return nullptr; |
371 | } |
372 | |
373 | /// Return the number of stack bytes taken up by the parameters to this |
374 | /// function. |
375 | virtual llvm::Expected<lldb::addr_t> GetParameterStackSize(Symbol &symbol) { |
376 | return llvm::createStringError(EC: make_error_code(E: llvm::errc::not_supported), |
377 | Msg: "Operation not supported." ); |
378 | } |
379 | |
380 | virtual void Dump(Stream &s) = 0; |
381 | |
382 | /// Metrics gathering functions |
383 | |
384 | /// Return the size in bytes of all loaded debug information or total possible |
385 | /// debug info in the symbol file. |
386 | /// |
387 | /// If the debug information is contained in sections of an ObjectFile, then |
388 | /// this call should add the size of all sections that contain debug |
389 | /// information. Symbols the symbol tables are not considered debug |
390 | /// information for this call to make it easy and quick for this number to be |
391 | /// calculated. If the symbol file is all debug information, the size of the |
392 | /// entire file should be returned. The default implementation of this |
393 | /// function will iterate over all sections in a module and add up their |
394 | /// debug info only section byte sizes. |
395 | /// |
396 | /// \param load_all_debug_info |
397 | /// If true, force loading any symbol files if they are not yet loaded and |
398 | /// add to the total size. Default to false. |
399 | /// |
400 | /// \returns |
401 | /// Total currently loaded debug info size in bytes |
402 | virtual uint64_t GetDebugInfoSize(bool load_all_debug_info = false) = 0; |
403 | |
404 | /// Return the time taken to parse the debug information. |
405 | /// |
406 | /// \returns 0.0 if no information has been parsed or if there is |
407 | /// no computational cost to parsing the debug information. |
408 | virtual StatsDuration::Duration GetDebugInfoParseTime() { return {}; } |
409 | |
410 | /// Return the time it took to index the debug information in the object |
411 | /// file. |
412 | /// |
413 | /// \returns 0.0 if the file doesn't need to be indexed or if it |
414 | /// hasn't been indexed yet, or a valid duration if it has. |
415 | virtual StatsDuration::Duration GetDebugInfoIndexTime() { return {}; } |
416 | |
417 | /// Get the additional modules that this symbol file uses to parse debug info. |
418 | /// |
419 | /// Some debug info is stored in stand alone object files that are represented |
420 | /// by unique modules that will show up in the statistics module list. Return |
421 | /// a list of modules that are not in the target module list that this symbol |
422 | /// file is currently using so that they can be tracked and assoicated with |
423 | /// the module in the statistics. |
424 | virtual ModuleList GetDebugInfoModules() { return ModuleList(); } |
425 | |
426 | /// Accessors for the bool that indicates if the debug info index was loaded |
427 | /// from, or saved to the module index cache. |
428 | /// |
429 | /// In statistics it is handy to know if a module's debug info was loaded from |
430 | /// or saved to the cache. When the debug info index is loaded from the cache |
431 | /// startup times can be faster. When the cache is enabled and the debug info |
432 | /// index is saved to the cache, debug sessions can be slower. These accessors |
433 | /// can be accessed by the statistics and emitted to help track these costs. |
434 | /// \{ |
435 | virtual bool GetDebugInfoIndexWasLoadedFromCache() const = 0; |
436 | virtual void SetDebugInfoIndexWasLoadedFromCache() = 0; |
437 | virtual bool GetDebugInfoIndexWasSavedToCache() const = 0; |
438 | virtual void SetDebugInfoIndexWasSavedToCache() = 0; |
439 | /// \} |
440 | |
441 | /// Accessors for the bool that indicates if there was debug info, but errors |
442 | /// stopped variables from being able to be displayed correctly. See |
443 | /// GetFrameVariableError() for details on what are considered errors. |
444 | virtual bool GetDebugInfoHadFrameVariableErrors() const = 0; |
445 | virtual void SetDebugInfoHadFrameVariableErrors() = 0; |
446 | |
447 | /// Return true if separate debug info files are supported and this function |
448 | /// succeeded, false otherwise. |
449 | /// |
450 | /// \param[out] d |
451 | /// If this function succeeded, then this will be a dictionary that |
452 | /// contains the keys "type", "symfile", and "separate-debug-info-files". |
453 | /// "type" can be used to assume the structure of each object in |
454 | /// "separate-debug-info-files". |
455 | /// \param errors_only |
456 | /// If true, then only return separate debug info files that encountered |
457 | /// errors during loading. If false, then return all expected separate |
458 | /// debug info files, regardless of whether they were successfully loaded. |
459 | virtual bool GetSeparateDebugInfo(StructuredData::Dictionary &d, |
460 | bool errors_only) { |
461 | return false; |
462 | }; |
463 | |
464 | virtual lldb::TypeSP |
465 | MakeType(lldb::user_id_t uid, ConstString name, |
466 | std::optional<uint64_t> byte_size, SymbolContextScope *context, |
467 | lldb::user_id_t encoding_uid, |
468 | Type::EncodingDataType encoding_uid_type, const Declaration &decl, |
469 | const CompilerType &compiler_qual_type, |
470 | Type::ResolveState compiler_type_resolve_state, |
471 | uint32_t opaque_payload = 0) = 0; |
472 | |
473 | virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0; |
474 | |
475 | /// Returns a map of compilation unit to the compile option arguments |
476 | /// associated with that compilation unit. |
477 | std::unordered_map<lldb::CompUnitSP, Args> GetCompileOptions() { |
478 | std::unordered_map<lldb::CompUnitSP, Args> args; |
479 | GetCompileOptions(args); |
480 | return args; |
481 | } |
482 | |
483 | protected: |
484 | void AssertModuleLock(); |
485 | |
486 | virtual void GetCompileOptions( |
487 | std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {} |
488 | |
489 | private: |
490 | SymbolFile(const SymbolFile &) = delete; |
491 | const SymbolFile &operator=(const SymbolFile &) = delete; |
492 | }; |
493 | |
494 | /// Containing protected virtual methods for child classes to override. |
495 | /// Most actual SymbolFile implementations should inherit from this class. |
496 | class SymbolFileCommon : public SymbolFile { |
497 | /// LLVM RTTI support. |
498 | static char ID; |
499 | |
500 | public: |
501 | /// LLVM RTTI support. |
502 | /// \{ |
503 | bool isA(const void *ClassID) const override { |
504 | return ClassID == &ID || SymbolFile::isA(ClassID); |
505 | } |
506 | static bool classof(const SymbolFileCommon *obj) { return obj->isA(ClassID: &ID); } |
507 | /// \} |
508 | |
509 | // Constructors and Destructors |
510 | SymbolFileCommon(lldb::ObjectFileSP objfile_sp) |
511 | : m_objfile_sp(std::move(objfile_sp)) {} |
512 | |
513 | ~SymbolFileCommon() override = default; |
514 | |
515 | uint32_t GetAbilities() override { |
516 | if (!m_calculated_abilities) { |
517 | m_abilities = CalculateAbilities(); |
518 | m_calculated_abilities = true; |
519 | } |
520 | return m_abilities; |
521 | } |
522 | |
523 | Symtab *GetSymtab() override; |
524 | |
525 | ObjectFile *GetObjectFile() override { return m_objfile_sp.get(); } |
526 | const ObjectFile *GetObjectFile() const override { |
527 | return m_objfile_sp.get(); |
528 | } |
529 | ObjectFile *GetMainObjectFile() override; |
530 | |
531 | /// Notify the SymbolFile that the file addresses in the Sections |
532 | /// for this module have been changed. |
533 | void SectionFileAddressesChanged() override; |
534 | |
535 | // Compile Unit function calls |
536 | // Approach 1 - iterator |
537 | uint32_t GetNumCompileUnits() override; |
538 | lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override; |
539 | |
540 | llvm::Expected<lldb::TypeSystemSP> |
541 | GetTypeSystemForLanguage(lldb::LanguageType language) override; |
542 | |
543 | void Dump(Stream &s) override; |
544 | |
545 | uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override; |
546 | |
547 | bool GetDebugInfoIndexWasLoadedFromCache() const override { |
548 | return m_index_was_loaded_from_cache; |
549 | } |
550 | void SetDebugInfoIndexWasLoadedFromCache() override { |
551 | m_index_was_loaded_from_cache = true; |
552 | } |
553 | bool GetDebugInfoIndexWasSavedToCache() const override { |
554 | return m_index_was_saved_to_cache; |
555 | } |
556 | void SetDebugInfoIndexWasSavedToCache() override { |
557 | m_index_was_saved_to_cache = true; |
558 | } |
559 | bool GetDebugInfoHadFrameVariableErrors() const override { |
560 | return m_debug_info_had_variable_errors; |
561 | } |
562 | void SetDebugInfoHadFrameVariableErrors() override { |
563 | m_debug_info_had_variable_errors = true; |
564 | } |
565 | |
566 | /// This function is used to create types that belong to a SymbolFile. The |
567 | /// symbol file will own a strong reference to the type in an internal type |
568 | /// list. |
569 | lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name, |
570 | std::optional<uint64_t> byte_size, |
571 | SymbolContextScope *context, |
572 | lldb::user_id_t encoding_uid, |
573 | Type::EncodingDataType encoding_uid_type, |
574 | const Declaration &decl, |
575 | const CompilerType &compiler_qual_type, |
576 | Type::ResolveState compiler_type_resolve_state, |
577 | uint32_t opaque_payload = 0) override { |
578 | lldb::TypeSP type_sp (new Type( |
579 | uid, this, name, byte_size, context, encoding_uid, |
580 | encoding_uid_type, decl, compiler_qual_type, |
581 | compiler_type_resolve_state, opaque_payload)); |
582 | m_type_list.Insert(type: type_sp); |
583 | return type_sp; |
584 | } |
585 | |
586 | lldb::TypeSP CopyType(const lldb::TypeSP &other_type) override { |
587 | // Make sure the real symbol file matches when copying types. |
588 | if (GetBackingSymbolFile() != other_type->GetSymbolFile()) |
589 | return lldb::TypeSP(); |
590 | lldb::TypeSP type_sp(new Type(*other_type)); |
591 | m_type_list.Insert(type: type_sp); |
592 | return type_sp; |
593 | } |
594 | |
595 | protected: |
596 | virtual uint32_t CalculateNumCompileUnits() = 0; |
597 | virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0; |
598 | virtual TypeList &GetTypeList() { return m_type_list; } |
599 | void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp); |
600 | |
601 | lldb::ObjectFileSP m_objfile_sp; // Keep a reference to the object file in |
602 | // case it isn't the same as the module |
603 | // object file (debug symbols in a separate |
604 | // file) |
605 | std::optional<std::vector<lldb::CompUnitSP>> m_compile_units; |
606 | TypeList m_type_list; |
607 | uint32_t m_abilities = 0; |
608 | bool m_calculated_abilities = false; |
609 | bool m_index_was_loaded_from_cache = false; |
610 | bool m_index_was_saved_to_cache = false; |
611 | /// Set to true if any variable feteching errors have been found when calling |
612 | /// GetFrameVariableError(). This will be emitted in the "statistics dump" |
613 | /// information for a module. |
614 | bool m_debug_info_had_variable_errors = false; |
615 | |
616 | private: |
617 | SymbolFileCommon(const SymbolFileCommon &) = delete; |
618 | const SymbolFileCommon &operator=(const SymbolFileCommon &) = delete; |
619 | |
620 | /// Do not use m_symtab directly, as it may be freed. Use GetSymtab() |
621 | /// to access it instead. |
622 | Symtab *m_symtab = nullptr; |
623 | }; |
624 | |
625 | } // namespace lldb_private |
626 | |
627 | #endif // LLDB_SYMBOL_SYMBOLFILE_H |
628 | |