Files
revng-revng/tools/trace/run/Main.cpp
Giacomo Vercesi a2b7d0e0bf PipelineC: add tracing
Add support for tracing onto the PipelineC. This is done by:
1. Creating wrapper functions for each PipelineC function with the
   script in `scripts/PipelineC_add_tracing.py`. These will call a
   special function called `wrap` which will ultimately call a method
   with a `_` prepended to the name
2. Conversion of all PipelineC methods in `PipelineC.cpp` to `static`
   and their rename with a `_` in front, in order for them to work with
   the wrapper function in (1)
3. Generation of 2 additional include files, one for types and one for
   functions, to be used by users of tracing files in order to have
   introspection.

These steps allow the creation of a trace file with the use of the
`REVNG_C_API_TRACE_PATH` environment variable. The traces can then be
used in conjunction with the `revng trace run` and `revng trace
inspect` commands.
2023-04-20 14:43:13 +02:00

117 lines
3.6 KiB
C++

//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
// rcc-ignore: initrevng
#include <iostream>
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "revng/PipelineC/PipelineC.h"
#include "revng/PipelineC/Tracing/Trace.h"
#include "revng/Support/Assert.h"
#include "revng/Support/CommandLine.h"
using revng::tracing::Trace;
static llvm::ExitOnError AbortOnError;
namespace Options {
using namespace llvm::cl;
namespace detail {
using llvm::StringRef;
struct BoolString {
bool Set = false;
std::string String;
};
class BoolStringParser : public parser<BoolString> {
public:
BoolStringParser(Option &O) : parser(O) {}
bool parse(Option &O,
StringRef ArgName,
const StringRef ArgValue,
BoolString &Val) {
Val.Set = true;
Val.String = ArgValue.str();
return false;
}
enum ValueExpected getValueExpectedFlagDefault() const {
return ValueOptional;
}
};
} // namespace detail
using BoolStringOpt = opt<detail::BoolString, false, detail::BoolStringParser>;
static OptionCategory TraceRunToolCategory("Tool options", "");
static opt<std::string> TraceFile(Positional,
Required,
cat(TraceRunToolCategory),
desc("<input trace file>"));
static BoolStringOpt TemporaryRoot("temporary-root",
cat(TraceRunToolCategory),
desc("Directory used to create temporary "
"directories needed for execution"));
static opt<bool> SoftAsserts("soft-asserts",
init(false),
cat(TraceRunToolCategory),
desc("Turn some assertions into warnings"));
static llvm::cl::list<uint64_t> BreakAt("break-at",
ZeroOrMore,
cat(TraceRunToolCategory),
desc("Command Indexes to break at"));
static alias SoftAssertsA("s",
desc("Alias for --soft-asserts"),
aliasopt(SoftAsserts),
cat(TraceRunToolCategory),
NotHidden);
static alias BreakAtA("b",
desc("Alias for --break-at"),
aliasopt(BreakAt),
NotHidden,
cat(TraceRunToolCategory));
static alias TemporaryRootA("t",
desc("Alias for --temporary-root"),
aliasopt(TemporaryRoot),
NotHidden,
cat(TraceRunToolCategory));
} // namespace Options
int main(int argc, const char *argv[]) {
llvm::cl::HideUnrelatedOptions(Options::TraceRunToolCategory);
rp_initialize(argc, argv, 0, {});
Trace TheTrace = AbortOnError(Trace::fromFile(Options::TraceFile));
std::string TemporaryRoot;
if (Options::TemporaryRoot.Set) {
if (Options::TemporaryRoot.String.empty()) {
llvm::SmallString<128> Output;
llvm::sys::fs::createUniqueDirectory("revng-run-trace-root", Output);
TemporaryRoot = Output.str().str();
dbg << "Creating temporary root directory: " << TemporaryRoot << "\n";
} else {
TemporaryRoot = Options::TemporaryRoot.String;
}
}
revng::tracing::RunTraceOptions Options = {
.SoftAsserts = Options::SoftAsserts,
.BreakAt = { Options::BreakAt.begin(), Options::BreakAt.end() },
.TemporaryRoot = TemporaryRoot,
};
AbortOnError(TheTrace.run(Options));
rp_shutdown();
return EXIT_SUCCESS;
}