llvm-project/llvm/tools/lli/ExecutionUtils.h
Stefan Gränitz f47ff8cff1 [lli] Test debug support in RuntimeDyld with built-in functions
When lli runs the below IR, it emits in-memory debug objects and registers them with the GDB JIT interface. The tests dump and check the registered information. IR has limited ability to produce complex output in a portable way. Instead the tests rely on built-in functions implemented in lli. They use a new command line flag `-generate=function-name` to instruct the ORC JIT to expose the built-in function with the given name to the JITed program.

`debug-descriptor-elf-minimal.ll` calls `__dump_jit_debug_descriptor()` to reflect the list of debug entries issued for itself after emitting the main module. The output is textual and can be checked straight away.

`debug-objects-elf-minimal.ll` calls `__dump_jit_debug_objects()`, which instructs lli to walk through the list of debug entries and append the encountered in-memory objects to the program output. We feed this output into llvm-dwarfdump to parse the DWARF in each file and dump their structures.

We can do the same for JITLink once D97335 has landed.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D97694
2021-03-02 10:39:09 +01:00

61 lines
1.9 KiB
C++

//===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// Contains utilities for executing code in lli.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
#define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/Mangling.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ToolOutputFile.h"
#include <memory>
#include <utility>
namespace llvm {
enum class BuiltinFunctionKind {
DumpDebugDescriptor,
DumpDebugObjects,
};
// Utility class to expose symbols for special-purpose functions to the JIT.
class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
public:
LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
orc::MangleAndInterner &Mangle);
Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
const orc::SymbolLookupSet &Symbols) override;
void appendDebugObject(const char *Addr, size_t Size) {
TestOut->os().write(Addr, Size);
}
private:
orc::SymbolMap BuiltinFunctions;
std::unique_ptr<ToolOutputFile> TestOut;
template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
BuiltinFunctions[Name] = JITEvaluatedSymbol(
pointerToJITTargetAddress(Handler), JITSymbolFlags::Exported);
}
static std::unique_ptr<ToolOutputFile> createToolOutput();
};
} // end namespace llvm
#endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H