ObjectFile.h 28 KB

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