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::DataBufferSP data_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::DataBufferSP data_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::DataBufferSP &data_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 size_t
178 GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset,
179 lldb::offset_t file_size, ModuleSpecList &specs,
181
182 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
183 lldb::DataBufferSP &data_sp,
184 lldb::offset_t data_offset,
185 lldb::offset_t file_offset,
186 lldb::offset_t file_size,
188 static bool IsObjectFile(lldb_private::FileSpec file_spec);
189 /// Split a path into a file path with object name.
190 ///
191 /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into
192 /// the actual path name and into the object name so we can make a valid
193 /// object file from it.
194 ///
195 /// \param[in] path_with_object
196 /// A path that might contain an archive path with a .o file
197 /// specified in parens in the basename of the path.
198 ///
199 /// \param[out] archive_file
200 /// If \b true is returned, \a file_spec will be filled in with
201 /// the path to the archive.
202 ///
203 /// \param[out] archive_object
204 /// If \b true is returned, \a object will be filled in with
205 /// the name of the object inside the archive.
206 ///
207 /// \return
208 /// \b true if the path matches the pattern of archive + object
209 /// and \a archive_file and \a archive_object are modified,
210 /// \b false otherwise and \a archive_file and \a archive_object
211 /// are guaranteed to be remain unchanged.
212 static bool SplitArchivePathWithObject(
213 llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file,
214 lldb_private::ConstString &archive_object, 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 /// Returns the offset into a file at which this object resides.
266 ///
267 /// Some files contain many object files, and this function allows access to
268 /// an object's offset within the file.
269 ///
270 /// \return
271 /// The offset in bytes into the file. Defaults to zero for
272 /// simple object files that a represented by an entire file.
273 virtual lldb::addr_t GetFileOffset() const { return m_file_offset; }
274
275 virtual lldb::addr_t GetByteSize() const { return m_length; }
276
277 /// Get accessor to the object file specification.
278 ///
279 /// \return
280 /// The file specification object pointer if there is one, or
281 /// NULL if this object is only from memory.
282 virtual FileSpec &GetFileSpec() { return m_file; }
283
284 /// Get const accessor to the object file specification.
285 ///
286 /// \return
287 /// The const file specification object pointer if there is one,
288 /// or NULL if this object is only from memory.
289 virtual const FileSpec &GetFileSpec() const { return m_file; }
290
291 /// Get the ArchSpec for this object file.
292 ///
293 /// \return
294 /// The ArchSpec of this object file. In case of error, an invalid
295 /// ArchSpec object is returned.
297
298 /// Gets the section list for the currently selected architecture (and
299 /// object for archives).
300 ///
301 /// Section list parsing can be deferred by ObjectFile instances until this
302 /// accessor is called the first time.
303 ///
304 /// \return
305 /// The list of sections contained in this object file.
306 virtual SectionList *GetSectionList(bool update_module_section_list = true);
307
308 virtual void CreateSections(SectionList &unified_section_list) = 0;
309
310 /// Notify the ObjectFile that the file addresses in the Sections for this
311 /// module have been changed.
313
314 /// Gets the symbol table for the currently selected architecture (and
315 /// object for archives).
316 ///
317 /// This function will manage when ParseSymtab(...) is called to actually do
318 /// the symbol table parsing in each plug-in. This function will take care of
319 /// taking all the necessary locks and finalizing the symbol table when the
320 /// symbol table does get parsed.
321 ///
322 /// \return
323 /// The symbol table for this object file.
324 Symtab *GetSymtab(bool can_create = true);
325
326 /// Parse the symbol table into the provides symbol table object.
327 ///
328 /// Symbol table parsing will be done once when this function is called by
329 /// each object file plugin. All of the necessary locks will already be
330 /// acquired before this function is called and the symbol table object to
331 /// populate is supplied as an argument and doesn't need to be created by
332 /// each plug-in.
333 ///
334 /// \param
335 /// The symbol table to populate.
336 virtual void ParseSymtab(Symtab &symtab) = 0;
337
338 /// Perform relocations on the section if necessary.
339 ///
340 virtual void RelocateSection(lldb_private::Section *section);
341
342 /// Appends a Symbol for the specified so_addr to the symbol table.
343 ///
344 /// If verify_unique is false, the symbol table is not searched to determine
345 /// if a Symbol found at this address has already been added to the symbol
346 /// table. When verify_unique is true, this method resolves the Symbol as
347 /// the first match in the SymbolTable and appends a Symbol only if
348 /// required/found.
349 ///
350 /// \return
351 /// The resolved symbol or nullptr. Returns nullptr if a
352 /// a Symbol could not be found for the specified so_addr.
353 virtual Symbol *ResolveSymbolForAddress(const Address &so_addr,
354 bool verify_unique) {
355 // Typically overridden to lazily add stripped symbols recoverable from the
356 // exception handling unwind information (i.e. without parsing the entire
357 // eh_frame section.
358 //
359 // The availability of LC_FUNCTION_STARTS allows ObjectFileMachO to
360 // efficiently add stripped symbols when the symbol table is first
361 // constructed. Poorer cousins are PECoff and ELF.
362 return nullptr;
363 }
364
365 /// Detect if this object file has been stripped of local symbols.
366 /// Detect if this object file has been stripped of local symbols.
367 ///
368 /// \return
369 /// Return \b true if the object file has been stripped of local
370 /// symbols.
371 virtual bool IsStripped() = 0;
372
373 /// Frees the symbol table.
374 ///
375 /// This function should only be used when an object file is
376 virtual void ClearSymtab();
377
378 /// Gets the UUID for this object file.
379 ///
380 /// If the object file format contains a UUID, the value should be returned.
381 /// Else ObjectFile instances should return the MD5 checksum of all of the
382 /// bytes for the object file (or memory for memory based object files).
383 ///
384 /// \return
385 /// The object file's UUID. In case of an error, an empty UUID is
386 /// returned.
387 virtual UUID GetUUID() = 0;
388
389 /// Gets the file spec list of libraries re-exported by this object file.
390 ///
391 /// If the object file format has the notion of one library re-exporting the
392 /// symbols from another, the re-exported libraries will be returned in the
393 /// FileSpecList.
394 ///
395 /// \return
396 /// Returns filespeclist.
400
401 /// Sets the load address for an entire module, assuming a rigid slide of
402 /// sections, if possible in the implementation.
403 ///
404 /// \return
405 /// Returns true iff any section's load address changed.
406 virtual bool SetLoadAddress(Target &target, lldb::addr_t value,
407 bool value_is_offset) {
408 return false;
409 }
410
411 /// Gets whether endian swapping should occur when extracting data from this
412 /// object file.
413 ///
414 /// \return
415 /// Returns \b true if endian swapping is needed, \b false
416 /// otherwise.
417 virtual lldb::ByteOrder GetByteOrder() const = 0;
418
419 /// Attempts to parse the object header.
420 ///
421 /// This function is used as a test to see if a given plug-in instance can
422 /// parse the header data already contained in ObjectFile::m_data_nsp. If an
423 /// object file parser does not recognize that magic bytes in a header,
424 /// false should be returned and the next plug-in can attempt to parse an
425 /// object file.
426 ///
427 /// \return
428 /// Returns \b true if the header was parsed successfully, \b
429 /// false otherwise.
430 virtual bool ParseHeader() = 0;
431
432 /// Returns if the function bounds for symbols in this symbol file are
433 /// likely accurate.
434 ///
435 /// The unwinder can emulate the instructions of functions to understand
436 /// prologue/epilogue code sequences, where registers are spilled on the
437 /// stack, etc. This feature relies on having the correct start addresses
438 /// of all functions. If the ObjectFile has a way to tell that symbols have
439 /// been stripped and there's no way to reconstruct start addresses (e.g.
440 /// LC_FUNCTION_STARTS on Mach-O, or eh_frame unwind info), the ObjectFile
441 /// should indicate that assembly emulation should not be used for this
442 /// module.
443 ///
444 /// It is uncommon for this to return false. An ObjectFile needs to be sure
445 /// that symbol start addresses are unavailable before false is returned.
446 /// If it is unclear, this should return true.
447 ///
448 /// \return
449 /// Returns true if assembly emulation should be used for this
450 /// module.
451 /// Only returns false if the ObjectFile is sure that symbol
452 /// addresses are insufficient for accurate assembly emulation.
453 virtual bool AllowAssemblyEmulationUnwindPlans() { return true; }
454
455 /// Similar to Process::GetImageInfoAddress().
456 ///
457 /// Some platforms embed auxiliary structures useful to debuggers in the
458 /// address space of the inferior process. This method returns the address
459 /// of such a structure if the information can be resolved via entries in
460 /// the object file. ELF, for example, provides a means to hook into the
461 /// runtime linker so that a debugger may monitor the loading and unloading
462 /// of shared libraries.
463 ///
464 /// \return
465 /// The address of any auxiliary tables, or an invalid address if this
466 /// object file format does not support or contain such information.
468 return Address();
469 }
470
471 /// Returns the address of the Entry Point in this object file - if the
472 /// object file doesn't have an entry point (because it is not an executable
473 /// file) then an invalid address is returned.
474 ///
475 /// \return
476 /// Returns the entry address for this module.
478
479 /// Returns base address of this object file.
480 ///
481 /// This also sometimes referred to as the "preferred load address" or the
482 /// "image base address". Addresses within object files are often expressed
483 /// relative to this base. If this address corresponds to a specific section
484 /// (usually the first byte of the first section) then the returned address
485 /// will have this section set. Otherwise, the address will just have the
486 /// offset member filled in, indicating that this represents a file address.
490
491 virtual uint32_t GetNumThreadContexts() { return 0; }
492
493 /// Some object files may have an identifier string embedded in them, e.g.
494 /// in a Mach-O core file using the LC_IDENT load command (which is
495 /// obsolete, but can still be found in some old files)
496 ///
497 /// \return
498 /// Returns the identifier string if one exists, else an empty
499 /// string.
500 virtual std::string GetIdentifierString () {
501 return std::string();
502 }
503
504 /// Some object files may have the number of bits used for addressing
505 /// embedded in them, e.g. a Mach-O core file using an LC_NOTE. These
506 /// object files can return an AddressableBits object that can can be
507 /// used to set the address masks in the Process.
508 ///
509 /// \return
510 /// Returns an AddressableBits object which can be used to set
511 /// the address masks in the Process.
513
514 /// When the ObjectFile is a core file, lldb needs to locate the "binary" in
515 /// the core file. lldb can iterate over the pages looking for a valid
516 /// binary, but some core files may have metadata describing where the main
517 /// binary is exactly which removes ambiguity when there are multiple
518 /// binaries present in the captured memory pages.
519 ///
520 /// \param[out] value
521 /// The address or offset (slide) where the binary is loaded in memory.
522 /// LLDB_INVALID_ADDRESS for unspecified. If an offset is given,
523 /// this offset should be added to the binary's file address to get
524 /// the load address.
525 ///
526 /// \param[out] value_is_offset
527 /// Specifies if \b value is a load address, or an offset to calculate
528 /// the load address.
529 ///
530 /// \param[out] uuid
531 /// If the uuid of the binary is specified, this will be set.
532 /// If no UUID is available, will be cleared.
533 ///
534 /// \param[out] type
535 /// Return the type of the binary, which will dictate which
536 /// DynamicLoader plugin should be used.
537 ///
538 /// \return
539 /// Returns true if either address or uuid has been set.
541 bool &value_is_offset, UUID &uuid,
543 value = LLDB_INVALID_ADDRESS;
544 value_is_offset = false;
545 uuid.Clear();
546 return false;
547 }
548
549 /// Get metadata about thread ids from the corefile.
550 ///
551 /// The corefile may have metadata (e.g. a Mach-O "process metadata"
552 /// LC_NOTE) which for the threads in the process; this method tries
553 /// to retrieve them.
554 ///
555 /// \param[out] tids
556 /// Filled in with a vector of tid_t's that matches the number
557 /// of threads in the corefile (ObjectFile::GetNumThreadContexts).
558 /// If a tid is not specified for one of the corefile threads,
559 /// that entry in the vector will have LLDB_INVALID_THREAD_ID and
560 /// the caller should assign a tid to the thread that does not
561 /// conflict with the ones provided in this array.
562 /// As additional metadata are added, this method may return a
563 /// \a tids vector with no thread id's specified at all; the
564 /// corefile may only specify one of the other metadata.
565 ///
566 /// \return
567 /// Returns true if thread metadata was found in this corefile.
568 ///
569 virtual bool GetCorefileThreadExtraInfos(std::vector<lldb::tid_t> &tids) {
570 return false;
571 }
572
573 /// Get process metadata from the corefile in a StructuredData dictionary.
574 ///
575 /// The corefile may have notes (e.g. a Mach-O "process metadata" LC_NOTE)
576 /// which provide metadata about the process and threads in a JSON or
577 /// similar format.
578 ///
579 /// \return
580 /// A StructuredData object with the metadata in the note, if there is
581 /// one. An empty shared pointer is returned if not metadata is found,
582 /// or a problem parsing it.
584
588 }
589
590 /// The object file should be able to calculate its type by looking at its
591 /// file header and possibly the sections or other data in the object file.
592 /// The file type is used in the debugger to help select the correct plug-
593 /// ins for the job at hand, so this is important to get right. If any
594 /// eTypeXXX definitions do not match up with the type of file you are
595 /// loading, please feel free to add a new enumeration value.
596 ///
597 /// \return
598 /// The calculated file type for the current object file.
599 virtual Type CalculateType() = 0;
600
601 /// In cases where the type can't be calculated (elf files), this routine
602 /// allows someone to explicitly set it. As an example, SymbolVendorELF uses
603 /// this routine to set eTypeDebugInfo when loading debug link files.
604 virtual void SetType(Type type) { m_type = type; }
605
606 /// The object file should be able to calculate the strata of the object
607 /// file.
608 ///
609 /// Many object files for platforms might be for either user space debugging
610 /// or for kernel debugging. If your object file subclass can figure this
611 /// out, it will help with debugger plug-in selection when it comes time to
612 /// debug.
613 ///
614 /// \return
615 /// The calculated object file strata for the current object
616 /// file.
617 virtual Strata CalculateStrata() = 0;
618
619 /// Get the object file version numbers.
620 ///
621 /// Many object files have a set of version numbers that describe the
622 /// version of the executable or shared library. Typically there are major,
623 /// minor and build, but there may be more. This function will extract the
624 /// versions from object files if they are available.
625 ///
626 /// \return
627 /// This function returns extracted version numbers as a
628 /// llvm::VersionTuple. In case of error an empty VersionTuple is
629 /// returned.
630 virtual llvm::VersionTuple GetVersion() { return llvm::VersionTuple(); }
631
632 /// Get the minimum OS version this object file can run on.
633 ///
634 /// Some object files have information that specifies the minimum OS version
635 /// that they can be used on.
636 ///
637 /// \return
638 /// This function returns extracted version numbers as a
639 /// llvm::VersionTuple. In case of error an empty VersionTuple is
640 /// returned.
641 virtual llvm::VersionTuple GetMinimumOSVersion() {
642 return llvm::VersionTuple();
643 }
644
645 /// Get the SDK OS version this object file was built with.
646 ///
647 /// \return
648 /// This function returns extracted version numbers as a
649 /// llvm::VersionTuple. In case of error an empty VersionTuple is
650 /// returned.
651 virtual llvm::VersionTuple GetSDKVersion() { return llvm::VersionTuple(); }
652
653 /// Return true if this file is a dynamic link editor (dyld)
654 ///
655 /// Often times dyld has symbols that mirror symbols in libc and other
656 /// shared libraries (like "malloc" and "free") and the user does _not_ want
657 /// to stop in these shared libraries by default. We can ask the ObjectFile
658 /// if it is such a file and should be avoided for things like settings
659 /// breakpoints and doing function lookups for expressions.
660 virtual bool GetIsDynamicLinkEditor() { return false; }
661
662 // Member Functions
664 if (m_type == eTypeInvalid)
666 return m_type;
667 }
668
672 return m_strata;
673 }
674
675 // When an object file is in memory, subclasses should try and lock the
676 // process weak pointer. If the process weak pointer produces a valid
677 // ProcessSP, then subclasses can call this function to read memory.
679 ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr,
680 size_t byte_size);
681
682 // This function returns raw file contents. Do not use it if you want
683 // transparent decompression of section contents.
684 size_t GetData(lldb::offset_t offset, size_t length,
685 DataExtractor &data) const;
686
687 // This function returns raw file contents. Do not use it if you want
688 // transparent decompression of section contents.
689 size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const;
690
691 // This function will transparently decompress section data if the section if
692 // compressed.
693 virtual size_t ReadSectionData(Section *section,
694 lldb::offset_t section_offset, void *dst,
695 size_t dst_len);
696
697 // This function will transparently decompress section data if the section if
698 // compressed. Note that for compressed section the resulting data size may
699 // be larger than what Section::GetFileSize reports.
700 virtual size_t ReadSectionData(Section *section,
701 DataExtractor &section_data);
702
703 // Returns the section data size. This is special-cased for PECOFF
704 // due to file alignment.
705 virtual size_t GetSectionDataSize(Section *section) {
706 return section->GetFileSize();
707 }
708
709 /// Returns true if the object file exists only in memory.
711
712 // Strip linker annotations (such as @@VERSION) from symbol names.
713 virtual llvm::StringRef
714 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
715 return symbol_name;
716 }
717
718 /// Can we trust the address ranges accelerator associated with this object
719 /// file to be complete.
720 virtual bool CanTrustAddressRanges() { return false; }
721
723 llvm::StringRef name,
725
726 /// Parses the section type from a section name for DWARF sections.
727 ///
728 /// The \a name must be stripped of the default prefix (e.g. ".debug_" or
729 /// "__debug_"). If there's no matching section type, \a eSectionTypeOther
730 /// will be returned.
731 static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name);
732
733 /// Loads this objfile to memory.
734 ///
735 /// Loads the bits needed to create an executable image to the memory. It is
736 /// useful with bare-metal targets where target does not have the ability to
737 /// start a process itself.
738 ///
739 /// \param[in] target
740 /// Target where to load.
741 virtual std::vector<LoadableData> GetLoadableData(Target &target);
742
743 /// Creates a plugin-specific call frame info
744 virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo();
745
746 /// Load binaries listed in a corefile
747 ///
748 /// A corefile may have metadata listing binaries that can be loaded,
749 /// and the offsets at which they were loaded. This method will try
750 /// to add them to the Target. If any binaries were loaded,
751 ///
752 /// \param[in] process
753 /// Process where to load binaries.
754 ///
755 /// \return
756 /// Returns true if any binaries were loaded.
757
759 return false;
760 }
761
762 /// Returns true if the section is a global offset table section.
763 virtual bool IsGOTSection(const lldb_private::Section &section) const {
764 assert(section.GetObjectFile() == this && "Wrong object file!");
765 return false;
766 }
767
768 /// Get a hash that can be used for caching object file releated information.
769 ///
770 /// Data for object files can be cached between runs of debug sessions and
771 /// a module can end up using a main file and a symbol file, both of which
772 /// can be object files. So we need a unique hash that identifies an object
773 /// file when storing cached data.
774 uint32_t GetCacheHash();
775
776 static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
777 uint64_t Offset);
778 std::string GetObjectName() const;
779
780protected:
782
783 // Member variables.
787 lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the
788 ///address in memory
789 lldb::addr_t m_length; ///< The length of this object file if it is known (can
790 ///be zero if length is unknown or can't be
791 ///determined).
792 DataExtractorNSP m_data_nsp; ///< The data for this object file so things
793 ///< can be parsed lazily. This shared pointer
794 ///< will always have a DataExtractor object,
795 ///< although it may only be default-constructed.
797 /// Set if the object file only exists in memory.
799 std::unique_ptr<lldb_private::SectionList> m_sections_up;
800 std::unique_ptr<lldb_private::Symtab> m_symtab_up;
801 /// We need a llvm::once_flag that we can use to avoid locking the module
802 /// lock and deadlocking LLDB. See comments in ObjectFile::GetSymtab() for
803 /// the full details. We also need to be able to clear the symbol table, so we
804 /// need to use a std::unique_ptr to a llvm::once_flag so if we clear the
805 /// symbol table, we can have a new once flag to use when it is created again.
806 std::unique_ptr<llvm::once_flag> m_symtab_once_up;
807 std::optional<uint32_t> m_cache_hash;
808
809 /// Sets the architecture for a module. At present the architecture can
810 /// only be set if it is invalid. It is not allowed to switch from one
811 /// concrete architecture to another.
812 ///
813 /// \param[in] new_arch
814 /// The architecture this module will be set to.
815 ///
816 /// \return
817 /// Returns \b true if the architecture was changed, \b
818 /// false otherwise.
819 bool SetModulesArchitecture(const ArchSpec &new_arch);
820
821 /// The number of bytes to read when going through the plugins.
823
824private:
825 ObjectFile(const ObjectFile &) = delete;
826 const ObjectFile &operator=(const ObjectFile &) = delete;
827};
828
829} // namespace lldb_private
830
831namespace llvm {
832template <> struct format_provider<lldb_private::ObjectFile::Type> {
833 static void format(const lldb_private::ObjectFile::Type &type,
834 raw_ostream &OS, StringRef Style);
835};
836
837template <> struct format_provider<lldb_private::ObjectFile::Strata> {
838 static void format(const lldb_private::ObjectFile::Strata &strata,
839 raw_ostream &OS, StringRef Style);
840};
841
842namespace json {
843bool fromJSON(const llvm::json::Value &value, lldb_private::ObjectFile::Type &,
844 llvm::json::Path path);
845} // namespace json
846} // namespace llvm
847
848#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:31
A uniqued constant string class.
Definition ConstString.h:40
An data extractor class.
A file collection class.
A file utility class.
Definition FileSpec.h:57
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:90
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:569
virtual std::string GetIdentifierString()
Some object files may have an identifier string embedded in them, e.g.
Definition ObjectFile.h:500
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
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:406
virtual const FileSpec & GetFileSpec() const
Get const accessor to the object file specification.
Definition ObjectFile.h:289
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:799
const ObjectFile & operator=(const ObjectFile &)=delete
static bool IsObjectFile(lldb_private::FileSpec 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:763
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
virtual llvm::StringRef StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const
Definition ObjectFile.h:714
~ObjectFile() override
Destructor.
std::unique_ptr< lldb_private::Symtab > m_symtab_up
Definition ObjectFile.h:800
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:798
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:586
virtual uint32_t GetNumThreadContexts()
Definition ObjectFile.h:491
static size_t g_initial_bytes_to_read
The number of bytes to read when going through the plugins.
Definition ObjectFile.h:822
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition ObjectFile.h:467
virtual bool LoadCoreFileImages(lldb_private::Process &process)
Load binaries listed in a corefile.
Definition ObjectFile.h:758
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:792
virtual lldb::addr_t GetFileOffset() const
Returns the offset into a file at which this object resides.
Definition ObjectFile.h:273
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:477
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
size_t GetData(lldb::offset_t offset, size_t length, DataExtractor &data) const
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:604
virtual lldb_private::AddressableBits GetAddressableBits()
Some object files may have the number of bits used for addressing embedded in them,...
Definition ObjectFile.h:512
virtual Symbol * ResolveSymbolForAddress(const Address &so_addr, bool verify_unique)
Appends a Symbol for the specified so_addr to the symbol table.
Definition ObjectFile.h:353
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
Definition ObjectFile.h:787
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:705
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:641
virtual bool ParseHeader()=0
Attempts to parse the object header.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:282
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:720
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:453
NonNullSharedPtr< lldb_private::DataExtractor > DataExtractorNSP
Definition ObjectFile.h:781
virtual llvm::VersionTuple GetVersion()
Get the object file version numbers.
Definition ObjectFile.h:630
static bool SplitArchivePathWithObject(llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file, lldb_private::ConstString &archive_object, bool must_exist)
Split a path into a file path with object name.
virtual void CreateSections(SectionList &unified_section_list)=0
virtual bool isA(const void *ClassID) const
Definition ObjectFile.h:218
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:312
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:807
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
virtual UUID GetUUID()=0
Gets the UUID for this object file.
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:806
bool IsInMemory() const
Returns true if the object file exists only in memory.
Definition ObjectFile.h:710
lldb::ProcessWP m_process_wp
Definition ObjectFile.h:796
uint32_t GetCacheHash()
Get a hash that can be used for caching object file releated 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:789
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:540
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:583
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:487
virtual bool GetIsDynamicLinkEditor()
Return true if this file is a dynamic link editor (dyld)
Definition ObjectFile.h:660
static size_t GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs, lldb::DataBufferSP data_sp=lldb::DataBufferSP())
virtual llvm::VersionTuple GetSDKVersion()
Get the SDK OS version this object file was built with.
Definition ObjectFile.h:651
virtual lldb::addr_t GetByteSize() const
Definition ObjectFile.h:275
virtual lldb_private::FileSpecList GetReExportedLibraries()
Gets the file spec list of libraries re-exported by this object file.
Definition ObjectFile.h:397
virtual ArchSpec GetArchitecture()=0
Get the ArchSpec for this object file.
A plug-in interface definition class for debugging a process.
Definition Process.h:354
ObjectFile * GetObjectFile()
Definition Section.h:233
lldb::offset_t GetFileSize() const
Definition Section.h:189
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:85
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::Module > ModuleSP
bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSection &section, llvm::json::Path path)
Definition Section.cpp:722
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)