LLDB mainline
Module.h
Go to the documentation of this file.
1//===-- Module.h ------------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_CORE_MODULE_H
10#define LLDB_CORE_MODULE_H
11
12#include "lldb/Core/Address.h"
24#include "lldb/Utility/Locked.h"
25#include "lldb/Utility/Status.h"
26#include "lldb/Utility/UUID.h"
28#include "lldb/lldb-defines.h"
30#include "lldb/lldb-forward.h"
31#include "lldb/lldb-types.h"
32
33#include "llvm/ADT/STLFunctionalExtras.h"
34#include "llvm/ADT/StableHashing.h"
35#include "llvm/ADT/StringRef.h"
36#include "llvm/ADT/StringSet.h"
37#include "llvm/Support/Chrono.h"
38
39#include <atomic>
40#include <cstddef>
41#include <cstdint>
42#include <memory>
43#include <mutex>
44#include <optional>
45#include <string>
46#include <vector>
47
48namespace lldb_private {
50class Function;
51class Log;
52class ObjectFile;
54class SectionList;
55class Stream;
56class Symbol;
57class SymbolContext;
59class SymbolFile;
60class Symtab;
61class Target;
62class TypeList;
63class TypeMap;
64class VariableList;
65
66/// Options used by Module::FindFunctions. This cannot be a nested class
67/// because it must be forward-declared in ModuleList.h.
69 /// Include the symbol table.
70 bool include_symbols = false;
71 /// Include inlined functions.
72 bool include_inlines = false;
73};
74
75/// \class Module Module.h "lldb/Core/Module.h"
76/// A class that describes an executable image and its associated
77/// object and symbol files.
78///
79/// The module is designed to be able to select a single slice of an
80/// executable image as it would appear on disk and during program execution.
81///
82/// Modules control when and if information is parsed according to which
83/// accessors are called. For example the object file (ObjectFile)
84/// representation will only be parsed if the object file is requested using
85/// the Module::GetObjectFile() is called. The debug symbols will only be
86/// parsed if the symbol file (SymbolFile) is requested using the
87/// Module::GetSymbolFile() method.
88///
89/// The module will parse more detailed information as more queries are made.
90class Module : public std::enable_shared_from_this<Module>,
91 public SymbolContextScope,
92 public UserID {
93public:
94 class LookupInfo;
95 // Static functions that can track the lifetime of module objects. This is
96 // handy because we might have Module objects that are in shared pointers
97 // that aren't in the global module list (from ModuleList). If this is the
98 // case we need to know about it. The modules in the global list maintained
99 // by these functions can be viewed using the "target modules list" command
100 // using the "--global" (-g for short).
101 static size_t GetNumberAllocatedModules();
102
103 static Module *GetAllocatedModuleAtIndex(size_t idx);
104
105 static std::recursive_mutex &GetAllocationModuleCollectionMutex();
106
107 /// Construct with file specification and architecture.
108 ///
109 /// Clients that wish to share modules with other targets should use
110 /// ModuleList::GetSharedModule().
111 ///
112 /// \param[in] file_spec
113 /// The file specification for the on disk representation of
114 /// this executable image.
115 ///
116 /// \param[in] arch
117 /// The architecture to set as the current architecture in
118 /// this module.
119 ///
120 /// \param[in] object_name
121 /// The name of an object in a module used to extract a module
122 /// within a module (.a files and modules that contain multiple
123 /// architectures).
124 ///
125 /// \param[in] object_offset
126 /// The offset within an existing module used to extract a
127 /// module within a module (.a files and modules that contain
128 /// multiple architectures).
129 Module(
130 const FileSpec &file_spec, const ArchSpec &arch,
131 std::string object_name = std::string(), lldb::offset_t object_offset = 0,
132 const llvm::sys::TimePoint<> &object_mod_time = llvm::sys::TimePoint<>());
133
134 Module(const ModuleSpec &module_spec);
135
136 template <typename ObjFilePlugin, typename... Args>
138 // Must create a module and place it into a shared pointer before we can
139 // create an object file since it has a std::weak_ptr back to the module,
140 // so we need to control the creation carefully in this static function
141 lldb::ModuleSP module_sp(new Module());
142 module_sp->m_objfile_sp =
143 std::make_shared<ObjFilePlugin>(module_sp, std::forward<Args>(args)...);
144 module_sp->m_did_load_objfile.store(true, std::memory_order_relaxed);
145
146 // Once we get the object file, set module ArchSpec to the one we get from
147 // the object file. If the object file does not have an architecture, we
148 // consider the creation a failure.
149 ArchSpec arch = module_sp->m_objfile_sp->GetArchitecture();
150 if (!arch)
151 return nullptr;
152 module_sp->m_arch = arch;
153
154 // Also copy the object file's FileSpec.
155 module_sp->m_file = module_sp->m_objfile_sp->GetFileSpec();
156 return module_sp;
157 }
158
159 /// Destructor.
160 ~Module() override;
161
162 bool MatchesModuleSpec(const ModuleSpec &module_ref);
163
164 /// Set the load address for all sections in a module to be the file address
165 /// plus \a slide.
166 ///
167 /// Many times a module will be loaded in a target with a constant offset
168 /// applied to all top level sections. This function can set the load
169 /// address for all top level sections to be the section file address +
170 /// offset.
171 ///
172 /// \param[in] target
173 /// The target in which to apply the section load addresses.
174 ///
175 /// \param[in] value
176 /// if \a value_is_offset is true, then value is the offset to
177 /// apply to all file addresses for all top level sections in
178 /// the object file as each section load address is being set.
179 /// If \a value_is_offset is false, then "value" is the new
180 /// absolute base address for the image.
181 ///
182 /// \param[in] value_is_offset
183 /// If \b true, then \a value is an offset to apply to each
184 /// file address of each top level section.
185 /// If \b false, then \a value is the image base address that
186 /// will be used to rigidly slide all loadable sections.
187 ///
188 /// \param[out] changed
189 /// If any section load addresses were changed in \a target,
190 /// then \a changed will be set to \b true. Else \a changed
191 /// will be set to false. This allows this function to be
192 /// called multiple times on the same module for the same
193 /// target. If the module hasn't moved, then \a changed will
194 /// be false and no module updated notification will need to
195 /// be sent out.
196 ///
197 /// \return
198 /// /b True if any sections were successfully loaded in \a target,
199 /// /b false otherwise.
200 bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset,
201 bool &changed);
202
203 /// \copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
204 ///
205 /// \see SymbolContextScope
206 void CalculateSymbolContext(SymbolContext *sc) override;
207
209
210 void
211 GetDescription(llvm::raw_ostream &s,
213
214 /// Get the module path and object name.
215 ///
216 /// Modules can refer to object files. In this case the specification is
217 /// simple and would return the path to the file:
218 ///
219 /// "/usr/lib/foo.dylib"
220 ///
221 /// Modules can be .o files inside of a BSD archive (.a file). In this case,
222 /// the object specification will look like:
223 ///
224 /// "/usr/lib/foo.a(bar.o)"
225 ///
226 /// There are many places where logging wants to log this fully qualified
227 /// specification, so we centralize this functionality here.
228 ///
229 /// \return
230 /// The object path + object name if there is one.
231 std::string GetSpecificationDescription() const;
232
233 /// Dump a description of this object to a Stream.
234 ///
235 /// Dump a description of the contents of this object to the supplied stream
236 /// \a s. The dumped content will be only what has been loaded or parsed up
237 /// to this point at which this function is called, so this is a good way to
238 /// see what has been parsed in a module.
239 ///
240 /// \param[in] s
241 /// The stream to which to dump the object description.
242 void Dump(Stream *s);
243
244 /// \copydoc SymbolContextScope::DumpSymbolContext(Stream*)
245 ///
246 /// \see SymbolContextScope
247 void DumpSymbolContext(Stream *s) override;
248
249 /// Find a symbol in the object file's symbol table.
250 ///
251 /// \param[in] name
252 /// The name of the symbol that we are looking for.
253 ///
254 /// \param[in] symbol_type
255 /// If set to eSymbolTypeAny, find a symbol of any type that
256 /// has a name that matches \a name. If set to any other valid
257 /// SymbolType enumeration value, then search only for
258 /// symbols that match \a symbol_type.
259 ///
260 /// \return
261 /// Returns a valid symbol pointer if a symbol was found,
262 /// nullptr otherwise.
265
267 lldb::SymbolType symbol_type,
268 SymbolContextList &sc_list);
269
271 const RegularExpression &regex, lldb::SymbolType symbol_type,
272 SymbolContextList &sc_list,
274
275 /// Find a function symbols in the object file's symbol table.
276 ///
277 /// \param[in] name
278 /// The name of the symbol that we are looking for.
279 ///
280 /// \param[in] name_type_mask
281 /// A mask that has one or more bitwise OR'ed values from the
282 /// lldb::FunctionNameType enumeration type that indicate what
283 /// kind of names we are looking for.
284 ///
285 /// \param[out] sc_list
286 /// A list to append any matching symbol contexts to.
287 void FindFunctionSymbols(ConstString name, uint32_t name_type_mask,
288 SymbolContextList &sc_list);
289
290 /// Find compile units by partial or full path.
291 ///
292 /// Finds all compile units that match \a path in all of the modules and
293 /// returns the results in \a sc_list.
294 ///
295 /// \param[in] path
296 /// The name of the function we are looking for.
297 ///
298 /// \param[out] sc_list
299 /// A symbol context list that gets filled in with all of the
300 /// matches.
301 void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list);
302
303 /// Find functions by a vector of lookup infos.
304 ///
305 /// If the function is an inlined function, it will have a block,
306 /// representing the inlined function, and the function will be the
307 /// containing function. If it is not inlined, then the block will be NULL.
308 void FindFunctions(llvm::ArrayRef<LookupInfo> lookup_infos,
309 const CompilerDeclContext &parent_decl_ctx,
310 const ModuleFunctionSearchOptions &options,
311 SymbolContextList &sc_list);
312 /// Find functions by name.
313 ///
314 /// If the function is an inlined function, it will have a block,
315 /// representing the inlined function, and the function will be the
316 /// containing function. If it is not inlined, then the block will be NULL.
317 ///
318 /// \param[in] name
319 /// The name of the function we are looking for.
320 ///
321 /// \param[in] name_type_mask
322 /// A bit mask of bits that indicate what kind of names should
323 /// be used when doing the lookup. Bits include fully qualified
324 /// names, base names, C++ methods, or ObjC selectors.
325 /// See FunctionNameType for more details.
326 ///
327 /// \param[out] sc_list
328 /// A symbol context list that gets filled in with all of the
329 /// matches.
331 const CompilerDeclContext &parent_decl_ctx,
332 lldb::FunctionNameType name_type_mask,
333 const ModuleFunctionSearchOptions &options,
334 SymbolContextList &sc_list);
335
336 /// Find functions by compiler context.
337 void FindFunctions(llvm::ArrayRef<CompilerContext> compiler_ctx,
338 lldb::FunctionNameType name_type_mask,
339 const ModuleFunctionSearchOptions &options,
340 SymbolContextList &sc_list);
341
342 /// Find functions by name.
343 ///
344 /// If the function is an inlined function, it will have a block,
345 /// representing the inlined function, and the function will be the
346 /// containing function. If it is not inlined, then the block will be NULL.
347 ///
348 /// \param[in] regex
349 /// A regular expression to use when matching the name.
350 ///
351 /// \param[out] sc_list
352 /// A symbol context list that gets filled in with all of the
353 /// matches.
354 void FindFunctions(const RegularExpression &regex,
355 const ModuleFunctionSearchOptions &options,
356 SymbolContextList &sc_list);
357
358 /// Find addresses by file/line
359 ///
360 /// \param[in] target_sp
361 /// The target the addresses are desired for.
362 ///
363 /// \param[in] file
364 /// Source file to locate.
365 ///
366 /// \param[in] line
367 /// Source line to locate.
368 ///
369 /// \param[in] function
370 /// Optional filter function. Addresses within this function will be
371 /// added to the 'local' list. All others will be added to the 'extern'
372 /// list.
373 ///
374 /// \param[out] output_local
375 /// All matching addresses within 'function'
376 ///
377 /// \param[out] output_extern
378 /// All matching addresses not within 'function'
379 void FindAddressesForLine(const lldb::TargetSP target_sp,
380 const FileSpec &file, uint32_t line,
381 Function *function,
382 std::vector<Address> &output_local,
383 std::vector<Address> &output_extern);
384
385 /// Find global and static variables by name.
386 ///
387 /// \param[in] name
388 /// The name of the global or static variable we are looking
389 /// for.
390 ///
391 /// \param[in] parent_decl_ctx
392 /// If valid, a decl context that results must exist within
393 ///
394 /// \param[in] max_matches
395 /// Allow the number of matches to be limited to \a
396 /// max_matches. Specify UINT32_MAX to get all possible matches.
397 ///
398 /// \param[in] variable_list
399 /// A list of variables that gets the matches appended to.
400 ///
402 const CompilerDeclContext &parent_decl_ctx,
403 size_t max_matches, VariableList &variable_list);
404
405 /// Find global and static variables by regular expression.
406 ///
407 /// \param[in] regex
408 /// A regular expression to use when matching the name.
409 ///
410 /// \param[in] max_matches
411 /// Allow the number of matches to be limited to \a
412 /// max_matches. Specify UINT32_MAX to get all possible matches.
413 ///
414 /// \param[in] variable_list
415 /// A list of variables that gets the matches appended to.
416 ///
417 void FindGlobalVariables(const RegularExpression &regex, size_t max_matches,
418 VariableList &variable_list);
419
420 /// Find types using a type-matching object that contains all search
421 /// parameters.
422 ///
423 /// \see lldb_private::TypeQuery
424 ///
425 /// \param[in] query
426 /// A type matching object that contains all of the details of the type
427 /// search.
428 ///
429 /// \param[in] results
430 /// Any matching types will be populated into the \a results object using
431 /// TypeMap::InsertUnique(...).
432 void FindTypes(const TypeQuery &query, TypeResults &results);
433
434 /// Get const accessor for the module architecture.
435 ///
436 /// \return
437 /// A const reference to the architecture object.
438 const ArchSpec &GetArchitecture() const;
439
440 /// Get const accessor for the module file specification.
441 ///
442 /// This function returns the file for the module on the host system that is
443 /// running LLDB. This can differ from the path on the platform since we
444 /// might be doing remote debugging.
445 ///
446 /// \return
447 /// A const reference to the file specification object.
448 const FileSpec &GetFileSpec() const { return m_file; }
449
450 /// Get accessor for the module platform file specification.
451 ///
452 /// Platform file refers to the path of the module as it is known on the
453 /// remote system on which it is being debugged. For local debugging this is
454 /// always the same as Module::GetFileSpec(). But remote debugging might
455 /// mention a file "/usr/lib/liba.dylib" which might be locally downloaded
456 /// and cached. In this case the platform file could be something like:
457 /// "/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib" The
458 /// file could also be cached in a local developer kit directory.
459 ///
460 /// \return
461 /// A const reference to the file specification object.
463 if (m_platform_file)
464 return m_platform_file;
465 return m_file;
466 }
467
468 void SetPlatformFileSpec(const FileSpec &file) { m_platform_file = file; }
469
472 }
473
476 }
477
479
481
482 void PreloadSymbols();
483
484 void SetSymbolFileFileSpec(const FileSpec &file);
485
486 const llvm::sys::TimePoint<> &GetModificationTime() const {
487 return m_mod_time;
488 }
489
490 const llvm::sys::TimePoint<> &GetObjectModificationTime() const {
491 return m_object_mod_time;
492 }
493
494 /// This callback will be called by SymbolFile implementations when
495 /// parsing a compile unit that contains SDK information.
496 /// \param sysroot will be added to the path remapping dictionary.
497 void RegisterXcodeSDK(llvm::StringRef sdk, llvm::StringRef sysroot);
498
499 /// Tells whether this module is capable of being the main executable for a
500 /// process.
501 ///
502 /// \return
503 /// \b true if it is, \b false otherwise.
504 bool IsExecutable();
505
506 /// Tells whether this module has been loaded in the target passed in. This
507 /// call doesn't distinguish between whether the module is loaded by the
508 /// dynamic loader, or by a "target module add" type call.
509 ///
510 /// \param[in] target
511 /// The target to check whether this is loaded in.
512 ///
513 /// \return
514 /// \b true if it is, \b false otherwise.
515 bool IsLoadedInTarget(Target *target);
516
517 /// Get the number of compile units for this module.
518 ///
519 /// \return
520 /// The number of compile units that the symbol vendor plug-in
521 /// finds.
522 size_t GetNumCompileUnits();
523
525
526 llvm::StringRef GetObjectName() const;
527
528 std::optional<lldb::addr_t> GetMemoryModuleAddress() const {
530 }
531
532 uint64_t GetObjectOffset() const { return m_object_offset; }
533
534 uint64_t GetObjectSize() const { return m_object_size; }
535
536 /// Describe this module, preserving the parsed object's bounds and any
537 /// already-provided bytes.
538 ///
539 /// This may load the module's object file.
541
542 /// Get the object file representation for the current architecture.
543 ///
544 /// If the object file has not been located or parsed yet, this function
545 /// will find the best ObjectFile plug-in that can parse Module::m_file.
546 ///
547 /// \return
548 /// If Module::m_file does not exist, or no plug-in was found
549 /// that can parse the file, or the object file doesn't contain
550 /// the current architecture in Module::m_arch, nullptr will be
551 /// returned, else a valid object file interface will be
552 /// returned. The returned pointer is owned by this object and
553 /// remains valid as long as the object is around.
554 virtual ObjectFile *GetObjectFile();
555
556 /// Like GetObjectFile, but the returned handle holds the Module mutex for
557 /// its lifetime, serializing concurrent access to the ObjectFile against
558 /// other callers using the locked accessors.
560
561 /// Get the entry point address of this module's object file.
562 ///
563 /// \return
564 /// An invalid Address if there is no object file or the object file
565 /// has no entry point.
567
568 /// Get the unified section list for the module. This is the section list
569 /// created by the module's object file and any debug info and symbol files
570 /// created by the symbol vendor.
571 ///
572 /// If the symbol vendor has not been loaded yet, this function will return
573 /// the section list for the object file.
574 ///
575 /// \return
576 /// Unified module section list.
577 virtual SectionList *GetSectionList();
578
579 /// Like GetSectionList, but the returned handle holds the Module mutex for
580 /// its lifetime.
582
583 /// Notify the module that the file addresses for the Sections have been
584 /// updated.
585 ///
586 /// If the Section file addresses for a module are updated, this method
587 /// should be called. Any parts of the module, object file, or symbol file
588 /// that has cached those file addresses must invalidate or update its
589 /// cache.
590 virtual void SectionFileAddressesChanged();
591
592 /// Returns a reference to the UnwindTable for this Module
593 ///
594 /// The UnwindTable contains FuncUnwinders objects for any function in this
595 /// Module. If a FuncUnwinders object hasn't been created yet (i.e. the
596 /// function has yet to be unwound in a stack walk), it will be created when
597 /// requested. Specifically, we do not create FuncUnwinders objects for
598 /// functions until they are needed.
599 ///
600 /// \return
601 /// Returns the unwind table for this module. If this object has no
602 /// associated object file, an empty UnwindTable is returned.
604
605 llvm::VersionTuple GetVersion();
606
607 /// Load an object file from memory.
608 ///
609 /// If available, the size of the object file in memory may be passed to
610 /// avoid additional round trips to process memory. If the size is not
611 /// provided, a default value is used. This value should be large enough to
612 /// enable the ObjectFile plugins to read the header of the object file
613 /// without going back to the process.
614 ///
615 /// If \a disable_memory_symtab_caching is true, the symbol table for the
616 /// object file will not be loaded from or saved to the index cache, even if
617 /// caching of memory modules is enabled.
618 ///
619 /// \return
620 /// The object file loaded from memory or nullptr, if the operation
621 /// failed (see the `error` for more information in that case).
623 lldb::addr_t header_addr, Status &error,
624 bool disable_memory_symtab_caching,
625 size_t size_to_read = 512);
626
627 /// Get the module's symbol file
628 ///
629 /// If the symbol file has already been loaded, this function returns it. All
630 /// arguments are ignored. If the symbol file has not been located yet, and
631 /// the can_create argument is false, the function returns nullptr. If
632 /// can_create is true, this function will find the best SymbolFile plug-in
633 /// that can use the current object file. feedback_strm, if not null, is used
634 /// to report the details of the search process.
635 virtual SymbolFile *GetSymbolFile(bool can_create = true,
636 Stream *feedback_strm = nullptr);
637
638 /// Like GetSymbolFile, but the returned handle holds the Module mutex for
639 /// its lifetime.
640 LockedPtr<SymbolFile> GetSymbolFileLocked(bool can_create = true,
641 Stream *feedback_strm = nullptr);
642
643 /// Get the module's symbol table
644 ///
645 /// If the symbol table has already been loaded, this function returns it.
646 /// Otherwise, it will only be loaded when can_create is true.
647 Symtab *GetSymtab(bool can_create = true);
648
649 /// Like GetSymtab, but the returned handle holds the Module mutex for its
650 /// lifetime.
651 LockedPtr<Symtab> GetSymtabLocked(bool can_create = true);
652
653 /// Get a bitmask of lldb::SymtabState flags describing the object file's
654 /// symbol table state.
655 ///
656 /// This does not cause the object file or its symbol table to be created,
657 /// and doesn't wait for a symbol table being parsed on another thread to be
658 /// finished. If the symbol table hasn't been created yet, or no state has
659 /// been recorded for it, lldb::eSymtabStateNone is returned.
660 uint32_t GetSymtabState();
661
662 /// Get a reference to the UUID value contained in this object.
663 ///
664 /// If the executable image file doesn't not have a UUID value built into
665 /// the file format, an MD5 checksum of the entire file, or slice of the
666 /// file for the current architecture should be used.
667 ///
668 /// \return
669 /// A const pointer to the internal copy of the UUID value in
670 /// this module if this module has a valid UUID value, NULL
671 /// otherwise.
673
674 /// A debugging function that will cause everything in a module to
675 /// be parsed.
676 ///
677 /// All compile units will be parsed, along with all globals and static
678 /// variables and all functions for those compile units. All types, scopes,
679 /// local variables, static variables, global variables, and line tables
680 /// will be parsed. This can be used prior to dumping a module to see a
681 /// complete list of the resulting debug information that gets parsed, or as
682 /// a debug function to ensure that the module can consume all of the debug
683 /// data the symbol vendor provides.
685
686 bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr);
687
688 /// Resolve the symbol context for the given address.
689 ///
690 /// Tries to resolve the matching symbol context based on a lookup from the
691 /// current symbol vendor. If the lazy lookup fails, an attempt is made to
692 /// parse the eh_frame section to handle stripped symbols. If this fails,
693 /// an attempt is made to resolve the symbol to the previous address to
694 /// handle the case of a function with a tail call.
695 ///
696 /// Use properties of the modified SymbolContext to inspect any resolved
697 /// target, module, compilation unit, symbol, function, function block or
698 /// line entry. Use the return value to determine which of these properties
699 /// have been modified.
700 ///
701 /// \param[in] so_addr
702 /// A load address to resolve.
703 ///
704 /// \param[in] resolve_scope
705 /// The scope that should be resolved (see SymbolContext::Scope).
706 /// A combination of flags from the enumeration SymbolContextItem
707 /// requesting a resolution depth. Note that the flags that are
708 /// actually resolved may be a superset of the requested flags.
709 /// For instance, eSymbolContextSymbol requires resolution of
710 /// eSymbolContextModule, and eSymbolContextFunction requires
711 /// eSymbolContextSymbol.
712 ///
713 /// \param[out] sc
714 /// The SymbolContext that is modified based on symbol resolution.
715 ///
716 /// \param[in] resolve_tail_call_address
717 /// Determines if so_addr should resolve to a symbol in the case
718 /// of a function whose last instruction is a call. In this case,
719 /// the PC can be one past the address range of the function.
720 ///
721 /// \return
722 /// The scope that has been resolved (see SymbolContext::Scope).
723 ///
724 /// \see SymbolContext::Scope
726 const Address &so_addr, lldb::SymbolContextItem resolve_scope,
727 SymbolContext &sc, bool resolve_tail_call_address = false);
728
729 /// Resolve items in the symbol context for a given file and line.
730 ///
731 /// Tries to resolve \a file_path and \a line to a list of matching symbol
732 /// contexts.
733 ///
734 /// The line table entries contains addresses that can be used to further
735 /// resolve the values in each match: the function, block, symbol. Care
736 /// should be taken to minimize the amount of information that is requested
737 /// to only what is needed -- typically the module, compile unit, line table
738 /// and line table entry are sufficient.
739 ///
740 /// \param[in] file_path
741 /// A path to a source file to match. If \a file_path does not
742 /// specify a directory, then this query will match all files
743 /// whose base filename matches. If \a file_path does specify
744 /// a directory, the fullpath to the file must match.
745 ///
746 /// \param[in] line
747 /// The source line to match, or zero if just the compile unit
748 /// should be resolved.
749 ///
750 /// \param[in] check_inlines
751 /// Check for inline file and line number matches. This option
752 /// should be used sparingly as it will cause all line tables
753 /// for every compile unit to be parsed and searched for
754 /// matching inline file entries.
755 ///
756 /// \param[in] resolve_scope
757 /// The scope that should be resolved (see
758 /// SymbolContext::Scope).
759 ///
760 /// \param[out] sc_list
761 /// A symbol context list that gets matching symbols contexts
762 /// appended to.
763 ///
764 /// \return
765 /// The number of matches that were added to \a sc_list.
766 ///
767 /// \see SymbolContext::Scope
769 const char *file_path, uint32_t line, bool check_inlines,
770 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list);
771
772 /// Resolve items in the symbol context for a given file and line.
773 ///
774 /// Tries to resolve \a file_spec and \a line to a list of matching symbol
775 /// contexts.
776 ///
777 /// The line table entries contains addresses that can be used to further
778 /// resolve the values in each match: the function, block, symbol. Care
779 /// should be taken to minimize the amount of information that is requested
780 /// to only what is needed -- typically the module, compile unit, line table
781 /// and line table entry are sufficient.
782 ///
783 /// \param[in] file_spec
784 /// A file spec to a source file to match. If \a file_path does
785 /// not specify a directory, then this query will match all
786 /// files whose base filename matches. If \a file_path does
787 /// specify a directory, the fullpath to the file must match.
788 ///
789 /// \param[in] line
790 /// The source line to match, or zero if just the compile unit
791 /// should be resolved.
792 ///
793 /// \param[in] check_inlines
794 /// Check for inline file and line number matches. This option
795 /// should be used sparingly as it will cause all line tables
796 /// for every compile unit to be parsed and searched for
797 /// matching inline file entries.
798 ///
799 /// \param[in] resolve_scope
800 /// The scope that should be resolved (see
801 /// SymbolContext::Scope).
802 ///
803 /// \param[out] sc_list
804 /// A symbol context list that gets filled in with all of the
805 /// matches.
806 ///
807 /// \return
808 /// A integer that contains SymbolContext::Scope bits set for
809 /// each item that was successfully resolved.
810 ///
811 /// \see SymbolContext::Scope
813 const FileSpec &file_spec, uint32_t line, bool check_inlines,
814 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list);
815
816 void SetFileSpecAndObjectName(const FileSpec &file, std::string object_name);
817
819
820 llvm::Expected<lldb::TypeSystemSP>
822
823 /// Call \p callback for each \p TypeSystem in this \p Module.
824 /// Return true from callback to keep iterating, false to stop iterating.
825 void ForEachTypeSystem(llvm::function_ref<bool(lldb::TypeSystemSP)> callback);
826
827 // Special error functions that can do printf style formatting that will
828 // prepend the message with something appropriate for this module (like the
829 // architecture, path and object name (if any)). This centralizes code so
830 // that everyone doesn't need to format their error and log messages on their
831 // own and keeps the output a bit more consistent.
832 template <typename... Args>
833 void LogMessage(Log *log, const char *format, Args &&...args) {
834 LogMessage(log, llvm::formatv(format, std::forward<Args>(args)...));
835 }
836
837 template <typename... Args>
838 void LogMessageVerboseBacktrace(Log *log, const char *format,
839 Args &&...args) {
841 log, llvm::formatv(format, std::forward<Args>(args)...));
842 }
843
844 template <typename... Args>
845 void ReportWarning(const char *format, Args &&...args) {
846 ReportWarning(llvm::formatv(format, std::forward<Args>(args)...));
847 }
848
849 template <typename... Args>
850 void ReportError(const char *format, Args &&...args) {
851 ReportError(llvm::formatv(format, std::forward<Args>(args)...));
852 }
853
854 /// Report an error that may be a bug in LLDB, see
855 /// Debugger::ReportInternalError.
856 template <typename... Args>
857 void ReportInternalError(const char *format, Args &&...args) {
858 ReportError(llvm::formatv(format, std::forward<Args>(args)...),
859 /*internal_error=*/true);
860 }
861
862 // Only report an error once when the module is first detected to be modified
863 // so we don't spam the console with many messages.
864 template <typename... Args>
865 void ReportErrorIfModifyDetected(const char *format, Args &&...args) {
867 llvm::formatv(format, std::forward<Args>(args)...));
868 }
869
870 void ReportWarningOptimization(std::optional<lldb::user_id_t> debugger_id);
871
872 void
874 std::optional<lldb::user_id_t> debugger_id);
875
876 // Return true if the file backing this module has changed since the module
877 // was originally created since we saved the initial file modification time
878 // when the module first gets created.
879 bool FileHasChanged() const;
880
881 // SymbolFile and ObjectFile member objects should lock the
882 // module mutex to avoid deadlocks.
883 std::recursive_mutex &GetMutex() const { return m_mutex; }
884
886
888 return m_source_mappings;
889 }
890
891 /// Finds a source file given a file spec using the module source path
892 /// remappings (if any).
893 ///
894 /// Tries to resolve \a orig_spec by checking the module source path
895 /// remappings. It makes sure the file exists, so this call can be expensive
896 /// if the remappings are on a network file system, so use this function
897 /// sparingly (not in a tight debug info parsing loop).
898 ///
899 /// \param[in] orig_spec
900 /// The original source file path to try and remap.
901 ///
902 /// \param[out] new_spec
903 /// The newly remapped filespec that is guaranteed to exist.
904 ///
905 /// \return
906 /// /b true if \a orig_spec was successfully located and
907 /// \a new_spec is filled in with an existing file spec,
908 /// \b false otherwise.
909 bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec);
910
911 /// Remaps a source file given \a path into \a new_path.
912 ///
913 /// Remaps \a path if any source remappings match. This function does NOT
914 /// stat the file system so it can be used in tight loops where debug info
915 /// is being parsed.
916 ///
917 /// \param[in] path
918 /// The original source file path to try and remap.
919 ///
920 /// \return
921 /// The newly remapped filespec that is may or may not exist if
922 /// \a path was successfully located.
923 std::optional<std::string> RemapSourceFile(llvm::StringRef path);
924 bool RemapSourceFile(const char *, std::string &) const = delete;
925
926 /// Register a directory to be searched for \c compilation-prefix-map.json
927 /// on the first call to RemapSourceFile or FindSourceFile. Duplicate
928 /// directories are silently ignored.
930
931 /// Update the ArchSpec to a more specific variant.
932 bool MergeArchitecture(const ArchSpec &arch_spec);
933
934 /// Accessor for the symbol table parse time metric.
935 ///
936 /// The value is returned as a reference to allow it to be updated by the
937 /// ElapsedTime RAII object.
939
940 /// Accessor for the symbol table index time metric.
941 ///
942 /// The value is returned as a reference to allow it to be updated by the
943 /// ElapsedTime RAII object.
945
949
950 void ResetStatistics();
951
952 /// \class LookupInfo Module.h "lldb/Core/Module.h"
953 /// A class that encapsulates name lookup information.
954 ///
955 /// Users can type a wide variety of partial names when setting breakpoints
956 /// by name or when looking for functions by name. The SymbolFile object is
957 /// only required to implement name lookup for function basenames and for
958 /// fully mangled names. This means if the user types in a partial name, we
959 /// must reduce this to a name lookup that will work with all SymbolFile
960 /// objects. So we might reduce a name lookup to look for a basename, and then
961 /// prune out any results that don't match.
962 ///
963 /// The "m_name" member variable represents the name as it was typed by the
964 /// user. "m_lookup_name" will be the name we actually search for through
965 /// the symbol or objects files. Lanaguage is included in case we need to
966 /// filter results by language at a later date. The "m_name_type_mask"
967 /// member variable tells us what kinds of names we are looking for and can
968 /// help us prune out unwanted results.
969 ///
970 /// Function lookups are done in Module.cpp, ModuleList.cpp and in
971 /// BreakpointResolverName.cpp and they all now use this class to do lookups
972 /// correctly.
974 public:
975 LookupInfo() = default;
976
977 /// Copies an existing LookupInfo with a different lookup name.
978 LookupInfo(const LookupInfo &lookup_info, ConstString lookup_name);
979
980 /// Creates a vector of lookup infos for function name resolution.
981 ///
982 /// \param[in] name
983 /// The function name to search for. This can be a simple name like
984 /// "foo" or a qualified name like "Class::method".
985 ///
986 /// \param[in] name_type_mask
987 /// A bitmask specifying what types of names to search for
988 /// (e.g., eFunctionNameTypeFull, eFunctionNameTypeBase,
989 /// eFunctionNameTypeMethod, eFunctionNameTypeAuto). Multiple types
990 /// can be combined with bitwise OR.
991 ///
992 /// \param[in] lang_type
993 /// The language to create lookups for. If eLanguageTypeUnknown is
994 /// passed, creates one LookupInfo for each language plugin currently
995 /// available in LLDB, except for full-name lookups that would repeat
996 /// the lookup of another language. If a specific language is provided,
997 /// creates only a single LookupInfo for that language.
998 ///
999 /// \param[in] lookup_name_override
1000 /// Manually override the name used for lookup. This parameter is
1001 /// optional. If not provided, it will be set to the value of the name
1002 /// parameter.
1003 ///
1004 /// \return
1005 /// A vector of LookupInfo objects, one per relevant language.
1006 static std::vector<LookupInfo>
1007 MakeLookupInfos(ConstString name, lldb::FunctionNameType name_type_mask,
1008 lldb::LanguageType lang_type,
1009 ConstString lookup_name_override = {});
1010
1011 ConstString GetName() const { return m_name; }
1012
1014
1015 lldb::FunctionNameType GetNameTypeMask() const { return m_name_type_mask; }
1016
1018
1020 ConstString function_name,
1021 lldb::LanguageType language_type = lldb::eLanguageTypeUnknown) const;
1022
1023 void Prune(SymbolContextList &sc_list, size_t start_idx) const;
1024
1025 /// Returns true if this lookup equals \p other in everything but the
1026 /// language.
1027 bool EqualsIgnoringLanguage(const LookupInfo &other) const;
1028
1029 protected:
1030 // When adding a member, also compare it in EqualsIgnoringLanguage().
1031
1032 /// What the user originally typed
1034
1035 /// The actual name will lookup when calling in the object or symbol file
1037
1038 /// Limit matches to only be for this language
1040
1041 /// One or more bits from lldb::FunctionNameType that indicate what kind of
1042 /// names we are looking for
1043 lldb::FunctionNameType m_name_type_mask = lldb::eFunctionNameTypeNone;
1044
1045 /// If \b true, then demangled names that match will need to contain
1046 /// "m_name" in order to be considered a match
1048
1049 private:
1050 LookupInfo(ConstString name, ConstString lookup_name_override,
1051 lldb::FunctionNameType name_type_mask,
1052 lldb::LanguageType lang_type);
1053 };
1054
1055 /// Get a unique hash for this module.
1056 ///
1057 /// The hash should be enough to identify the file on disk and the
1058 /// architecture of the file. If the module represents an object inside of a
1059 /// file, then the hash should include the object name and object offset to
1060 /// ensure a unique hash. Some examples:
1061 /// - just a regular object file (mach-o, elf, coff, etc) should create a hash
1062 /// - a universal mach-o file that contains multiple architectures,
1063 /// each architecture slice should have a unique hash even though they come
1064 /// from the same file
1065 /// - a .o file inside of a BSD archive. Each .o file will have an object name
1066 /// and object offset that should produce a unique hash. The object offset
1067 /// is needed as BSD archive files can contain multiple .o files that have
1068 /// the same name.
1069 ///
1070 /// This hash value does not change as the binary is recompiled during
1071 /// development. DataFileCache's CacheSignature() creates a hash based
1072 /// on the mod time/UUID to reflect when a binary has been recompiled.
1073 uint32_t Hash();
1074
1075 /// Get a unique cache key for the current module.
1076 ///
1077 /// The cache key must be unique for a file on disk and not change if the file
1078 /// is updated. This allows cache data to use this key as a prefix and as
1079 /// files are modified on disk, we will overwrite the previous cache file. If
1080 /// one file can contain multiple files, like a universal mach-o file or like
1081 /// BSD archive, the cache key must contain enough information to
1082 /// differentiate these different files.
1083 std::string GetCacheKey();
1084
1091
1092 /// Get the global index file cache.
1093 ///
1094 /// LLDB can cache data for a module between runs. This cache directory can be
1095 /// used to stored data that previously was manually created each time you
1096 /// debug. Examples include debug information indexes, symbol tables, memory
1097 /// module headerbytes, and more.
1098 ///
1099 /// The argument provided indicates the type of file that is being
1100 /// read/written to in DataFileCache, and the user's settings for that
1101 /// type of file will be consulted to decide whether it should be cached
1102 /// or not.
1103 ///
1104 /// \param[in] type
1105 /// The type of file this code will read/write into the DataFileCache.
1106 ///
1107 /// \returns
1108 /// If lldb settings have caching enabled for this type of file, return
1109 /// a pointer to the data file cache. If caching is not enabled,
1110 /// return nullptr.
1112
1113protected:
1114 // Member Variables
1115 mutable std::recursive_mutex m_mutex; ///< A mutex to keep this object happy
1116 /// in multi-threaded environments.
1117
1118 /// The modification time for this module when it was created.
1119 llvm::sys::TimePoint<> m_mod_time;
1120
1121 ArchSpec m_arch; ///< The architecture for this module.
1122 UUID m_uuid; ///< Each module is assumed to have a unique identifier to help
1123 /// match it up to debug symbols.
1124 FileSpec m_file; ///< The file representation on disk for this module (if
1125 /// there is one).
1126 FileSpec m_platform_file; ///< The path to the module on the platform on which
1127 /// it is being debugged
1128 FileSpec m_remote_install_file; ///< If set when debugging on remote
1129 /// platforms, this module will be installed
1130 /// at this location
1131 FileSpec m_symfile_spec; ///< If this path is valid, then this is the file
1132 /// that _will_ be used as the symbol file for this
1133 /// module
1134 std::string m_object_name; ///< The name an object within this module that is
1135 /// selected, or empty of the module is represented
1136 /// by \a m_file.
1137 std::optional<lldb::addr_t>
1138 m_memory_module_addr; ///< For a Module read from memory,
1139 /// the address it was read from.
1140 uint64_t m_object_offset = 0;
1141 uint64_t m_object_size = 0;
1142 llvm::sys::TimePoint<> m_object_mod_time;
1143
1144 /// DataExtractor containing the module image, if it was provided at
1145 /// construction time. Otherwise the data will be retrieved by mapping
1146 /// one of the FileSpec members above.
1148
1149 lldb::ObjectFileSP m_objfile_sp; ///< A shared pointer to the object file
1150 /// parser for this module as it may or may
1151 /// not be shared with the SymbolFile
1152 UnwindTable m_unwind_table; ///< Table of FuncUnwinders
1153 /// objects created for this
1154 /// Module's functions
1156 m_symfile_up; ///< A pointer to the symbol vendor for this module.
1157 std::vector<lldb::SymbolVendorUP>
1158 m_old_symfiles; ///< If anyone calls Module::SetSymbolFileFileSpec() and
1159 /// changes the symbol file,
1160 ///< we need to keep all old symbol files around in case anyone has type
1161 /// references to them
1162 TypeSystemMap m_type_system_map; ///< A map of any type systems associated
1163 /// with this module
1164 /// Module specific source remappings for when you have debug info for a
1165 /// module that doesn't match where the sources currently are.
1168
1169 /// Directories registered via AddPrefixMapSearchDir, searched lazily on the
1170 /// first call to RemapSourceFile or FindSourceFile. Cleared after searching.
1171 llvm::StringSet<> m_prefix_map_search_dirs;
1172
1173 /// Search each registered directory upward for compilation-prefix-map.json
1174 /// and apply any found mappings to m_source_mappings. Called at most once.
1175 /// Must be called with m_mutex held.
1177
1178 lldb::SectionListUP m_sections_up; ///< Unified section list for module that
1179 /// is used by the ObjectFile and
1180 /// ObjectFile instances for the debug info
1181
1182 /// Guards the lazy construction of m_sections_up.
1183 mutable std::recursive_mutex m_sections_mutex;
1184
1185 std::atomic<bool> m_did_load_objfile{false};
1186 std::atomic<bool> m_did_load_symfile{false};
1187 std::atomic<bool> m_did_set_uuid{false};
1188 std::atomic<bool> m_did_preload_symbols{false};
1189 mutable bool m_file_has_changed : 1,
1190 m_first_file_changed_log : 1; /// See if the module was modified after it
1191 /// was initially opened.
1192 /// We store a symbol table parse time duration here because we might have
1193 /// an object file and a symbol file which both have symbol tables. The parse
1194 /// time for the symbol tables can be aggregated here.
1196 /// We store a symbol named index time duration here because we might have
1197 /// an object file and a symbol file which both have symbol tables. The parse
1198 /// time for the symbol tables can be aggregated here.
1200
1202
1203 /// Hashes of the warnings and errors already reported, to report each once.
1205
1207 std::vector<uint32_t> &symbol_indexes,
1208 SymbolContextList &sc_list);
1209
1210 bool SetArchitecture(const ArchSpec &new_arch);
1211
1213
1214 friend class ModuleList;
1215 friend class ObjectFile;
1216 friend class SymbolFile;
1217
1218private:
1219 Module(); // Only used internally by CreateJITModule ()
1220
1221 Module(const Module &) = delete;
1222 const Module &operator=(const Module &) = delete;
1223
1224 void LogMessage(Log *log, const llvm::formatv_object_base &payload);
1226 const llvm::formatv_object_base &payload);
1227 void ReportWarning(const llvm::formatv_object_base &payload);
1228 void ReportError(const llvm::formatv_object_base &payload,
1229 bool internal_error = false);
1230 void ReportErrorIfModifyDetected(const llvm::formatv_object_base &payload);
1231 /// Returns true the first time \p msg is passed.
1232 bool ShouldReportDiagnostic(llvm::StringRef msg);
1233};
1234
1235} // namespace lldb_private
1236
1237#endif // LLDB_CORE_MODULE_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
An architecture specification class.
Definition ArchSpec.h:32
A command line argument class.
Definition Args.h:33
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition ConstString.h:40
This class enables data to be cached into a directory using the llvm caching code.
A file utility class.
Definition FileSpec.h:56
A class that describes a function.
Definition Function.h:386
PathMappingList GetSymlinkMappings() const
static ModuleListProperties & GetGlobalModuleListProperties()
A class that encapsulates name lookup information.
Definition Module.h:973
lldb::FunctionNameType GetNameTypeMask() const
Definition Module.h:1015
bool EqualsIgnoringLanguage(const LookupInfo &other) const
Returns true if this lookup equals other in everything but the language.
Definition Module.cpp:748
lldb::LanguageType GetLanguageType() const
Definition Module.h:1017
ConstString GetLookupName() const
Definition Module.h:1013
LookupInfo(ConstString name, ConstString lookup_name_override, lldb::FunctionNameType name_type_mask, lldb::LanguageType lang_type)
ConstString m_lookup_name
The actual name will lookup when calling in the object or symbol file.
Definition Module.h:1036
lldb::FunctionNameType m_name_type_mask
One or more bits from lldb::FunctionNameType that indicate what kind of names we are looking for.
Definition Module.h:1043
bool NameMatchesLookupInfo(ConstString function_name, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown) const
Definition Module.cpp:755
lldb::LanguageType m_language
Limit matches to only be for this language.
Definition Module.h:1039
ConstString m_name
What the user originally typed.
Definition Module.h:1033
ConstString GetName() const
Definition Module.h:1011
static std::vector< LookupInfo > MakeLookupInfos(ConstString name, lldb::FunctionNameType name_type_mask, lldb::LanguageType lang_type, ConstString lookup_name_override={})
Creates a vector of lookup infos for function name resolution.
Definition Module.cpp:710
void Prune(SymbolContextList &sc_list, size_t start_idx) const
Definition Module.cpp:788
bool m_match_name_after_lookup
If true, then demangled names that match will need to contain "m_name" in order to be considered a ma...
Definition Module.h:1047
static lldb::ModuleSP CreateModuleFromObjectFile(Args &&...args)
Definition Module.h:137
std::atomic< bool > m_did_preload_symbols
Definition Module.h:1188
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
Definition Module.cpp:364
uint32_t ResolveSymbolContextForFilePath(const char *file_path, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list)
Resolve items in the symbol context for a given file and line.
Definition Module.cpp:588
std::atomic< bool > m_did_set_uuid
Definition Module.h:1187
void ReportWarningOptimization(std::optional< lldb::user_id_t > debugger_id)
Definition Module.cpp:1121
std::optional< lldb::addr_t > GetMemoryModuleAddress() const
Definition Module.h:528
@ eLLDBIndexTypeMemoryModuleSymtab
Definition Module.h:1088
@ eLLDBIndexTypeMemoryModuleHeaderBytes
Definition Module.h:1089
Module(const Module &)=delete
PathMappingList m_source_mappings
Module specific source remappings for when you have debug info for a module that doesn't match where ...
Definition Module.h:1166
llvm::sys::TimePoint m_object_mod_time
Definition Module.h:1142
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1235
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, size_t max_matches, VariableList &variable_list)
Find global and static variables by name.
Definition Module.cpp:618
void ReportWarning(const char *format, Args &&...args)
Definition Module.h:845
FileSpec m_file
The file representation on disk for this module (if there is one).
Definition Module.h:1124
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:1017
std::vector< lldb::SymbolVendorUP > m_old_symfiles
If anyone calls Module::SetSymbolFileFileSpec() and changes the symbol file,.
Definition Module.h:1158
void ReportWarningUnsupportedLanguage(lldb::LanguageType language, std::optional< lldb::user_id_t > debugger_id)
Definition Module.cpp:1136
const llvm::sys::TimePoint & GetObjectModificationTime() const
Definition Module.h:490
Module(const FileSpec &file_spec, const ArchSpec &arch, std::string object_name=std::string(), lldb::offset_t object_offset=0, const llvm::sys::TimePoint<> &object_mod_time=llvm::sys::TimePoint<>())
Construct with file specification and architecture.
Definition Module.cpp:238
void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list)
Find compile units by partial or full path.
Definition Module.cpp:632
uint32_t Hash()
Get a unique hash for this module.
Definition Module.cpp:1712
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Module.cpp:424
static Module * GetAllocatedModuleAtIndex(size_t idx)
Definition Module.cpp:121
std::optional< std::string > RemapSourceFile(llvm::StringRef path)
Remaps a source file given path into new_path.
Definition Module.cpp:1638
bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec)
Finds a source file given a file spec using the module source path remappings (if any).
Definition Module.cpp:1570
void FindFunctions(llvm::ArrayRef< LookupInfo > lookup_infos, const CompilerDeclContext &parent_decl_ctx, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list)
Find functions by a vector of lookup infos.
UUID m_uuid
Each module is assumed to have a unique identifier to help match it up to debug symbols.
Definition Module.h:1122
const FileSpec & GetSymbolFileFileSpec() const
Definition Module.h:478
llvm::sys::TimePoint m_mod_time
The modification time for this module when it was created.
Definition Module.h:1119
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition Module.cpp:436
FileSpec m_remote_install_file
If set when debugging on remote platforms, this module will be installed at this location.
Definition Module.h:1128
llvm::StringRef GetObjectName() const
Definition Module.cpp:1233
LockedPtr< SectionList > GetSectionListLocked()
Like GetSectionList, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1309
uint32_t ResolveSymbolContextForAddress(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc, bool resolve_tail_call_address=false)
Resolve the symbol context for the given address.
Definition Module.cpp:455
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1115
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
Definition Module.cpp:104
void SetFileSpecAndObjectName(const FileSpec &file, std::string object_name)
Definition Module.cpp:1061
void FindFunctions(llvm::ArrayRef< CompilerContext > compiler_ctx, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list)
Find functions by compiler context.
bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
Set the load address for all sections in a module to be the file address plus slide.
Definition Module.cpp:1520
void SetSymbolFileFileSpec(const FileSpec &file)
Definition Module.cpp:1426
Address GetObjectFileEntryPointAddress()
Get the entry point address of this module's object file.
Definition Module.cpp:1303
void RegisterXcodeSDK(llvm::StringRef sdk, llvm::StringRef sysroot)
This callback will be called by SymbolFile implementations when parsing a compile unit that contains ...
Definition Module.cpp:1646
void AddPrefixMapSearchDir(FileSpec dir)
Register a directory to be searched for compilation-prefix-map.json on the first call to RemapSourceF...
Definition Module.cpp:1580
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list)
Definition Module.cpp:1379
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition Module.cpp:420
LockedPtr< Symtab > GetSymtabLocked(bool can_create=true)
Like GetSymtab, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1319
FileSpec m_symfile_spec
If this path is valid, then this is the file that will be used as the symbol file for this module.
Definition Module.h:1131
ThreadSafeDenseSet< llvm::stable_hash > m_shown_diagnostics
Hashes of the warnings and errors already reported, to report each once.
Definition Module.h:1204
void ReportInternalError(const char *format, Args &&...args)
Report an error that may be a bug in LLDB, see Debugger::ReportInternalError.
Definition Module.h:857
std::optional< lldb::addr_t > m_memory_module_addr
For a Module read from memory, the address it was read from.
Definition Module.h:1138
lldb::DataExtractorSP m_extractor_sp
DataExtractor containing the module image, if it was provided at construction time.
Definition Module.h:1147
StatsDuration m_symtab_index_time
We store a symbol named index time duration here because we might have an object file and a symbol fi...
Definition Module.h:1199
static DataFileCache * GetIndexCache(LLDBIndexType type)
Get the global index file cache.
Definition Module.cpp:1736
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:448
PathMappingList & GetSourceMappingList()
Definition Module.h:885
ArchSpec m_arch
The architecture for this module.
Definition Module.h:1121
void ReportError(const char *format, Args &&...args)
Definition Module.h:850
void SetPlatformFileSpec(const FileSpec &file)
Definition Module.h:468
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition Module.h:462
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition Module.h:1156
const Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type=lldb::eSymbolTypeAny)
Find a symbol in the object file's symbol table.
Definition Module.cpp:1343
std::recursive_mutex & GetMutex() const
Definition Module.h:883
llvm::VersionTuple GetVersion()
Definition Module.cpp:1697
void FindAddressesForLine(const lldb::TargetSP target_sp, const FileSpec &file, uint32_t line, Function *function, std::vector< Address > &output_local, std::vector< Address > &output_extern)
Find addresses by file/line.
Definition Module.cpp:971
StatisticsMap & GetSymbolLocatorStatistics()
Definition Module.h:946
void LoadPrefixMapsIfNeeded()
Search each registered directory upward for compilation-prefix-map.json and apply any found mappings ...
Definition Module.cpp:1585
std::string m_object_name
The name an object within this module that is selected, or empty of the module is represented by m_fi...
Definition Module.h:1134
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition Module.cpp:426
void FindFunctions(ConstString name, const CompilerDeclContext &parent_decl_ctx, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list)
Find functions by name.
void FindFunctionSymbols(ConstString name, uint32_t name_type_mask, SymbolContextList &sc_list)
Find a function symbols in the object file's symbol table.
Definition Module.cpp:1371
llvm::StringSet m_prefix_map_search_dirs
Directories registered via AddPrefixMapSearchDir, searched lazily on the first call to RemapSourceFil...
Definition Module.h:1171
Symtab * GetSymtab(bool can_create=true)
Get the module's symbol table.
Definition Module.cpp:1044
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition Module.cpp:430
void LogMessage(Log *log, const char *format, Args &&...args)
Definition Module.h:833
bool MatchesModuleSpec(const ModuleSpec &module_ref)
Definition Module.cpp:1536
bool RemapSourceFile(const char *, std::string &) const =delete
~Module() override
Destructor.
Definition Module.cpp:268
static size_t GetNumberAllocatedModules()
Definition Module.cpp:115
ModuleSpec GetModuleSpec()
Describe this module, preserving the parsed object's bounds and any already-provided bytes.
Definition Module.cpp:347
TypeSystemMap m_type_system_map
A map of any type systems associated with this module.
Definition Module.h:1162
uint64_t m_object_offset
Definition Module.h:1140
ObjectFile * GetMemoryObjectFile(const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Status &error, bool disable_memory_symtab_caching, size_t size_to_read=512)
Load an object file from memory.
Definition Module.cpp:296
const PathMappingList & GetSourceMappingList() const
Definition Module.h:887
void ForEachTypeSystem(llvm::function_ref< bool(lldb::TypeSystemSP)> callback)
Call callback for each TypeSystem in this Module.
Definition Module.cpp:384
uint64_t m_object_size
Definition Module.h:1141
lldb::SectionListUP m_sections_up
Unified section list for module that is used by the ObjectFile and ObjectFile instances for the debug...
Definition Module.h:1178
bool IsExecutable()
Tells whether this module is capable of being the main executable for a process.
Definition Module.cpp:1488
FileSpec m_platform_file
The path to the module on the platform on which it is being debugged.
Definition Module.h:1126
bool MergeArchitecture(const ArchSpec &arch_spec)
Update the ArchSpec to a more specific variant.
Definition Module.cpp:1669
bool FileHasChanged() const
Definition Module.cpp:1110
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition Module.cpp:1070
friend class ObjectFile
Definition Module.h:1215
void LogMessageVerboseBacktrace(Log *log, const char *format, Args &&...args)
Definition Module.h:838
bool GetIsDynamicLinkEditor()
Definition Module.cpp:1703
std::string GetCacheKey()
Get a unique cache key for the current module.
Definition Module.cpp:1726
virtual SectionList * GetSectionList()
Get the unified section list for the module.
Definition Module.cpp:1283
uint64_t GetObjectOffset() const
Definition Module.h:532
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language)
Definition Module.cpp:380
void Dump(Stream *s)
Dump a description of this object to a Stream.
Definition Module.cpp:1215
StatsDuration & GetSymtabIndexTime()
Accessor for the symbol table index time metric.
Definition Module.h:944
friend class ModuleList
Definition Module.h:1214
uint32_t ResolveSymbolContextsForFileSpec(const FileSpec &file_spec, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list)
Resolve items in the symbol context for a given file and line.
Definition Module.cpp:596
uint64_t GetObjectSize() const
Definition Module.h:534
lldb::ObjectFileSP m_objfile_sp
A shared pointer to the object file parser for this module as it may or may not be shared with the Sy...
Definition Module.h:1149
void ReportErrorIfModifyDetected(const char *format, Args &&...args)
Definition Module.h:865
void FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, Mangled::NamePreference mangling_preference=Mangled::ePreferDemangled)
Definition Module.cpp:1391
std::atomic< bool > m_did_load_symfile
Definition Module.h:1186
UnwindTable & GetUnwindTable()
Returns a reference to the UnwindTable for this Module.
Definition Module.cpp:1331
LockedPtr< SymbolFile > GetSymbolFileLocked(bool can_create=true, Stream *feedback_strm=nullptr)
Like GetSymbolFile, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1313
void SetRemoteInstallFileSpec(const FileSpec &file)
Definition Module.h:474
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1072
UnwindTable m_unwind_table
Table of FuncUnwinders objects created for this Module's functions.
Definition Module.h:1152
uint32_t GetSymtabState()
Get a bitmask of lldb::SymtabState flags describing the object file's symbol table state.
Definition Module.cpp:1050
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:448
bool IsLoadedInTarget(Target *target)
Tells whether this module has been loaded in the target passed in.
Definition Module.cpp:1495
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
Definition Module.cpp:1087
ModuleSpecList GetSeparateDebugInfoFiles()
Definition Module.cpp:1767
std::recursive_mutex m_sections_mutex
Guards the lazy construction of m_sections_up.
Definition Module.h:1183
bool m_first_file_changed_log
Definition Module.h:1190
void SymbolIndicesToSymbolContextList(Symtab *symtab, std::vector< uint32_t > &symbol_indexes, SymbolContextList &sc_list)
Definition Module.cpp:1353
bool ShouldReportDiagnostic(llvm::StringRef msg)
Returns true the first time msg is passed.
Definition Module.cpp:1165
const llvm::sys::TimePoint & GetModificationTime() const
Definition Module.h:486
const FileSpec & GetRemoteInstallFileSpec() const
Definition Module.h:470
virtual void SectionFileAddressesChanged()
Notify the module that the file addresses for the Sections have been updated.
Definition Module.cpp:1323
std::atomic< bool > m_did_load_objfile
Definition Module.h:1185
friend class SymbolFile
Definition Module.h:1216
const Module & operator=(const Module &)=delete
StatisticsMap m_symbol_locator_duration_map
Definition Module.h:1201
void FindTypes(const TypeQuery &query, TypeResults &results)
Find types using a type-matching object that contains all search parameters.
Definition Module.cpp:995
bool SetArchitecture(const ArchSpec &new_arch)
Definition Module.cpp:1512
SectionList * GetUnifiedSectionList()
Definition Module.cpp:1337
StatsDuration m_symtab_parse_time
See if the module was modified after it was initially opened.
Definition Module.h:1195
void ParseAllDebugSymbols()
A debugging function that will cause everything in a module to be parsed.
Definition Module.cpp:389
LockedPtr< ObjectFile > GetObjectFileLocked()
Like GetObjectFile, but the returned handle holds the Module mutex for its lifetime,...
Definition Module.cpp:1299
StatsDuration & GetSymtabParseTime()
Accessor for the symbol table parse time metric.
Definition Module.h:938
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:47
A class to count time for plugins.
Definition Statistics.h:94
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Defines a list of symbol context objects.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Provides public interface for all SymbolFiles.
Definition SymbolFile.h:51
A class that contains all state required for type lookups.
This class tracks the state and results of a TypeQuery.
Represents UUID's of various sizes.
Definition UUID.h:27
A class that represents a running process on the host machine.
Locked< T *, Mutex > LockedPtr
Exclusive (write) access aliases.
Definition Locked.h:149
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelFull
uint64_t offset_t
Definition lldb-types.h:86
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Process > ProcessSP
SymbolType
Symbol types.
std::unique_ptr< lldb_private::SymbolVendor > SymbolVendorUP
std::unique_ptr< lldb_private::SectionList > SectionListUP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Options used by Module::FindFunctions.
Definition Module.h:68
bool include_inlines
Include inlined functions.
Definition Module.h:72
bool include_symbols
Include the symbol table.
Definition Module.h:70
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33