LLVM 22.0.0git
BacktraceTools.h
Go to the documentation of this file.
1//===-- BacktraceTools.h - Backtrace symbolication tools -------*- 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// Tools for dumping symbol tables and symbolicating backtraces.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_BACKTRACETOOLS_H
14#define LLVM_EXECUTIONENGINE_ORC_BACKTRACETOOLS_H
15
18#include "llvm/Support/Error.h"
20
21#include <memory>
22#include <mutex>
23#include <string>
24
25namespace llvm::orc {
26
27/// Dumps symbol tables from LinkGraphs to enable backtrace symbolication.
28///
29/// This plugin appends symbol information to a file in the following format:
30/// "<link graph name>"
31/// <address> <symbol name>
32/// <address> <symbol name>
33/// ...
34///
35/// Where addresses are in hexadecimal and symbol names are for defined symbols.
37public:
38 /// Create a SymbolTableDumpPlugin that will append symbol information
39 /// to the file at the given path.
41 Create(StringRef Path);
42
43 /// Create a SymbolTableDumpPlugin. The resulting object is in an invalid
44 /// state if, upon return, EC != std::error_code().
45 /// Prefer SymbolTableDumpPlugin::Create.
46 SymbolTableDumpPlugin(StringRef Path, std::error_code &EC);
47
52
55 jitlink::PassConfiguration &Config) override;
56
60
62 return Error::success();
63 }
64
66 ResourceKey SrcKey) override {}
67
68private:
69 raw_fd_ostream OutputStream;
70 std::mutex DumpMutex;
71};
72
73/// A class for symbolicating backtraces using a previously dumped symbol table.
74class LLVM_ABI DumpedSymbolTable {
75public:
76 /// Create a DumpedSymbolTable from the given path.
78
79 /// Given a backtrace, try to symbolicate any unsymbolicated lines using the
80 /// symbol addresses in the dumped symbol table.
81 LLVM_ABI std::string symbolicate(StringRef Backtrace);
82
83private:
84 DumpedSymbolTable(std::unique_ptr<MemoryBuffer> SymtabBuffer);
85
86 void parseBuffer();
87
88 struct SymbolInfo {
89 StringRef SymName;
90 StringRef GraphName;
91 };
92
93 std::map<uint64_t, SymbolInfo> SymbolInfos;
94 std::unique_ptr<MemoryBuffer> SymtabBuffer;
95};
96
97} // namespace llvm::orc
98
99#endif // LLVM_EXECUTIONENGINE_ORC_BACKTRACETOOLS_H
#define LLVM_ABI
Definition Compiler.h:213
#define G(x, y, z)
Definition MD5.cpp:55
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM_ABI std::string symbolicate(StringRef Backtrace)
Given a backtrace, try to symbolicate any unsymbolicated lines using the symbol addresses in the dump...
static Expected< DumpedSymbolTable > Create(StringRef Path)
Create a DumpedSymbolTable from the given path.
Represents a JIT'd dynamic library.
Definition Core.h:919
Plugin instances can be added to the ObjectLinkingLayer to receive callbacks when code is loaded or e...
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition Core.h:593
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::PassConfiguration &Config) override
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
SymbolTableDumpPlugin(StringRef Path, std::error_code &EC)
Create a SymbolTableDumpPlugin.
static Expected< std::shared_ptr< SymbolTableDumpPlugin > > Create(StringRef Path)
Create a SymbolTableDumpPlugin that will append symbol information to the file at the given path.
SymbolTableDumpPlugin(const SymbolTableDumpPlugin &)=delete
SymbolTableDumpPlugin & operator=(const SymbolTableDumpPlugin &)=delete
SymbolTableDumpPlugin & operator=(SymbolTableDumpPlugin &&)=delete
Error notifyFailed(MaterializationResponsibility &MR) override
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override
SymbolTableDumpPlugin(SymbolTableDumpPlugin &&)=delete
A raw_ostream that writes to a file descriptor.
uintptr_t ResourceKey
Definition Core.h:79