]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Module.h
MFV r316920: 8023 Panic destroying a metaslab deferred range tree
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / Module.h
1 //===-- Module.h ------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Module_h_
11 #define liblldb_Module_h_
12
13 #include "lldb/Symbol/SymbolContextScope.h"
14
15 // Project includes
16 #include "lldb/Core/ArchSpec.h"
17 #include "lldb/Core/UUID.h"
18 #include "lldb/Host/FileSpec.h"
19 #include "lldb/Symbol/TypeSystem.h"
20 #include "lldb/Target/PathMappingList.h"
21 #include "lldb/lldb-forward.h"
22
23 // Other libraries and framework includes
24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Support/Chrono.h"
27
28 // C Includes
29 // C++ Includes
30 #include <atomic>
31 #include <mutex>
32 #include <string>
33 #include <vector>
34
35 namespace lldb_private {
36
37 //----------------------------------------------------------------------
38 /// @class Module Module.h "lldb/Core/Module.h"
39 /// @brief A class that describes an executable image and its associated
40 ///        object and symbol files.
41 ///
42 /// The module is designed to be able to select a single slice of an
43 /// executable image as it would appear on disk and during program
44 /// execution.
45 ///
46 /// Modules control when and if information is parsed according to which
47 /// accessors are called. For example the object file (ObjectFile)
48 /// representation will only be parsed if the object file is requested
49 /// using the Module::GetObjectFile() is called. The debug symbols
50 /// will only be parsed if the symbol vendor (SymbolVendor) is
51 /// requested using the Module::GetSymbolVendor() is called.
52 ///
53 /// The module will parse more detailed information as more queries are
54 /// made.
55 //----------------------------------------------------------------------
56 class Module : public std::enable_shared_from_this<Module>,
57                public SymbolContextScope {
58 public:
59   // Static functions that can track the lifetime of module objects.
60   // This is handy because we might have Module objects that are in
61   // shared pointers that aren't in the global module list (from
62   // ModuleList). If this is the case we need to know about it.
63   // The modules in the global list maintained by these functions
64   // can be viewed using the "target modules list" command using the
65   // "--global" (-g for short).
66   static size_t GetNumberAllocatedModules();
67
68   static Module *GetAllocatedModuleAtIndex(size_t idx);
69
70   static std::recursive_mutex &GetAllocationModuleCollectionMutex();
71
72   //------------------------------------------------------------------
73   /// Construct with file specification and architecture.
74   ///
75   /// Clients that wish to share modules with other targets should
76   /// use ModuleList::GetSharedModule().
77   ///
78   /// @param[in] file_spec
79   ///     The file specification for the on disk representation of
80   ///     this executable image.
81   ///
82   /// @param[in] arch
83   ///     The architecture to set as the current architecture in
84   ///     this module.
85   ///
86   /// @param[in] object_name
87   ///     The name of an object in a module used to extract a module
88   ///     within a module (.a files and modules that contain multiple
89   ///     architectures).
90   ///
91   /// @param[in] object_offset
92   ///     The offset within an existing module used to extract a
93   ///     module within a module (.a files and modules that contain
94   ///     multiple architectures).
95   //------------------------------------------------------------------
96   Module(
97       const FileSpec &file_spec, const ArchSpec &arch,
98       const ConstString *object_name = nullptr,
99       lldb::offset_t object_offset = 0,
100       const llvm::sys::TimePoint<> &object_mod_time = llvm::sys::TimePoint<>());
101
102   Module(const ModuleSpec &module_spec);
103
104   static lldb::ModuleSP
105   CreateJITModule(const lldb::ObjectFileJITDelegateSP &delegate_sp);
106
107   //------------------------------------------------------------------
108   /// Destructor.
109   //------------------------------------------------------------------
110   ~Module() override;
111
112   bool MatchesModuleSpec(const ModuleSpec &module_ref);
113
114   //------------------------------------------------------------------
115   /// Set the load address for all sections in a module to be the
116   /// file address plus \a slide.
117   ///
118   /// Many times a module will be loaded in a target with a constant
119   /// offset applied to all top level sections. This function can
120   /// set the load address for all top level sections to be the
121   /// section file address + offset.
122   ///
123   /// @param[in] target
124   ///     The target in which to apply the section load addresses.
125   ///
126   /// @param[in] value
127   ///     if \a value_is_offset is true, then value is the offset to
128   ///     apply to all file addresses for all top level sections in
129   ///     the object file as each section load address is being set.
130   ///     If \a value_is_offset is false, then "value" is the new
131   ///     absolute base address for the image.
132   ///
133   /// @param[in] value_is_offset
134   ///     If \b true, then \a value is an offset to apply to each
135   ///     file address of each top level section.
136   ///     If \b false, then \a value is the image base address that
137   ///     will be used to rigidly slide all loadable sections.
138   ///
139   /// @param[out] changed
140   ///     If any section load addresses were changed in \a target,
141   ///     then \a changed will be set to \b true. Else \a changed
142   ///     will be set to false. This allows this function to be
143   ///     called multiple times on the same module for the same
144   ///     target. If the module hasn't moved, then \a changed will
145   ///     be false and no module updated notification will need to
146   ///     be sent out.
147   ///
148   /// @return
149   ///     /b True if any sections were successfully loaded in \a target,
150   ///     /b false otherwise.
151   //------------------------------------------------------------------
152   bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset,
153                       bool &changed);
154
155   //------------------------------------------------------------------
156   /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
157   ///
158   /// @see SymbolContextScope
159   //------------------------------------------------------------------
160   void CalculateSymbolContext(SymbolContext *sc) override;
161
162   lldb::ModuleSP CalculateSymbolContextModule() override;
163
164   void
165   GetDescription(Stream *s,
166                  lldb::DescriptionLevel level = lldb::eDescriptionLevelFull);
167
168   //------------------------------------------------------------------
169   /// Get the module path and object name.
170   ///
171   /// Modules can refer to object files. In this case the specification
172   /// is simple and would return the path to the file:
173   ///
174   ///     "/usr/lib/foo.dylib"
175   ///
176   /// Modules can be .o files inside of a BSD archive (.a file). In
177   /// this case, the object specification will look like:
178   ///
179   ///     "/usr/lib/foo.a(bar.o)"
180   ///
181   /// There are many places where logging wants to log this fully
182   /// qualified specification, so we centralize this functionality
183   /// here.
184   ///
185   /// @return
186   ///     The object path + object name if there is one.
187   //------------------------------------------------------------------
188   std::string GetSpecificationDescription() const;
189
190   //------------------------------------------------------------------
191   /// Dump a description of this object to a Stream.
192   ///
193   /// Dump a description of the contents of this object to the
194   /// supplied stream \a s. The dumped content will be only what has
195   /// been loaded or parsed up to this point at which this function
196   /// is called, so this is a good way to see what has been parsed
197   /// in a module.
198   ///
199   /// @param[in] s
200   ///     The stream to which to dump the object description.
201   //------------------------------------------------------------------
202   void Dump(Stream *s);
203
204   //------------------------------------------------------------------
205   /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
206   ///
207   /// @see SymbolContextScope
208   //------------------------------------------------------------------
209   void DumpSymbolContext(Stream *s) override;
210
211   //------------------------------------------------------------------
212   /// Find a symbol in the object file's symbol table.
213   ///
214   /// @param[in] name
215   ///     The name of the symbol that we are looking for.
216   ///
217   /// @param[in] symbol_type
218   ///     If set to eSymbolTypeAny, find a symbol of any type that
219   ///     has a name that matches \a name. If set to any other valid
220   ///     SymbolType enumeration value, then search only for
221   ///     symbols that match \a symbol_type.
222   ///
223   /// @return
224   ///     Returns a valid symbol pointer if a symbol was found,
225   ///     nullptr otherwise.
226   //------------------------------------------------------------------
227   const Symbol *FindFirstSymbolWithNameAndType(
228       const ConstString &name,
229       lldb::SymbolType symbol_type = lldb::eSymbolTypeAny);
230
231   size_t FindSymbolsWithNameAndType(const ConstString &name,
232                                     lldb::SymbolType symbol_type,
233                                     SymbolContextList &sc_list);
234
235   size_t FindSymbolsMatchingRegExAndType(const RegularExpression &regex,
236                                          lldb::SymbolType symbol_type,
237                                          SymbolContextList &sc_list);
238
239   //------------------------------------------------------------------
240   /// Find a function symbols in the object file's symbol table.
241   ///
242   /// @param[in] name
243   ///     The name of the symbol that we are looking for.
244   ///
245   /// @param[in] name_type_mask
246   ///     A mask that has one or more bitwise OR'ed values from the
247   ///     lldb::FunctionNameType enumeration type that indicate what
248   ///     kind of names we are looking for.
249   ///
250   /// @param[out] sc_list
251   ///     A list to append any matching symbol contexts to.
252   ///
253   /// @return
254   ///     The number of symbol contexts that were added to \a sc_list
255   //------------------------------------------------------------------
256   size_t FindFunctionSymbols(const ConstString &name, uint32_t name_type_mask,
257                              SymbolContextList &sc_list);
258
259   //------------------------------------------------------------------
260   /// Find compile units by partial or full path.
261   ///
262   /// Finds all compile units that match \a path in all of the modules
263   /// and returns the results in \a sc_list.
264   ///
265   /// @param[in] path
266   ///     The name of the function we are looking for.
267   ///
268   /// @param[in] append
269   ///     If \b true, then append any compile units that were found
270   ///     to \a sc_list. If \b false, then the \a sc_list is cleared
271   ///     and the contents of \a sc_list are replaced.
272   ///
273   /// @param[out] sc_list
274   ///     A symbol context list that gets filled in with all of the
275   ///     matches.
276   ///
277   /// @return
278   ///     The number of matches added to \a sc_list.
279   //------------------------------------------------------------------
280   size_t FindCompileUnits(const FileSpec &path, bool append,
281                           SymbolContextList &sc_list);
282
283   //------------------------------------------------------------------
284   /// Find functions by name.
285   ///
286   /// If the function is an inlined function, it will have a block,
287   /// representing the inlined function, and the function will be the
288   /// containing function.  If it is not inlined, then the block will
289   /// be NULL.
290   ///
291   /// @param[in] name
292   ///     The name of the compile unit we are looking for.
293   ///
294   /// @param[in] namespace_decl
295   ///     If valid, a namespace to search in.
296   ///
297   /// @param[in] name_type_mask
298   ///     A bit mask of bits that indicate what kind of names should
299   ///     be used when doing the lookup. Bits include fully qualified
300   ///     names, base names, C++ methods, or ObjC selectors.
301   ///     See FunctionNameType for more details.
302   ///
303   /// @param[in] append
304   ///     If \b true, any matches will be appended to \a sc_list, else
305   ///     matches replace the contents of \a sc_list.
306   ///
307   /// @param[out] sc_list
308   ///     A symbol context list that gets filled in with all of the
309   ///     matches.
310   ///
311   /// @return
312   ///     The number of matches added to \a sc_list.
313   //------------------------------------------------------------------
314   size_t FindFunctions(const ConstString &name,
315                        const CompilerDeclContext *parent_decl_ctx,
316                        uint32_t name_type_mask, bool symbols_ok,
317                        bool inlines_ok, bool append,
318                        SymbolContextList &sc_list);
319
320   //------------------------------------------------------------------
321   /// Find functions by name.
322   ///
323   /// If the function is an inlined function, it will have a block,
324   /// representing the inlined function, and the function will be the
325   /// containing function.  If it is not inlined, then the block will
326   /// be NULL.
327   ///
328   /// @param[in] regex
329   ///     A regular expression to use when matching the name.
330   ///
331   /// @param[in] append
332   ///     If \b true, any matches will be appended to \a sc_list, else
333   ///     matches replace the contents of \a sc_list.
334   ///
335   /// @param[out] sc_list
336   ///     A symbol context list that gets filled in with all of the
337   ///     matches.
338   ///
339   /// @return
340   ///     The number of matches added to \a sc_list.
341   //------------------------------------------------------------------
342   size_t FindFunctions(const RegularExpression &regex, bool symbols_ok,
343                        bool inlines_ok, bool append,
344                        SymbolContextList &sc_list);
345
346   //------------------------------------------------------------------
347   /// Find addresses by file/line
348   ///
349   /// @param[in] target_sp
350   ///     The target the addresses are desired for.
351   ///
352   /// @param[in] file
353   ///     Source file to locate.
354   ///
355   /// @param[in] line
356   ///     Source line to locate.
357   ///
358   /// @param[in] function
359   ///       Optional filter function. Addresses within this function will be
360   ///     added to the 'local' list. All others will be added to the 'extern'
361   ///     list.
362   ///
363   /// @param[out] output_local
364   ///     All matching addresses within 'function'
365   ///
366   /// @param[out] output_extern
367   ///     All matching addresses not within 'function'
368   void FindAddressesForLine(const lldb::TargetSP target_sp,
369                             const FileSpec &file, uint32_t line,
370                             Function *function,
371                             std::vector<Address> &output_local,
372                             std::vector<Address> &output_extern);
373
374   //------------------------------------------------------------------
375   /// Find global and static variables by name.
376   ///
377   /// @param[in] name
378   ///     The name of the global or static variable we are looking
379   ///     for.
380   ///
381   /// @param[in] parent_decl_ctx
382   ///     If valid, a decl context that results must exist within
383   ///
384   /// @param[in] append
385   ///     If \b true, any matches will be appended to \a
386   ///     variable_list, else matches replace the contents of
387   ///     \a variable_list.
388   ///
389   /// @param[in] max_matches
390   ///     Allow the number of matches to be limited to \a
391   ///     max_matches. Specify UINT32_MAX to get all possible matches.
392   ///
393   /// @param[in] variable_list
394   ///     A list of variables that gets the matches appended to (if
395   ///     \a append it \b true), or replace (if \a append is \b false).
396   ///
397   /// @return
398   ///     The number of matches added to \a variable_list.
399   //------------------------------------------------------------------
400   size_t FindGlobalVariables(const ConstString &name,
401                              const CompilerDeclContext *parent_decl_ctx,
402                              bool append, size_t max_matches,
403                              VariableList &variable_list);
404
405   //------------------------------------------------------------------
406   /// Find global and static variables by regular expression.
407   ///
408   /// @param[in] regex
409   ///     A regular expression to use when matching the name.
410   ///
411   /// @param[in] append
412   ///     If \b true, any matches will be appended to \a
413   ///     variable_list, else matches replace the contents of
414   ///     \a variable_list.
415   ///
416   /// @param[in] max_matches
417   ///     Allow the number of matches to be limited to \a
418   ///     max_matches. Specify UINT32_MAX to get all possible matches.
419   ///
420   /// @param[in] variable_list
421   ///     A list of variables that gets the matches appended to (if
422   ///     \a append it \b true), or replace (if \a append is \b false).
423   ///
424   /// @return
425   ///     The number of matches added to \a variable_list.
426   //------------------------------------------------------------------
427   size_t FindGlobalVariables(const RegularExpression &regex, bool append,
428                              size_t max_matches, VariableList &variable_list);
429
430   //------------------------------------------------------------------
431   /// Find types by name.
432   ///
433   /// Type lookups in modules go through the SymbolVendor (which will
434   /// use one or more SymbolFile subclasses). The SymbolFile needs to
435   /// be able to lookup types by basename and not the fully qualified
436   /// typename. This allows the type accelerator tables to stay small,
437   /// even with heavily templatized C++. The type search will then
438   /// narrow down the search results. If "exact_match" is true, then
439   /// the type search will only match exact type name matches. If
440   /// "exact_match" is false, the type will match as long as the base
441   /// typename matches and as long as any immediate containing
442   /// namespaces/class scopes that are specified match. So to search
443   /// for a type "d" in "b::c", the name "b::c::d" can be specified
444   /// and it will match any class/namespace "b" which contains a
445   /// class/namespace "c" which contains type "d". We do this to
446   /// allow users to not always have to specify complete scoping on
447   /// all expressions, but it also allows for exact matching when
448   /// required.
449   ///
450   /// @param[in] sc
451   ///     A symbol context that scopes where to extract a type list
452   ///     from.
453   ///
454   /// @param[in] type_name
455   ///     The name of the type we are looking for that is a fully
456   ///     or partially qualified type name.
457   ///
458   /// @param[in] exact_match
459   ///     If \b true, \a type_name is fully qualified and must match
460   ///     exactly. If \b false, \a type_name is a partially qualified
461   ///     name where the leading namespaces or classes can be
462   ///     omitted to make finding types that a user may type
463   ///     easier.
464   ///
465   /// @param[out] type_list
466   ///     A type list gets populated with any matches.
467   ///
468   /// @return
469   ///     The number of matches added to \a type_list.
470   //------------------------------------------------------------------
471   size_t
472   FindTypes(const SymbolContext &sc, const ConstString &type_name,
473             bool exact_match, size_t max_matches,
474             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
475             TypeList &types);
476
477   lldb::TypeSP FindFirstType(const SymbolContext &sc,
478                              const ConstString &type_name, bool exact_match);
479
480   //------------------------------------------------------------------
481   /// Find types by name that are in a namespace. This function is
482   /// used by the expression parser when searches need to happen in
483   /// an exact namespace scope.
484   ///
485   /// @param[in] sc
486   ///     A symbol context that scopes where to extract a type list
487   ///     from.
488   ///
489   /// @param[in] type_name
490   ///     The name of a type within a namespace that should not include
491   ///     any qualifying namespaces (just a type basename).
492   ///
493   /// @param[in] namespace_decl
494   ///     The namespace declaration that this type must exist in.
495   ///
496   /// @param[out] type_list
497   ///     A type list gets populated with any matches.
498   ///
499   /// @return
500   ///     The number of matches added to \a type_list.
501   //------------------------------------------------------------------
502   size_t FindTypesInNamespace(const SymbolContext &sc,
503                               const ConstString &type_name,
504                               const CompilerDeclContext *parent_decl_ctx,
505                               size_t max_matches, TypeList &type_list);
506
507   //------------------------------------------------------------------
508   /// Get const accessor for the module architecture.
509   ///
510   /// @return
511   ///     A const reference to the architecture object.
512   //------------------------------------------------------------------
513   const ArchSpec &GetArchitecture() const;
514
515   //------------------------------------------------------------------
516   /// Get const accessor for the module file specification.
517   ///
518   /// This function returns the file for the module on the host system
519   /// that is running LLDB. This can differ from the path on the
520   /// platform since we might be doing remote debugging.
521   ///
522   /// @return
523   ///     A const reference to the file specification object.
524   //------------------------------------------------------------------
525   const FileSpec &GetFileSpec() const { return m_file; }
526
527   //------------------------------------------------------------------
528   /// Get accessor for the module platform file specification.
529   ///
530   /// Platform file refers to the path of the module as it is known on
531   /// the remote system on which it is being debugged. For local
532   /// debugging this is always the same as Module::GetFileSpec(). But
533   /// remote debugging might mention a file "/usr/lib/liba.dylib"
534   /// which might be locally downloaded and cached. In this case the
535   /// platform file could be something like:
536   /// "/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib"
537   /// The file could also be cached in a local developer kit directory.
538   ///
539   /// @return
540   ///     A const reference to the file specification object.
541   //------------------------------------------------------------------
542   const FileSpec &GetPlatformFileSpec() const {
543     if (m_platform_file)
544       return m_platform_file;
545     return m_file;
546   }
547
548   void SetPlatformFileSpec(const FileSpec &file) { m_platform_file = file; }
549
550   const FileSpec &GetRemoteInstallFileSpec() const {
551     return m_remote_install_file;
552   }
553
554   void SetRemoteInstallFileSpec(const FileSpec &file) {
555     m_remote_install_file = file;
556   }
557
558   const FileSpec &GetSymbolFileFileSpec() const { return m_symfile_spec; }
559
560   void SetSymbolFileFileSpec(const FileSpec &file);
561
562   const llvm::sys::TimePoint<> &GetModificationTime() const {
563     return m_mod_time;
564   }
565
566   const llvm::sys::TimePoint<> &GetObjectModificationTime() const {
567     return m_object_mod_time;
568   }
569
570   void SetObjectModificationTime(const llvm::sys::TimePoint<> &mod_time) {
571     m_mod_time = mod_time;
572   }
573
574   //------------------------------------------------------------------
575   /// Tells whether this module is capable of being the main executable
576   /// for a process.
577   ///
578   /// @return
579   ///     \b true if it is, \b false otherwise.
580   //------------------------------------------------------------------
581   bool IsExecutable();
582
583   //------------------------------------------------------------------
584   /// Tells whether this module has been loaded in the target passed in.
585   /// This call doesn't distinguish between whether the module is loaded
586   /// by the dynamic loader, or by a "target module add" type call.
587   ///
588   /// @param[in] target
589   ///    The target to check whether this is loaded in.
590   ///
591   /// @return
592   ///     \b true if it is, \b false otherwise.
593   //------------------------------------------------------------------
594   bool IsLoadedInTarget(Target *target);
595
596   bool LoadScriptingResourceInTarget(Target *target, Error &error,
597                                      Stream *feedback_stream = nullptr);
598
599   //------------------------------------------------------------------
600   /// Get the number of compile units for this module.
601   ///
602   /// @return
603   ///     The number of compile units that the symbol vendor plug-in
604   ///     finds.
605   //------------------------------------------------------------------
606   size_t GetNumCompileUnits();
607
608   lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx);
609
610   const ConstString &GetObjectName() const;
611
612   uint64_t GetObjectOffset() const { return m_object_offset; }
613
614   //------------------------------------------------------------------
615   /// Get the object file representation for the current architecture.
616   ///
617   /// If the object file has not been located or parsed yet, this
618   /// function will find the best ObjectFile plug-in that can parse
619   /// Module::m_file.
620   ///
621   /// @return
622   ///     If Module::m_file does not exist, or no plug-in was found
623   ///     that can parse the file, or the object file doesn't contain
624   ///     the current architecture in Module::m_arch, nullptr will be
625   ///     returned, else a valid object file interface will be
626   ///     returned. The returned pointer is owned by this object and
627   ///     remains valid as long as the object is around.
628   //------------------------------------------------------------------
629   virtual ObjectFile *GetObjectFile();
630
631   //------------------------------------------------------------------
632   /// Get the unified section list for the module. This is the section
633   /// list created by the module's object file and any debug info and
634   /// symbol files created by the symbol vendor.
635   ///
636   /// If the symbol vendor has not been loaded yet, this function
637   /// will return the section list for the object file.
638   ///
639   /// @return
640   ///     Unified module section list.
641   //------------------------------------------------------------------
642   virtual SectionList *GetSectionList();
643
644   //------------------------------------------------------------------
645   /// Notify the module that the file addresses for the Sections have
646   /// been updated.
647   ///
648   /// If the Section file addresses for a module are updated, this
649   /// method should be called.  Any parts of the module, object file,
650   /// or symbol file that has cached those file addresses must invalidate
651   /// or update its cache.
652   //------------------------------------------------------------------
653   virtual void SectionFileAddressesChanged();
654
655   uint32_t GetVersion(uint32_t *versions, uint32_t num_versions);
656
657   //------------------------------------------------------------------
658   /// Load an object file from memory.
659   ///
660   /// If available, the size of the object file in memory may be
661   /// passed to avoid additional round trips to process memory.
662   /// If the size is not provided, a default value is used. This
663   /// value should be large enough to enable the ObjectFile plugins
664   /// to read the header of the object file without going back to the
665   /// process.
666   ///
667   /// @return
668   ///     The object file loaded from memory or nullptr, if the operation
669   ///     failed (see the `error` for more information in that case).
670   //------------------------------------------------------------------
671   ObjectFile *GetMemoryObjectFile(const lldb::ProcessSP &process_sp,
672                                   lldb::addr_t header_addr, Error &error,
673                                   size_t size_to_read = 512);
674   //------------------------------------------------------------------
675   /// Get the symbol vendor interface for the current architecture.
676   ///
677   /// If the symbol vendor file has not been located yet, this
678   /// function will find the best SymbolVendor plug-in that can
679   /// use the current object file.
680   ///
681   /// @return
682   ///     If this module does not have a valid object file, or no
683   ///     plug-in can be found that can use the object file, nullptr will
684   ///     be returned, else a valid symbol vendor plug-in interface
685   ///     will be returned. The returned pointer is owned by this
686   ///     object and remains valid as long as the object is around.
687   //------------------------------------------------------------------
688   virtual SymbolVendor *
689   GetSymbolVendor(bool can_create = true,
690                   lldb_private::Stream *feedback_strm = nullptr);
691
692   //------------------------------------------------------------------
693   /// Get accessor the type list for this module.
694   ///
695   /// @return
696   ///     A valid type list pointer, or nullptr if there is no valid
697   ///     symbol vendor for this module.
698   //------------------------------------------------------------------
699   TypeList *GetTypeList();
700
701   //------------------------------------------------------------------
702   /// Get a pointer to the UUID value contained in this object.
703   ///
704   /// If the executable image file doesn't not have a UUID value built
705   /// into the file format, an MD5 checksum of the entire file, or
706   /// slice of the file for the current architecture should be used.
707   ///
708   /// @return
709   ///     A const pointer to the internal copy of the UUID value in
710   ///     this module if this module has a valid UUID value, NULL
711   ///     otherwise.
712   //------------------------------------------------------------------
713   const lldb_private::UUID &GetUUID();
714
715   //------------------------------------------------------------------
716   /// A debugging function that will cause everything in a module to
717   /// be parsed.
718   ///
719   /// All compile units will be parsed, along with all globals and
720   /// static variables and all functions for those compile units.
721   /// All types, scopes, local variables, static variables, global
722   /// variables, and line tables will be parsed. This can be used
723   /// prior to dumping a module to see a complete list of the
724   /// resulting debug information that gets parsed, or as a debug
725   /// function to ensure that the module can consume all of the
726   /// debug data the symbol vendor provides.
727   //------------------------------------------------------------------
728   void ParseAllDebugSymbols();
729
730   bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr);
731
732   //------------------------------------------------------------------
733   /// Resolve the symbol context for the given address.
734   ///
735   /// Tries to resolve the matching symbol context based on a lookup
736   /// from the current symbol vendor.  If the lazy lookup fails,
737   /// an attempt is made to parse the eh_frame section to handle
738   /// stripped symbols.  If this fails, an attempt is made to resolve
739   /// the symbol to the previous address to handle the case of a
740   /// function with a tail call.
741   ///
742   /// Use properties of the modified SymbolContext to inspect any
743   /// resolved target, module, compilation unit, symbol, function,
744   /// function block or line entry.  Use the return value to determine
745   /// which of these properties have been modified.
746   ///
747   /// @param[in] so_addr
748   ///     A load address to resolve.
749   ///
750   /// @param[in] resolve_scope
751   ///     The scope that should be resolved (see SymbolContext::Scope).
752   ///     A combination of flags from the enumeration SymbolContextItem
753   ///     requesting a resolution depth.  Note that the flags that are
754   ///     actually resolved may be a superset of the requested flags.
755   ///     For instance, eSymbolContextSymbol requires resolution of
756   ///     eSymbolContextModule, and eSymbolContextFunction requires
757   ///     eSymbolContextSymbol.
758   ///
759   /// @param[out] sc
760   ///     The SymbolContext that is modified based on symbol resolution.
761   ///
762   /// @param[in] resolve_tail_call_address
763   ///     Determines if so_addr should resolve to a symbol in the case
764   ///     of a function whose last instruction is a call.  In this case,
765   ///     the PC can be one past the address range of the function.
766   ///
767   /// @return
768   ///     The scope that has been resolved (see SymbolContext::Scope).
769   ///
770   /// @see SymbolContext::Scope
771   //------------------------------------------------------------------
772   uint32_t
773   ResolveSymbolContextForAddress(const Address &so_addr, uint32_t resolve_scope,
774                                  SymbolContext &sc,
775                                  bool resolve_tail_call_address = false);
776
777   //------------------------------------------------------------------
778   /// Resolve items in the symbol context for a given file and line.
779   ///
780   /// Tries to resolve \a file_path and \a line to a list of matching
781   /// symbol contexts.
782   ///
783   /// The line table entries contains addresses that can be used to
784   /// further resolve the values in each match: the function, block,
785   /// symbol. Care should be taken to minimize the amount of
786   /// information that is requested to only what is needed --
787   /// typically the module, compile unit, line table and line table
788   /// entry are sufficient.
789   ///
790   /// @param[in] file_path
791   ///     A path to a source file to match. If \a file_path does not
792   ///     specify a directory, then this query will match all files
793   ///     whose base filename matches. If \a file_path does specify
794   ///     a directory, the fullpath to the file must match.
795   ///
796   /// @param[in] line
797   ///     The source line to match, or zero if just the compile unit
798   ///     should be resolved.
799   ///
800   /// @param[in] check_inlines
801   ///     Check for inline file and line number matches. This option
802   ///     should be used sparingly as it will cause all line tables
803   ///     for every compile unit to be parsed and searched for
804   ///     matching inline file entries.
805   ///
806   /// @param[in] resolve_scope
807   ///     The scope that should be resolved (see
808   ///     SymbolContext::Scope).
809   ///
810   /// @param[out] sc_list
811   ///     A symbol context list that gets matching symbols contexts
812   ///     appended to.
813   ///
814   /// @return
815   ///     The number of matches that were added to \a sc_list.
816   ///
817   /// @see SymbolContext::Scope
818   //------------------------------------------------------------------
819   uint32_t ResolveSymbolContextForFilePath(const char *file_path, uint32_t line,
820                                            bool check_inlines,
821                                            uint32_t resolve_scope,
822                                            SymbolContextList &sc_list);
823
824   //------------------------------------------------------------------
825   /// Resolve items in the symbol context for a given file and line.
826   ///
827   /// Tries to resolve \a file_spec and \a line to a list of matching
828   /// symbol contexts.
829   ///
830   /// The line table entries contains addresses that can be used to
831   /// further resolve the values in each match: the function, block,
832   /// symbol. Care should be taken to minimize the amount of
833   /// information that is requested to only what is needed --
834   /// typically the module, compile unit, line table and line table
835   /// entry are sufficient.
836   ///
837   /// @param[in] file_spec
838   ///     A file spec to a source file to match. If \a file_path does
839   ///     not specify a directory, then this query will match all
840   ///     files whose base filename matches. If \a file_path does
841   ///     specify a directory, the fullpath to the file must match.
842   ///
843   /// @param[in] line
844   ///     The source line to match, or zero if just the compile unit
845   ///     should be resolved.
846   ///
847   /// @param[in] check_inlines
848   ///     Check for inline file and line number matches. This option
849   ///     should be used sparingly as it will cause all line tables
850   ///     for every compile unit to be parsed and searched for
851   ///     matching inline file entries.
852   ///
853   /// @param[in] resolve_scope
854   ///     The scope that should be resolved (see
855   ///     SymbolContext::Scope).
856   ///
857   /// @param[out] sc_list
858   ///     A symbol context list that gets filled in with all of the
859   ///     matches.
860   ///
861   /// @return
862   ///     A integer that contains SymbolContext::Scope bits set for
863   ///     each item that was successfully resolved.
864   ///
865   /// @see SymbolContext::Scope
866   //------------------------------------------------------------------
867   uint32_t ResolveSymbolContextsForFileSpec(const FileSpec &file_spec,
868                                             uint32_t line, bool check_inlines,
869                                             uint32_t resolve_scope,
870                                             SymbolContextList &sc_list);
871
872   void SetFileSpecAndObjectName(const FileSpec &file,
873                                 const ConstString &object_name);
874
875   bool GetIsDynamicLinkEditor();
876
877   TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language);
878
879   // Special error functions that can do printf style formatting that will
880   // prepend the message with
881   // something appropriate for this module (like the architecture, path and
882   // object name (if any)).
883   // This centralizes code so that everyone doesn't need to format their error
884   // and log messages on
885   // their own and keeps the output a bit more consistent.
886   void LogMessage(Log *log, const char *format, ...)
887       __attribute__((format(printf, 3, 4)));
888
889   void LogMessageVerboseBacktrace(Log *log, const char *format, ...)
890       __attribute__((format(printf, 3, 4)));
891
892   void ReportWarning(const char *format, ...)
893       __attribute__((format(printf, 2, 3)));
894
895   void ReportError(const char *format, ...)
896       __attribute__((format(printf, 2, 3)));
897
898   // Only report an error once when the module is first detected to be modified
899   // so we don't spam the console with many messages.
900   void ReportErrorIfModifyDetected(const char *format, ...)
901       __attribute__((format(printf, 2, 3)));
902
903   //------------------------------------------------------------------
904   // Return true if the file backing this module has changed since the
905   // module was originally created  since we saved the initial file
906   // modification time when the module first gets created.
907   //------------------------------------------------------------------
908   bool FileHasChanged() const;
909
910   //------------------------------------------------------------------
911   // SymbolVendor, SymbolFile and ObjectFile member objects should
912   // lock the module mutex to avoid deadlocks.
913   //------------------------------------------------------------------
914   std::recursive_mutex &GetMutex() const { return m_mutex; }
915
916   PathMappingList &GetSourceMappingList() { return m_source_mappings; }
917
918   const PathMappingList &GetSourceMappingList() const {
919     return m_source_mappings;
920   }
921
922   //------------------------------------------------------------------
923   /// Finds a source file given a file spec using the module source
924   /// path remappings (if any).
925   ///
926   /// Tries to resolve \a orig_spec by checking the module source path
927   /// remappings. It makes sure the file exists, so this call can be
928   /// expensive if the remappings are on a network file system, so
929   /// use this function sparingly (not in a tight debug info parsing
930   /// loop).
931   ///
932   /// @param[in] orig_spec
933   ///     The original source file path to try and remap.
934   ///
935   /// @param[out] new_spec
936   ///     The newly remapped filespec that is guaranteed to exist.
937   ///
938   /// @return
939   ///     /b true if \a orig_spec was successfully located and
940   ///     \a new_spec is filled in with an existing file spec,
941   ///     \b false otherwise.
942   //------------------------------------------------------------------
943   bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const;
944
945   //------------------------------------------------------------------
946   /// Remaps a source file given \a path into \a new_path.
947   ///
948   /// Remaps \a path if any source remappings match. This function
949   /// does NOT stat the file system so it can be used in tight loops
950   /// where debug info is being parsed.
951   ///
952   /// @param[in] path
953   ///     The original source file path to try and remap.
954   ///
955   /// @param[out] new_path
956   ///     The newly remapped filespec that is may or may not exist.
957   ///
958   /// @return
959   ///     /b true if \a path was successfully located and \a new_path
960   ///     is filled in with a new source path, \b false otherwise.
961   //------------------------------------------------------------------
962   bool RemapSourceFile(llvm::StringRef path, std::string &new_path) const;
963   bool RemapSourceFile(const char *, std::string &) const = delete;
964
965   //----------------------------------------------------------------------
966   /// @class LookupInfo Module.h "lldb/Core/Module.h"
967   /// @brief A class that encapsulates name lookup information.
968   ///
969   /// Users can type a wide variety of partial names when setting
970   /// breakpoints by name or when looking for functions by name.
971   /// SymbolVendor and SymbolFile objects are only required to implement
972   /// name lookup for function basenames and for fully mangled names.
973   /// This means if the user types in a partial name, we must reduce this
974   /// to a name lookup that will work with all SymbolFile objects. So we
975   /// might reduce a name lookup to look for a basename, and then prune
976   /// out any results that don't match.
977   ///
978   /// The "m_name" member variable represents the name as it was typed
979   /// by the user. "m_lookup_name" will be the name we actually search
980   /// for through the symbol or objects files. Lanaguage is included in
981   /// case we need to filter results by language at a later date. The
982   /// "m_name_type_mask" member variable tells us what kinds of names we
983   /// are looking for and can help us prune out unwanted results.
984   ///
985   /// Function lookups are done in Module.cpp, ModuleList.cpp and in
986   /// BreakpointResolverName.cpp and they all now use this class to do
987   /// lookups correctly.
988   //----------------------------------------------------------------------
989   class LookupInfo {
990   public:
991     LookupInfo()
992         : m_name(), m_lookup_name(), m_language(lldb::eLanguageTypeUnknown),
993           m_name_type_mask(0), m_match_name_after_lookup(false) {}
994
995     LookupInfo(const ConstString &name, uint32_t name_type_mask,
996                lldb::LanguageType language);
997
998     const ConstString &GetName() const { return m_name; }
999
1000     void SetName(const ConstString &name) { m_name = name; }
1001
1002     const ConstString &GetLookupName() const { return m_lookup_name; }
1003
1004     void SetLookupName(const ConstString &name) { m_lookup_name = name; }
1005
1006     uint32_t GetNameTypeMask() const { return m_name_type_mask; }
1007
1008     void SetNameTypeMask(uint32_t mask) { m_name_type_mask = mask; }
1009
1010     void Prune(SymbolContextList &sc_list, size_t start_idx) const;
1011
1012   protected:
1013     ConstString m_name;        ///< What the user originally typed
1014     ConstString m_lookup_name; ///< The actual name will lookup when calling in
1015                                ///the object or symbol file
1016     lldb::LanguageType
1017         m_language;            ///< Limit matches to only be for this language
1018     uint32_t m_name_type_mask; ///< One or more bits from lldb::FunctionNameType
1019                                ///that indicate what kind of names we are
1020                                ///looking for
1021     bool m_match_name_after_lookup; ///< If \b true, then demangled names that
1022                                     ///match will need to contain "m_name" in
1023                                     ///order to be considered a match
1024   };
1025
1026 protected:
1027   //------------------------------------------------------------------
1028   // Member Variables
1029   //------------------------------------------------------------------
1030   mutable std::recursive_mutex m_mutex; ///< A mutex to keep this object happy
1031                                         ///in multi-threaded environments.
1032
1033   /// The modification time for this module when it was created.
1034   llvm::sys::TimePoint<> m_mod_time;
1035
1036   ArchSpec m_arch;      ///< The architecture for this module.
1037   UUID m_uuid; ///< Each module is assumed to have a unique identifier to help
1038                ///match it up to debug symbols.
1039   FileSpec m_file; ///< The file representation on disk for this module (if
1040                    ///there is one).
1041   FileSpec m_platform_file; ///< The path to the module on the platform on which
1042                             ///it is being debugged
1043   FileSpec m_remote_install_file; ///< If set when debugging on remote
1044                                   ///platforms, this module will be installed at
1045                                   ///this location
1046   FileSpec m_symfile_spec;   ///< If this path is valid, then this is the file
1047                              ///that _will_ be used as the symbol file for this
1048                              ///module
1049   ConstString m_object_name; ///< The name an object within this module that is
1050                              ///selected, or empty of the module is represented
1051                              ///by \a m_file.
1052   uint64_t m_object_offset;
1053   llvm::sys::TimePoint<> m_object_mod_time;
1054   lldb::ObjectFileSP m_objfile_sp; ///< A shared pointer to the object file
1055                                    ///parser for this module as it may or may
1056                                    ///not be shared with the SymbolFile
1057   lldb::SymbolVendorUP
1058       m_symfile_ap; ///< A pointer to the symbol vendor for this module.
1059   std::vector<lldb::SymbolVendorUP>
1060       m_old_symfiles; ///< If anyone calls Module::SetSymbolFileFileSpec() and
1061                       ///changes the symbol file,
1062   ///< we need to keep all old symbol files around in case anyone has type
1063   ///references to them
1064   TypeSystemMap m_type_system_map;   ///< A map of any type systems associated
1065                                      ///with this module
1066   PathMappingList m_source_mappings; ///< Module specific source remappings for
1067                                      ///when you have debug info for a module
1068                                      ///that doesn't match where the sources
1069                                      ///currently are
1070   lldb::SectionListUP m_sections_ap; ///< Unified section list for module that
1071                                      ///is used by the ObjectFile and and
1072                                      ///ObjectFile instances for the debug info
1073
1074   std::atomic<bool> m_did_load_objfile{false};
1075   std::atomic<bool> m_did_load_symbol_vendor{false};
1076   std::atomic<bool> m_did_parse_uuid{false};
1077   mutable bool m_file_has_changed : 1,
1078       m_first_file_changed_log : 1; /// See if the module was modified after it
1079                                     /// was initially opened.
1080
1081   //------------------------------------------------------------------
1082   /// Resolve a file or load virtual address.
1083   ///
1084   /// Tries to resolve \a vm_addr as a file address (if \a
1085   /// vm_addr_is_file_addr is true) or as a load address if \a
1086   /// vm_addr_is_file_addr is false) in the symbol vendor.
1087   /// \a resolve_scope indicates what clients wish to resolve
1088   /// and can be used to limit the scope of what is parsed.
1089   ///
1090   /// @param[in] vm_addr
1091   ///     The load virtual address to resolve.
1092   ///
1093   /// @param[in] vm_addr_is_file_addr
1094   ///     If \b true, \a vm_addr is a file address, else \a vm_addr
1095   ///     if a load address.
1096   ///
1097   /// @param[in] resolve_scope
1098   ///     The scope that should be resolved (see
1099   ///     SymbolContext::Scope).
1100   ///
1101   /// @param[out] so_addr
1102   ///     The section offset based address that got resolved if
1103   ///     any bits are returned.
1104   ///
1105   /// @param[out] sc
1106   //      The symbol context that has objects filled in. Each bit
1107   ///     in the \a resolve_scope pertains to a member in the \a sc.
1108   ///
1109   /// @return
1110   ///     A integer that contains SymbolContext::Scope bits set for
1111   ///     each item that was successfully resolved.
1112   ///
1113   /// @see SymbolContext::Scope
1114   //------------------------------------------------------------------
1115   uint32_t ResolveSymbolContextForAddress(lldb::addr_t vm_addr,
1116                                           bool vm_addr_is_file_addr,
1117                                           uint32_t resolve_scope,
1118                                           Address &so_addr, SymbolContext &sc);
1119
1120   void SymbolIndicesToSymbolContextList(Symtab *symtab,
1121                                         std::vector<uint32_t> &symbol_indexes,
1122                                         SymbolContextList &sc_list);
1123
1124   bool SetArchitecture(const ArchSpec &new_arch);
1125
1126   SectionList *GetUnifiedSectionList();
1127
1128   friend class ModuleList;
1129   friend class ObjectFile;
1130   friend class SymbolFile;
1131
1132 private:
1133   Module(); // Only used internally by CreateJITModule ()
1134
1135   size_t FindTypes_Impl(
1136       const SymbolContext &sc, const ConstString &name,
1137       const CompilerDeclContext *parent_decl_ctx, bool append,
1138       size_t max_matches,
1139       llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1140       TypeMap &types);
1141
1142   DISALLOW_COPY_AND_ASSIGN(Module);
1143 };
1144
1145 } // namespace lldb_private
1146
1147 #endif // liblldb_Module_h_