LLDB mainline
ObjectFile.h
Go to the documentation of this file.
1//===-- ObjectFile.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_SYMBOL_OBJECTFILE_H
10#define LLDB_SYMBOL_OBJECTFILE_H
11
14#include "lldb/Symbol/Symtab.h"
18#include "lldb/Utility/Endian.h"
23#include "lldb/Utility/UUID.h"
24#include "lldb/lldb-private.h"
25#include "llvm/Support/Threading.h"
26#include "llvm/Support/VersionTuple.h"
27#include <atomic>
28#include <optional>
29
30namespace lldb_private {
31
32/// \class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h"
33/// A plug-in interface definition class for object file parsers.
34///
35/// Object files belong to Module objects and know how to extract information
36/// from executable, shared library, and object (.o) files used by operating
37/// system runtime. The symbol table and section list for an object file.
38///
39/// Object files can be represented by the entire file, or by part of a file.
40/// An example of a partial file ObjectFile is one that contains information
41/// for one of multiple architectures in the same file.
42///
43/// Once an architecture is selected the object file information can be
44/// extracted from this abstract class.
45class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
46 public PluginInterface,
47 public ModuleChild {
49
50public:
51 enum Type {
53 /// A core file that has a checkpoint of a program's execution state.
55 /// A normal executable.
57 /// An object file that contains only debug information.
59 /// The platform's dynamic linker executable.
61 /// An intermediate object file.
63 /// A shared library that can be used during execution.
65 /// A library that can be linked against but not used for execution.
67 /// JIT code that has symbols, sections and possibly debug info.
70 };
71
80
81 /// If we have a corefile binary hint, this enum
82 /// specifies the binary type which we can use to
83 /// select the correct DynamicLoader plugin.
87 /// kernel binary
89 /// user process binary, dyld addr
91 /// user process binary, dyld_all_image_infos addr
93 /// standalone binary / firmware
95 };
96
97 struct LoadableData {
99 llvm::ArrayRef<uint8_t> Contents;
100 };
101
102 /// Construct with a parent module, offset, and header data.
103 ///
104 /// Object files belong to modules and a valid module must be supplied upon
105 /// construction. The at an offset within a file for objects that contain
106 /// more than one architecture or object.
107 ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr,
108 lldb::offset_t file_offset, lldb::offset_t length,
109 lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset);
110
111 ObjectFile(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp,
112 lldb::addr_t header_addr, lldb::DataExtractorSP extractor_sp);
113
114 /// Destructor.
115 ///
116 /// The destructor is virtual since this class is designed to be inherited
117 /// from by the plug-in instance.
118 ~ObjectFile() override;
119
120 /// Dump a description of this object to a Stream.
121 ///
122 /// Dump a description of the current contents of this object to the
123 /// supplied stream \a s. The dumping should include the section list if it
124 /// has been parsed, and the symbol table if it has been parsed.
125 ///
126 /// \param[in] s
127 /// The stream to which to dump the object description.
128 virtual void Dump(Stream *s) = 0;
129
130 /// Find a ObjectFile plug-in that can parse \a file_spec.
131 ///
132 /// Scans all loaded plug-in interfaces that implement versions of the
133 /// ObjectFile plug-in interface and returns the first instance that can
134 /// parse the file.
135 ///
136 /// \param[in] module_sp
137 /// The parent module that owns this object file.
138 ///
139 /// \param[in] file_spec
140 /// A file specification that indicates which file to use as the
141 /// object file.
142 ///
143 /// \param[in] file_offset
144 /// The offset into the file at which to start parsing the
145 /// object. This is for files that contain multiple
146 /// architectures or objects.
147 ///
148 /// \param[in] file_size
149 /// The size of the current object file if it can be determined
150 /// or if it is known. This can be zero.
151 ///
152 /// \see ObjectFile::ParseHeader()
153 static lldb::ObjectFileSP
154 FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec,
155 lldb::offset_t file_offset, lldb::offset_t file_size,
156 lldb::DataExtractorSP extractor_sp, lldb::offset_t &data_offset);
157
158 /// Find a ObjectFile plug-in that can parse a file in memory.
159 ///
160 /// Scans all loaded plug-in interfaces that implement versions of the
161 /// ObjectFile plug-in interface and returns the first instance that can
162 /// parse the file.
163 ///
164 /// \param[in] module_sp
165 /// The parent module that owns this object file.
166 ///
167 /// \param[in] process_sp
168 /// A shared pointer to the process whose memory space contains
169 /// an object file. This will be stored as a std::weak_ptr.
170 ///
171 /// \param[in] header_addr
172 /// The address of the header for the object file in memory.
173 static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp,
174 const lldb::ProcessSP &process_sp,
175 lldb::addr_t header_addr,
176 lldb::WritableDataBufferSP file_data_sp);
177
178 static ModuleSpecList
179 GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset,
180 lldb::offset_t file_size,
182
183 static ModuleSpecList
185 lldb::DataExtractorSP &extractor_sp,
186 lldb::offset_t file_offset, lldb::offset_t file_size);
187 static bool IsObjectFile(lldb_private::FileSpec file_spec);
188 /// Split a path into a file path with object name.
189 ///
190 /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into
191 /// the actual path name and into the object name so we can make a valid
192 /// object file from it.
193 ///
194 /// \param[in] path_with_object
195 /// A path that might contain an archive path with a .o file
196 /// specified in parens in the basename of the path.
197 ///
198 /// \param[out] archive_file
199 /// If \b true is returned, \a file_spec will be filled in with
200 /// the path to the archive.
201 ///
202 /// \param[out] archive_object
203 /// If \b true is returned, \a object will be filled in with
204 /// the name of the object inside the archive.
205 ///
206 /// \return
207 /// \b true if the path matches the pattern of archive + object
208 /// and \a archive_file and \a archive_object are modified,
209 /// \b false otherwise and \a archive_file and \a archive_object
210 /// are guaranteed to be remain unchanged.
211 static bool SplitArchivePathWithObject(llvm::StringRef path_with_object,
212 lldb_private::FileSpec &archive_file,
213 llvm::StringRef &archive_object,
214 bool must_exist);
215
216 // LLVM RTTI support
217 static char ID;
218 virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
219
220 /// Gets the address size in bytes for the current object file.
221 ///
222 /// \return
223 /// The size of an address in bytes for the currently selected
224 /// architecture (and object for archives). Returns zero if no
225 /// architecture or object has been selected.
226 virtual uint32_t GetAddressByteSize() const = 0;
227
228 /// Get the address type given a file address in an object file.
229 ///
230 /// Many binary file formats know what kinds This is primarily for ARM
231 /// binaries, though it can be applied to any executable file format that
232 /// supports different opcode types within the same binary. ARM binaries
233 /// support having both ARM and Thumb within the same executable container.
234 /// We need to be able to get \return
235 /// The size of an address in bytes for the currently selected
236 /// architecture (and object for archives). Returns zero if no
237 /// architecture or object has been selected.
238 virtual AddressClass GetAddressClass(lldb::addr_t file_addr);
239
240 /// Extract the dependent modules from an object file.
241 ///
242 /// If an object file has information about which other images it depends on
243 /// (such as shared libraries), this function will provide the list. Since
244 /// many executables or shared libraries may depend on the same files,
245 /// FileSpecList::AppendIfUnique(const FileSpec &) should be used to make
246 /// sure any files that are added are not already in the list.
247 ///
248 /// \param[out] file_list
249 /// A list of file specification objects that gets dependent
250 /// files appended to.
251 ///
252 /// \return
253 /// The number of new files that were appended to \a file_list.
254 ///
255 /// \see FileSpecList::AppendIfUnique(const FileSpec &)
256 virtual uint32_t GetDependentModules(FileSpecList &file_list) = 0;
257
258 /// Tells whether this object file is capable of being the main executable
259 /// for a process.
260 ///
261 /// \return
262 /// \b true if it is, \b false otherwise.
263 virtual bool IsExecutable() const = 0;
264
265 /// Tells whether this object file is part of a shared cache.
266 virtual bool IsSharedCacheBinary() const { return false; }
267
268 /// Returns the offset into a file at which this object resides.
269 ///
270 /// Some files contain many object files, and this function allows access to
271 /// an object's offset within the file.
272 ///
273 /// \return
274 /// The offset in bytes into the file. Defaults to zero for
275 /// simple object files that a represented by an entire file.
276 virtual lldb::addr_t GetFileOffset() const { return m_file_offset; }
277
278 virtual lldb::addr_t GetByteSize() const { return m_length; }
279
280 /// Get accessor to the object file specification.
281 ///
282 /// \return
283 /// The file specification object pointer if there is one, or
284 /// NULL if this object is only from memory.
285 virtual FileSpec &GetFileSpec() { return m_file; }
286
287 /// Get const accessor to the object file specification.
288 ///
289 /// \return
290 /// The const file specification object pointer if there is one,
291 /// or NULL if this object is only from memory.
292 virtual const FileSpec &GetFileSpec() const { return m_file; }
293
294 /// Get the ArchSpec for this object file.
295 ///
296 /// \return
297 /// The ArchSpec of this object file. In case of error, an invalid
298 /// ArchSpec object is returned.
300
301 /// Gets the section list for the currently selected architecture (and
302 /// object for archives).
303 ///
304 /// Section list parsing can be deferred by ObjectFile instances until this
305 /// accessor is called the first time.
306 ///
307 /// \return
308 /// The list of sections contained in this object file.
309 virtual SectionList *GetSectionList(bool update_module_section_list = true);
310
311 virtual void CreateSections(SectionList &unified_section_list) = 0;
312
313 /// Notify the ObjectFile that the file addresses in the Sections for this
314 /// module have been changed.
316
317 /// Gets the symbol table for the currently selected architecture (and
318 /// object for archives).
319 ///
320 /// This function will manage when ParseSymtab(...) is called to actually do
321 /// the symbol table parsing in each plug-in. This function will take care of
322 /// taking all the necessary locks and finalizing the symbol table when the
323 /// symbol table does get parsed.
324 ///
325 /// \return
326 /// The symbol table for this object file.
327 Symtab *GetSymtab(bool can_create = true);
328
329 /// Parse the symbol table into the provides symbol table object.
330 ///
331 /// Symbol table parsing will be done once when this function is called by
332 /// each object file plugin. All of the necessary locks will already be
333 /// acquired before this function is called and the symbol table object to
334 /// populate is supplied as an argument and doesn't need to be created by
335 /// each plug-in.
336 ///
337 /// \param
338 /// The symbol table to populate.
339 virtual void ParseSymtab(Symtab &symtab) = 0;
340
341 /// Perform relocations on the section if necessary.
342 ///
343 virtual void RelocateSection(lldb_private::Section *section);
344
345 /// Detect if this object file has been stripped of local symbols.
346 /// Detect if this object file has been stripped of local symbols.
347 ///
348 /// \return
349 /// Return \b true if the object file has been stripped of local
350 /// symbols.
351 virtual bool IsStripped() = 0;
352
353 /// Frees the symbol table.
354 ///
355 /// This function should only be used when an object file is
356 virtual void ClearSymtab();
357
358 /// Gets the UUID for this object file.
359 ///
360 /// If the object file format contains a UUID, the value should be returned.
361 /// Else ObjectFile instances should return the MD5 checksum of all of the
362 /// bytes for the object file (or memory for memory based object files).
363 ///
364 /// \return
365 /// The object file's UUID. In case of an error, an empty UUID is
366 /// returned.
367 virtual UUID GetUUID() = 0;
368
369 /// Gets the file spec list of libraries re-exported by this object file.
370 ///
371 /// If the object file format has the notion of one library re-exporting the
372 /// symbols from another, the re-exported libraries will be returned in the
373 /// FileSpecList.
374 ///
375 /// \return
376 /// Returns filespeclist.
380
381 /// Whether a symbol that this object file has not itself tagged as a
382 /// re-export can still be shadowed by one of GetReExportedLibraries().
384 return false;
385 }
386
387 /// Sets the load address for an entire module, assuming a rigid slide of
388 /// sections, if possible in the implementation.
389 ///
390 /// \return
391 /// Returns true iff any section's load address changed.
392 virtual bool SetLoadAddress(Target &target, lldb::addr_t value,
393 bool value_is_offset) {
394 return false;
395 }
396
397 /// Gets whether endian swapping should occur when extracting data from this
398 /// object file.
399 ///
400 /// \return
401 /// Returns \b true if endian swapping is needed, \b false
402 /// otherwise.
403 virtual lldb::ByteOrder GetByteOrder() const = 0;
404
405 /// Attempts to parse the object header.
406 ///
407 /// This function is used as a test to see if a given plug-in instance can
408 /// parse the header data already contained in ObjectFile::m_data_nsp. If an
409 /// object file parser does not recognize that magic bytes in a header,
410 /// false should be returned and the next plug-in can attempt to parse an
411 /// object file.
412 ///
413 /// \return
414 /// Returns \b true if the header was parsed successfully, \b
415 /// false otherwise.
416 virtual bool ParseHeader() = 0;
417
418 /// Returns if the function bounds for symbols in this symbol file are
419 /// likely accurate.
420 ///
421 /// The unwinder can emulate the instructions of functions to understand
422 /// prologue/epilogue code sequences, where registers are spilled on the
423 /// stack, etc. This feature relies on having the correct start addresses
424 /// of all functions. If the ObjectFile has a way to tell that symbols have
425 /// been stripped and there's no way to reconstruct start addresses (e.g.
426 /// LC_FUNCTION_STARTS on Mach-O, or eh_frame unwind info), the ObjectFile
427 /// should indicate that assembly emulation should not be used for this
428 /// module.
429 ///
430 /// It is uncommon for this to return false. An ObjectFile needs to be sure
431 /// that symbol start addresses are unavailable before false is returned.
432 /// If it is unclear, this should return true.
433 ///
434 /// \return
435 /// Returns true if assembly emulation should be used for this
436 /// module.
437 /// Only returns false if the ObjectFile is sure that symbol
438 /// addresses are insufficient for accurate assembly emulation.
439 virtual bool AllowAssemblyEmulationUnwindPlans() { return true; }
440
441 /// Similar to Process::GetImageInfoAddress().
442 ///
443 /// Some platforms embed auxiliary structures useful to debuggers in the
444 /// address space of the inferior process. This method returns the address
445 /// of such a structure if the information can be resolved via entries in
446 /// the object file. ELF, for example, provides a means to hook into the
447 /// runtime linker so that a debugger may monitor the loading and unloading
448 /// of shared libraries.
449 ///
450 /// \return
451 /// The address of any auxiliary tables, or an invalid address if this
452 /// object file format does not support or contain such information.
454 return Address();
455 }
456
457 /// Returns the address of the Entry Point in this object file - if the
458 /// object file doesn't have an entry point (because it is not an executable
459 /// file) then an invalid address is returned.
460 ///
461 /// \return
462 /// Returns the entry address for this module.
464
465 /// Returns base address of this object file.
466 ///
467 /// This also sometimes referred to as the "preferred load address" or the
468 /// "image base address". Addresses within object files are often expressed
469 /// relative to this base. If this address corresponds to a specific section
470 /// (usually the first byte of the first section) then the returned address
471 /// will have this section set. Otherwise, the address will just have the
472 /// offset member filled in, indicating that this represents a file address.
476
477 virtual uint32_t GetNumThreadContexts() { return 0; }
478
479 /// Some object files may have an identifier string embedded in them, e.g.
480 /// in a Mach-O core file using the LC_IDENT load command (which is
481 /// obsolete, but can still be found in some old files)
482 ///
483 /// \return
484 /// Returns the identifier string if one exists, else an empty
485 /// string.
486 virtual std::string GetIdentifierString () {
487 return std::string();
488 }
489
490 /// Some object files may have the number of bits used for addressing
491 /// embedded in them, e.g. a Mach-O core file using an LC_NOTE. These
492 /// object files can return an AddressableBits object that can can be
493 /// used to set the address masks in the Process.
494 ///
495 /// \return
496 /// Returns an AddressableBits object which can be used to set
497 /// the address masks in the Process.
499
500 /// When the ObjectFile is a core file, lldb needs to locate the "binary" in
501 /// the core file. lldb can iterate over the pages looking for a valid
502 /// binary, but some core files may have metadata describing where the main
503 /// binary is exactly which removes ambiguity when there are multiple
504 /// binaries present in the captured memory pages.
505 ///
506 /// \param[out] value
507 /// The address or offset (slide) where the binary is loaded in memory.
508 /// LLDB_INVALID_ADDRESS for unspecified. If an offset is given,
509 /// this offset should be added to the binary's file address to get
510 /// the load address.
511 ///
512 /// \param[out] value_is_offset
513 /// Specifies if \b value is a load address, or an offset to calculate
514 /// the load address.
515 ///
516 /// \param[out] uuid
517 /// If the uuid of the binary is specified, this will be set.
518 /// If no UUID is available, will be cleared.
519 ///
520 /// \param[out] type
521 /// Return the type of the binary, which will dictate which
522 /// DynamicLoader plugin should be used.
523 ///
524 /// \return
525 /// Returns true if either address or uuid has been set.
527 bool &value_is_offset, UUID &uuid,
529 value = LLDB_INVALID_ADDRESS;
530 value_is_offset = false;
531 uuid.Clear();
532 return false;
533 }
534
535 /// Get metadata about thread ids from the corefile.
536 ///
537 /// The corefile may have metadata (e.g. a Mach-O "process metadata"
538 /// LC_NOTE) which for the threads in the process; this method tries
539 /// to retrieve them.
540 ///
541 /// \param[out] tids
542 /// Filled in with a vector of tid_t's that matches the number
543 /// of threads in the corefile (ObjectFile::GetNumThreadContexts).
544 /// If a tid is not specified for one of the corefile threads,
545 /// that entry in the vector will have LLDB_INVALID_THREAD_ID and
546 /// the caller should assign a tid to the thread that does not
547 /// conflict with the ones provided in this array.
548 /// As additional metadata are added, this method may return a
549 /// \a tids vector with no thread id's specified at all; the
550 /// corefile may only specify one of the other metadata.
551 ///
552 /// \return
553 /// Returns true if thread metadata was found in this corefile.
554 ///
555 virtual bool GetCorefileThreadExtraInfos(std::vector<lldb::tid_t> &tids) {
556 return false;
557 }
558
559 /// Get process metadata from the corefile in a StructuredData dictionary.
560 ///
561 /// The corefile may have notes (e.g. a Mach-O "process metadata" LC_NOTE)
562 /// which provide metadata about the process and threads in a JSON or
563 /// similar format.
564 ///
565 /// \return
566 /// A StructuredData object with the metadata in the note, if there is
567 /// one. An empty shared pointer is returned if not metadata is found,
568 /// or a problem parsing it.
570
574 }
575
576 /// The object file should be able to calculate its type by looking at its
577 /// file header and possibly the sections or other data in the object file.
578 /// The file type is used in the debugger to help select the correct plug-
579 /// ins for the job at hand, so this is important to get right. If any
580 /// eTypeXXX definitions do not match up with the type of file you are
581 /// loading, please feel free to add a new enumeration value.
582 ///
583 /// \return
584 /// The calculated file type for the current object file.
585 virtual Type CalculateType() = 0;
586
587 /// In cases where the type can't be calculated (elf files), this routine
588 /// allows someone to explicitly set it. As an example, SymbolVendorELF uses
589 /// this routine to set eTypeDebugInfo when loading debug link files.
590 virtual void SetType(Type type) { m_type = type; }
591
592 /// The object file should be able to calculate the strata of the object
593 /// file.
594 ///
595 /// Many object files for platforms might be for either user space debugging
596 /// or for kernel debugging. If your object file subclass can figure this
597 /// out, it will help with debugger plug-in selection when it comes time to
598 /// debug.
599 ///
600 /// \return
601 /// The calculated object file strata for the current object
602 /// file.
603 virtual Strata CalculateStrata() = 0;
604
605 /// Get the object file version numbers.
606 ///
607 /// Many object files have a set of version numbers that describe the
608 /// version of the executable or shared library. Typically there are major,
609 /// minor and build, but there may be more. This function will extract the
610 /// versions from object files if they are available.
611 ///
612 /// \return
613 /// This function returns extracted version numbers as a
614 /// llvm::VersionTuple. In case of error an empty VersionTuple is
615 /// returned.
616 virtual llvm::VersionTuple GetVersion() { return llvm::VersionTuple(); }
617
618 /// Get the minimum OS version this object file can run on.
619 ///
620 /// Some object files have information that specifies the minimum OS version
621 /// that they can be used on.
622 ///
623 /// \return
624 /// This function returns extracted version numbers as a
625 /// llvm::VersionTuple. In case of error an empty VersionTuple is
626 /// returned.
627 virtual llvm::VersionTuple GetMinimumOSVersion() {
628 return llvm::VersionTuple();
629 }
630
631 /// Get the SDK OS version this object file was built with.
632 ///
633 /// \return
634 /// This function returns extracted version numbers as a
635 /// llvm::VersionTuple. In case of error an empty VersionTuple is
636 /// returned.
637 virtual llvm::VersionTuple GetSDKVersion() { return llvm::VersionTuple(); }
638
639 /// Return true if this file is a dynamic link editor (dyld)
640 ///
641 /// Often times dyld has symbols that mirror symbols in libc and other
642 /// shared libraries (like "malloc" and "free") and the user does _not_ want
643 /// to stop in these shared libraries by default. We can ask the ObjectFile
644 /// if it is such a file and should be avoided for things like settings
645 /// breakpoints and doing function lookups for expressions.
646 virtual bool GetIsDynamicLinkEditor() { return false; }
647
648 // Member Functions
650 if (m_type == eTypeInvalid)
652 return m_type;
653 }
654
658 return m_strata;
659 }
660
661 // When an object file is in memory, subclasses should try and lock the
662 // process weak pointer. If the process weak pointer produces a valid
663 // ProcessSP, then subclasses can call this function to read memory.
665 ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr,
666 size_t byte_size);
667
668 // This function returns raw file contents. Do not use it if you want
669 // transparent decompression of section contents.
670 size_t GetData(lldb::offset_t offset, size_t length,
671 lldb::DataExtractorSP &data_sp) const;
672
673 // This function returns raw file contents. Do not use it if you want
674 // transparent decompression of section contents.
675 size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const;
676
677 // This function will transparently decompress section data if the section if
678 // compressed.
679 virtual size_t ReadSectionData(Section *section,
680 lldb::offset_t section_offset, void *dst,
681 size_t dst_len);
682
683 // This function will transparently decompress section data if the section if
684 // compressed. Note that for compressed section the resulting data size may
685 // be larger than what Section::GetFileSize reports.
686 virtual size_t ReadSectionData(Section *section,
687 DataExtractor &section_data);
688
689 // Returns the section data size. This is special-cased for PECOFF
690 // due to file alignment.
691 virtual size_t GetSectionDataSize(Section *section) {
692 return section->GetFileSize();
693 }
694
695 /// Returns true if the object file exists only in memory.
697
698 /// Returns true if the symbol table for this in-memory object file should
699 /// not be loaded from the index cache or saved to the index cache, even
700 /// if caching of memory modules is enabled.
704
705 void SetDisableMemorySymtabCaching(bool disable) {
707 }
708
709 // Strip linker annotations (such as @@VERSION) from symbol names.
710 virtual llvm::StringRef
711 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
712 return symbol_name;
713 }
714
715 /// Can we trust the address ranges accelerator associated with this object
716 /// file to be complete.
717 virtual bool CanTrustAddressRanges() { return false; }
718
720 llvm::StringRef name,
722
723 /// Parses the section type from a section name for DWARF sections.
724 ///
725 /// The \a name must be stripped of the default prefix (e.g. ".debug_" or
726 /// "__debug_"). If there's no matching section type, \a eSectionTypeOther
727 /// will be returned.
728 static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name);
729
730 /// Loads this objfile to memory.
731 ///
732 /// Loads the bits needed to create an executable image to the memory. It is
733 /// useful with bare-metal targets where target does not have the ability to
734 /// start a process itself.
735 ///
736 /// \param[in] target
737 /// Target where to load.
738 virtual std::vector<LoadableData> GetLoadableData(Target &target);
739
740 /// Creates a plugin-specific call frame info
741 virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo();
742
743 /// Load binaries listed in a corefile
744 ///
745 /// A corefile may have metadata listing binaries that can be loaded,
746 /// and the offsets at which they were loaded. This method will try
747 /// to add them to the Target. If any binaries were loaded,
748 ///
749 /// \param[in] process
750 /// Process where to load binaries.
751 ///
752 /// \return
753 /// Returns true if any binaries were loaded.
754
756 return false;
757 }
758
759 /// Returns true if the section is a global offset table section.
760 virtual bool IsGOTSection(const lldb_private::Section &section) const {
761 assert(section.GetObjectFile() == this && "Wrong object file!");
762 return false;
763 }
764
765 /// Get a hash that can be used for caching object file related information.
766 ///
767 /// Data for object files can be cached between runs of debug sessions and
768 /// a Module can end up using a ObjectFile and a SymbolFile, both of which
769 /// can be ObjectFiles in reality. We need a unique hash that identifies
770 /// an ObjectFile when storing cached data.
771 ///
772 /// The hash value returned does not change when the same binary is
773 /// rebuilt with changes; it does not incorporate a mod date or UUID
774 /// like DataFileCache's CacheSignature does.
775 uint32_t GetCacheHash();
776
777 static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
778 uint64_t Offset);
779 std::string GetObjectName() const;
780
781protected:
783
784 // Member variables.
788 lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the
789 ///address in memory
790 lldb::addr_t m_length; ///< The length of this object file if it is known (can
791 ///be zero if length is unknown or can't be
792 ///determined).
793 DataExtractorNSP m_data_nsp; ///< The data for this object file so things
794 ///< can be parsed lazily. This shared pointer
795 ///< will always have a DataExtractor object,
796 ///< although it may only be default-constructed.
798 /// Set if the object file only exists in memory.
800 /// Set if the symbol table for an in-memory object file should not be
801 /// loaded from the index cache.
803
804 std::unique_ptr<lldb_private::SectionList> m_sections_up;
805 std::recursive_mutex m_sections_mutex;
806
807 /// Owned. Atomic because GetSymtab(/*can_create=*/false) reads it without
808 /// synchronizing with the llvm::once_flag below.
809 std::atomic<lldb_private::Symtab *> m_symtab = nullptr;
810 /// We need a llvm::once_flag that we can use to avoid locking the module
811 /// lock and deadlocking LLDB. See comments in ObjectFile::GetSymtab() for
812 /// the full details. We also need to be able to clear the symbol table, so we
813 /// need to use a std::unique_ptr to a llvm::once_flag so if we clear the
814 /// symbol table, we can have a new once flag to use when it is created again.
815 std::unique_ptr<llvm::once_flag> m_symtab_once_up;
816 std::optional<uint32_t> m_cache_hash;
817
818 /// Sets the architecture for a module. At present the architecture can
819 /// only be set if it is invalid. It is not allowed to switch from one
820 /// concrete architecture to another.
821 ///
822 /// \param[in] new_arch
823 /// The architecture this module will be set to.
824 ///
825 /// \return
826 /// Returns \b true if the architecture was changed, \b
827 /// false otherwise.
828 bool SetModulesArchitecture(const ArchSpec &new_arch);
829
830 /// The number of bytes to read when going through the plugins.
832
833private:
834 ObjectFile(const ObjectFile &) = delete;
835 const ObjectFile &operator=(const ObjectFile &) = delete;
836};
837
838} // namespace lldb_private
839
840namespace llvm {
841template <> struct format_provider<lldb_private::ObjectFile::Type> {
842 static void format(const lldb_private::ObjectFile::Type &type,
843 raw_ostream &OS, StringRef Style);
844};
845
846template <> struct format_provider<lldb_private::ObjectFile::Strata> {
847 static void format(const lldb_private::ObjectFile::Strata &strata,
848 raw_ostream &OS, StringRef Style);
849};
850
851namespace json {
852bool fromJSON(const llvm::json::Value &value, lldb_private::ObjectFile::Type &,
853 llvm::json::Path path);
854} // namespace json
855} // namespace llvm
856
857#endif // LLDB_SYMBOL_OBJECTFILE_H
A section + offset based address class.
Definition Address.h:62
A class which holds the metadata from a remote stub/corefile note about how many bits are used for ad...
An architecture specification class.
Definition ArchSpec.h:32
An data extractor class.
A file collection class.
A file utility class.
Definition FileSpec.h:56
ModuleChild(const lldb::ModuleSP &module_sp)
Construct with owning module.
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:92
A non-nullable shared pointer that always holds a valid object.
virtual bool GetCorefileThreadExtraInfos(std::vector< lldb::tid_t > &tids)
Get metadata about thread ids from the corefile.
Definition ObjectFile.h:555
std::atomic< lldb_private::Symtab * > m_symtab
Owned.
Definition ObjectFile.h:809
virtual std::string GetIdentifierString()
Some object files may have an identifier string embedded in them, e.g.
Definition ObjectFile.h:486
virtual bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset)
Sets the load address for an entire module, assuming a rigid slide of sections, if possible in the im...
Definition ObjectFile.h:392
virtual const FileSpec & GetFileSpec() const
Get const accessor to the object file specification.
Definition ObjectFile.h:292
static bool SplitArchivePathWithObject(llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file, llvm::StringRef &archive_object, bool must_exist)
Split a path into a file path with object name.
virtual void Dump(Stream *s)=0
Dump a description of this object to a Stream.
std::unique_ptr< lldb_private::SectionList > m_sections_up
Definition ObjectFile.h:804
const ObjectFile & operator=(const ObjectFile &)=delete
static bool IsObjectFile(lldb_private::FileSpec file_spec)
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP extractor_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
virtual bool IsGOTSection(const lldb_private::Section &section) const
Returns true if the section is a global offset table section.
Definition ObjectFile.h:760
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
virtual llvm::StringRef StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const
Definition ObjectFile.h:711
~ObjectFile() override
Destructor.
virtual uint32_t GetDependentModules(FileSpecList &file_list)=0
Extract the dependent modules from an object file.
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
Definition ObjectFile.h:799
virtual bool IsStripped()=0
Detect if this object file has been stripped of local symbols.
virtual lldb::RegisterContextSP GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread)
Definition ObjectFile.h:572
virtual uint32_t GetNumThreadContexts()
Definition ObjectFile.h:477
virtual bool ReExportedLibrariesShadowLocalDefinitions() const
Whether a symbol that this object file has not itself tagged as a re-export can still be shadowed by ...
Definition ObjectFile.h:383
static size_t g_initial_bytes_to_read
The number of bytes to read when going through the plugins.
Definition ObjectFile.h:831
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition ObjectFile.h:453
virtual bool LoadCoreFileImages(lldb_private::Process &process)
Load binaries listed in a corefile.
Definition ObjectFile.h:755
static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name)
Parses the section type from a section name for DWARF sections.
virtual void ParseSymtab(Symtab &symtab)=0
Parse the symbol table into the provides symbol table object.
virtual AddressClass GetAddressClass(lldb::addr_t file_addr)
Get the address type given a file address in an object file.
Symtab * GetSymtab(bool can_create=true)
Gets the symbol table for the currently selected architecture (and object for archives).
DataExtractorNSP m_data_nsp
The data for this object file so things can be parsed lazily.
Definition ObjectFile.h:793
virtual lldb::addr_t GetFileOffset() const
Returns the offset into a file at which this object resides.
Definition ObjectFile.h:276
virtual lldb_private::Address GetEntryPointAddress()
Returns the address of the Entry Point in this object file - if the object file doesn't have an entry...
Definition ObjectFile.h:463
std::recursive_mutex m_sections_mutex
Definition ObjectFile.h:805
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
virtual Strata CalculateStrata()=0
The object file should be able to calculate the strata of the object file.
@ eTypeExecutable
A normal executable.
Definition ObjectFile.h:56
@ eTypeDebugInfo
An object file that contains only debug information.
Definition ObjectFile.h:58
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition ObjectFile.h:66
@ eTypeObjectFile
An intermediate object file.
Definition ObjectFile.h:62
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition ObjectFile.h:60
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition ObjectFile.h:54
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition ObjectFile.h:64
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
Definition ObjectFile.h:68
virtual void SetType(Type type)
In cases where the type can't be calculated (elf files), this routine allows someone to explicitly se...
Definition ObjectFile.h:590
virtual bool IsSharedCacheBinary() const
Tells whether this object file is part of a shared cache.
Definition ObjectFile.h:266
bool GetDisableMemorySymtabCaching() const
Returns true if the symbol table for this in-memory object file should not be loaded from the index c...
Definition ObjectFile.h:701
virtual lldb_private::AddressableBits GetAddressableBits()
Some object files may have the number of bits used for addressing embedded in them,...
Definition ObjectFile.h:498
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
Definition ObjectFile.h:788
static lldb::SymbolType GetSymbolTypeFromName(llvm::StringRef name, lldb::SymbolType symbol_type_hint=lldb::eSymbolTypeUndefined)
virtual bool IsExecutable() const =0
Tells whether this object file is capable of being the main executable for a process.
virtual size_t GetSectionDataSize(Section *section)
Definition ObjectFile.h:691
virtual std::unique_ptr< CallFrameInfo > CreateCallFrameInfo()
Creates a plugin-specific call frame info.
virtual void ClearSymtab()
Frees the symbol table.
bool SetModulesArchitecture(const ArchSpec &new_arch)
Sets the architecture for a module.
virtual llvm::VersionTuple GetMinimumOSVersion()
Get the minimum OS version this object file can run on.
Definition ObjectFile.h:627
virtual bool ParseHeader()=0
Attempts to parse the object header.
bool m_disable_memory_symtab_caching
Set if the symbol table for an in-memory object file should not be loaded from the index cache.
Definition ObjectFile.h:802
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:285
virtual Type CalculateType()=0
The object file should be able to calculate its type by looking at its file header and possibly the s...
ObjectFile(const ObjectFile &)=delete
std::string GetObjectName() const
virtual bool CanTrustAddressRanges()
Can we trust the address ranges accelerator associated with this object file to be complete.
Definition ObjectFile.h:717
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
virtual bool AllowAssemblyEmulationUnwindPlans()
Returns if the function bounds for symbols in this symbol file are likely accurate.
Definition ObjectFile.h:439
NonNullSharedPtr< lldb_private::DataExtractor > DataExtractorNSP
Definition ObjectFile.h:782
virtual llvm::VersionTuple GetVersion()
Get the object file version numbers.
Definition ObjectFile.h:616
virtual void CreateSections(SectionList &unified_section_list)=0
virtual bool isA(const void *ClassID) const
Definition ObjectFile.h:218
size_t GetData(lldb::offset_t offset, size_t length, lldb::DataExtractorSP &data_sp) const
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
virtual void SectionFileAddressesChanged()
Notify the ObjectFile that the file addresses in the Sections for this module have been changed.
Definition ObjectFile.h:315
virtual uint32_t GetAddressByteSize() const =0
Gets the address size in bytes for the current object file.
virtual void RelocateSection(lldb_private::Section *section)
Perform relocations on the section if necessary.
std::optional< uint32_t > m_cache_hash
Definition ObjectFile.h:816
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
static ModuleSpecList GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP=lldb::DataExtractorSP())
virtual UUID GetUUID()=0
Gets the UUID for this object file.
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
std::unique_ptr< llvm::once_flag > m_symtab_once_up
We need a llvm::once_flag that we can use to avoid locking the module lock and deadlocking LLDB.
Definition ObjectFile.h:815
bool IsInMemory() const
Returns true if the object file exists only in memory.
Definition ObjectFile.h:696
lldb::ProcessWP m_process_wp
Definition ObjectFile.h:797
uint32_t GetCacheHash()
Get a hash that can be used for caching object file related information.
lldb::addr_t m_length
The length of this object file if it is known (can be zero if length is unknown or can't be determine...
Definition ObjectFile.h:790
void SetDisableMemorySymtabCaching(bool disable)
Definition ObjectFile.h:705
virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &value, bool &value_is_offset, UUID &uuid, ObjectFile::BinaryType &type)
When the ObjectFile is a core file, lldb needs to locate the "binary" in the core file.
Definition ObjectFile.h:526
virtual size_t ReadSectionData(Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len)
virtual StructuredData::ObjectSP GetCorefileProcessMetadata()
Get process metadata from the corefile in a StructuredData dictionary.
Definition ObjectFile.h:569
BinaryType
If we have a corefile binary hint, this enum specifies the binary type which we can use to select the...
Definition ObjectFile.h:84
@ eBinaryTypeKernel
kernel binary
Definition ObjectFile.h:88
@ eBinaryTypeUser
user process binary, dyld addr
Definition ObjectFile.h:90
@ eBinaryTypeUserAllImageInfos
user process binary, dyld_all_image_infos addr
Definition ObjectFile.h:92
@ eBinaryTypeStandalone
standalone binary / firmware
Definition ObjectFile.h:94
virtual lldb_private::Address GetBaseAddress()
Returns base address of this object file.
Definition ObjectFile.h:473
virtual bool GetIsDynamicLinkEditor()
Return true if this file is a dynamic link editor (dyld)
Definition ObjectFile.h:646
virtual llvm::VersionTuple GetSDKVersion()
Get the SDK OS version this object file was built with.
Definition ObjectFile.h:637
virtual lldb::addr_t GetByteSize() const
Definition ObjectFile.h:278
virtual lldb_private::FileSpecList GetReExportedLibraries()
Gets the file spec list of libraries re-exported by this object file.
Definition ObjectFile.h:377
virtual ArchSpec GetArchitecture()=0
Get the ArchSpec for this object file.
A plug-in interface definition class for debugging a process.
Definition Process.h:370
ObjectFile * GetObjectFile()
Definition Section.h:230
lldb::offset_t GetFileSize() const
Definition Section.h:186
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::shared_ptr< Object > ObjectSP
Represents UUID's of various sizes.
Definition UUID.h:27
void Clear()
Definition UUID.h:62
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
uint64_t offset_t
Definition lldb-types.h:86
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::Process > ProcessSP
SymbolType
Symbol types.
@ eSymbolTypeUndefined
ByteOrder
Byte ordering definitions.
std::weak_ptr< lldb_private::Process > ProcessWP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSection &section, llvm::json::Path path)
Definition Section.cpp:720
llvm::ArrayRef< uint8_t > Contents
Definition ObjectFile.h:99
static void format(const lldb_private::ObjectFile::Strata &strata, raw_ostream &OS, StringRef Style)
static void format(const lldb_private::ObjectFile::Type &type, raw_ostream &OS, StringRef Style)