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"
14#include "lldb/Core/PluginInterface.h"
15#include "lldb/Symbol/Symtab.h"
16#include "lldb/Symbol/UnwindTable.h"
17#include "lldb/Utility/DataExtractor.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
24namespace lldb_private {
25
26class ObjectFileJITDelegate {
27public:
28 ObjectFileJITDelegate() {}
29
30 virtual ~ObjectFileJITDelegate() {}
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.
58class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
59 public PluginInterface,
60 public ModuleChild {
61 friend class lldb_private::Module;
62
63public:
64 enum Type {
65 eTypeInvalid = 0,
66 /// A core file that has a checkpoint of a program's execution state.
67 eTypeCoreFile,
68 /// A normal executable.
69 eTypeExecutable,
70 /// An object file that contains only debug information.
71 eTypeDebugInfo,
72 /// The platform's dynamic linker executable.
73 eTypeDynamicLinker,
74 /// An intermediate object file.
75 eTypeObjectFile,
76 /// A shared library that can be used during execution.
77 eTypeSharedLibrary,
78 /// A library that can be linked against but not used for execution.
79 eTypeStubLibrary,
80 /// JIT code that has symbols, sections and possibly debug info.
81 eTypeJIT,
82 eTypeUnknown
83 };
84
85 enum Strata {
86 eStrataInvalid = 0,
87 eStrataUnknown,
88 eStrataUser,
89 eStrataKernel,
90 eStrataRawImage,
91 eStrataJIT
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 {
98 eBinaryTypeInvalid = 0,
99 eBinaryTypeUnknown,
100 eBinaryTypeKernel, /// kernel binary
101 eBinaryTypeUser, /// user process binary
102 eBinaryTypeStandalone /// standalone binary / firmware
103 };
104
105 struct LoadableData {
106 lldb::addr_t Dest;
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,
196 lldb_private::ModuleSpecList &specs);
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.
461 virtual lldb_private::Address GetImageInfoAddress(Target *target) {
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.
471 virtual lldb_private::Address GetEntryPointAddress() { return Address(); }
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.
481 virtual lldb_private::Address GetBaseAddress() {
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.
494 virtual std::string GetIdentifierString () {
495 return std::string();
496 }
497
498 /// When the ObjectFile is a core file, lldb needs to locate the "binary" in
499 /// the core file. lldb can iterate over the pages looking for a valid
500 /// binary, but some core files may have metadata describing where the main
501 /// binary is exactly which removes ambiguity when there are multiple
502 /// binaries present in the captured memory pages.
503 ///
504 /// \param[out] address
505 /// If the address of the binary is specified, this will be set.
506 /// This is an address is the virtual address space of the core file
507 /// memory segments; it is not an offset into the object file.
508 /// If no address is available, will be set to LLDB_INVALID_ADDRESS.
509 ///
510 /// \param[out] uuid
511 /// If the uuid of the binary is specified, this will be set.
512 /// If no UUID is available, will be cleared.
513 ///
514 /// \param[out] type
515 /// Return the type of the binary, which will dictate which
516 /// DynamicLoader plugin should be used.
517 ///
518 /// \return
519 /// Returns true if either address or uuid has been set.
520 virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &address, UUID &uuid,
521 ObjectFile::BinaryType &type) {
522 address = LLDB_INVALID_ADDRESS;
523 uuid.Clear();
524 return false;
525 }
526
527 virtual lldb::RegisterContextSP
528 GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) {
529 return lldb::RegisterContextSP();
530 }
531
532 /// The object file should be able to calculate its type by looking at its
533 /// file header and possibly the sections or other data in the object file.
534 /// The file type is used in the debugger to help select the correct plug-
535 /// ins for the job at hand, so this is important to get right. If any
536 /// eTypeXXX definitions do not match up with the type of file you are
537 /// loading, please feel free to add a new enumeration value.
538 ///
539 /// \return
540 /// The calculated file type for the current object file.
541 virtual Type CalculateType() = 0;
542
543 /// In cases where the type can't be calculated (elf files), this routine
544 /// allows someone to explicitly set it. As an example, SymbolVendorELF uses
545 /// this routine to set eTypeDebugInfo when loading debug link files.
546 virtual void SetType(Type type) { m_type = type; }
547
548 /// The object file should be able to calculate the strata of the object
549 /// file.
550 ///
551 /// Many object files for platforms might be for either user space debugging
552 /// or for kernel debugging. If your object file subclass can figure this
553 /// out, it will help with debugger plug-in selection when it comes time to
554 /// debug.
555 ///
556 /// \return
557 /// The calculated object file strata for the current object
558 /// file.
559 virtual Strata CalculateStrata() = 0;
560
561 /// Get the object file version numbers.
562 ///
563 /// Many object files have a set of version numbers that describe the
564 /// version of the executable or shared library. Typically there are major,
565 /// minor and build, but there may be more. This function will extract the
566 /// versions from object files if they are available.
567 ///
568 /// \return
569 /// This function returns extracted version numbers as a
570 /// llvm::VersionTuple. In case of error an empty VersionTuple is
571 /// returned.
572 virtual llvm::VersionTuple GetVersion() { return llvm::VersionTuple(); }
573
574 /// Get the minimum OS version this object file can run on.
575 ///
576 /// Some object files have information that specifies the minimum OS version
577 /// that they can be used on.
578 ///
579 /// \return
580 /// This function returns extracted version numbers as a
581 /// llvm::VersionTuple. In case of error an empty VersionTuple is
582 /// returned.
583 virtual llvm::VersionTuple GetMinimumOSVersion() {
584 return llvm::VersionTuple();
585 }
586
587 /// Get the SDK OS version this object file was built with.
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 GetSDKVersion() { return llvm::VersionTuple(); }
594
595 /// Return true if this file is a dynamic link editor (dyld)
596 ///
597 /// Often times dyld has symbols that mirror symbols in libc and other
598 /// shared libraries (like "malloc" and "free") and the user does _not_ want
599 /// to stop in these shared libraries by default. We can ask the ObjectFile
600 /// if it is such a file and should be avoided for things like settings
601 /// breakpoints and doing function lookups for expressions.
602 virtual bool GetIsDynamicLinkEditor() { return false; }
603
604 // Member Functions
605 Type GetType() {
606 if (m_type == eTypeInvalid)
607 m_type = CalculateType();
608 return m_type;
609 }
610
611 Strata GetStrata() {
612 if (m_strata == eStrataInvalid)
613 m_strata = CalculateStrata();
614 return m_strata;
615 }
616
617 // When an object file is in memory, subclasses should try and lock the
618 // process weak pointer. If the process weak pointer produces a valid
619 // ProcessSP, then subclasses can call this function to read memory.
620 static lldb::DataBufferSP ReadMemory(const lldb::ProcessSP &process_sp,
621 lldb::addr_t addr, size_t byte_size);
622
623 // This function returns raw file contents. Do not use it if you want
624 // transparent decompression of section contents.
625 size_t GetData(lldb::offset_t offset, size_t length,
626 DataExtractor &data) const;
627
628 // This function returns raw file contents. Do not use it if you want
629 // transparent decompression of section contents.
630 size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const;
631
632 // This function will transparently decompress section data if the section if
633 // compressed.
634 virtual size_t ReadSectionData(Section *section,
635 lldb::offset_t section_offset, void *dst,
636 size_t dst_len);
637
638 // This function will transparently decompress section data if the section if
639 // compressed. Note that for compressed section the resulting data size may
640 // be larger than what Section::GetFileSize reports.
641 virtual size_t ReadSectionData(Section *section,
642 DataExtractor &section_data);
643
644 bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; }
645
646 // Strip linker annotations (such as @@VERSION) from symbol names.
647 virtual llvm::StringRef
648 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
649 return symbol_name;
650 }
651
652 static lldb::SymbolType GetSymbolTypeFromName(
653 llvm::StringRef name,
654 lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined);
655
656 /// Loads this objfile to memory.
657 ///
658 /// Loads the bits needed to create an executable image to the memory. It is
659 /// useful with bare-metal targets where target does not have the ability to
660 /// start a process itself.
661 ///
662 /// \param[in] target
663 /// Target where to load.
664 virtual std::vector<LoadableData> GetLoadableData(Target &target);
665
666 /// Creates a plugin-specific call frame info
667 virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo();
668
669protected:
670 // Member variables.
671 FileSpec m_file;
672 Type m_type;
673 Strata m_strata;
674 lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the
675 ///address in memory
676 lldb::addr_t m_length; ///< The length of this object file if it is known (can
677 ///be zero if length is unknown or can't be
678 ///determined).
679 DataExtractor
680 m_data; ///< The data for this object file so things can be parsed lazily.
681 lldb::ProcessWP m_process_wp;
682 const lldb::addr_t m_memory_addr;
683 std::unique_ptr<lldb_private::SectionList> m_sections_up;
684 std::unique_ptr<lldb_private::Symtab> m_symtab_up;
685 uint32_t m_synthetic_symbol_idx;
686
687 /// Sets the architecture for a module. At present the architecture can
688 /// only be set if it is invalid. It is not allowed to switch from one
689 /// concrete architecture to another.
690 ///
691 /// \param[in] new_arch
692 /// The architecture this module will be set to.
693 ///
694 /// \return
695 /// Returns \b true if the architecture was changed, \b
696 /// false otherwise.
697 bool SetModulesArchitecture(const ArchSpec &new_arch);
698
699 ConstString GetNextSyntheticSymbolName();
700
701 static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
702 uint64_t Offset);
703
704private:
705 ObjectFile(const ObjectFile &) = delete;
706 const ObjectFile &operator=(const ObjectFile &) = delete;
707};
708
709} // namespace lldb_private
710
711namespace llvm {
712template <> struct format_provider<lldb_private::ObjectFile::Type> {
713 static void format(const lldb_private::ObjectFile::Type &type,
714 raw_ostream &OS, StringRef Style);
715};
716
717template <> struct format_provider<lldb_private::ObjectFile::Strata> {
718 static void format(const lldb_private::ObjectFile::Strata &strata,
719 raw_ostream &OS, StringRef Style);
720};
721} // namespace llvm
722
723#endif // LLDB_SYMBOL_OBJECTFILE_H
724