Warning: This file is not a C or C++ file. It does not have highlighting.

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

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of lldb/include/lldb/Symbol/ObjectFile.h