1254721Semaste//===-- Module.h ------------------------------------------------*- C++ -*-===//
2254721Semaste//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6254721Semaste//
7254721Semaste//===----------------------------------------------------------------------===//
8254721Semaste
9254721Semaste#ifndef liblldb_Module_h_
10254721Semaste#define liblldb_Module_h_
11254721Semaste
12344779Sdim#include "lldb/Core/Address.h"
13344779Sdim#include "lldb/Core/ModuleSpec.h"
14344779Sdim#include "lldb/Symbol/ObjectFile.h"
15314564Sdim#include "lldb/Symbol/SymbolContextScope.h"
16296417Sdim#include "lldb/Symbol/TypeSystem.h"
17254721Semaste#include "lldb/Target/PathMappingList.h"
18327952Sdim#include "lldb/Utility/ArchSpec.h"
19344779Sdim#include "lldb/Utility/ConstString.h"
20321369Sdim#include "lldb/Utility/FileSpec.h"
21344779Sdim#include "lldb/Utility/Status.h"
22321369Sdim#include "lldb/Utility/UUID.h"
23344779Sdim#include "lldb/lldb-defines.h"
24344779Sdim#include "lldb/lldb-enumerations.h"
25314564Sdim#include "lldb/lldb-forward.h"
26344779Sdim#include "lldb/lldb-types.h"
27314564Sdim
28309124Sdim#include "llvm/ADT/DenseSet.h"
29314564Sdim#include "llvm/ADT/StringRef.h"
30314564Sdim#include "llvm/Support/Chrono.h"
31254721Semaste
32314564Sdim#include <atomic>
33344779Sdim#include <memory>
34314564Sdim#include <mutex>
35344779Sdim#include <stddef.h>
36344779Sdim#include <stdint.h>
37314564Sdim#include <string>
38314564Sdim#include <vector>
39314564Sdim
40254721Semastenamespace lldb_private {
41321369Sdimclass CompilerDeclContext;
42321369Sdimclass Function;
43321369Sdimclass Log;
44321369Sdimclass ObjectFile;
45321369Sdimclass RegularExpression;
46321369Sdimclass SectionList;
47321369Sdimclass Stream;
48321369Sdimclass Symbol;
49321369Sdimclass SymbolContext;
50321369Sdimclass SymbolContextList;
51321369Sdimclass SymbolFile;
52321369Sdimclass Symtab;
53321369Sdimclass Target;
54321369Sdimclass TypeList;
55321369Sdimclass TypeMap;
56321369Sdimclass VariableList;
57254721Semaste
58353358Sdim/// \class Module Module.h "lldb/Core/Module.h"
59341825Sdim/// A class that describes an executable image and its associated
60254721Semaste///        object and symbol files.
61254721Semaste///
62254721Semaste/// The module is designed to be able to select a single slice of an
63341825Sdim/// executable image as it would appear on disk and during program execution.
64254721Semaste///
65254721Semaste/// Modules control when and if information is parsed according to which
66254721Semaste/// accessors are called. For example the object file (ObjectFile)
67341825Sdim/// representation will only be parsed if the object file is requested using
68341825Sdim/// the Module::GetObjectFile() is called. The debug symbols will only be
69360784Sdim/// parsed if the symbol file (SymbolFile) is requested using the
70360784Sdim/// Module::GetSymbolFile() method.
71254721Semaste///
72341825Sdim/// The module will parse more detailed information as more queries are made.
73314564Sdimclass Module : public std::enable_shared_from_this<Module>,
74314564Sdim               public SymbolContextScope {
75254721Semastepublic:
76341825Sdim  // Static functions that can track the lifetime of module objects. This is
77341825Sdim  // handy because we might have Module objects that are in shared pointers
78341825Sdim  // that aren't in the global module list (from ModuleList). If this is the
79341825Sdim  // case we need to know about it. The modules in the global list maintained
80341825Sdim  // by these functions can be viewed using the "target modules list" command
81341825Sdim  // using the "--global" (-g for short).
82314564Sdim  static size_t GetNumberAllocatedModules();
83254721Semaste
84314564Sdim  static Module *GetAllocatedModuleAtIndex(size_t idx);
85254721Semaste
86314564Sdim  static std::recursive_mutex &GetAllocationModuleCollectionMutex();
87254721Semaste
88314564Sdim  /// Construct with file specification and architecture.
89314564Sdim  ///
90341825Sdim  /// Clients that wish to share modules with other targets should use
91341825Sdim  /// ModuleList::GetSharedModule().
92314564Sdim  ///
93353358Sdim  /// \param[in] file_spec
94314564Sdim  ///     The file specification for the on disk representation of
95314564Sdim  ///     this executable image.
96314564Sdim  ///
97353358Sdim  /// \param[in] arch
98314564Sdim  ///     The architecture to set as the current architecture in
99314564Sdim  ///     this module.
100314564Sdim  ///
101353358Sdim  /// \param[in] object_name
102314564Sdim  ///     The name of an object in a module used to extract a module
103314564Sdim  ///     within a module (.a files and modules that contain multiple
104314564Sdim  ///     architectures).
105314564Sdim  ///
106353358Sdim  /// \param[in] object_offset
107314564Sdim  ///     The offset within an existing module used to extract a
108314564Sdim  ///     module within a module (.a files and modules that contain
109314564Sdim  ///     multiple architectures).
110314564Sdim  Module(
111314564Sdim      const FileSpec &file_spec, const ArchSpec &arch,
112314564Sdim      const ConstString *object_name = nullptr,
113314564Sdim      lldb::offset_t object_offset = 0,
114314564Sdim      const llvm::sys::TimePoint<> &object_mod_time = llvm::sys::TimePoint<>());
115254721Semaste
116314564Sdim  Module(const ModuleSpec &module_spec);
117254721Semaste
118341825Sdim  template <typename ObjFilePlugin, typename... Args>
119341825Sdim  static lldb::ModuleSP CreateModuleFromObjectFile(Args &&... args) {
120341825Sdim    // Must create a module and place it into a shared pointer before we can
121341825Sdim    // create an object file since it has a std::weak_ptr back to the module,
122341825Sdim    // so we need to control the creation carefully in this static function
123341825Sdim    lldb::ModuleSP module_sp(new Module());
124341825Sdim    module_sp->m_objfile_sp =
125341825Sdim        std::make_shared<ObjFilePlugin>(module_sp, std::forward<Args>(args)...);
126353358Sdim    module_sp->m_did_load_objfile.store(true, std::memory_order_relaxed);
127254721Semaste
128353358Sdim    // Once we get the object file, set module ArchSpec to the one we get from
129353358Sdim    // the object file. If the object file does not have an architecture, we
130353358Sdim    // consider the creation a failure.
131353358Sdim    ArchSpec arch = module_sp->m_objfile_sp->GetArchitecture();
132353358Sdim    if (!arch)
133353358Sdim      return nullptr;
134353358Sdim    module_sp->m_arch = arch;
135353358Sdim
136353358Sdim    // Also copy the object file's FileSpec.
137353358Sdim    module_sp->m_file = module_sp->m_objfile_sp->GetFileSpec();
138353358Sdim    return module_sp;
139341825Sdim  }
140341825Sdim
141314564Sdim  /// Destructor.
142314564Sdim  ~Module() override;
143254721Semaste
144314564Sdim  bool MatchesModuleSpec(const ModuleSpec &module_ref);
145254721Semaste
146341825Sdim  /// Set the load address for all sections in a module to be the file address
147341825Sdim  /// plus \a slide.
148314564Sdim  ///
149341825Sdim  /// Many times a module will be loaded in a target with a constant offset
150341825Sdim  /// applied to all top level sections. This function can set the load
151341825Sdim  /// address for all top level sections to be the section file address +
152341825Sdim  /// offset.
153314564Sdim  ///
154353358Sdim  /// \param[in] target
155314564Sdim  ///     The target in which to apply the section load addresses.
156314564Sdim  ///
157353358Sdim  /// \param[in] value
158314564Sdim  ///     if \a value_is_offset is true, then value is the offset to
159314564Sdim  ///     apply to all file addresses for all top level sections in
160314564Sdim  ///     the object file as each section load address is being set.
161314564Sdim  ///     If \a value_is_offset is false, then "value" is the new
162314564Sdim  ///     absolute base address for the image.
163314564Sdim  ///
164353358Sdim  /// \param[in] value_is_offset
165314564Sdim  ///     If \b true, then \a value is an offset to apply to each
166314564Sdim  ///     file address of each top level section.
167314564Sdim  ///     If \b false, then \a value is the image base address that
168314564Sdim  ///     will be used to rigidly slide all loadable sections.
169314564Sdim  ///
170353358Sdim  /// \param[out] changed
171314564Sdim  ///     If any section load addresses were changed in \a target,
172314564Sdim  ///     then \a changed will be set to \b true. Else \a changed
173314564Sdim  ///     will be set to false. This allows this function to be
174314564Sdim  ///     called multiple times on the same module for the same
175314564Sdim  ///     target. If the module hasn't moved, then \a changed will
176314564Sdim  ///     be false and no module updated notification will need to
177314564Sdim  ///     be sent out.
178314564Sdim  ///
179353358Sdim  /// \return
180314564Sdim  ///     /b True if any sections were successfully loaded in \a target,
181314564Sdim  ///     /b false otherwise.
182314564Sdim  bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset,
183314564Sdim                      bool &changed);
184254721Semaste
185353358Sdim  /// \copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
186314564Sdim  ///
187353358Sdim  /// \see SymbolContextScope
188314564Sdim  void CalculateSymbolContext(SymbolContext *sc) override;
189254721Semaste
190314564Sdim  lldb::ModuleSP CalculateSymbolContextModule() override;
191254721Semaste
192314564Sdim  void
193360784Sdim  GetDescription(llvm::raw_ostream &s,
194314564Sdim                 lldb::DescriptionLevel level = lldb::eDescriptionLevelFull);
195254721Semaste
196314564Sdim  /// Get the module path and object name.
197314564Sdim  ///
198341825Sdim  /// Modules can refer to object files. In this case the specification is
199341825Sdim  /// simple and would return the path to the file:
200314564Sdim  ///
201314564Sdim  ///     "/usr/lib/foo.dylib"
202314564Sdim  ///
203341825Sdim  /// Modules can be .o files inside of a BSD archive (.a file). In this case,
204341825Sdim  /// the object specification will look like:
205314564Sdim  ///
206314564Sdim  ///     "/usr/lib/foo.a(bar.o)"
207314564Sdim  ///
208341825Sdim  /// There are many places where logging wants to log this fully qualified
209341825Sdim  /// specification, so we centralize this functionality here.
210314564Sdim  ///
211353358Sdim  /// \return
212314564Sdim  ///     The object path + object name if there is one.
213314564Sdim  std::string GetSpecificationDescription() const;
214254721Semaste
215314564Sdim  /// Dump a description of this object to a Stream.
216314564Sdim  ///
217341825Sdim  /// Dump a description of the contents of this object to the supplied stream
218341825Sdim  /// \a s. The dumped content will be only what has been loaded or parsed up
219341825Sdim  /// to this point at which this function is called, so this is a good way to
220341825Sdim  /// see what has been parsed in a module.
221314564Sdim  ///
222353358Sdim  /// \param[in] s
223314564Sdim  ///     The stream to which to dump the object description.
224314564Sdim  void Dump(Stream *s);
225254721Semaste
226353358Sdim  /// \copydoc SymbolContextScope::DumpSymbolContext(Stream*)
227314564Sdim  ///
228353358Sdim  /// \see SymbolContextScope
229314564Sdim  void DumpSymbolContext(Stream *s) override;
230254721Semaste
231314564Sdim  /// Find a symbol in the object file's symbol table.
232314564Sdim  ///
233353358Sdim  /// \param[in] name
234314564Sdim  ///     The name of the symbol that we are looking for.
235314564Sdim  ///
236353358Sdim  /// \param[in] symbol_type
237314564Sdim  ///     If set to eSymbolTypeAny, find a symbol of any type that
238314564Sdim  ///     has a name that matches \a name. If set to any other valid
239314564Sdim  ///     SymbolType enumeration value, then search only for
240314564Sdim  ///     symbols that match \a symbol_type.
241314564Sdim  ///
242353358Sdim  /// \return
243314564Sdim  ///     Returns a valid symbol pointer if a symbol was found,
244314564Sdim  ///     nullptr otherwise.
245314564Sdim  const Symbol *FindFirstSymbolWithNameAndType(
246353358Sdim      ConstString name,
247314564Sdim      lldb::SymbolType symbol_type = lldb::eSymbolTypeAny);
248254721Semaste
249360784Sdim  void FindSymbolsWithNameAndType(ConstString name,
250360784Sdim                                  lldb::SymbolType symbol_type,
251360784Sdim                                  SymbolContextList &sc_list);
252254721Semaste
253360784Sdim  void FindSymbolsMatchingRegExAndType(const RegularExpression &regex,
254360784Sdim                                       lldb::SymbolType symbol_type,
255360784Sdim                                       SymbolContextList &sc_list);
256258054Semaste
257314564Sdim  /// Find a function symbols in the object file's symbol table.
258314564Sdim  ///
259353358Sdim  /// \param[in] name
260314564Sdim  ///     The name of the symbol that we are looking for.
261314564Sdim  ///
262353358Sdim  /// \param[in] name_type_mask
263314564Sdim  ///     A mask that has one or more bitwise OR'ed values from the
264314564Sdim  ///     lldb::FunctionNameType enumeration type that indicate what
265314564Sdim  ///     kind of names we are looking for.
266314564Sdim  ///
267353358Sdim  /// \param[out] sc_list
268314564Sdim  ///     A list to append any matching symbol contexts to.
269360784Sdim  void FindFunctionSymbols(ConstString name, uint32_t name_type_mask,
270360784Sdim                           SymbolContextList &sc_list);
271254721Semaste
272314564Sdim  /// Find compile units by partial or full path.
273314564Sdim  ///
274341825Sdim  /// Finds all compile units that match \a path in all of the modules and
275341825Sdim  /// returns the results in \a sc_list.
276314564Sdim  ///
277353358Sdim  /// \param[in] path
278314564Sdim  ///     The name of the function we are looking for.
279314564Sdim  ///
280353358Sdim  /// \param[out] sc_list
281314564Sdim  ///     A symbol context list that gets filled in with all of the
282314564Sdim  ///     matches.
283360784Sdim  void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list);
284254721Semaste
285314564Sdim  /// Find functions by name.
286314564Sdim  ///
287314564Sdim  /// If the function is an inlined function, it will have a block,
288314564Sdim  /// representing the inlined function, and the function will be the
289341825Sdim  /// containing function.  If it is not inlined, then the block will be NULL.
290314564Sdim  ///
291353358Sdim  /// \param[in] name
292314564Sdim  ///     The name of the compile unit we are looking for.
293314564Sdim  ///
294353358Sdim  /// \param[in] name_type_mask
295314564Sdim  ///     A bit mask of bits that indicate what kind of names should
296314564Sdim  ///     be used when doing the lookup. Bits include fully qualified
297314564Sdim  ///     names, base names, C++ methods, or ObjC selectors.
298314564Sdim  ///     See FunctionNameType for more details.
299314564Sdim  ///
300353358Sdim  /// \param[out] sc_list
301314564Sdim  ///     A symbol context list that gets filled in with all of the
302314564Sdim  ///     matches.
303360784Sdim  void FindFunctions(ConstString name,
304360784Sdim                     const CompilerDeclContext *parent_decl_ctx,
305360784Sdim                     lldb::FunctionNameType name_type_mask, bool symbols_ok,
306360784Sdim                     bool inlines_ok, SymbolContextList &sc_list);
307254721Semaste
308314564Sdim  /// Find functions by name.
309314564Sdim  ///
310314564Sdim  /// If the function is an inlined function, it will have a block,
311314564Sdim  /// representing the inlined function, and the function will be the
312341825Sdim  /// containing function.  If it is not inlined, then the block will be NULL.
313314564Sdim  ///
314353358Sdim  /// \param[in] regex
315314564Sdim  ///     A regular expression to use when matching the name.
316314564Sdim  ///
317353358Sdim  /// \param[out] sc_list
318314564Sdim  ///     A symbol context list that gets filled in with all of the
319314564Sdim  ///     matches.
320360784Sdim  void FindFunctions(const RegularExpression &regex, bool symbols_ok,
321360784Sdim                     bool inlines_ok, SymbolContextList &sc_list);
322254721Semaste
323314564Sdim  /// Find addresses by file/line
324314564Sdim  ///
325353358Sdim  /// \param[in] target_sp
326314564Sdim  ///     The target the addresses are desired for.
327314564Sdim  ///
328353358Sdim  /// \param[in] file
329314564Sdim  ///     Source file to locate.
330314564Sdim  ///
331353358Sdim  /// \param[in] line
332314564Sdim  ///     Source line to locate.
333314564Sdim  ///
334353358Sdim  /// \param[in] function
335314564Sdim  ///	    Optional filter function. Addresses within this function will be
336314564Sdim  ///     added to the 'local' list. All others will be added to the 'extern'
337314564Sdim  ///     list.
338314564Sdim  ///
339353358Sdim  /// \param[out] output_local
340314564Sdim  ///     All matching addresses within 'function'
341314564Sdim  ///
342353358Sdim  /// \param[out] output_extern
343314564Sdim  ///     All matching addresses not within 'function'
344314564Sdim  void FindAddressesForLine(const lldb::TargetSP target_sp,
345314564Sdim                            const FileSpec &file, uint32_t line,
346314564Sdim                            Function *function,
347314564Sdim                            std::vector<Address> &output_local,
348314564Sdim                            std::vector<Address> &output_extern);
349254721Semaste
350314564Sdim  /// Find global and static variables by name.
351314564Sdim  ///
352353358Sdim  /// \param[in] name
353314564Sdim  ///     The name of the global or static variable we are looking
354314564Sdim  ///     for.
355314564Sdim  ///
356353358Sdim  /// \param[in] parent_decl_ctx
357314564Sdim  ///     If valid, a decl context that results must exist within
358314564Sdim  ///
359353358Sdim  /// \param[in] max_matches
360314564Sdim  ///     Allow the number of matches to be limited to \a
361314564Sdim  ///     max_matches. Specify UINT32_MAX to get all possible matches.
362314564Sdim  ///
363353358Sdim  /// \param[in] variable_list
364341825Sdim  ///     A list of variables that gets the matches appended to.
365314564Sdim  ///
366360784Sdim  void FindGlobalVariables(ConstString name,
367360784Sdim                           const CompilerDeclContext *parent_decl_ctx,
368360784Sdim                           size_t max_matches, VariableList &variable_list);
369254721Semaste
370314564Sdim  /// Find global and static variables by regular expression.
371314564Sdim  ///
372353358Sdim  /// \param[in] regex
373314564Sdim  ///     A regular expression to use when matching the name.
374314564Sdim  ///
375353358Sdim  /// \param[in] max_matches
376314564Sdim  ///     Allow the number of matches to be limited to \a
377314564Sdim  ///     max_matches. Specify UINT32_MAX to get all possible matches.
378314564Sdim  ///
379353358Sdim  /// \param[in] variable_list
380341825Sdim  ///     A list of variables that gets the matches appended to.
381314564Sdim  ///
382360784Sdim  void FindGlobalVariables(const RegularExpression &regex, size_t max_matches,
383360784Sdim                           VariableList &variable_list);
384254721Semaste
385314564Sdim  /// Find types by name.
386314564Sdim  ///
387360784Sdim  /// Type lookups in modules go through the SymbolFile. The SymbolFile needs to
388360784Sdim  /// be able to lookup types by basename and not the fully qualified typename.
389360784Sdim  /// This allows the type accelerator tables to stay small, even with heavily
390341825Sdim  /// templatized C++. The type search will then narrow down the search
391341825Sdim  /// results. If "exact_match" is true, then the type search will only match
392341825Sdim  /// exact type name matches. If "exact_match" is false, the type will match
393341825Sdim  /// as long as the base typename matches and as long as any immediate
394341825Sdim  /// containing namespaces/class scopes that are specified match. So to
395341825Sdim  /// search for a type "d" in "b::c", the name "b::c::d" can be specified and
396341825Sdim  /// it will match any class/namespace "b" which contains a class/namespace
397341825Sdim  /// "c" which contains type "d". We do this to allow users to not always
398341825Sdim  /// have to specify complete scoping on all expressions, but it also allows
399341825Sdim  /// for exact matching when required.
400314564Sdim  ///
401353358Sdim  /// \param[in] type_name
402314564Sdim  ///     The name of the type we are looking for that is a fully
403314564Sdim  ///     or partially qualified type name.
404314564Sdim  ///
405353358Sdim  /// \param[in] exact_match
406314564Sdim  ///     If \b true, \a type_name is fully qualified and must match
407314564Sdim  ///     exactly. If \b false, \a type_name is a partially qualified
408314564Sdim  ///     name where the leading namespaces or classes can be
409314564Sdim  ///     omitted to make finding types that a user may type
410314564Sdim  ///     easier.
411314564Sdim  ///
412360784Sdim  /// \param[out] types
413314564Sdim  ///     A type list gets populated with any matches.
414314564Sdim  ///
415360784Sdim  void
416353358Sdim  FindTypes(ConstString type_name, bool exact_match, size_t max_matches,
417314564Sdim            llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
418314564Sdim            TypeList &types);
419254721Semaste
420360784Sdim  /// Find types by name.
421360784Sdim  ///
422360784Sdim  /// This behaves like the other FindTypes method but allows to
423360784Sdim  /// specify a DeclContext and a language for the type being searched
424360784Sdim  /// for.
425360784Sdim  ///
426360784Sdim  /// \param searched_symbol_files
427360784Sdim  ///     Prevents one file from being visited multiple times.
428360784Sdim  void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
429360784Sdim                 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
430360784Sdim                 TypeMap &types);
431360784Sdim
432314564Sdim  lldb::TypeSP FindFirstType(const SymbolContext &sc,
433353358Sdim                             ConstString type_name, bool exact_match);
434254721Semaste
435341825Sdim  /// Find types by name that are in a namespace. This function is used by the
436341825Sdim  /// expression parser when searches need to happen in an exact namespace
437341825Sdim  /// scope.
438314564Sdim  ///
439353358Sdim  /// \param[in] type_name
440314564Sdim  ///     The name of a type within a namespace that should not include
441314564Sdim  ///     any qualifying namespaces (just a type basename).
442314564Sdim  ///
443353358Sdim  /// \param[out] type_list
444314564Sdim  ///     A type list gets populated with any matches.
445360784Sdim  void FindTypesInNamespace(ConstString type_name,
446360784Sdim                            const CompilerDeclContext *parent_decl_ctx,
447360784Sdim                            size_t max_matches, TypeList &type_list);
448254721Semaste
449314564Sdim  /// Get const accessor for the module architecture.
450314564Sdim  ///
451353358Sdim  /// \return
452314564Sdim  ///     A const reference to the architecture object.
453314564Sdim  const ArchSpec &GetArchitecture() const;
454254721Semaste
455314564Sdim  /// Get const accessor for the module file specification.
456314564Sdim  ///
457341825Sdim  /// This function returns the file for the module on the host system that is
458341825Sdim  /// running LLDB. This can differ from the path on the platform since we
459341825Sdim  /// might be doing remote debugging.
460314564Sdim  ///
461353358Sdim  /// \return
462314564Sdim  ///     A const reference to the file specification object.
463314564Sdim  const FileSpec &GetFileSpec() const { return m_file; }
464254721Semaste
465314564Sdim  /// Get accessor for the module platform file specification.
466314564Sdim  ///
467341825Sdim  /// Platform file refers to the path of the module as it is known on the
468341825Sdim  /// remote system on which it is being debugged. For local debugging this is
469341825Sdim  /// always the same as Module::GetFileSpec(). But remote debugging might
470341825Sdim  /// mention a file "/usr/lib/liba.dylib" which might be locally downloaded
471341825Sdim  /// and cached. In this case the platform file could be something like:
472341825Sdim  /// "/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib" The
473341825Sdim  /// file could also be cached in a local developer kit directory.
474314564Sdim  ///
475353358Sdim  /// \return
476314564Sdim  ///     A const reference to the file specification object.
477314564Sdim  const FileSpec &GetPlatformFileSpec() const {
478314564Sdim    if (m_platform_file)
479314564Sdim      return m_platform_file;
480314564Sdim    return m_file;
481314564Sdim  }
482254721Semaste
483314564Sdim  void SetPlatformFileSpec(const FileSpec &file) { m_platform_file = file; }
484254721Semaste
485314564Sdim  const FileSpec &GetRemoteInstallFileSpec() const {
486314564Sdim    return m_remote_install_file;
487314564Sdim  }
488296417Sdim
489314564Sdim  void SetRemoteInstallFileSpec(const FileSpec &file) {
490314564Sdim    m_remote_install_file = file;
491314564Sdim  }
492254721Semaste
493314564Sdim  const FileSpec &GetSymbolFileFileSpec() const { return m_symfile_spec; }
494254721Semaste
495321369Sdim  void PreloadSymbols();
496321369Sdim
497314564Sdim  void SetSymbolFileFileSpec(const FileSpec &file);
498254721Semaste
499314564Sdim  const llvm::sys::TimePoint<> &GetModificationTime() const {
500314564Sdim    return m_mod_time;
501314564Sdim  }
502254721Semaste
503314564Sdim  const llvm::sys::TimePoint<> &GetObjectModificationTime() const {
504314564Sdim    return m_object_mod_time;
505314564Sdim  }
506254721Semaste
507314564Sdim  void SetObjectModificationTime(const llvm::sys::TimePoint<> &mod_time) {
508314564Sdim    m_mod_time = mod_time;
509314564Sdim  }
510254721Semaste
511341825Sdim  /// Tells whether this module is capable of being the main executable for a
512341825Sdim  /// process.
513314564Sdim  ///
514353358Sdim  /// \return
515314564Sdim  ///     \b true if it is, \b false otherwise.
516314564Sdim  bool IsExecutable();
517276479Sdim
518341825Sdim  /// Tells whether this module has been loaded in the target passed in. This
519341825Sdim  /// call doesn't distinguish between whether the module is loaded by the
520341825Sdim  /// dynamic loader, or by a "target module add" type call.
521314564Sdim  ///
522353358Sdim  /// \param[in] target
523314564Sdim  ///    The target to check whether this is loaded in.
524314564Sdim  ///
525353358Sdim  /// \return
526314564Sdim  ///     \b true if it is, \b false otherwise.
527314564Sdim  bool IsLoadedInTarget(Target *target);
528254721Semaste
529321369Sdim  bool LoadScriptingResourceInTarget(Target *target, Status &error,
530314564Sdim                                     Stream *feedback_stream = nullptr);
531254721Semaste
532314564Sdim  /// Get the number of compile units for this module.
533314564Sdim  ///
534353358Sdim  /// \return
535314564Sdim  ///     The number of compile units that the symbol vendor plug-in
536314564Sdim  ///     finds.
537314564Sdim  size_t GetNumCompileUnits();
538254721Semaste
539314564Sdim  lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx);
540254721Semaste
541353358Sdim  ConstString GetObjectName() const;
542254721Semaste
543314564Sdim  uint64_t GetObjectOffset() const { return m_object_offset; }
544254721Semaste
545314564Sdim  /// Get the object file representation for the current architecture.
546314564Sdim  ///
547341825Sdim  /// If the object file has not been located or parsed yet, this function
548341825Sdim  /// will find the best ObjectFile plug-in that can parse Module::m_file.
549314564Sdim  ///
550353358Sdim  /// \return
551314564Sdim  ///     If Module::m_file does not exist, or no plug-in was found
552314564Sdim  ///     that can parse the file, or the object file doesn't contain
553314564Sdim  ///     the current architecture in Module::m_arch, nullptr will be
554314564Sdim  ///     returned, else a valid object file interface will be
555314564Sdim  ///     returned. The returned pointer is owned by this object and
556314564Sdim  ///     remains valid as long as the object is around.
557314564Sdim  virtual ObjectFile *GetObjectFile();
558254721Semaste
559341825Sdim  /// Get the unified section list for the module. This is the section list
560341825Sdim  /// created by the module's object file and any debug info and symbol files
561341825Sdim  /// created by the symbol vendor.
562314564Sdim  ///
563341825Sdim  /// If the symbol vendor has not been loaded yet, this function will return
564341825Sdim  /// the section list for the object file.
565314564Sdim  ///
566353358Sdim  /// \return
567314564Sdim  ///     Unified module section list.
568314564Sdim  virtual SectionList *GetSectionList();
569254721Semaste
570341825Sdim  /// Notify the module that the file addresses for the Sections have been
571341825Sdim  /// updated.
572314564Sdim  ///
573341825Sdim  /// If the Section file addresses for a module are updated, this method
574341825Sdim  /// should be called.  Any parts of the module, object file, or symbol file
575341825Sdim  /// that has cached those file addresses must invalidate or update its
576341825Sdim  /// cache.
577314564Sdim  virtual void SectionFileAddressesChanged();
578254721Semaste
579353358Sdim  /// Returns a reference to the UnwindTable for this Module
580353358Sdim  ///
581353358Sdim  /// The UnwindTable contains FuncUnwinders objects for any function in this
582353358Sdim  /// Module.  If a FuncUnwinders object hasn't been created yet (i.e. the
583353358Sdim  /// function has yet to be unwound in a stack walk), it will be created when
584353358Sdim  /// requested.  Specifically, we do not create FuncUnwinders objects for
585353358Sdim  /// functions until they are needed.
586353358Sdim  ///
587353358Sdim  /// \return
588353358Sdim  ///     Returns the unwind table for this module. If this object has no
589353358Sdim  ///     associated object file, an empty UnwindTable is returned.
590353358Sdim  UnwindTable &GetUnwindTable();
591353358Sdim
592341825Sdim  llvm::VersionTuple GetVersion();
593254721Semaste
594314564Sdim  /// Load an object file from memory.
595314564Sdim  ///
596341825Sdim  /// If available, the size of the object file in memory may be passed to
597341825Sdim  /// avoid additional round trips to process memory. If the size is not
598341825Sdim  /// provided, a default value is used. This value should be large enough to
599341825Sdim  /// enable the ObjectFile plugins to read the header of the object file
600341825Sdim  /// without going back to the process.
601314564Sdim  ///
602353358Sdim  /// \return
603314564Sdim  ///     The object file loaded from memory or nullptr, if the operation
604314564Sdim  ///     failed (see the `error` for more information in that case).
605314564Sdim  ObjectFile *GetMemoryObjectFile(const lldb::ProcessSP &process_sp,
606321369Sdim                                  lldb::addr_t header_addr, Status &error,
607314564Sdim                                  size_t size_to_read = 512);
608288943Sdim
609360784Sdim  /// Get the module's symbol file
610314564Sdim  ///
611360784Sdim  /// If the symbol file has already been loaded, this function returns it. All
612360784Sdim  /// arguments are ignored. If the symbol file has not been located yet, and
613360784Sdim  /// the can_create argument is false, the function returns nullptr. If
614360784Sdim  /// can_create is true, this function will find the best SymbolFile plug-in
615360784Sdim  /// that can use the current object file. feedback_strm, if not null, is used
616360784Sdim  /// to report the details of the search process.
617360784Sdim  virtual SymbolFile *GetSymbolFile(bool can_create = true,
618360784Sdim                                    Stream *feedback_strm = nullptr);
619254721Semaste
620360784Sdim  Symtab *GetSymtab();
621360784Sdim
622341825Sdim  /// Get a reference to the UUID value contained in this object.
623314564Sdim  ///
624341825Sdim  /// If the executable image file doesn't not have a UUID value built into
625341825Sdim  /// the file format, an MD5 checksum of the entire file, or slice of the
626341825Sdim  /// file for the current architecture should be used.
627314564Sdim  ///
628353358Sdim  /// \return
629314564Sdim  ///     A const pointer to the internal copy of the UUID value in
630314564Sdim  ///     this module if this module has a valid UUID value, NULL
631314564Sdim  ///     otherwise.
632314564Sdim  const lldb_private::UUID &GetUUID();
633254721Semaste
634314564Sdim  /// A debugging function that will cause everything in a module to
635314564Sdim  /// be parsed.
636314564Sdim  ///
637341825Sdim  /// All compile units will be parsed, along with all globals and static
638341825Sdim  /// variables and all functions for those compile units. All types, scopes,
639341825Sdim  /// local variables, static variables, global variables, and line tables
640341825Sdim  /// will be parsed. This can be used prior to dumping a module to see a
641341825Sdim  /// complete list of the resulting debug information that gets parsed, or as
642341825Sdim  /// a debug function to ensure that the module can consume all of the debug
643341825Sdim  /// data the symbol vendor provides.
644314564Sdim  void ParseAllDebugSymbols();
645254721Semaste
646314564Sdim  bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr);
647254721Semaste
648314564Sdim  /// Resolve the symbol context for the given address.
649314564Sdim  ///
650341825Sdim  /// Tries to resolve the matching symbol context based on a lookup from the
651341825Sdim  /// current symbol vendor.  If the lazy lookup fails, an attempt is made to
652341825Sdim  /// parse the eh_frame section to handle stripped symbols.  If this fails,
653341825Sdim  /// an attempt is made to resolve the symbol to the previous address to
654341825Sdim  /// handle the case of a function with a tail call.
655314564Sdim  ///
656341825Sdim  /// Use properties of the modified SymbolContext to inspect any resolved
657341825Sdim  /// target, module, compilation unit, symbol, function, function block or
658341825Sdim  /// line entry.  Use the return value to determine which of these properties
659341825Sdim  /// have been modified.
660314564Sdim  ///
661353358Sdim  /// \param[in] so_addr
662314564Sdim  ///     A load address to resolve.
663314564Sdim  ///
664353358Sdim  /// \param[in] resolve_scope
665314564Sdim  ///     The scope that should be resolved (see SymbolContext::Scope).
666314564Sdim  ///     A combination of flags from the enumeration SymbolContextItem
667314564Sdim  ///     requesting a resolution depth.  Note that the flags that are
668314564Sdim  ///     actually resolved may be a superset of the requested flags.
669314564Sdim  ///     For instance, eSymbolContextSymbol requires resolution of
670314564Sdim  ///     eSymbolContextModule, and eSymbolContextFunction requires
671314564Sdim  ///     eSymbolContextSymbol.
672314564Sdim  ///
673353358Sdim  /// \param[out] sc
674314564Sdim  ///     The SymbolContext that is modified based on symbol resolution.
675314564Sdim  ///
676353358Sdim  /// \param[in] resolve_tail_call_address
677314564Sdim  ///     Determines if so_addr should resolve to a symbol in the case
678314564Sdim  ///     of a function whose last instruction is a call.  In this case,
679314564Sdim  ///     the PC can be one past the address range of the function.
680314564Sdim  ///
681353358Sdim  /// \return
682314564Sdim  ///     The scope that has been resolved (see SymbolContext::Scope).
683314564Sdim  ///
684353358Sdim  /// \see SymbolContext::Scope
685344779Sdim  uint32_t ResolveSymbolContextForAddress(
686344779Sdim      const Address &so_addr, lldb::SymbolContextItem resolve_scope,
687344779Sdim      SymbolContext &sc, bool resolve_tail_call_address = false);
688254721Semaste
689314564Sdim  /// Resolve items in the symbol context for a given file and line.
690314564Sdim  ///
691341825Sdim  /// Tries to resolve \a file_path and \a line to a list of matching symbol
692341825Sdim  /// contexts.
693314564Sdim  ///
694341825Sdim  /// The line table entries contains addresses that can be used to further
695341825Sdim  /// resolve the values in each match: the function, block, symbol. Care
696341825Sdim  /// should be taken to minimize the amount of information that is requested
697341825Sdim  /// to only what is needed -- typically the module, compile unit, line table
698341825Sdim  /// and line table entry are sufficient.
699314564Sdim  ///
700353358Sdim  /// \param[in] file_path
701314564Sdim  ///     A path to a source file to match. If \a file_path does not
702314564Sdim  ///     specify a directory, then this query will match all files
703314564Sdim  ///     whose base filename matches. If \a file_path does specify
704314564Sdim  ///     a directory, the fullpath to the file must match.
705314564Sdim  ///
706353358Sdim  /// \param[in] line
707314564Sdim  ///     The source line to match, or zero if just the compile unit
708314564Sdim  ///     should be resolved.
709314564Sdim  ///
710353358Sdim  /// \param[in] check_inlines
711314564Sdim  ///     Check for inline file and line number matches. This option
712314564Sdim  ///     should be used sparingly as it will cause all line tables
713314564Sdim  ///     for every compile unit to be parsed and searched for
714314564Sdim  ///     matching inline file entries.
715314564Sdim  ///
716353358Sdim  /// \param[in] resolve_scope
717314564Sdim  ///     The scope that should be resolved (see
718314564Sdim  ///     SymbolContext::Scope).
719314564Sdim  ///
720353358Sdim  /// \param[out] sc_list
721314564Sdim  ///     A symbol context list that gets matching symbols contexts
722314564Sdim  ///     appended to.
723314564Sdim  ///
724353358Sdim  /// \return
725314564Sdim  ///     The number of matches that were added to \a sc_list.
726314564Sdim  ///
727353358Sdim  /// \see SymbolContext::Scope
728344779Sdim  uint32_t ResolveSymbolContextForFilePath(
729344779Sdim      const char *file_path, uint32_t line, bool check_inlines,
730344779Sdim      lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list);
731254721Semaste
732314564Sdim  /// Resolve items in the symbol context for a given file and line.
733314564Sdim  ///
734341825Sdim  /// Tries to resolve \a file_spec and \a line to a list of matching symbol
735341825Sdim  /// contexts.
736314564Sdim  ///
737341825Sdim  /// The line table entries contains addresses that can be used to further
738341825Sdim  /// resolve the values in each match: the function, block, symbol. Care
739341825Sdim  /// should be taken to minimize the amount of information that is requested
740341825Sdim  /// to only what is needed -- typically the module, compile unit, line table
741341825Sdim  /// and line table entry are sufficient.
742314564Sdim  ///
743353358Sdim  /// \param[in] file_spec
744314564Sdim  ///     A file spec to a source file to match. If \a file_path does
745314564Sdim  ///     not specify a directory, then this query will match all
746314564Sdim  ///     files whose base filename matches. If \a file_path does
747314564Sdim  ///     specify a directory, the fullpath to the file must match.
748314564Sdim  ///
749353358Sdim  /// \param[in] line
750314564Sdim  ///     The source line to match, or zero if just the compile unit
751314564Sdim  ///     should be resolved.
752314564Sdim  ///
753353358Sdim  /// \param[in] check_inlines
754314564Sdim  ///     Check for inline file and line number matches. This option
755314564Sdim  ///     should be used sparingly as it will cause all line tables
756314564Sdim  ///     for every compile unit to be parsed and searched for
757314564Sdim  ///     matching inline file entries.
758314564Sdim  ///
759353358Sdim  /// \param[in] resolve_scope
760314564Sdim  ///     The scope that should be resolved (see
761314564Sdim  ///     SymbolContext::Scope).
762314564Sdim  ///
763353358Sdim  /// \param[out] sc_list
764314564Sdim  ///     A symbol context list that gets filled in with all of the
765314564Sdim  ///     matches.
766314564Sdim  ///
767353358Sdim  /// \return
768314564Sdim  ///     A integer that contains SymbolContext::Scope bits set for
769314564Sdim  ///     each item that was successfully resolved.
770314564Sdim  ///
771353358Sdim  /// \see SymbolContext::Scope
772344779Sdim  uint32_t ResolveSymbolContextsForFileSpec(
773344779Sdim      const FileSpec &file_spec, uint32_t line, bool check_inlines,
774344779Sdim      lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list);
775254721Semaste
776314564Sdim  void SetFileSpecAndObjectName(const FileSpec &file,
777353358Sdim                                ConstString object_name);
778254721Semaste
779314564Sdim  bool GetIsDynamicLinkEditor();
780309124Sdim
781360784Sdim  llvm::Expected<TypeSystem &>
782360784Sdim  GetTypeSystemForLanguage(lldb::LanguageType language);
783309124Sdim
784314564Sdim  // Special error functions that can do printf style formatting that will
785341825Sdim  // prepend the message with something appropriate for this module (like the
786341825Sdim  // architecture, path and object name (if any)). This centralizes code so
787341825Sdim  // that everyone doesn't need to format their error and log messages on their
788341825Sdim  // own and keeps the output a bit more consistent.
789314564Sdim  void LogMessage(Log *log, const char *format, ...)
790314564Sdim      __attribute__((format(printf, 3, 4)));
791309124Sdim
792314564Sdim  void LogMessageVerboseBacktrace(Log *log, const char *format, ...)
793314564Sdim      __attribute__((format(printf, 3, 4)));
794309124Sdim
795314564Sdim  void ReportWarning(const char *format, ...)
796314564Sdim      __attribute__((format(printf, 2, 3)));
797309124Sdim
798314564Sdim  void ReportError(const char *format, ...)
799314564Sdim      __attribute__((format(printf, 2, 3)));
800309124Sdim
801314564Sdim  // Only report an error once when the module is first detected to be modified
802314564Sdim  // so we don't spam the console with many messages.
803314564Sdim  void ReportErrorIfModifyDetected(const char *format, ...)
804314564Sdim      __attribute__((format(printf, 2, 3)));
805309124Sdim
806341825Sdim  // Return true if the file backing this module has changed since the module
807341825Sdim  // was originally created  since we saved the initial file modification time
808341825Sdim  // when the module first gets created.
809314564Sdim  bool FileHasChanged() const;
810309124Sdim
811360784Sdim  // SymbolFile and ObjectFile member objects should lock the
812341825Sdim  // module mutex to avoid deadlocks.
813314564Sdim  std::recursive_mutex &GetMutex() const { return m_mutex; }
814309124Sdim
815314564Sdim  PathMappingList &GetSourceMappingList() { return m_source_mappings; }
816314564Sdim
817314564Sdim  const PathMappingList &GetSourceMappingList() const {
818314564Sdim    return m_source_mappings;
819314564Sdim  }
820314564Sdim
821341825Sdim  /// Finds a source file given a file spec using the module source path
822341825Sdim  /// remappings (if any).
823314564Sdim  ///
824314564Sdim  /// Tries to resolve \a orig_spec by checking the module source path
825341825Sdim  /// remappings. It makes sure the file exists, so this call can be expensive
826341825Sdim  /// if the remappings are on a network file system, so use this function
827341825Sdim  /// sparingly (not in a tight debug info parsing loop).
828314564Sdim  ///
829353358Sdim  /// \param[in] orig_spec
830314564Sdim  ///     The original source file path to try and remap.
831314564Sdim  ///
832353358Sdim  /// \param[out] new_spec
833314564Sdim  ///     The newly remapped filespec that is guaranteed to exist.
834314564Sdim  ///
835353358Sdim  /// \return
836314564Sdim  ///     /b true if \a orig_spec was successfully located and
837314564Sdim  ///     \a new_spec is filled in with an existing file spec,
838314564Sdim  ///     \b false otherwise.
839314564Sdim  bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const;
840314564Sdim
841314564Sdim  /// Remaps a source file given \a path into \a new_path.
842314564Sdim  ///
843341825Sdim  /// Remaps \a path if any source remappings match. This function does NOT
844341825Sdim  /// stat the file system so it can be used in tight loops where debug info
845341825Sdim  /// is being parsed.
846314564Sdim  ///
847353358Sdim  /// \param[in] path
848314564Sdim  ///     The original source file path to try and remap.
849314564Sdim  ///
850353358Sdim  /// \param[out] new_path
851314564Sdim  ///     The newly remapped filespec that is may or may not exist.
852314564Sdim  ///
853353358Sdim  /// \return
854314564Sdim  ///     /b true if \a path was successfully located and \a new_path
855314564Sdim  ///     is filled in with a new source path, \b false otherwise.
856314564Sdim  bool RemapSourceFile(llvm::StringRef path, std::string &new_path) const;
857314564Sdim  bool RemapSourceFile(const char *, std::string &) const = delete;
858314564Sdim
859360784Sdim  /// Update the ArchSpec to a more specific variant.
860360784Sdim  bool MergeArchitecture(const ArchSpec &arch_spec);
861360784Sdim
862353358Sdim  /// \class LookupInfo Module.h "lldb/Core/Module.h"
863341825Sdim  /// A class that encapsulates name lookup information.
864314564Sdim  ///
865341825Sdim  /// Users can type a wide variety of partial names when setting breakpoints
866360784Sdim  /// by name or when looking for functions by name. The SymbolFile object is
867360784Sdim  /// only required to implement name lookup for function basenames and for
868360784Sdim  /// fully mangled names. This means if the user types in a partial name, we
869360784Sdim  /// must reduce this to a name lookup that will work with all SymbolFile
870360784Sdim  /// objects. So we might reduce a name lookup to look for a basename, and then
871360784Sdim  /// prune out any results that don't match.
872314564Sdim  ///
873341825Sdim  /// The "m_name" member variable represents the name as it was typed by the
874341825Sdim  /// user. "m_lookup_name" will be the name we actually search for through
875341825Sdim  /// the symbol or objects files. Lanaguage is included in case we need to
876341825Sdim  /// filter results by language at a later date. The "m_name_type_mask"
877341825Sdim  /// member variable tells us what kinds of names we are looking for and can
878341825Sdim  /// help us prune out unwanted results.
879314564Sdim  ///
880314564Sdim  /// Function lookups are done in Module.cpp, ModuleList.cpp and in
881341825Sdim  /// BreakpointResolverName.cpp and they all now use this class to do lookups
882341825Sdim  /// correctly.
883314564Sdim  class LookupInfo {
884314564Sdim  public:
885314564Sdim    LookupInfo()
886314564Sdim        : m_name(), m_lookup_name(), m_language(lldb::eLanguageTypeUnknown),
887344779Sdim          m_name_type_mask(lldb::eFunctionNameTypeNone),
888344779Sdim          m_match_name_after_lookup(false) {}
889314564Sdim
890353358Sdim    LookupInfo(ConstString name, lldb::FunctionNameType name_type_mask,
891314564Sdim               lldb::LanguageType language);
892314564Sdim
893353358Sdim    ConstString GetName() const { return m_name; }
894314564Sdim
895353358Sdim    void SetName(ConstString name) { m_name = name; }
896314564Sdim
897353358Sdim    ConstString GetLookupName() const { return m_lookup_name; }
898314564Sdim
899353358Sdim    void SetLookupName(ConstString name) { m_lookup_name = name; }
900314564Sdim
901344779Sdim    lldb::FunctionNameType GetNameTypeMask() const { return m_name_type_mask; }
902314564Sdim
903344779Sdim    void SetNameTypeMask(lldb::FunctionNameType mask) {
904344779Sdim      m_name_type_mask = mask;
905344779Sdim    }
906314564Sdim
907314564Sdim    void Prune(SymbolContextList &sc_list, size_t start_idx) const;
908314564Sdim
909314564Sdim  protected:
910344779Sdim    /// What the user originally typed
911344779Sdim    ConstString m_name;
912344779Sdim
913344779Sdim    /// The actual name will lookup when calling in the object or symbol file
914344779Sdim    ConstString m_lookup_name;
915344779Sdim
916344779Sdim    /// Limit matches to only be for this language
917344779Sdim    lldb::LanguageType m_language;
918344779Sdim
919344779Sdim    /// One or more bits from lldb::FunctionNameType that indicate what kind of
920344779Sdim    /// names we are looking for
921344779Sdim    lldb::FunctionNameType m_name_type_mask;
922344779Sdim
923344779Sdim    ///< If \b true, then demangled names that match will need to contain
924344779Sdim    ///< "m_name" in order to be considered a match
925344779Sdim    bool m_match_name_after_lookup;
926314564Sdim  };
927314564Sdim
928254721Semasteprotected:
929314564Sdim  // Member Variables
930314564Sdim  mutable std::recursive_mutex m_mutex; ///< A mutex to keep this object happy
931314564Sdim                                        ///in multi-threaded environments.
932254721Semaste
933314564Sdim  /// The modification time for this module when it was created.
934314564Sdim  llvm::sys::TimePoint<> m_mod_time;
935296417Sdim
936314564Sdim  ArchSpec m_arch;      ///< The architecture for this module.
937314564Sdim  UUID m_uuid; ///< Each module is assumed to have a unique identifier to help
938314564Sdim               ///match it up to debug symbols.
939314564Sdim  FileSpec m_file; ///< The file representation on disk for this module (if
940314564Sdim                   ///there is one).
941314564Sdim  FileSpec m_platform_file; ///< The path to the module on the platform on which
942314564Sdim                            ///it is being debugged
943314564Sdim  FileSpec m_remote_install_file; ///< If set when debugging on remote
944314564Sdim                                  ///platforms, this module will be installed at
945314564Sdim                                  ///this location
946314564Sdim  FileSpec m_symfile_spec;   ///< If this path is valid, then this is the file
947314564Sdim                             ///that _will_ be used as the symbol file for this
948314564Sdim                             ///module
949314564Sdim  ConstString m_object_name; ///< The name an object within this module that is
950314564Sdim                             ///selected, or empty of the module is represented
951314564Sdim                             ///by \a m_file.
952314564Sdim  uint64_t m_object_offset;
953314564Sdim  llvm::sys::TimePoint<> m_object_mod_time;
954314564Sdim  lldb::ObjectFileSP m_objfile_sp; ///< A shared pointer to the object file
955314564Sdim                                   ///parser for this module as it may or may
956314564Sdim                                   ///not be shared with the SymbolFile
957353358Sdim  llvm::Optional<UnwindTable> m_unwind_table; ///< Table of FuncUnwinders
958353358Sdim                                              /// objects created for this
959353358Sdim                                              /// Module's functions
960314564Sdim  lldb::SymbolVendorUP
961353358Sdim      m_symfile_up; ///< A pointer to the symbol vendor for this module.
962314564Sdim  std::vector<lldb::SymbolVendorUP>
963314564Sdim      m_old_symfiles; ///< If anyone calls Module::SetSymbolFileFileSpec() and
964314564Sdim                      ///changes the symbol file,
965314564Sdim  ///< we need to keep all old symbol files around in case anyone has type
966314564Sdim  ///references to them
967314564Sdim  TypeSystemMap m_type_system_map;   ///< A map of any type systems associated
968314564Sdim                                     ///with this module
969314564Sdim  PathMappingList m_source_mappings; ///< Module specific source remappings for
970314564Sdim                                     ///when you have debug info for a module
971314564Sdim                                     ///that doesn't match where the sources
972314564Sdim                                     ///currently are
973353358Sdim  lldb::SectionListUP m_sections_up; ///< Unified section list for module that
974353358Sdim                                     /// is used by the ObjectFile and and
975353358Sdim                                     /// ObjectFile instances for the debug info
976254721Semaste
977314564Sdim  std::atomic<bool> m_did_load_objfile{false};
978360784Sdim  std::atomic<bool> m_did_load_symfile{false};
979341825Sdim  std::atomic<bool> m_did_set_uuid{false};
980314564Sdim  mutable bool m_file_has_changed : 1,
981314564Sdim      m_first_file_changed_log : 1; /// See if the module was modified after it
982314564Sdim                                    /// was initially opened.
983254721Semaste
984314564Sdim  /// Resolve a file or load virtual address.
985314564Sdim  ///
986314564Sdim  /// Tries to resolve \a vm_addr as a file address (if \a
987314564Sdim  /// vm_addr_is_file_addr is true) or as a load address if \a
988341825Sdim  /// vm_addr_is_file_addr is false) in the symbol vendor. \a resolve_scope
989341825Sdim  /// indicates what clients wish to resolve and can be used to limit the
990341825Sdim  /// scope of what is parsed.
991314564Sdim  ///
992353358Sdim  /// \param[in] vm_addr
993314564Sdim  ///     The load virtual address to resolve.
994314564Sdim  ///
995353358Sdim  /// \param[in] vm_addr_is_file_addr
996314564Sdim  ///     If \b true, \a vm_addr is a file address, else \a vm_addr
997314564Sdim  ///     if a load address.
998314564Sdim  ///
999353358Sdim  /// \param[in] resolve_scope
1000314564Sdim  ///     The scope that should be resolved (see
1001314564Sdim  ///     SymbolContext::Scope).
1002314564Sdim  ///
1003353358Sdim  /// \param[out] so_addr
1004314564Sdim  ///     The section offset based address that got resolved if
1005314564Sdim  ///     any bits are returned.
1006314564Sdim  ///
1007353358Sdim  /// \param[out] sc
1008314564Sdim  //      The symbol context that has objects filled in. Each bit
1009314564Sdim  ///     in the \a resolve_scope pertains to a member in the \a sc.
1010314564Sdim  ///
1011353358Sdim  /// \return
1012314564Sdim  ///     A integer that contains SymbolContext::Scope bits set for
1013314564Sdim  ///     each item that was successfully resolved.
1014314564Sdim  ///
1015353358Sdim  /// \see SymbolContext::Scope
1016314564Sdim  uint32_t ResolveSymbolContextForAddress(lldb::addr_t vm_addr,
1017314564Sdim                                          bool vm_addr_is_file_addr,
1018344779Sdim                                          lldb::SymbolContextItem resolve_scope,
1019314564Sdim                                          Address &so_addr, SymbolContext &sc);
1020314564Sdim
1021314564Sdim  void SymbolIndicesToSymbolContextList(Symtab *symtab,
1022314564Sdim                                        std::vector<uint32_t> &symbol_indexes,
1023314564Sdim                                        SymbolContextList &sc_list);
1024314564Sdim
1025314564Sdim  bool SetArchitecture(const ArchSpec &new_arch);
1026314564Sdim
1027341825Sdim  void SetUUID(const lldb_private::UUID &uuid);
1028341825Sdim
1029314564Sdim  SectionList *GetUnifiedSectionList();
1030314564Sdim
1031314564Sdim  friend class ModuleList;
1032314564Sdim  friend class ObjectFile;
1033314564Sdim  friend class SymbolFile;
1034314564Sdim
1035254721Semasteprivate:
1036314564Sdim  Module(); // Only used internally by CreateJITModule ()
1037254721Semaste
1038360784Sdim  void FindTypes_Impl(
1039353358Sdim      ConstString name, const CompilerDeclContext *parent_decl_ctx,
1040360784Sdim      size_t max_matches,
1041314564Sdim      llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1042314564Sdim      TypeMap &types);
1043314564Sdim
1044314564Sdim  DISALLOW_COPY_AND_ASSIGN(Module);
1045254721Semaste};
1046254721Semaste
1047254721Semaste} // namespace lldb_private
1048254721Semaste
1049296417Sdim#endif // liblldb_Module_h_
1050