1 //===-- Module.h ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Module_h_
11 #define liblldb_Module_h_
13 #include "lldb/Symbol/SymbolContextScope.h"
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"
23 // Other libraries and framework includes
24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Support/Chrono.h"
35 namespace lldb_private {
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.
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
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.
53 /// The module will parse more detailed information as more queries are
55 //----------------------------------------------------------------------
56 class Module : public std::enable_shared_from_this<Module>,
57 public SymbolContextScope {
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();
68 static Module *GetAllocatedModuleAtIndex(size_t idx);
70 static std::recursive_mutex &GetAllocationModuleCollectionMutex();
72 //------------------------------------------------------------------
73 /// Construct with file specification and architecture.
75 /// Clients that wish to share modules with other targets should
76 /// use ModuleList::GetSharedModule().
78 /// @param[in] file_spec
79 /// The file specification for the on disk representation of
80 /// this executable image.
83 /// The architecture to set as the current architecture in
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
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 //------------------------------------------------------------------
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<>());
102 Module(const ModuleSpec &module_spec);
104 static lldb::ModuleSP
105 CreateJITModule(const lldb::ObjectFileJITDelegateSP &delegate_sp);
107 //------------------------------------------------------------------
109 //------------------------------------------------------------------
112 bool MatchesModuleSpec(const ModuleSpec &module_ref);
114 //------------------------------------------------------------------
115 /// Set the load address for all sections in a module to be the
116 /// file address plus \a slide.
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.
123 /// @param[in] target
124 /// The target in which to apply the section load addresses.
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.
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.
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
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,
155 //------------------------------------------------------------------
156 /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
158 /// @see SymbolContextScope
159 //------------------------------------------------------------------
160 void CalculateSymbolContext(SymbolContext *sc) override;
162 lldb::ModuleSP CalculateSymbolContextModule() override;
165 GetDescription(Stream *s,
166 lldb::DescriptionLevel level = lldb::eDescriptionLevelFull);
168 //------------------------------------------------------------------
169 /// Get the module path and object name.
171 /// Modules can refer to object files. In this case the specification
172 /// is simple and would return the path to the file:
174 /// "/usr/lib/foo.dylib"
176 /// Modules can be .o files inside of a BSD archive (.a file). In
177 /// this case, the object specification will look like:
179 /// "/usr/lib/foo.a(bar.o)"
181 /// There are many places where logging wants to log this fully
182 /// qualified specification, so we centralize this functionality
186 /// The object path + object name if there is one.
187 //------------------------------------------------------------------
188 std::string GetSpecificationDescription() const;
190 //------------------------------------------------------------------
191 /// Dump a description of this object to a Stream.
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
200 /// The stream to which to dump the object description.
201 //------------------------------------------------------------------
202 void Dump(Stream *s);
204 //------------------------------------------------------------------
205 /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
207 /// @see SymbolContextScope
208 //------------------------------------------------------------------
209 void DumpSymbolContext(Stream *s) override;
211 //------------------------------------------------------------------
212 /// Find a symbol in the object file's symbol table.
215 /// The name of the symbol that we are looking for.
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.
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);
231 size_t FindSymbolsWithNameAndType(const ConstString &name,
232 lldb::SymbolType symbol_type,
233 SymbolContextList &sc_list);
235 size_t FindSymbolsMatchingRegExAndType(const RegularExpression ®ex,
236 lldb::SymbolType symbol_type,
237 SymbolContextList &sc_list);
239 //------------------------------------------------------------------
240 /// Find a function symbols in the object file's symbol table.
243 /// The name of the symbol that we are looking for.
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.
250 /// @param[out] sc_list
251 /// A list to append any matching symbol contexts to.
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);
259 //------------------------------------------------------------------
260 /// Find compile units by partial or full path.
262 /// Finds all compile units that match \a path in all of the modules
263 /// and returns the results in \a sc_list.
266 /// The name of the function we are looking for.
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.
273 /// @param[out] sc_list
274 /// A symbol context list that gets filled in with all of the
278 /// The number of matches added to \a sc_list.
279 //------------------------------------------------------------------
280 size_t FindCompileUnits(const FileSpec &path, bool append,
281 SymbolContextList &sc_list);
283 //------------------------------------------------------------------
284 /// Find functions by name.
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
292 /// The name of the compile unit we are looking for.
294 /// @param[in] namespace_decl
295 /// If valid, a namespace to search in.
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.
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.
307 /// @param[out] sc_list
308 /// A symbol context list that gets filled in with all of the
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);
320 //------------------------------------------------------------------
321 /// Find functions by name.
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
329 /// A regular expression to use when matching the name.
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.
335 /// @param[out] sc_list
336 /// A symbol context list that gets filled in with all of the
340 /// The number of matches added to \a sc_list.
341 //------------------------------------------------------------------
342 size_t FindFunctions(const RegularExpression ®ex, bool symbols_ok,
343 bool inlines_ok, bool append,
344 SymbolContextList &sc_list);
346 //------------------------------------------------------------------
347 /// Find addresses by file/line
349 /// @param[in] target_sp
350 /// The target the addresses are desired for.
353 /// Source file to locate.
356 /// Source line to locate.
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'
363 /// @param[out] output_local
364 /// All matching addresses within 'function'
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,
371 std::vector<Address> &output_local,
372 std::vector<Address> &output_extern);
374 //------------------------------------------------------------------
375 /// Find global and static variables by name.
378 /// The name of the global or static variable we are looking
381 /// @param[in] parent_decl_ctx
382 /// If valid, a decl context that results must exist within
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.
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.
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).
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);
405 //------------------------------------------------------------------
406 /// Find global and static variables by regular expression.
409 /// A regular expression to use when matching the name.
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.
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.
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).
425 /// The number of matches added to \a variable_list.
426 //------------------------------------------------------------------
427 size_t FindGlobalVariables(const RegularExpression ®ex, bool append,
428 size_t max_matches, VariableList &variable_list);
430 //------------------------------------------------------------------
431 /// Find types by name.
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
451 /// A symbol context that scopes where to extract a type list
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.
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
465 /// @param[out] type_list
466 /// A type list gets populated with any matches.
469 /// The number of matches added to \a type_list.
470 //------------------------------------------------------------------
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,
477 lldb::TypeSP FindFirstType(const SymbolContext &sc,
478 const ConstString &type_name, bool exact_match);
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.
486 /// A symbol context that scopes where to extract a type list
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).
493 /// @param[in] namespace_decl
494 /// The namespace declaration that this type must exist in.
496 /// @param[out] type_list
497 /// A type list gets populated with any matches.
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);
507 //------------------------------------------------------------------
508 /// Get const accessor for the module architecture.
511 /// A const reference to the architecture object.
512 //------------------------------------------------------------------
513 const ArchSpec &GetArchitecture() const;
515 //------------------------------------------------------------------
516 /// Get const accessor for the module file specification.
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.
523 /// A const reference to the file specification object.
524 //------------------------------------------------------------------
525 const FileSpec &GetFileSpec() const { return m_file; }
527 //------------------------------------------------------------------
528 /// Get accessor for the module platform file specification.
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.
540 /// A const reference to the file specification object.
541 //------------------------------------------------------------------
542 const FileSpec &GetPlatformFileSpec() const {
544 return m_platform_file;
548 void SetPlatformFileSpec(const FileSpec &file) { m_platform_file = file; }
550 const FileSpec &GetRemoteInstallFileSpec() const {
551 return m_remote_install_file;
554 void SetRemoteInstallFileSpec(const FileSpec &file) {
555 m_remote_install_file = file;
558 const FileSpec &GetSymbolFileFileSpec() const { return m_symfile_spec; }
560 void SetSymbolFileFileSpec(const FileSpec &file);
562 const llvm::sys::TimePoint<> &GetModificationTime() const {
566 const llvm::sys::TimePoint<> &GetObjectModificationTime() const {
567 return m_object_mod_time;
570 void SetObjectModificationTime(const llvm::sys::TimePoint<> &mod_time) {
571 m_mod_time = mod_time;
574 //------------------------------------------------------------------
575 /// Tells whether this module is capable of being the main executable
579 /// \b true if it is, \b false otherwise.
580 //------------------------------------------------------------------
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.
588 /// @param[in] target
589 /// The target to check whether this is loaded in.
592 /// \b true if it is, \b false otherwise.
593 //------------------------------------------------------------------
594 bool IsLoadedInTarget(Target *target);
596 bool LoadScriptingResourceInTarget(Target *target, Error &error,
597 Stream *feedback_stream = nullptr);
599 //------------------------------------------------------------------
600 /// Get the number of compile units for this module.
603 /// The number of compile units that the symbol vendor plug-in
605 //------------------------------------------------------------------
606 size_t GetNumCompileUnits();
608 lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx);
610 const ConstString &GetObjectName() const;
612 uint64_t GetObjectOffset() const { return m_object_offset; }
614 //------------------------------------------------------------------
615 /// Get the object file representation for the current architecture.
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
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();
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.
636 /// If the symbol vendor has not been loaded yet, this function
637 /// will return the section list for the object file.
640 /// Unified module section list.
641 //------------------------------------------------------------------
642 virtual SectionList *GetSectionList();
644 //------------------------------------------------------------------
645 /// Notify the module that the file addresses for the Sections have
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();
655 uint32_t GetVersion(uint32_t *versions, uint32_t num_versions);
657 //------------------------------------------------------------------
658 /// Load an object file from memory.
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
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.
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.
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);
692 //------------------------------------------------------------------
693 /// Get accessor the type list for this module.
696 /// A valid type list pointer, or nullptr if there is no valid
697 /// symbol vendor for this module.
698 //------------------------------------------------------------------
699 TypeList *GetTypeList();
701 //------------------------------------------------------------------
702 /// Get a pointer to the UUID value contained in this object.
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.
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
712 //------------------------------------------------------------------
713 const lldb_private::UUID &GetUUID();
715 //------------------------------------------------------------------
716 /// A debugging function that will cause everything in a module to
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();
730 bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr);
732 //------------------------------------------------------------------
733 /// Resolve the symbol context for the given address.
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.
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.
747 /// @param[in] so_addr
748 /// A load address to resolve.
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.
760 /// The SymbolContext that is modified based on symbol resolution.
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.
768 /// The scope that has been resolved (see SymbolContext::Scope).
770 /// @see SymbolContext::Scope
771 //------------------------------------------------------------------
773 ResolveSymbolContextForAddress(const Address &so_addr, uint32_t resolve_scope,
775 bool resolve_tail_call_address = false);
777 //------------------------------------------------------------------
778 /// Resolve items in the symbol context for a given file and line.
780 /// Tries to resolve \a file_path and \a line to a list of matching
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.
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.
797 /// The source line to match, or zero if just the compile unit
798 /// should be resolved.
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.
806 /// @param[in] resolve_scope
807 /// The scope that should be resolved (see
808 /// SymbolContext::Scope).
810 /// @param[out] sc_list
811 /// A symbol context list that gets matching symbols contexts
815 /// The number of matches that were added to \a sc_list.
817 /// @see SymbolContext::Scope
818 //------------------------------------------------------------------
819 uint32_t ResolveSymbolContextForFilePath(const char *file_path, uint32_t line,
821 uint32_t resolve_scope,
822 SymbolContextList &sc_list);
824 //------------------------------------------------------------------
825 /// Resolve items in the symbol context for a given file and line.
827 /// Tries to resolve \a file_spec and \a line to a list of matching
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.
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.
844 /// The source line to match, or zero if just the compile unit
845 /// should be resolved.
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.
853 /// @param[in] resolve_scope
854 /// The scope that should be resolved (see
855 /// SymbolContext::Scope).
857 /// @param[out] sc_list
858 /// A symbol context list that gets filled in with all of the
862 /// A integer that contains SymbolContext::Scope bits set for
863 /// each item that was successfully resolved.
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);
872 void SetFileSpecAndObjectName(const FileSpec &file,
873 const ConstString &object_name);
875 bool GetIsDynamicLinkEditor();
877 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language);
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)));
889 void LogMessageVerboseBacktrace(Log *log, const char *format, ...)
890 __attribute__((format(printf, 3, 4)));
892 void ReportWarning(const char *format, ...)
893 __attribute__((format(printf, 2, 3)));
895 void ReportError(const char *format, ...)
896 __attribute__((format(printf, 2, 3)));
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)));
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;
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; }
916 PathMappingList &GetSourceMappingList() { return m_source_mappings; }
918 const PathMappingList &GetSourceMappingList() const {
919 return m_source_mappings;
922 //------------------------------------------------------------------
923 /// Finds a source file given a file spec using the module source
924 /// path remappings (if any).
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
932 /// @param[in] orig_spec
933 /// The original source file path to try and remap.
935 /// @param[out] new_spec
936 /// The newly remapped filespec that is guaranteed to exist.
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;
945 //------------------------------------------------------------------
946 /// Remaps a source file given \a path into \a new_path.
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.
953 /// The original source file path to try and remap.
955 /// @param[out] new_path
956 /// The newly remapped filespec that is may or may not exist.
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;
965 //----------------------------------------------------------------------
966 /// @class LookupInfo Module.h "lldb/Core/Module.h"
967 /// @brief A class that encapsulates name lookup information.
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.
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.
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 //----------------------------------------------------------------------
992 : m_name(), m_lookup_name(), m_language(lldb::eLanguageTypeUnknown),
993 m_name_type_mask(0), m_match_name_after_lookup(false) {}
995 LookupInfo(const ConstString &name, uint32_t name_type_mask,
996 lldb::LanguageType language);
998 const ConstString &GetName() const { return m_name; }
1000 void SetName(const ConstString &name) { m_name = name; }
1002 const ConstString &GetLookupName() const { return m_lookup_name; }
1004 void SetLookupName(const ConstString &name) { m_lookup_name = name; }
1006 uint32_t GetNameTypeMask() const { return m_name_type_mask; }
1008 void SetNameTypeMask(uint32_t mask) { m_name_type_mask = mask; }
1010 void Prune(SymbolContextList &sc_list, size_t start_idx) const;
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
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
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
1027 //------------------------------------------------------------------
1029 //------------------------------------------------------------------
1030 mutable std::recursive_mutex m_mutex; ///< A mutex to keep this object happy
1031 ///in multi-threaded environments.
1033 /// The modification time for this module when it was created.
1034 llvm::sys::TimePoint<> m_mod_time;
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
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
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
1049 ConstString m_object_name; ///< The name an object within this module that is
1050 ///selected, or empty of the module is represented
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
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
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
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.
1081 //------------------------------------------------------------------
1082 /// Resolve a file or load virtual address.
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.
1090 /// @param[in] vm_addr
1091 /// The load virtual address to resolve.
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.
1097 /// @param[in] resolve_scope
1098 /// The scope that should be resolved (see
1099 /// SymbolContext::Scope).
1101 /// @param[out] so_addr
1102 /// The section offset based address that got resolved if
1103 /// any bits are returned.
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.
1110 /// A integer that contains SymbolContext::Scope bits set for
1111 /// each item that was successfully resolved.
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);
1120 void SymbolIndicesToSymbolContextList(Symtab *symtab,
1121 std::vector<uint32_t> &symbol_indexes,
1122 SymbolContextList &sc_list);
1124 bool SetArchitecture(const ArchSpec &new_arch);
1126 SectionList *GetUnifiedSectionList();
1128 friend class ModuleList;
1129 friend class ObjectFile;
1130 friend class SymbolFile;
1133 Module(); // Only used internally by CreateJITModule ()
1135 size_t FindTypes_Impl(
1136 const SymbolContext &sc, const ConstString &name,
1137 const CompilerDeclContext *parent_decl_ctx, bool append,
1139 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1142 DISALLOW_COPY_AND_ASSIGN(Module);
1145 } // namespace lldb_private
1147 #endif // liblldb_Module_h_