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