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 
12 #include "lldb/Core/FileSpecList.h"
13 #include "lldb/Core/ModuleChild.h"
15 #include "lldb/Symbol/Symtab.h"
18 #include "lldb/Utility/Endian.h"
19 #include "lldb/Utility/FileSpec.h"
20 #include "lldb/Utility/UUID.h"
21 #include "lldb/lldb-private.h"
22 #include "llvm/Support/VersionTuple.h"
23 
24 namespace lldb_private {
25 
27 public:
28  ObjectFileJITDelegate() = default;
29 
30  virtual ~ObjectFileJITDelegate() = default;
31 
32  virtual lldb::ByteOrder GetByteOrder() const = 0;
33 
34  virtual uint32_t GetAddressByteSize() const = 0;
35 
36  virtual void PopulateSymtab(lldb_private::ObjectFile *obj_file,
37  lldb_private::Symtab &symtab) = 0;
38 
39  virtual void PopulateSectionList(lldb_private::ObjectFile *obj_file,
40  lldb_private::SectionList &section_list) = 0;
41 
42  virtual ArchSpec GetArchitecture() = 0;
43 };
44 
45 /// \class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h"
46 /// A plug-in interface definition class for object file parsers.
47 ///
48 /// Object files belong to Module objects and know how to extract information
49 /// from executable, shared library, and object (.o) files used by operating
50 /// system runtime. The symbol table and section list for an object file.
51 ///
52 /// Object files can be represented by the entire file, or by part of a file.
53 /// An example of a partial file ObjectFile is one that contains information
54 /// for one of multiple architectures in the same file.
55 ///
56 /// Once an architecture is selected the object file information can be
57 /// extracted from this abstract class.
58 class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
59  public PluginInterface,
60  public ModuleChild {
61  friend class lldb_private::Module;
62 
63 public:
64  enum Type {
66  /// A core file that has a checkpoint of a program's execution state.
68  /// A normal executable.
70  /// An object file that contains only debug information.
72  /// The platform's dynamic linker executable.
74  /// An intermediate object file.
76  /// A shared library that can be used during execution.
78  /// A library that can be linked against but not used for execution.
80  /// JIT code that has symbols, sections and possibly debug info.
83  };
84 
85  enum Strata {
92  };
93 
94  /// If we have a corefile binary hint, this enum
95  /// specifies the binary type which we can use to
96  /// select the correct DynamicLoader plugin.
97  enum BinaryType {
100  eBinaryTypeKernel, /// kernel binary
101  eBinaryTypeUser, /// user process binary
102  eBinaryTypeStandalone /// standalone binary / firmware
103  };
104 
105  struct LoadableData {
107  llvm::ArrayRef<uint8_t> Contents;
108  };
109 
110  /// Construct with a parent module, offset, and header data.
111  ///
112  /// Object files belong to modules and a valid module must be supplied upon
113  /// construction. The at an offset within a file for objects that contain
114  /// more than one architecture or object.
115  ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr,
116  lldb::offset_t file_offset, lldb::offset_t length,
117  const lldb::DataBufferSP &data_sp, lldb::offset_t data_offset);
118 
119  ObjectFile(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp,
120  lldb::addr_t header_addr, lldb::DataBufferSP &data_sp);
121 
122  /// Destructor.
123  ///
124  /// The destructor is virtual since this class is designed to be inherited
125  /// from by the plug-in instance.
126  ~ObjectFile() override;
127 
128  /// Dump a description of this object to a Stream.
129  ///
130  /// Dump a description of the current contents of this object to the
131  /// supplied stream \a s. The dumping should include the section list if it
132  /// has been parsed, and the symbol table if it has been parsed.
133  ///
134  /// \param[in] s
135  /// The stream to which to dump the object description.
136  virtual void Dump(Stream *s) = 0;
137 
138  /// Find a ObjectFile plug-in that can parse \a file_spec.
139  ///
140  /// Scans all loaded plug-in interfaces that implement versions of the
141  /// ObjectFile plug-in interface and returns the first instance that can
142  /// parse the file.
143  ///
144  /// \param[in] module_sp
145  /// The parent module that owns this object file.
146  ///
147  /// \param[in] file_spec
148  /// A file specification that indicates which file to use as the
149  /// object file.
150  ///
151  /// \param[in] file_offset
152  /// The offset into the file at which to start parsing the
153  /// object. This is for files that contain multiple
154  /// architectures or objects.
155  ///
156  /// \param[in] file_size
157  /// The size of the current object file if it can be determined
158  /// or if it is known. This can be zero.
159  ///
160  /// \see ObjectFile::ParseHeader()
161  static lldb::ObjectFileSP
162  FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec,
163  lldb::offset_t file_offset, lldb::offset_t file_size,
164  lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset);
165 
166  /// Find a ObjectFile plug-in that can parse a file in memory.
167  ///
168  /// Scans all loaded plug-in interfaces that implement versions of the
169  /// ObjectFile plug-in interface and returns the first instance that can
170  /// parse the file.
171  ///
172  /// \param[in] module_sp
173  /// The parent module that owns this object file.
174  ///
175  /// \param[in] process_sp
176  /// A shared pointer to the process whose memory space contains
177  /// an object file. This will be stored as a std::weak_ptr.
178  ///
179  /// \param[in] header_addr
180  /// The address of the header for the object file in memory.
181  static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp,
182  const lldb::ProcessSP &process_sp,
183  lldb::addr_t header_addr,
184  lldb::DataBufferSP &file_data_sp);
185 
186  static size_t
187  GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset,
188  lldb::offset_t file_size, ModuleSpecList &specs,
189  lldb::DataBufferSP data_sp = lldb::DataBufferSP());
190 
191  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
192  lldb::DataBufferSP &data_sp,
193  lldb::offset_t data_offset,
194  lldb::offset_t file_offset,
195  lldb::offset_t file_size,
197  /// Split a path into a file path with object name.
198  ///
199  /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into
200  /// the actual path name and into the object name so we can make a valid
201  /// object file from it.
202  ///
203  /// \param[in] path_with_object
204  /// A path that might contain an archive path with a .o file
205  /// specified in parens in the basename of the path.
206  ///
207  /// \param[out] archive_file
208  /// If \b true is returned, \a file_spec will be filled in with
209  /// the path to the archive.
210  ///
211  /// \param[out] archive_object
212  /// If \b true is returned, \a object will be filled in with
213  /// the name of the object inside the archive.
214  ///
215  /// \return
216  /// \b true if the path matches the pattern of archive + object
217  /// and \a archive_file and \a archive_object are modified,
218  /// \b false otherwise and \a archive_file and \a archive_object
219  /// are guaranteed to be remain unchanged.
220  static bool SplitArchivePathWithObject(
221  llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file,
222  lldb_private::ConstString &archive_object, bool must_exist);
223 
224  // LLVM RTTI support
225  static char ID;
226  virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
227 
228  /// Gets the address size in bytes for the current object file.
229  ///
230  /// \return
231  /// The size of an address in bytes for the currently selected
232  /// architecture (and object for archives). Returns zero if no
233  /// architecture or object has been selected.
234  virtual uint32_t GetAddressByteSize() const = 0;
235 
236  /// Get the address type given a file address in an object file.
237  ///
238  /// Many binary file formats know what kinds This is primarily for ARM
239  /// binaries, though it can be applied to any executable file format that
240  /// supports different opcode types within the same binary. ARM binaries
241  /// support having both ARM and Thumb within the same executable container.
242  /// We need to be able to get \return
243  /// The size of an address in bytes for the currently selected
244  /// architecture (and object for archives). Returns zero if no
245  /// architecture or object has been selected.
246  virtual AddressClass GetAddressClass(lldb::addr_t file_addr);
247 
248  /// Extract the dependent modules from an object file.
249  ///
250  /// If an object file has information about which other images it depends on
251  /// (such as shared libraries), this function will provide the list. Since
252  /// many executables or shared libraries may depend on the same files,
253  /// FileSpecList::AppendIfUnique(const FileSpec &) should be used to make
254  /// sure any files that are added are not already in the list.
255  ///
256  /// \param[out] file_list
257  /// A list of file specification objects that gets dependent
258  /// files appended to.
259  ///
260  /// \return
261  /// The number of new files that were appended to \a file_list.
262  ///
263  /// \see FileSpecList::AppendIfUnique(const FileSpec &)
264  virtual uint32_t GetDependentModules(FileSpecList &file_list) = 0;
265 
266  /// Tells whether this object file is capable of being the main executable
267  /// for a process.
268  ///
269  /// \return
270  /// \b true if it is, \b false otherwise.
271  virtual bool IsExecutable() const = 0;
272 
273  /// Returns the offset into a file at which this object resides.
274  ///
275  /// Some files contain many object files, and this function allows access to
276  /// an object's offset within the file.
277  ///
278  /// \return
279  /// The offset in bytes into the file. Defaults to zero for
280  /// simple object files that a represented by an entire file.
281  virtual lldb::addr_t GetFileOffset() const { return m_file_offset; }
282 
283  virtual lldb::addr_t GetByteSize() const { return m_length; }
284 
285  /// Get accessor to the object file specification.
286  ///
287  /// \return
288  /// The file specification object pointer if there is one, or
289  /// NULL if this object is only from memory.
290  virtual FileSpec &GetFileSpec() { return m_file; }
291 
292  /// Get const accessor to the object file specification.
293  ///
294  /// \return
295  /// The const file specification object pointer if there is one,
296  /// or NULL if this object is only from memory.
297  virtual const FileSpec &GetFileSpec() const { return m_file; }
298 
299  /// Get the ArchSpec for this object file.
300  ///
301  /// \return
302  /// The ArchSpec of this object file. In case of error, an invalid
303  /// ArchSpec object is returned.
304  virtual ArchSpec GetArchitecture() = 0;
305 
306  /// Gets the section list for the currently selected architecture (and
307  /// object for archives).
308  ///
309  /// Section list parsing can be deferred by ObjectFile instances until this
310  /// accessor is called the first time.
311  ///
312  /// \return
313  /// The list of sections contained in this object file.
314  virtual SectionList *GetSectionList(bool update_module_section_list = true);
315 
316  virtual void CreateSections(SectionList &unified_section_list) = 0;
317 
318  /// Notify the ObjectFile that the file addresses in the Sections for this
319  /// module have been changed.
320  virtual void SectionFileAddressesChanged() {}
321 
322  /// Gets the symbol table for the currently selected architecture (and
323  /// object for archives).
324  ///
325  /// Symbol table parsing can be deferred by ObjectFile instances until this
326  /// accessor is called the first time.
327  ///
328  /// \return
329  /// The symbol table for this object file.
330  virtual Symtab *GetSymtab() = 0;
331 
332  /// Perform relocations on the section if necessary.
333  ///
334  virtual void RelocateSection(lldb_private::Section *section);
335 
336  /// Appends a Symbol for the specified so_addr to the symbol table.
337  ///
338  /// If verify_unique is false, the symbol table is not searched to determine
339  /// if a Symbol found at this address has already been added to the symbol
340  /// table. When verify_unique is true, this method resolves the Symbol as
341  /// the first match in the SymbolTable and appends a Symbol only if
342  /// required/found.
343  ///
344  /// \return
345  /// The resolved symbol or nullptr. Returns nullptr if a
346  /// a Symbol could not be found for the specified so_addr.
347  virtual Symbol *ResolveSymbolForAddress(const Address &so_addr,
348  bool verify_unique) {
349  // Typically overridden to lazily add stripped symbols recoverable from the
350  // exception handling unwind information (i.e. without parsing the entire
351  // eh_frame section.
352  //
353  // The availability of LC_FUNCTION_STARTS allows ObjectFileMachO to
354  // efficiently add stripped symbols when the symbol table is first
355  // constructed. Poorer cousins are PECoff and ELF.
356  return nullptr;
357  }
358 
359  /// Detect if this object file has been stripped of local symbols.
360  /// Detect if this object file has been stripped of local symbols.
361  ///
362  /// \return
363  /// Return \b true if the object file has been stripped of local
364  /// symbols.
365  virtual bool IsStripped() = 0;
366 
367  /// Frees the symbol table.
368  ///
369  /// This function should only be used when an object file is
370  virtual void ClearSymtab();
371 
372  /// Gets the UUID for this object file.
373  ///
374  /// If the object file format contains a UUID, the value should be returned.
375  /// Else ObjectFile instances should return the MD5 checksum of all of the
376  /// bytes for the object file (or memory for memory based object files).
377  ///
378  /// \return
379  /// The object file's UUID. In case of an error, an empty UUID is
380  /// returned.
381  virtual UUID GetUUID() = 0;
382 
383  /// Gets the file spec list of libraries re-exported by this object file.
384  ///
385  /// If the object file format has the notion of one library re-exporting the
386  /// symbols from another, the re-exported libraries will be returned in the
387  /// FileSpecList.
388  ///
389  /// \return
390  /// Returns filespeclist.
391  virtual lldb_private::FileSpecList GetReExportedLibraries() {
392  return FileSpecList();
393  }
394 
395  /// Sets the load address for an entire module, assuming a rigid slide of
396  /// sections, if possible in the implementation.
397  ///
398  /// \return
399  /// Returns true iff any section's load address changed.
400  virtual bool SetLoadAddress(Target &target, lldb::addr_t value,
401  bool value_is_offset) {
402  return false;
403  }
404 
405  /// Gets whether endian swapping should occur when extracting data from this
406  /// object file.
407  ///
408  /// \return
409  /// Returns \b true if endian swapping is needed, \b false
410  /// otherwise.
411  virtual lldb::ByteOrder GetByteOrder() const = 0;
412 
413  /// Attempts to parse the object header.
414  ///
415  /// This function is used as a test to see if a given plug-in instance can
416  /// parse the header data already contained in ObjectFile::m_data. If an
417  /// object file parser does not recognize that magic bytes in a header,
418  /// false should be returned and the next plug-in can attempt to parse an
419  /// object file.
420  ///
421  /// \return
422  /// Returns \b true if the header was parsed successfully, \b
423  /// false otherwise.
424  virtual bool ParseHeader() = 0;
425 
426  /// Returns if the function bounds for symbols in this symbol file are
427  /// likely accurate.
428  ///
429  /// The unwinder can emulate the instructions of functions to understand
430  /// prologue/epilogue code sequences, where registers are spilled on the
431  /// stack, etc. This feature relies on having the correct start addresses
432  /// of all functions. If the ObjectFile has a way to tell that symbols have
433  /// been stripped and there's no way to reconstruct start addresses (e.g.
434  /// LC_FUNCTION_STARTS on Mach-O, or eh_frame unwind info), the ObjectFile
435  /// should indicate that assembly emulation should not be used for this
436  /// module.
437  ///
438  /// It is uncommon for this to return false. An ObjectFile needs to be sure
439  /// that symbol start addresses are unavailable before false is returned.
440  /// If it is unclear, this should return true.
441  ///
442  /// \return
443  /// Returns true if assembly emulation should be used for this
444  /// module.
445  /// Only returns false if the ObjectFile is sure that symbol
446  /// addresses are insufficient for accurate assembly emulation.
447  virtual bool AllowAssemblyEmulationUnwindPlans() { return true; }
448 
449  /// Similar to Process::GetImageInfoAddress().
450  ///
451  /// Some platforms embed auxiliary structures useful to debuggers in the
452  /// address space of the inferior process. This method returns the address
453  /// of such a structure if the information can be resolved via entries in
454  /// the object file. ELF, for example, provides a means to hook into the
455  /// runtime linker so that a debugger may monitor the loading and unloading
456  /// of shared libraries.
457  ///
458  /// \return
459  /// The address of any auxiliary tables, or an invalid address if this
460  /// object file format does not support or contain such information.
462  return Address();
463  }
464 
465  /// Returns the address of the Entry Point in this object file - if the
466  /// object file doesn't have an entry point (because it is not an executable
467  /// file) then an invalid address is returned.
468  ///
469  /// \return
470  /// Returns the entry address for this module.
472 
473  /// Returns base address of this object file.
474  ///
475  /// This also sometimes referred to as the "preferred load address" or the
476  /// "image base address". Addresses within object files are often expressed
477  /// relative to this base. If this address corresponds to a specific section
478  /// (usually the first byte of the first section) then the returned address
479  /// will have this section set. Otherwise, the address will just have the
480  /// offset member filled in, indicating that this represents a file address.
482  return Address(m_memory_addr);
483  }
484 
485  virtual uint32_t GetNumThreadContexts() { return 0; }
486 
487  /// Some object files may have an identifier string embedded in them, e.g.
488  /// in a Mach-O core file using the LC_IDENT load command (which is
489  /// obsolete, but can still be found in some old files)
490  ///
491  /// \return
492  /// Returns the identifier string if one exists, else an empty
493  /// string.
495  return std::string();
496  }
497 
498  /// Some object files may have the number of bits used for addressing
499  /// embedded in them, e.g. a Mach-O core file using an LC_NOTE. These
500  /// object files can return the address mask that should be used in
501  /// the Process.
502  /// \return
503  /// The mask will have bits set which aren't used for addressing --
504  /// typically, the high bits.
505  /// Zero is returned when no address bits mask is available.
506  virtual lldb::addr_t GetAddressMask() { return 0; }
507 
508  /// When the ObjectFile is a core file, lldb needs to locate the "binary" in
509  /// the core file. lldb can iterate over the pages looking for a valid
510  /// binary, but some core files may have metadata describing where the main
511  /// binary is exactly which removes ambiguity when there are multiple
512  /// binaries present in the captured memory pages.
513  ///
514  /// \param[out] address
515  /// If the address of the binary is specified, this will be set.
516  /// This is an address is the virtual address space of the core file
517  /// memory segments; it is not an offset into the object file.
518  /// If no address is available, will be set to LLDB_INVALID_ADDRESS.
519  ///
520  /// \param[out] uuid
521  /// If the uuid of the binary is specified, this will be set.
522  /// If no UUID is available, will be cleared.
523  ///
524  /// \param[out] type
525  /// Return the type of the binary, which will dictate which
526  /// DynamicLoader plugin should be used.
527  ///
528  /// \return
529  /// Returns true if either address or uuid has been set.
530  virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &address, UUID &uuid,
531  ObjectFile::BinaryType &type) {
532  address = LLDB_INVALID_ADDRESS;
533  uuid.Clear();
534  return false;
535  }
536 
537  virtual lldb::RegisterContextSP
539  return lldb::RegisterContextSP();
540  }
541 
542  /// The object file should be able to calculate its type by looking at its
543  /// file header and possibly the sections or other data in the object file.
544  /// The file type is used in the debugger to help select the correct plug-
545  /// ins for the job at hand, so this is important to get right. If any
546  /// eTypeXXX definitions do not match up with the type of file you are
547  /// loading, please feel free to add a new enumeration value.
548  ///
549  /// \return
550  /// The calculated file type for the current object file.
551  virtual Type CalculateType() = 0;
552 
553  /// In cases where the type can't be calculated (elf files), this routine
554  /// allows someone to explicitly set it. As an example, SymbolVendorELF uses
555  /// this routine to set eTypeDebugInfo when loading debug link files.
556  virtual void SetType(Type type) { m_type = type; }
557 
558  /// The object file should be able to calculate the strata of the object
559  /// file.
560  ///
561  /// Many object files for platforms might be for either user space debugging
562  /// or for kernel debugging. If your object file subclass can figure this
563  /// out, it will help with debugger plug-in selection when it comes time to
564  /// debug.
565  ///
566  /// \return
567  /// The calculated object file strata for the current object
568  /// file.
569  virtual Strata CalculateStrata() = 0;
570 
571  /// Get the object file version numbers.
572  ///
573  /// Many object files have a set of version numbers that describe the
574  /// version of the executable or shared library. Typically there are major,
575  /// minor and build, but there may be more. This function will extract the
576  /// versions from object files if they are available.
577  ///
578  /// \return
579  /// This function returns extracted version numbers as a
580  /// llvm::VersionTuple. In case of error an empty VersionTuple is
581  /// returned.
582  virtual llvm::VersionTuple GetVersion() { return llvm::VersionTuple(); }
583 
584  /// Get the minimum OS version this object file can run on.
585  ///
586  /// Some object files have information that specifies the minimum OS version
587  /// that they can be used on.
588  ///
589  /// \return
590  /// This function returns extracted version numbers as a
591  /// llvm::VersionTuple. In case of error an empty VersionTuple is
592  /// returned.
593  virtual llvm::VersionTuple GetMinimumOSVersion() {
594  return llvm::VersionTuple();
595  }
596 
597  /// Get the SDK OS version this object file was built with.
598  ///
599  /// \return
600  /// This function returns extracted version numbers as a
601  /// llvm::VersionTuple. In case of error an empty VersionTuple is
602  /// returned.
603  virtual llvm::VersionTuple GetSDKVersion() { return llvm::VersionTuple(); }
604 
605  /// Return true if this file is a dynamic link editor (dyld)
606  ///
607  /// Often times dyld has symbols that mirror symbols in libc and other
608  /// shared libraries (like "malloc" and "free") and the user does _not_ want
609  /// to stop in these shared libraries by default. We can ask the ObjectFile
610  /// if it is such a file and should be avoided for things like settings
611  /// breakpoints and doing function lookups for expressions.
612  virtual bool GetIsDynamicLinkEditor() { return false; }
613 
614  // Member Functions
616  if (m_type == eTypeInvalid)
617  m_type = CalculateType();
618  return m_type;
619  }
620 
622  if (m_strata == eStrataInvalid)
624  return m_strata;
625  }
626 
627  // When an object file is in memory, subclasses should try and lock the
628  // process weak pointer. If the process weak pointer produces a valid
629  // ProcessSP, then subclasses can call this function to read memory.
630  static lldb::DataBufferSP ReadMemory(const lldb::ProcessSP &process_sp,
631  lldb::addr_t addr, size_t byte_size);
632 
633  // This function returns raw file contents. Do not use it if you want
634  // transparent decompression of section contents.
635  size_t GetData(lldb::offset_t offset, size_t length,
636  DataExtractor &data) const;
637 
638  // This function returns raw file contents. Do not use it if you want
639  // transparent decompression of section contents.
640  size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const;
641 
642  // This function will transparently decompress section data if the section if
643  // compressed.
644  virtual size_t ReadSectionData(Section *section,
645  lldb::offset_t section_offset, void *dst,
646  size_t dst_len);
647 
648  // This function will transparently decompress section data if the section if
649  // compressed. Note that for compressed section the resulting data size may
650  // be larger than what Section::GetFileSize reports.
651  virtual size_t ReadSectionData(Section *section,
652  DataExtractor &section_data);
653 
654  bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; }
655 
656  // Strip linker annotations (such as @@VERSION) from symbol names.
657  virtual llvm::StringRef
658  StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
659  return symbol_name;
660  }
661 
663  llvm::StringRef name,
664  lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined);
665 
666  /// Loads this objfile to memory.
667  ///
668  /// Loads the bits needed to create an executable image to the memory. It is
669  /// useful with bare-metal targets where target does not have the ability to
670  /// start a process itself.
671  ///
672  /// \param[in] target
673  /// Target where to load.
674  virtual std::vector<LoadableData> GetLoadableData(Target &target);
675 
676  /// Creates a plugin-specific call frame info
677  virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo();
678 
679  /// Load binaries listed in a corefile
680  ///
681  /// A corefile may have metadata listing binaries that can be loaded,
682  /// and the offsets at which they were loaded. This method will try
683  /// to add them to the Target. If any binaries were loaded,
684  ///
685  /// \param[in] process
686  /// Process where to load binaries.
687  ///
688  /// \return
689  /// Returns true if any binaries were loaded.
690 
691  virtual bool LoadCoreFileImages(lldb_private::Process &process) {
692  return false;
693  }
694 
695 protected:
696  // Member variables.
700  lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the
701  ///address in memory
702  lldb::addr_t m_length; ///< The length of this object file if it is known (can
703  ///be zero if length is unknown or can't be
704  ///determined).
706  m_data; ///< The data for this object file so things can be parsed lazily.
707  lldb::ProcessWP m_process_wp;
709  std::unique_ptr<lldb_private::SectionList> m_sections_up;
710  std::unique_ptr<lldb_private::Symtab> m_symtab_up;
712 
713  /// Sets the architecture for a module. At present the architecture can
714  /// only be set if it is invalid. It is not allowed to switch from one
715  /// concrete architecture to another.
716  ///
717  /// \param[in] new_arch
718  /// The architecture this module will be set to.
719  ///
720  /// \return
721  /// Returns \b true if the architecture was changed, \b
722  /// false otherwise.
723  bool SetModulesArchitecture(const ArchSpec &new_arch);
724 
725  static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
726  uint64_t Offset);
727 
728 private:
729  ObjectFile(const ObjectFile &) = delete;
730  const ObjectFile &operator=(const ObjectFile &) = delete;
731 };
732 
733 } // namespace lldb_private
734 
735 namespace llvm {
736 template <> struct format_provider<lldb_private::ObjectFile::Type> {
737  static void format(const lldb_private::ObjectFile::Type &type,
738  raw_ostream &OS, StringRef Style);
739 };
740 
741 template <> struct format_provider<lldb_private::ObjectFile::Strata> {
742  static void format(const lldb_private::ObjectFile::Strata &strata,
743  raw_ostream &OS, StringRef Style);
744 };
745 } // namespace llvm
746 
747 #endif // LLDB_SYMBOL_OBJECTFILE_H
lldb_private::ObjectFile::GetSymbolTypeFromName
static lldb::SymbolType GetSymbolTypeFromName(llvm::StringRef name, lldb::SymbolType symbol_type_hint=lldb::eSymbolTypeUndefined)
Definition: ObjectFile.cpp:600
lldb_private::ObjectFile::MapFileData
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
Definition: ObjectFile.cpp:654
lldb_private::ObjectFile::isA
virtual bool isA(const void *ClassID) const
Definition: ObjectFile.h:226
lldb_private::UUID
Definition: UUID.h:23
lldb_private::ObjectFile::GetArchitecture
virtual ArchSpec GetArchitecture()=0
Get the ArchSpec for this object file.
lldb_private::ObjectFile::eBinaryTypeKernel
@ eBinaryTypeKernel
Definition: ObjectFile.h:100
llvm
Definition: Debugger.h:49
lldb_private::ObjectFile::CreateSections
virtual void CreateSections(SectionList &unified_section_list)=0
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ObjectFile::GetFileSpec
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition: ObjectFile.h:290
lldb_private::ModuleChild
Definition: ModuleChild.h:19
lldb_private::ObjectFile::m_memory_addr
const lldb::addr_t m_memory_addr
Definition: ObjectFile.h:708
lldb_private::ObjectFile::ParseHeader
virtual bool ParseHeader()=0
Attempts to parse the object header.
lldb_private::ObjectFile::GetModuleSpecifications
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())
lldb_private::AddressClass
AddressClass
Definition: lldb-private-enumerations.h:48
lldb_private::Symbol
Definition: Symbol.h:20
UUID.h
lldb_private::ObjectFile::GetSymtab
virtual Symtab * GetSymtab()=0
Gets the symbol table for the currently selected architecture (and object for archives).
lldb_private::ObjectFile::eTypeExecutable
@ eTypeExecutable
A normal executable.
Definition: ObjectFile.h:69
lldb_private::PluginInterface
Definition: PluginInterface.h:16
lldb_private::ObjectFile::m_strata
Strata m_strata
Definition: ObjectFile.h:699
lldb_private::ObjectFile::m_process_wp
lldb::ProcessWP m_process_wp
Definition: ObjectFile.h:707
lldb_private::ObjectFile::eStrataKernel
@ eStrataKernel
Definition: ObjectFile.h:89
lldb_private::ModuleSpecList
Definition: ModuleSpec.h:280
lldb_private::Process
Definition: Process.h:342
lldb_private::ObjectFile::RelocateSection
virtual void RelocateSection(lldb_private::Section *section)
Perform relocations on the section if necessary.
Definition: ObjectFile.cpp:650
lldb_private::ObjectFile::FindPlugin
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.
lldb_private::ObjectFile::eStrataInvalid
@ eStrataInvalid
Definition: ObjectFile.h:86
lldb_private::ObjectFile::ObjectFile
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, const lldb::DataBufferSP &data_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
Definition: ObjectFile.cpp:237
lldb_private::ObjectFile::AllowAssemblyEmulationUnwindPlans
virtual bool AllowAssemblyEmulationUnwindPlans()
Returns if the function bounds for symbols in this symbol file are likely accurate.
Definition: ObjectFile.h:447
lldb_private::ObjectFile::m_symtab_up
std::unique_ptr< lldb_private::Symtab > m_symtab_up
Definition: ObjectFile.h:710
lldb_private::ObjectFile::IsExecutable
virtual bool IsExecutable() const =0
Tells whether this object file is capable of being the main executable for a process.
lldb_private::ObjectFile::m_file
FileSpec m_file
Definition: ObjectFile.h:697
lldb_private::ObjectFile::GetAddressClass
virtual AddressClass GetAddressClass(lldb::addr_t file_addr)
Get the address type given a file address in an object file.
Definition: ObjectFile.cpp:292
lldb_private::ObjectFile::operator=
const ObjectFile & operator=(const ObjectFile &)=delete
lldb_private::ObjectFile::ReadSectionData
virtual size_t ReadSectionData(Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len)
Definition: ObjectFile.cpp:471
lldb_private::Module
Definition: Module.h:84
lldb_private::ObjectFile::GetSDKVersion
virtual llvm::VersionTuple GetSDKVersion()
Get the SDK OS version this object file was built with.
Definition: ObjectFile.h:603
lldb_private::SectionList
Definition: Section.h:34
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::ObjectFile::GetCorefileMainBinaryInfo
virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &address, 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:530
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ObjectFileJITDelegate
Definition: ObjectFile.h:26
lldb_private::ObjectFile::Type
Type
Definition: ObjectFile.h:64
lldb_private::Target
Definition: Target.h:454
lldb_private::ObjectFile::ReadMemory
static lldb::DataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
Definition: ObjectFile.cpp:443
lldb_private::ObjectFile::eTypeObjectFile
@ eTypeObjectFile
An intermediate object file.
Definition: ObjectFile.h:75
lldb_private::ObjectFileJITDelegate::GetByteOrder
virtual lldb::ByteOrder GetByteOrder() const =0
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::ObjectFile::CalculateStrata
virtual Strata CalculateStrata()=0
The object file should be able to calculate the strata of the object file.
lldb_private::ObjectFile::GetIsDynamicLinkEditor
virtual bool GetIsDynamicLinkEditor()
Return true if this file is a dynamic link editor (dyld)
Definition: ObjectFile.h:612
lldb_private::ObjectFile::GetSectionList
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:583
lldb_private::ObjectFile::LoadableData
Definition: ObjectFile.h:105
lldb_private::ObjectFile::eBinaryTypeUnknown
@ eBinaryTypeUnknown
Definition: ObjectFile.h:99
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb::eSymbolTypeUndefined
@ eSymbolTypeUndefined
Definition: lldb-enumerations.h:639
lldb_private::ObjectFile::m_length
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:702
lldb_private::ObjectFile::LoadableData::Dest
lldb::addr_t Dest
Definition: ObjectFile.h:106
lldb_private::ObjectFile::eStrataUser
@ eStrataUser
Definition: ObjectFile.h:88
lldb_private::ObjectFile::LoadableData::Contents
llvm::ArrayRef< uint8_t > Contents
Definition: ObjectFile.h:107
lldb_private::Thread
Definition: Thread.h:62
lldb_private::ObjectFile::GetFileSpec
virtual const FileSpec & GetFileSpec() const
Get const accessor to the object file specification.
Definition: ObjectFile.h:297
lldb_private::ObjectFile::m_synthetic_symbol_idx
uint32_t m_synthetic_symbol_idx
Definition: ObjectFile.h:711
lldb_private::ObjectFile::StripLinkerSymbolAnnotations
virtual llvm::StringRef StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const
Definition: ObjectFile.h:658
lldb_private::ObjectFile::GetImageInfoAddress
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition: ObjectFile.h:461
lldb_private::ObjectFile::eStrataRawImage
@ eStrataRawImage
Definition: ObjectFile.h:90
lldb_private::ObjectFile::GetThreadContextAtIndex
virtual lldb::RegisterContextSP GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread)
Definition: ObjectFile.h:538
lldb_private::ObjectFile::GetBaseAddress
virtual lldb_private::Address GetBaseAddress()
Returns base address of this object file.
Definition: ObjectFile.h:481
lldb_private::ObjectFile::eTypeCoreFile
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition: ObjectFile.h:67
lldb_private::ObjectFile::GetUUID
virtual UUID GetUUID()=0
Gets the UUID for this object file.
lldb_private::ObjectFile::GetIdentifierString
virtual std::string GetIdentifierString()
Some object files may have an identifier string embedded in them, e.g.
Definition: ObjectFile.h:494
lldb_private::ObjectFile::ResolveSymbolForAddress
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:347
FileSpecList.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ObjectFile::GetByteOrder
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
UnwindTable.h
PluginInterface.h
lldb_private::ObjectFile::eBinaryTypeStandalone
@ eBinaryTypeStandalone
user process binary
Definition: ObjectFile.h:102
lldb_private::ObjectFileJITDelegate::GetArchitecture
virtual ArchSpec GetArchitecture()=0
lldb_private::ObjectFile::eTypeSharedLibrary
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition: ObjectFile.h:77
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::ObjectFile::IsStripped
virtual bool IsStripped()=0
Detect if this object file has been stripped of local symbols.
lldb_private::ObjectFile::BinaryType
BinaryType
If we have a corefile binary hint, this enum specifies the binary type which we can use to select the...
Definition: ObjectFile.h:97
lldb::SymbolType
SymbolType
Symbol types.
Definition: lldb-enumerations.h:612
lldb_private::ObjectFile::Dump
virtual void Dump(Stream *s)=0
Dump a description of this object to a Stream.
lldb_private::ObjectFile::eBinaryTypeInvalid
@ eBinaryTypeInvalid
Definition: ObjectFile.h:98
lldb_private::ObjectFile::~ObjectFile
~ObjectFile() override
Destructor.
Definition: ObjectFile.cpp:280
lldb_private::ObjectFile::ID
static char ID
Definition: ObjectFile.h:225
lldb_private::ObjectFile::eTypeJIT
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
Definition: ObjectFile.h:81
lldb_private::ObjectFile::eBinaryTypeUser
@ eBinaryTypeUser
kernel binary
Definition: ObjectFile.h:101
lldb-private.h
lldb_private::Section
Definition: Section.h:96
lldb_private::ObjectFileJITDelegate::PopulateSectionList
virtual void PopulateSectionList(lldb_private::ObjectFile *obj_file, lldb_private::SectionList &section_list)=0
lldb_private::UUID::Clear
void Clear()
Definition: UUID.h:72
lldb_private::ObjectFile::eStrataUnknown
@ eStrataUnknown
Definition: ObjectFile.h:87
lldb_private::ObjectFile::LoadCoreFileImages
virtual bool LoadCoreFileImages(lldb_private::Process &process)
Load binaries listed in a corefile.
Definition: ObjectFile.h:691
lldb_private::ObjectFile::GetData
size_t GetData(lldb::offset_t offset, size_t length, DataExtractor &data) const
Definition: ObjectFile.cpp:457
lldb_private::ObjectFile::SplitArchivePathWithObject
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.
Definition: ObjectFile.cpp:553
lldb_private::Symtab
Definition: Symtab.h:22
lldb_private::ObjectFile::eTypeInvalid
@ eTypeInvalid
Definition: ObjectFile.h:65
uint32_t
lldb_private::ObjectFile::eTypeDebugInfo
@ eTypeDebugInfo
An object file that contains only debug information.
Definition: ObjectFile.h:71
lldb_private::ObjectFile::GetMinimumOSVersion
virtual llvm::VersionTuple GetMinimumOSVersion()
Get the minimum OS version this object file can run on.
Definition: ObjectFile.h:593
ModuleChild.h
lldb_private::ObjectFileJITDelegate::ObjectFileJITDelegate
ObjectFileJITDelegate()=default
lldb_private::Address
Definition: Address.h:59
lldb_private::ObjectFile::GetFileOffset
virtual lldb::addr_t GetFileOffset() const
Returns the offset into a file at which this object resides.
Definition: ObjectFile.h:281
lldb_private::ObjectFile::GetLoadableData
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
Definition: ObjectFile.cpp:620
lldb_private::ObjectFile::GetStrata
Strata GetStrata()
Definition: ObjectFile.h:621
lldb_private::ObjectFile::SetType
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:556
lldb_private::ObjectFile::eTypeStubLibrary
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition: ObjectFile.h:79
lldb_private::Type
Definition: Type.h:66
Symtab.h
lldb_private::ObjectFile::GetNumThreadContexts
virtual uint32_t GetNumThreadContexts()
Definition: ObjectFile.h:485
lldb_private::ObjectFile::ClearSymtab
virtual void ClearSymtab()
Frees the symbol table.
Definition: ObjectFile.cpp:571
lldb_private::ObjectFile::m_data
DataExtractor m_data
The data for this object file so things can be parsed lazily.
Definition: ObjectFile.h:706
lldb_private::ObjectFile::SetLoadAddress
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:400
lldb_private::ObjectFileJITDelegate::GetAddressByteSize
virtual uint32_t GetAddressByteSize() const =0
lldb_private::ObjectFile::m_file_offset
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
Definition: ObjectFile.h:700
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
DataExtractor.h
lldb_private::ObjectFile::eStrataJIT
@ eStrataJIT
Definition: ObjectFile.h:91
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ObjectFile::GetByteSize
virtual lldb::addr_t GetByteSize() const
Definition: ObjectFile.h:283
lldb_private::ObjectFile::IsInMemory
bool IsInMemory() const
Definition: ObjectFile.h:654
lldb_private::ObjectFile::GetAddressByteSize
virtual uint32_t GetAddressByteSize() const =0
Gets the address size in bytes for the current object file.
FileSpec.h
lldb_private::ObjectFile::GetVersion
virtual llvm::VersionTuple GetVersion()
Get the object file version numbers.
Definition: ObjectFile.h:582
lldb_private::ObjectFile::eTypeUnknown
@ eTypeUnknown
Definition: ObjectFile.h:82
lldb_private::ObjectFile::m_type
Type m_type
Definition: ObjectFile.h:698
lldb_private::ObjectFile::eTypeDynamicLinker
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition: ObjectFile.h:73
lldb_private::ObjectFile::CopyData
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
Definition: ObjectFile.cpp:464
lldb_private::ObjectFile::SetModulesArchitecture
bool SetModulesArchitecture(const ArchSpec &new_arch)
Sets the architecture for a module.
Definition: ObjectFile.cpp:285
lldb_private::ObjectFile::CalculateType
virtual Type CalculateType()=0
The object file should be able to calculate its type by looking at its file header and possibly the s...
lldb_private::ObjectFile::SectionFileAddressesChanged
virtual void SectionFileAddressesChanged()
Notify the ObjectFile that the file addresses in the Sections for this module have been changed.
Definition: ObjectFile.h:320
lldb_private::ObjectFile::CreateCallFrameInfo
virtual std::unique_ptr< CallFrameInfo > CreateCallFrameInfo()
Creates a plugin-specific call frame info.
Definition: ObjectFile.cpp:646
lldb_private::ObjectFile::Strata
Strata
Definition: ObjectFile.h:85
Endian.h
lldb_private::ObjectFileJITDelegate::PopulateSymtab
virtual void PopulateSymtab(lldb_private::ObjectFile *obj_file, lldb_private::Symtab &symtab)=0
lldb_private::ObjectFile::GetDependentModules
virtual uint32_t GetDependentModules(FileSpecList &file_list)=0
Extract the dependent modules from an object file.
lldb_private::ObjectFile::GetEntryPointAddress
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:471
lldb_private::ObjectFile
Definition: ObjectFile.h:58
lldb_private::ObjectFile::GetReExportedLibraries
virtual lldb_private::FileSpecList GetReExportedLibraries()
Gets the file spec list of libraries re-exported by this object file.
Definition: ObjectFile.h:391
lldb_private::ObjectFileJITDelegate::~ObjectFileJITDelegate
virtual ~ObjectFileJITDelegate()=default
lldb_private::ObjectFile::m_sections_up
std::unique_ptr< lldb_private::SectionList > m_sections_up
Definition: ObjectFile.h:709
lldb_private::ObjectFile::GetType
Type GetType()
Definition: ObjectFile.h:615
lldb_private::ObjectFile::GetAddressMask
virtual lldb::addr_t GetAddressMask()
Some object files may have the number of bits used for addressing embedded in them,...
Definition: ObjectFile.h:506
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138