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