2017-02-09 09:09:54 +08:00
|
|
|
//===- SymbolizableObjectFile.h ---------------------------------*- C++ -*-===//
|
2015-10-30 06:21:37 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-10-30 06:21:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the SymbolizableObjectFile class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
|
|
|
|
#define LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
|
|
|
|
|
2017-02-09 09:09:54 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/DebugInfo/DIContext.h"
|
2015-10-30 06:21:37 +08:00
|
|
|
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
|
2020-09-17 19:52:23 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
2017-02-09 09:09:54 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2020-09-17 19:52:23 +08:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2015-10-30 06:21:37 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-02-09 09:09:54 +08:00
|
|
|
|
2015-10-30 06:21:37 +08:00
|
|
|
class DataExtractor;
|
|
|
|
|
|
|
|
namespace symbolize {
|
|
|
|
|
|
|
|
class SymbolizableObjectFile : public SymbolizableModule {
|
|
|
|
public:
|
2020-06-12 04:00:54 +08:00
|
|
|
static Expected<std::unique_ptr<SymbolizableObjectFile>>
|
2019-08-06 04:59:25 +08:00
|
|
|
create(const object::ObjectFile *Obj, std::unique_ptr<DIContext> DICtx,
|
|
|
|
bool UntagAddresses);
|
2015-10-30 06:21:37 +08:00
|
|
|
|
2019-02-27 21:17:36 +08:00
|
|
|
DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
|
2020-03-20 08:26:13 +08:00
|
|
|
DILineInfoSpecifier LineInfoSpecifier,
|
2015-10-30 06:21:37 +08:00
|
|
|
bool UseSymbolTable) const override;
|
2019-02-27 21:17:36 +08:00
|
|
|
DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
|
2020-03-20 08:26:13 +08:00
|
|
|
DILineInfoSpecifier LineInfoSpecifier,
|
2015-10-30 06:21:37 +08:00
|
|
|
bool UseSymbolTable) const override;
|
2019-02-27 21:17:36 +08:00
|
|
|
DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override;
|
2019-06-25 04:03:23 +08:00
|
|
|
std::vector<DILocal>
|
|
|
|
symbolizeFrame(object::SectionedAddress ModuleOffset) const override;
|
2015-10-30 06:21:37 +08:00
|
|
|
|
|
|
|
// Return true if this is a 32-bit x86 PE COFF module.
|
|
|
|
bool isWin32Module() const override;
|
|
|
|
|
|
|
|
// Returns the preferred base of the module, i.e. where the loader would place
|
|
|
|
// it in memory assuming there were no conflicts.
|
|
|
|
uint64_t getModulePreferredBase() const override;
|
|
|
|
|
|
|
|
private:
|
2015-11-14 01:00:36 +08:00
|
|
|
bool shouldOverrideWithSymbolTable(FunctionNameKind FNKind,
|
|
|
|
bool UseSymbolTable) const;
|
|
|
|
|
2021-02-12 11:22:44 +08:00
|
|
|
bool getNameFromSymbolTable(uint64_t Address, std::string &Name,
|
|
|
|
uint64_t &Addr, uint64_t &Size,
|
2021-02-11 01:47:10 +08:00
|
|
|
std::string &FileName) const;
|
2015-10-30 06:21:37 +08:00
|
|
|
// For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
|
|
|
|
// (function descriptor) section and OpdExtractor refers to its contents.
|
2020-06-12 04:00:54 +08:00
|
|
|
Error addSymbol(const object::SymbolRef &Symbol, uint64_t SymbolSize,
|
|
|
|
DataExtractor *OpdExtractor = nullptr,
|
|
|
|
uint64_t OpdAddress = 0);
|
|
|
|
Error addCoffExportSymbols(const object::COFFObjectFile *CoffObj);
|
2015-10-30 06:21:37 +08:00
|
|
|
|
2019-03-23 16:08:40 +08:00
|
|
|
/// Search for the first occurence of specified Address in ObjectFile.
|
|
|
|
uint64_t getModuleSectionIndexForAddress(uint64_t Address) const;
|
|
|
|
|
2019-07-09 03:28:57 +08:00
|
|
|
const object::ObjectFile *Module;
|
2015-10-30 06:21:37 +08:00
|
|
|
std::unique_ptr<DIContext> DebugInfoContext;
|
2019-08-06 04:59:25 +08:00
|
|
|
bool UntagAddresses;
|
2015-10-30 06:21:37 +08:00
|
|
|
|
|
|
|
struct SymbolDesc {
|
|
|
|
uint64_t Addr;
|
|
|
|
// If size is 0, assume that symbol occupies the whole memory range up to
|
|
|
|
// the following symbol.
|
|
|
|
uint64_t Size;
|
2017-02-09 09:09:54 +08:00
|
|
|
|
2021-02-11 01:47:10 +08:00
|
|
|
StringRef Name;
|
|
|
|
// Non-zero if this is an ELF local symbol. See the comment in
|
|
|
|
// getNameFromSymbolTable.
|
|
|
|
uint32_t ELFLocalSymIdx;
|
|
|
|
|
2019-04-04 19:08:45 +08:00
|
|
|
bool operator<(const SymbolDesc &RHS) const {
|
|
|
|
return Addr != RHS.Addr ? Addr < RHS.Addr : Size < RHS.Size;
|
2015-10-30 06:21:37 +08:00
|
|
|
}
|
|
|
|
};
|
2021-02-12 11:22:44 +08:00
|
|
|
std::vector<SymbolDesc> Symbols;
|
2021-02-11 01:47:10 +08:00
|
|
|
// (index, filename) pairs of ELF STT_FILE symbols.
|
|
|
|
std::vector<std::pair<uint32_t, StringRef>> FileSymbols;
|
2015-10-30 06:21:37 +08:00
|
|
|
|
2019-07-09 03:28:57 +08:00
|
|
|
SymbolizableObjectFile(const object::ObjectFile *Obj,
|
2019-08-06 04:59:25 +08:00
|
|
|
std::unique_ptr<DIContext> DICtx,
|
|
|
|
bool UntagAddresses);
|
2015-10-30 06:21:37 +08:00
|
|
|
};
|
|
|
|
|
2017-02-09 09:09:54 +08:00
|
|
|
} // end namespace symbolize
|
|
|
|
|
|
|
|
} // end namespace llvm
|
2015-10-30 06:21:37 +08:00
|
|
|
|
2017-02-09 09:09:54 +08:00
|
|
|
#endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
|