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 /// Get the object file representation for the current architecture.
535 ///
536 /// If the object file has not been located or parsed yet, this function
537 /// will find the best ObjectFile plug-in that can parse Module::m_file.
538 ///
539 /// \return
540 /// If Module::m_file does not exist, or no plug-in was found
541 /// that can parse the file, or the object file doesn't contain
542 /// the current architecture in Module::m_arch, nullptr will be
543 /// returned, else a valid object file interface will be
544 /// returned. The returned pointer is owned by this object and
545 /// remains valid as long as the object is around.
546 virtual ObjectFile *GetObjectFile();
547
548 /// Like GetObjectFile, but the returned handle holds the Module mutex for
549 /// its lifetime, serializing concurrent access to the ObjectFile against
550 /// other callers using the locked accessors.
552
553 /// Get the unified section list for the module. This is the section list
554 /// created by the module's object file and any debug info and symbol files
555 /// created by the symbol vendor.
556 ///
557 /// If the symbol vendor has not been loaded yet, this function will return
558 /// the section list for the object file.
559 ///
560 /// \return
561 /// Unified module section list.
562 virtual SectionList *GetSectionList();
563
564 /// Like GetSectionList, but the returned handle holds the Module mutex for
565 /// its lifetime.
567
568 /// Notify the module that the file addresses for the Sections have been
569 /// updated.
570 ///
571 /// If the Section file addresses for a module are updated, this method
572 /// should be called. Any parts of the module, object file, or symbol file
573 /// that has cached those file addresses must invalidate or update its
574 /// cache.
575 virtual void SectionFileAddressesChanged();
576
577 /// Returns a reference to the UnwindTable for this Module
578 ///
579 /// The UnwindTable contains FuncUnwinders objects for any function in this
580 /// Module. If a FuncUnwinders object hasn't been created yet (i.e. the
581 /// function has yet to be unwound in a stack walk), it will be created when
582 /// requested. Specifically, we do not create FuncUnwinders objects for
583 /// functions until they are needed.
584 ///
585 /// \return
586 /// Returns the unwind table for this module. If this object has no
587 /// associated object file, an empty UnwindTable is returned.
589
590 llvm::VersionTuple GetVersion();
591
592 /// Load an object file from memory.
593 ///
594 /// If available, the size of the object file in memory may be passed to
595 /// avoid additional round trips to process memory. If the size is not
596 /// provided, a default value is used. This value should be large enough to
597 /// enable the ObjectFile plugins to read the header of the object file
598 /// without going back to the process.
599 ///
600 /// If \a disable_memory_symtab_caching is true, the symbol table for the
601 /// object file will not be loaded from or saved to the index cache, even if
602 /// caching of memory modules is enabled.
603 ///
604 /// \return
605 /// The object file loaded from memory or nullptr, if the operation
606 /// failed (see the `error` for more information in that case).
608 lldb::addr_t header_addr, Status &error,
609 bool disable_memory_symtab_caching,
610 size_t size_to_read = 512);
611
612 /// Get the module's symbol file
613 ///
614 /// If the symbol file has already been loaded, this function returns it. All
615 /// arguments are ignored. If the symbol file has not been located yet, and
616 /// the can_create argument is false, the function returns nullptr. If
617 /// can_create is true, this function will find the best SymbolFile plug-in
618 /// that can use the current object file. feedback_strm, if not null, is used
619 /// to report the details of the search process.
620 virtual SymbolFile *GetSymbolFile(bool can_create = true,
621 Stream *feedback_strm = nullptr);
622
623 /// Like GetSymbolFile, but the returned handle holds the Module mutex for
624 /// its lifetime.
625 LockedPtr<SymbolFile> GetSymbolFileLocked(bool can_create = true,
626 Stream *feedback_strm = nullptr);
627
628 /// Get the module's symbol table
629 ///
630 /// If the symbol table has already been loaded, this function returns it.
631 /// Otherwise, it will only be loaded when can_create is true.
632 Symtab *GetSymtab(bool can_create = true);
633
634 /// Like GetSymtab, but the returned handle holds the Module mutex for its
635 /// lifetime.
636 LockedPtr<Symtab> GetSymtabLocked(bool can_create = true);
637
638 /// Get a bitmask of lldb::SymtabState flags describing the object file's
639 /// symbol table state.
640 ///
641 /// This does not cause the symbol table to be created. If it hasn't been
642 /// created yet, or no state has been recorded for it, lldb::eSymtabStateNone
643 /// is returned.
644 uint32_t GetSymtabState();
645
646 /// Get a reference to the UUID value contained in this object.
647 ///
648 /// If the executable image file doesn't not have a UUID value built into
649 /// the file format, an MD5 checksum of the entire file, or slice of the
650 /// file for the current architecture should be used.
651 ///
652 /// \return
653 /// A const pointer to the internal copy of the UUID value in
654 /// this module if this module has a valid UUID value, NULL
655 /// otherwise.
657
658 /// A debugging function that will cause everything in a module to
659 /// be parsed.
660 ///
661 /// All compile units will be parsed, along with all globals and static
662 /// variables and all functions for those compile units. All types, scopes,
663 /// local variables, static variables, global variables, and line tables
664 /// will be parsed. This can be used prior to dumping a module to see a
665 /// complete list of the resulting debug information that gets parsed, or as
666 /// a debug function to ensure that the module can consume all of the debug
667 /// data the symbol vendor provides.
669
670 bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr);
671
672 /// Resolve the symbol context for the given address.
673 ///
674 /// Tries to resolve the matching symbol context based on a lookup from the
675 /// current symbol vendor. If the lazy lookup fails, an attempt is made to
676 /// parse the eh_frame section to handle stripped symbols. If this fails,
677 /// an attempt is made to resolve the symbol to the previous address to
678 /// handle the case of a function with a tail call.
679 ///
680 /// Use properties of the modified SymbolContext to inspect any resolved
681 /// target, module, compilation unit, symbol, function, function block or
682 /// line entry. Use the return value to determine which of these properties
683 /// have been modified.
684 ///
685 /// \param[in] so_addr
686 /// A load address to resolve.
687 ///
688 /// \param[in] resolve_scope
689 /// The scope that should be resolved (see SymbolContext::Scope).
690 /// A combination of flags from the enumeration SymbolContextItem
691 /// requesting a resolution depth. Note that the flags that are
692 /// actually resolved may be a superset of the requested flags.
693 /// For instance, eSymbolContextSymbol requires resolution of
694 /// eSymbolContextModule, and eSymbolContextFunction requires
695 /// eSymbolContextSymbol.
696 ///
697 /// \param[out] sc
698 /// The SymbolContext that is modified based on symbol resolution.
699 ///
700 /// \param[in] resolve_tail_call_address
701 /// Determines if so_addr should resolve to a symbol in the case
702 /// of a function whose last instruction is a call. In this case,
703 /// the PC can be one past the address range of the function.
704 ///
705 /// \return
706 /// The scope that has been resolved (see SymbolContext::Scope).
707 ///
708 /// \see SymbolContext::Scope
710 const Address &so_addr, lldb::SymbolContextItem resolve_scope,
711 SymbolContext &sc, bool resolve_tail_call_address = false);
712
713 /// Resolve items in the symbol context for a given file and line.
714 ///
715 /// Tries to resolve \a file_path and \a line to a list of matching symbol
716 /// contexts.
717 ///
718 /// The line table entries contains addresses that can be used to further
719 /// resolve the values in each match: the function, block, symbol. Care
720 /// should be taken to minimize the amount of information that is requested
721 /// to only what is needed -- typically the module, compile unit, line table
722 /// and line table entry are sufficient.
723 ///
724 /// \param[in] file_path
725 /// A path to a source file to match. If \a file_path does not
726 /// specify a directory, then this query will match all files
727 /// whose base filename matches. If \a file_path does specify
728 /// a directory, the fullpath to the file must match.
729 ///
730 /// \param[in] line
731 /// The source line to match, or zero if just the compile unit
732 /// should be resolved.
733 ///
734 /// \param[in] check_inlines
735 /// Check for inline file and line number matches. This option
736 /// should be used sparingly as it will cause all line tables
737 /// for every compile unit to be parsed and searched for
738 /// matching inline file entries.
739 ///
740 /// \param[in] resolve_scope
741 /// The scope that should be resolved (see
742 /// SymbolContext::Scope).
743 ///
744 /// \param[out] sc_list
745 /// A symbol context list that gets matching symbols contexts
746 /// appended to.
747 ///
748 /// \return
749 /// The number of matches that were added to \a sc_list.
750 ///
751 /// \see SymbolContext::Scope
753 const char *file_path, uint32_t line, bool check_inlines,
754 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list);
755
756 /// Resolve items in the symbol context for a given file and line.
757 ///
758 /// Tries to resolve \a file_spec and \a line to a list of matching symbol
759 /// contexts.
760 ///
761 /// The line table entries contains addresses that can be used to further
762 /// resolve the values in each match: the function, block, symbol. Care
763 /// should be taken to minimize the amount of information that is requested
764 /// to only what is needed -- typically the module, compile unit, line table
765 /// and line table entry are sufficient.
766 ///
767 /// \param[in] file_spec
768 /// A file spec to a source file to match. If \a file_path does
769 /// not specify a directory, then this query will match all
770 /// files whose base filename matches. If \a file_path does
771 /// specify a directory, the fullpath to the file must match.
772 ///
773 /// \param[in] line
774 /// The source line to match, or zero if just the compile unit
775 /// should be resolved.
776 ///
777 /// \param[in] check_inlines
778 /// Check for inline file and line number matches. This option
779 /// should be used sparingly as it will cause all line tables
780 /// for every compile unit to be parsed and searched for
781 /// matching inline file entries.
782 ///
783 /// \param[in] resolve_scope
784 /// The scope that should be resolved (see
785 /// SymbolContext::Scope).
786 ///
787 /// \param[out] sc_list
788 /// A symbol context list that gets filled in with all of the
789 /// matches.
790 ///
791 /// \return
792 /// A integer that contains SymbolContext::Scope bits set for
793 /// each item that was successfully resolved.
794 ///
795 /// \see SymbolContext::Scope
797 const FileSpec &file_spec, uint32_t line, bool check_inlines,
798 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list);
799
800 void SetFileSpecAndObjectName(const FileSpec &file, std::string object_name);
801
803
804 llvm::Expected<lldb::TypeSystemSP>
806
807 /// Call \p callback for each \p TypeSystem in this \p Module.
808 /// Return true from callback to keep iterating, false to stop iterating.
809 void ForEachTypeSystem(llvm::function_ref<bool(lldb::TypeSystemSP)> callback);
810
811 // Special error functions that can do printf style formatting that will
812 // prepend the message with something appropriate for this module (like the
813 // architecture, path and object name (if any)). This centralizes code so
814 // that everyone doesn't need to format their error and log messages on their
815 // own and keeps the output a bit more consistent.
816 template <typename... Args>
817 void LogMessage(Log *log, const char *format, Args &&...args) {
818 LogMessage(log, llvm::formatv(format, std::forward<Args>(args)...));
819 }
820
821 template <typename... Args>
822 void LogMessageVerboseBacktrace(Log *log, const char *format,
823 Args &&...args) {
825 log, llvm::formatv(format, std::forward<Args>(args)...));
826 }
827
828 template <typename... Args>
829 void ReportWarning(const char *format, Args &&...args) {
830 ReportWarning(llvm::formatv(format, std::forward<Args>(args)...));
831 }
832
833 template <typename... Args>
834 void ReportError(const char *format, Args &&...args) {
835 ReportError(llvm::formatv(format, std::forward<Args>(args)...));
836 }
837
838 /// Report an error that may be a bug in LLDB, see
839 /// Debugger::ReportInternalError.
840 template <typename... Args>
841 void ReportInternalError(const char *format, Args &&...args) {
842 ReportError(llvm::formatv(format, std::forward<Args>(args)...),
843 /*internal_error=*/true);
844 }
845
846 // Only report an error once when the module is first detected to be modified
847 // so we don't spam the console with many messages.
848 template <typename... Args>
849 void ReportErrorIfModifyDetected(const char *format, Args &&...args) {
851 llvm::formatv(format, std::forward<Args>(args)...));
852 }
853
854 void ReportWarningOptimization(std::optional<lldb::user_id_t> debugger_id);
855
856 void
858 std::optional<lldb::user_id_t> debugger_id);
859
860 // Return true if the file backing this module has changed since the module
861 // was originally created since we saved the initial file modification time
862 // when the module first gets created.
863 bool FileHasChanged() const;
864
865 // SymbolFile and ObjectFile member objects should lock the
866 // module mutex to avoid deadlocks.
867 std::recursive_mutex &GetMutex() const { return m_mutex; }
868
870
872 return m_source_mappings;
873 }
874
875 /// Finds a source file given a file spec using the module source path
876 /// remappings (if any).
877 ///
878 /// Tries to resolve \a orig_spec by checking the module source path
879 /// remappings. It makes sure the file exists, so this call can be expensive
880 /// if the remappings are on a network file system, so use this function
881 /// sparingly (not in a tight debug info parsing loop).
882 ///
883 /// \param[in] orig_spec
884 /// The original source file path to try and remap.
885 ///
886 /// \param[out] new_spec
887 /// The newly remapped filespec that is guaranteed to exist.
888 ///
889 /// \return
890 /// /b true if \a orig_spec was successfully located and
891 /// \a new_spec is filled in with an existing file spec,
892 /// \b false otherwise.
893 bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec);
894
895 /// Remaps a source file given \a path into \a new_path.
896 ///
897 /// Remaps \a path if any source remappings match. This function does NOT
898 /// stat the file system so it can be used in tight loops where debug info
899 /// is being parsed.
900 ///
901 /// \param[in] path
902 /// The original source file path to try and remap.
903 ///
904 /// \return
905 /// The newly remapped filespec that is may or may not exist if
906 /// \a path was successfully located.
907 std::optional<std::string> RemapSourceFile(llvm::StringRef path);
908 bool RemapSourceFile(const char *, std::string &) const = delete;
909
910 /// Register a directory to be searched for \c compilation-prefix-map.json
911 /// on the first call to RemapSourceFile or FindSourceFile. Duplicate
912 /// directories are silently ignored.
914
915 /// Update the ArchSpec to a more specific variant.
916 bool MergeArchitecture(const ArchSpec &arch_spec);
917
918 /// Accessor for the symbol table parse time metric.
919 ///
920 /// The value is returned as a reference to allow it to be updated by the
921 /// ElapsedTime RAII object.
923
924 /// Accessor for the symbol table index time metric.
925 ///
926 /// The value is returned as a reference to allow it to be updated by the
927 /// ElapsedTime RAII object.
929
933
934 void ResetStatistics();
935
936 /// \class LookupInfo Module.h "lldb/Core/Module.h"
937 /// A class that encapsulates name lookup information.
938 ///
939 /// Users can type a wide variety of partial names when setting breakpoints
940 /// by name or when looking for functions by name. The SymbolFile object is
941 /// only required to implement name lookup for function basenames and for
942 /// fully mangled names. This means if the user types in a partial name, we
943 /// must reduce this to a name lookup that will work with all SymbolFile
944 /// objects. So we might reduce a name lookup to look for a basename, and then
945 /// prune out any results that don't match.
946 ///
947 /// The "m_name" member variable represents the name as it was typed by the
948 /// user. "m_lookup_name" will be the name we actually search for through
949 /// the symbol or objects files. Lanaguage is included in case we need to
950 /// filter results by language at a later date. The "m_name_type_mask"
951 /// member variable tells us what kinds of names we are looking for and can
952 /// help us prune out unwanted results.
953 ///
954 /// Function lookups are done in Module.cpp, ModuleList.cpp and in
955 /// BreakpointResolverName.cpp and they all now use this class to do lookups
956 /// correctly.
958 public:
959 LookupInfo() = default;
960
961 /// Copies an existing LookupInfo with a different lookup name.
962 LookupInfo(const LookupInfo &lookup_info, ConstString lookup_name);
963
964 /// Creates a vector of lookup infos for function name resolution.
965 ///
966 /// \param[in] name
967 /// The function name to search for. This can be a simple name like
968 /// "foo" or a qualified name like "Class::method".
969 ///
970 /// \param[in] name_type_mask
971 /// A bitmask specifying what types of names to search for
972 /// (e.g., eFunctionNameTypeFull, eFunctionNameTypeBase,
973 /// eFunctionNameTypeMethod, eFunctionNameTypeAuto). Multiple types
974 /// can be combined with bitwise OR.
975 ///
976 /// \param[in] lang_type
977 /// The language to create lookups for. If eLanguageTypeUnknown is
978 /// passed, creates one LookupInfo for each language plugin currently
979 /// available in LLDB, except for full-name lookups that would repeat
980 /// the lookup of another language. If a specific language is provided,
981 /// creates only a single LookupInfo for that language.
982 ///
983 /// \param[in] lookup_name_override
984 /// Manually override the name used for lookup. This parameter is
985 /// optional. If not provided, it will be set to the value of the name
986 /// parameter.
987 ///
988 /// \return
989 /// A vector of LookupInfo objects, one per relevant language.
990 static std::vector<LookupInfo>
991 MakeLookupInfos(ConstString name, lldb::FunctionNameType name_type_mask,
992 lldb::LanguageType lang_type,
993 ConstString lookup_name_override = {});
994
995 ConstString GetName() const { return m_name; }
996
998
999 lldb::FunctionNameType GetNameTypeMask() const { return m_name_type_mask; }
1000
1002
1004 ConstString function_name,
1005 lldb::LanguageType language_type = lldb::eLanguageTypeUnknown) const;
1006
1007 void Prune(SymbolContextList &sc_list, size_t start_idx) const;
1008
1009 /// Returns true if this lookup equals \p other in everything but the
1010 /// language.
1011 bool EqualsIgnoringLanguage(const LookupInfo &other) const;
1012
1013 protected:
1014 // When adding a member, also compare it in EqualsIgnoringLanguage().
1015
1016 /// What the user originally typed
1018
1019 /// The actual name will lookup when calling in the object or symbol file
1021
1022 /// Limit matches to only be for this language
1024
1025 /// One or more bits from lldb::FunctionNameType that indicate what kind of
1026 /// names we are looking for
1027 lldb::FunctionNameType m_name_type_mask = lldb::eFunctionNameTypeNone;
1028
1029 /// If \b true, then demangled names that match will need to contain
1030 /// "m_name" in order to be considered a match
1032
1033 private:
1034 LookupInfo(ConstString name, ConstString lookup_name_override,
1035 lldb::FunctionNameType name_type_mask,
1036 lldb::LanguageType lang_type);
1037 };
1038
1039 /// Get a unique hash for this module.
1040 ///
1041 /// The hash should be enough to identify the file on disk and the
1042 /// architecture of the file. If the module represents an object inside of a
1043 /// file, then the hash should include the object name and object offset to
1044 /// ensure a unique hash. Some examples:
1045 /// - just a regular object file (mach-o, elf, coff, etc) should create a hash
1046 /// - a universal mach-o file that contains multiple architectures,
1047 /// each architecture slice should have a unique hash even though they come
1048 /// from the same file
1049 /// - a .o file inside of a BSD archive. Each .o file will have an object name
1050 /// and object offset that should produce a unique hash. The object offset
1051 /// is needed as BSD archive files can contain multiple .o files that have
1052 /// the same name.
1053 ///
1054 /// This hash value does not change as the binary is recompiled during
1055 /// development. DataFileCache's CacheSignature() creates a hash based
1056 /// on the mod time/UUID to reflect when a binary has been recompiled.
1057 uint32_t Hash();
1058
1059 /// Get a unique cache key for the current module.
1060 ///
1061 /// The cache key must be unique for a file on disk and not change if the file
1062 /// is updated. This allows cache data to use this key as a prefix and as
1063 /// files are modified on disk, we will overwrite the previous cache file. If
1064 /// one file can contain multiple files, like a universal mach-o file or like
1065 /// BSD archive, the cache key must contain enough information to
1066 /// differentiate these different files.
1067 std::string GetCacheKey();
1068
1074
1075 /// Get the global index file cache.
1076 ///
1077 /// LLDB can cache data for a module between runs. This cache directory can be
1078 /// used to stored data that previously was manually created each time you
1079 /// debug. Examples include debug information indexes, symbol tables, memory
1080 /// module headerbytes, and more.
1081 ///
1082 /// The argument provided indicates the type of file that is being
1083 /// read/written to in DataFileCache, and the user's settings for that
1084 /// type of file will be consulted to decide whether it should be cached
1085 /// or not.
1086 ///
1087 /// \param[in] type
1088 /// The type of file this code will read/write into the DataFileCache.
1089 ///
1090 /// \returns
1091 /// If lldb settings have caching enabled for this type of file, return
1092 /// a pointer to the data file cache. If caching is not enabled,
1093 /// return nullptr.
1095
1096protected:
1097 // Member Variables
1098 mutable std::recursive_mutex m_mutex; ///< A mutex to keep this object happy
1099 /// in multi-threaded environments.
1100
1101 /// The modification time for this module when it was created.
1102 llvm::sys::TimePoint<> m_mod_time;
1103
1104 ArchSpec m_arch; ///< The architecture for this module.
1105 UUID m_uuid; ///< Each module is assumed to have a unique identifier to help
1106 /// match it up to debug symbols.
1107 FileSpec m_file; ///< The file representation on disk for this module (if
1108 /// there is one).
1109 FileSpec m_platform_file; ///< The path to the module on the platform on which
1110 /// it is being debugged
1111 FileSpec m_remote_install_file; ///< If set when debugging on remote
1112 /// platforms, this module will be installed
1113 /// at this location
1114 FileSpec m_symfile_spec; ///< If this path is valid, then this is the file
1115 /// that _will_ be used as the symbol file for this
1116 /// module
1117 std::string m_object_name; ///< The name an object within this module that is
1118 /// selected, or empty of the module is represented
1119 /// by \a m_file.
1120 std::optional<lldb::addr_t>
1121 m_memory_module_addr; ///< For a Module read from memory,
1122 /// the address it was read from.
1123 uint64_t m_object_offset = 0;
1124 llvm::sys::TimePoint<> m_object_mod_time;
1125
1126 /// DataExtractor containing the module image, if it was provided at
1127 /// construction time. Otherwise the data will be retrieved by mapping
1128 /// one of the FileSpec members above.
1130
1131 lldb::ObjectFileSP m_objfile_sp; ///< A shared pointer to the object file
1132 /// parser for this module as it may or may
1133 /// not be shared with the SymbolFile
1134 UnwindTable m_unwind_table; ///< Table of FuncUnwinders
1135 /// objects created for this
1136 /// Module's functions
1138 m_symfile_up; ///< A pointer to the symbol vendor for this module.
1139 std::vector<lldb::SymbolVendorUP>
1140 m_old_symfiles; ///< If anyone calls Module::SetSymbolFileFileSpec() and
1141 /// changes the symbol file,
1142 ///< we need to keep all old symbol files around in case anyone has type
1143 /// references to them
1144 TypeSystemMap m_type_system_map; ///< A map of any type systems associated
1145 /// with this module
1146 /// Module specific source remappings for when you have debug info for a
1147 /// module that doesn't match where the sources currently are.
1150
1151 /// Directories registered via AddPrefixMapSearchDir, searched lazily on the
1152 /// first call to RemapSourceFile or FindSourceFile. Cleared after searching.
1153 llvm::StringSet<> m_prefix_map_search_dirs;
1154
1155 /// Search each registered directory upward for compilation-prefix-map.json
1156 /// and apply any found mappings to m_source_mappings. Called at most once.
1157 /// Must be called with m_mutex held.
1159
1160 lldb::SectionListUP m_sections_up; ///< Unified section list for module that
1161 /// is used by the ObjectFile and
1162 /// ObjectFile instances for the debug info
1163
1164 /// Guards the lazy construction of m_sections_up.
1165 mutable std::recursive_mutex m_sections_mutex;
1166
1167 std::atomic<bool> m_did_load_objfile{false};
1168 std::atomic<bool> m_did_load_symfile{false};
1169 std::atomic<bool> m_did_set_uuid{false};
1170 std::atomic<bool> m_did_preload_symbols{false};
1171 mutable bool m_file_has_changed : 1,
1172 m_first_file_changed_log : 1; /// See if the module was modified after it
1173 /// was initially opened.
1174 /// We store a symbol table parse time duration here because we might have
1175 /// an object file and a symbol file which both have symbol tables. The parse
1176 /// time for the symbol tables can be aggregated here.
1178 /// We store a symbol named index time duration here because we might have
1179 /// an object file and a symbol file which both have symbol tables. The parse
1180 /// time for the symbol tables can be aggregated here.
1182
1184
1185 /// Hashes of the warnings and errors already reported, to report each once.
1187
1189 std::vector<uint32_t> &symbol_indexes,
1190 SymbolContextList &sc_list);
1191
1192 bool SetArchitecture(const ArchSpec &new_arch);
1193
1195
1196 friend class ModuleList;
1197 friend class ObjectFile;
1198 friend class SymbolFile;
1199
1200private:
1201 Module(); // Only used internally by CreateJITModule ()
1202
1203 Module(const Module &) = delete;
1204 const Module &operator=(const Module &) = delete;
1205
1206 void LogMessage(Log *log, const llvm::formatv_object_base &payload);
1208 const llvm::formatv_object_base &payload);
1209 void ReportWarning(const llvm::formatv_object_base &payload);
1210 void ReportError(const llvm::formatv_object_base &payload,
1211 bool internal_error = false);
1212 void ReportErrorIfModifyDetected(const llvm::formatv_object_base &payload);
1213 /// Returns true the first time \p msg is passed.
1214 bool ShouldReportDiagnostic(llvm::StringRef msg);
1215};
1216
1217} // namespace lldb_private
1218
1219#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:957
lldb::FunctionNameType GetNameTypeMask() const
Definition Module.h:999
bool EqualsIgnoringLanguage(const LookupInfo &other) const
Returns true if this lookup equals other in everything but the language.
Definition Module.cpp:725
lldb::LanguageType GetLanguageType() const
Definition Module.h:1001
ConstString GetLookupName() const
Definition Module.h:997
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:1020
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:1027
bool NameMatchesLookupInfo(ConstString function_name, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown) const
Definition Module.cpp:732
lldb::LanguageType m_language
Limit matches to only be for this language.
Definition Module.h:1023
ConstString m_name
What the user originally typed.
Definition Module.h:1017
ConstString GetName() const
Definition Module.h:995
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:687
void Prune(SymbolContextList &sc_list, size_t start_idx) const
Definition Module.cpp:765
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:1031
static lldb::ModuleSP CreateModuleFromObjectFile(Args &&...args)
Definition Module.h:137
std::atomic< bool > m_did_preload_symbols
Definition Module.h:1170
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
Definition Module.cpp:341
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:565
std::atomic< bool > m_did_set_uuid
Definition Module.h:1169
void ReportWarningOptimization(std::optional< lldb::user_id_t > debugger_id)
Definition Module.cpp:1094
std::optional< lldb::addr_t > GetMemoryModuleAddress() const
Definition Module.h:528
@ eLLDBIndexTypeMemoryModuleSymtab
Definition Module.h:1072
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:1148
llvm::sys::TimePoint m_object_mod_time
Definition Module.h:1124
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1208
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:595
void ReportWarning(const char *format, Args &&...args)
Definition Module.h:829
FileSpec m_file
The file representation on disk for this module (if there is one).
Definition Module.h:1107
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:994
std::vector< lldb::SymbolVendorUP > m_old_symfiles
If anyone calls Module::SetSymbolFileFileSpec() and changes the symbol file,.
Definition Module.h:1140
void ReportWarningUnsupportedLanguage(lldb::LanguageType language, std::optional< lldb::user_id_t > debugger_id)
Definition Module.cpp:1109
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:232
void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list)
Find compile units by partial or full path.
Definition Module.cpp:609
uint32_t Hash()
Get a unique hash for this module.
Definition Module.cpp:1673
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Module.cpp:401
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:1599
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:1531
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:1105
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:1102
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition Module.cpp:413
FileSpec m_remote_install_file
If set when debugging on remote platforms, this module will be installed at this location.
Definition Module.h:1111
llvm::StringRef GetObjectName() const
Definition Module.cpp:1206
LockedPtr< SectionList > GetSectionListLocked()
Like GetSectionList, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1270
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:432
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1098
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
Definition Module.cpp:104
void SetFileSpecAndObjectName(const FileSpec &file, std::string object_name)
Definition Module.cpp:1034
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:1481
void SetSymbolFileFileSpec(const FileSpec &file)
Definition Module.cpp:1387
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:1607
void AddPrefixMapSearchDir(FileSpec dir)
Register a directory to be searched for compilation-prefix-map.json on the first call to RemapSourceF...
Definition Module.cpp:1541
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list)
Definition Module.cpp:1340
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition Module.cpp:397
LockedPtr< Symtab > GetSymtabLocked(bool can_create=true)
Like GetSymtab, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1280
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:1114
ThreadSafeDenseSet< llvm::stable_hash > m_shown_diagnostics
Hashes of the warnings and errors already reported, to report each once.
Definition Module.h:1186
void ReportInternalError(const char *format, Args &&...args)
Report an error that may be a bug in LLDB, see Debugger::ReportInternalError.
Definition Module.h:841
std::optional< lldb::addr_t > m_memory_module_addr
For a Module read from memory, the address it was read from.
Definition Module.h:1121
lldb::DataExtractorSP m_extractor_sp
DataExtractor containing the module image, if it was provided at construction time.
Definition Module.h:1129
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:1181
static DataFileCache * GetIndexCache(LLDBIndexType type)
Get the global index file cache.
Definition Module.cpp:1697
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:425
PathMappingList & GetSourceMappingList()
Definition Module.h:869
ArchSpec m_arch
The architecture for this module.
Definition Module.h:1104
void ReportError(const char *format, Args &&...args)
Definition Module.h:834
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:1138
const Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type=lldb::eSymbolTypeAny)
Find a symbol in the object file's symbol table.
Definition Module.cpp:1304
std::recursive_mutex & GetMutex() const
Definition Module.h:867
llvm::VersionTuple GetVersion()
Definition Module.cpp:1658
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:948
StatisticsMap & GetSymbolLocatorStatistics()
Definition Module.h:930
void LoadPrefixMapsIfNeeded()
Search each registered directory upward for compilation-prefix-map.json and apply any found mappings ...
Definition Module.cpp:1546
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:1117
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition Module.cpp:403
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:1332
llvm::StringSet m_prefix_map_search_dirs
Directories registered via AddPrefixMapSearchDir, searched lazily on the first call to RemapSourceFil...
Definition Module.h:1153
Symtab * GetSymtab(bool can_create=true)
Get the module's symbol table.
Definition Module.cpp:1021
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition Module.cpp:407
void LogMessage(Log *log, const char *format, Args &&...args)
Definition Module.h:817
bool MatchesModuleSpec(const ModuleSpec &module_ref)
Definition Module.cpp:1497
bool RemapSourceFile(const char *, std::string &) const =delete
~Module() override
Destructor.
Definition Module.cpp:262
static size_t GetNumberAllocatedModules()
Definition Module.cpp:115
TypeSystemMap m_type_system_map
A map of any type systems associated with this module.
Definition Module.h:1144
uint64_t m_object_offset
Definition Module.h:1123
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:290
const PathMappingList & GetSourceMappingList() const
Definition Module.h:871
void ForEachTypeSystem(llvm::function_ref< bool(lldb::TypeSystemSP)> callback)
Call callback for each TypeSystem in this Module.
Definition Module.cpp:361
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:1160
bool IsExecutable()
Tells whether this module is capable of being the main executable for a process.
Definition Module.cpp:1449
FileSpec m_platform_file
The path to the module on the platform on which it is being debugged.
Definition Module.h:1109
bool MergeArchitecture(const ArchSpec &arch_spec)
Update the ArchSpec to a more specific variant.
Definition Module.cpp:1630
bool FileHasChanged() const
Definition Module.cpp:1083
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition Module.cpp:1043
friend class ObjectFile
Definition Module.h:1197
void LogMessageVerboseBacktrace(Log *log, const char *format, Args &&...args)
Definition Module.h:822
bool GetIsDynamicLinkEditor()
Definition Module.cpp:1664
std::string GetCacheKey()
Get a unique cache key for the current module.
Definition Module.cpp:1687
virtual SectionList * GetSectionList()
Get the unified section list for the module.
Definition Module.cpp:1250
uint64_t GetObjectOffset() const
Definition Module.h:532
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language)
Definition Module.cpp:357
void Dump(Stream *s)
Dump a description of this object to a Stream.
Definition Module.cpp:1188
StatsDuration & GetSymtabIndexTime()
Accessor for the symbol table index time metric.
Definition Module.h:928
friend class ModuleList
Definition Module.h:1196
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:573
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:1131
void ReportErrorIfModifyDetected(const char *format, Args &&...args)
Definition Module.h:849
void FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, Mangled::NamePreference mangling_preference=Mangled::ePreferDemangled)
Definition Module.cpp:1352
std::atomic< bool > m_did_load_symfile
Definition Module.h:1168
UnwindTable & GetUnwindTable()
Returns a reference to the UnwindTable for this Module.
Definition Module.cpp:1292
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:1274
void SetRemoteInstallFileSpec(const FileSpec &file)
Definition Module.h:474
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1045
UnwindTable m_unwind_table
Table of FuncUnwinders objects created for this Module's functions.
Definition Module.h:1134
uint32_t GetSymtabState()
Get a bitmask of lldb::SymtabState flags describing the object file's symbol table state.
Definition Module.cpp:1027
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:1456
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
Definition Module.cpp:1060
ModuleSpecList GetSeparateDebugInfoFiles()
Definition Module.cpp:1717
std::recursive_mutex m_sections_mutex
Guards the lazy construction of m_sections_up.
Definition Module.h:1165
bool m_first_file_changed_log
Definition Module.h:1172
void SymbolIndicesToSymbolContextList(Symtab *symtab, std::vector< uint32_t > &symbol_indexes, SymbolContextList &sc_list)
Definition Module.cpp:1314
bool ShouldReportDiagnostic(llvm::StringRef msg)
Returns true the first time msg is passed.
Definition Module.cpp:1138
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:1284
std::atomic< bool > m_did_load_objfile
Definition Module.h:1167
friend class SymbolFile
Definition Module.h:1198
const Module & operator=(const Module &)=delete
StatisticsMap m_symbol_locator_duration_map
Definition Module.h:1183
void FindTypes(const TypeQuery &query, TypeResults &results)
Find types using a type-matching object that contains all search parameters.
Definition Module.cpp:972
bool SetArchitecture(const ArchSpec &new_arch)
Definition Module.cpp:1473
SectionList * GetUnifiedSectionList()
Definition Module.cpp:1298
StatsDuration m_symtab_parse_time
See if the module was modified after it was initially opened.
Definition Module.h:1177
void ParseAllDebugSymbols()
A debugging function that will cause everything in a module to be parsed.
Definition Module.cpp:366
LockedPtr< ObjectFile > GetObjectFileLocked()
Like GetObjectFile, but the returned handle holds the Module mutex for its lifetime,...
Definition Module.cpp:1266
StatsDuration & GetSymtabParseTime()
Accessor for the symbol table parse time metric.
Definition Module.h:922
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
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