Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:46

0001 //===- SymbolizableObjectFile.h ---------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the SymbolizableObjectFile class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 #ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
0013 #define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
0014 
0015 #include "llvm/ADT/StringRef.h"
0016 #include "llvm/DebugInfo/DIContext.h"
0017 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
0018 #include "llvm/Support/Error.h"
0019 #include <cstdint>
0020 #include <memory>
0021 #include <string>
0022 #include <utility>
0023 #include <vector>
0024 
0025 namespace llvm {
0026 
0027 class DataExtractor;
0028 
0029 namespace symbolize {
0030 
0031 class SymbolizableObjectFile : public SymbolizableModule {
0032 public:
0033   static Expected<std::unique_ptr<SymbolizableObjectFile>>
0034   create(const object::ObjectFile *Obj, std::unique_ptr<DIContext> DICtx,
0035          bool UntagAddresses);
0036 
0037   DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
0038                            DILineInfoSpecifier LineInfoSpecifier,
0039                            bool UseSymbolTable) const override;
0040   DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
0041                                       DILineInfoSpecifier LineInfoSpecifier,
0042                                       bool UseSymbolTable) const override;
0043   DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override;
0044   std::vector<DILocal>
0045   symbolizeFrame(object::SectionedAddress ModuleOffset) const override;
0046   std::vector<object::SectionedAddress>
0047   findSymbol(StringRef Symbol, uint64_t Offset) const override;
0048 
0049   // Return true if this is a 32-bit x86 PE COFF module.
0050   bool isWin32Module() const override;
0051 
0052   // Returns the preferred base of the module, i.e. where the loader would place
0053   // it in memory assuming there were no conflicts.
0054   uint64_t getModulePreferredBase() const override;
0055 
0056 private:
0057   bool shouldOverrideWithSymbolTable(FunctionNameKind FNKind,
0058                                      bool UseSymbolTable) const;
0059 
0060   bool getNameFromSymbolTable(uint64_t Address, std::string &Name,
0061                               uint64_t &Addr, uint64_t &Size,
0062                               std::string &FileName) const;
0063   // For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
0064   // (function descriptor) section and OpdExtractor refers to its contents.
0065   Error addSymbol(const object::SymbolRef &Symbol, uint64_t SymbolSize,
0066                   DataExtractor *OpdExtractor = nullptr,
0067                   uint64_t OpdAddress = 0);
0068   Error addCoffExportSymbols(const object::COFFObjectFile *CoffObj);
0069 
0070   /// Search for the first occurence of specified Address in ObjectFile.
0071   uint64_t getModuleSectionIndexForAddress(uint64_t Address) const;
0072 
0073   const object::ObjectFile *Module;
0074   std::unique_ptr<DIContext> DebugInfoContext;
0075   bool UntagAddresses;
0076 
0077   struct SymbolDesc {
0078     uint64_t Addr;
0079     // If size is 0, assume that symbol occupies the whole memory range up to
0080     // the following symbol.
0081     uint64_t Size;
0082 
0083     StringRef Name;
0084     // Non-zero if this is an ELF local symbol. See the comment in
0085     // getNameFromSymbolTable.
0086     uint32_t ELFLocalSymIdx;
0087 
0088     bool operator<(const SymbolDesc &RHS) const {
0089       return Addr != RHS.Addr ? Addr < RHS.Addr : Size < RHS.Size;
0090     }
0091   };
0092   std::vector<SymbolDesc> Symbols;
0093   // (index, filename) pairs of ELF STT_FILE symbols.
0094   std::vector<std::pair<uint32_t, StringRef>> FileSymbols;
0095 
0096   SymbolizableObjectFile(const object::ObjectFile *Obj,
0097                          std::unique_ptr<DIContext> DICtx,
0098                          bool UntagAddresses);
0099 };
0100 
0101 } // end namespace symbolize
0102 
0103 } // end namespace llvm
0104 
0105 #endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H