Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If there is a 'state' folder in the cwd and the user didn't specify one, use it! #169

Merged
merged 3 commits into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/wtf/wtf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <fmt/format.h>
#include <random>

namespace fs = std::filesystem;

int main(int argc, const char *argv[]) {
//
// Set up the arguments.
Expand Down Expand Up @@ -47,9 +49,9 @@ int main(int argc, const char *argv[]) {
Opts.Master.CrashesPath = Opts.Master.TargetPath / "crashes";
}

if (!std::filesystem::exists(Opts.Master.InputsPath) ||
!std::filesystem::exists(Opts.Master.OutputsPath) ||
!std::filesystem::exists(Opts.Master.CrashesPath)) {
if (!fs::exists(Opts.Master.InputsPath) ||
!fs::exists(Opts.Master.OutputsPath) ||
!fs::exists(Opts.Master.CrashesPath)) {
throw CLI::ParseError(
fmt::format("Expected to find inputs/outputs/crashes directories "
"in '{}'.",
Expand Down Expand Up @@ -101,6 +103,16 @@ int main(int argc, const char *argv[]) {

CLI::App *RunCmd =
Wtf.add_subcommand("run", "Run and trace options")->callback([&Opts] {
//
// If the state path is empty and a 'state' folder is available, let's
// use it.
//

if (Opts.StatePath.empty() && fs::is_directory("state")) {
fmt::print("Found a 'state' folder in the cwd, so using it.\n");
Opts.StatePath = "state";
}

//
// Populate other paths based on the based state path.
//
Expand Down Expand Up @@ -131,8 +143,7 @@ int main(int argc, const char *argv[]) {
// Ensure that they exist just as a quick check.
//

if (!std::filesystem::exists(Opts.DumpPath) ||
!std::filesystem::exists(Opts.CpuStatePath)) {
if (!fs::exists(Opts.DumpPath) || !fs::exists(Opts.CpuStatePath)) {
throw CLI::ParseError(fmt::format("Expected to find state/mem.dmp, "
"state/regs.json files in '{}'.",
Opts.StatePath.string()),
Expand All @@ -151,7 +162,7 @@ int main(int argc, const char *argv[]) {
}

#ifdef LINUX
if (!std::filesystem::exists(Opts.SymbolFilePath)) {
if (!fs::exists(Opts.SymbolFilePath)) {
throw CLI::ParseError(
fmt::format("Expected to find a state/symbol-store.json file in "
"'{}'. You need to generate it from Windows.",
Expand Down Expand Up @@ -216,8 +227,7 @@ int main(int argc, const char *argv[]) {

RunCmd->add_option("--state", Opts.StatePath, "State directory")
->check(CLI::ExistingDirectory)
->description("State directory which contains memory and cpu state.")
->required();
->description("State directory which contains memory and cpu state.");

RunCmd
->add_option("--guest-files", Opts.GuestFilesPath,
Expand Down Expand Up @@ -277,13 +287,12 @@ int main(int argc, const char *argv[]) {
// Ensure that they exist just as a quick check.
//

if (!std::filesystem::exists(Opts.DumpPath) ||
!std::filesystem::exists(Opts.CpuStatePath)) {
if (!fs::exists(Opts.DumpPath) || !fs::exists(Opts.CpuStatePath)) {
throw CLI::ParseError(
fmt::format("Expected to find a state/mem.dmp file, a "
"state/regs.json file, an inputs directory, an "
"outputs directory, a crashes directory in '{}'.",
Opts.Fuzz.TargetPath.string()),
fmt::format(
"Expected to find mem.dmp/regs.json files in '{}/state', "
"inputs/outputs/crashes directories in '{}'.",
Opts.Fuzz.TargetPath.string(), Opts.Fuzz.TargetPath.string()),
EXIT_FAILURE);
}

Expand All @@ -304,7 +313,7 @@ int main(int argc, const char *argv[]) {
}

#ifdef LINUX
if (!std::filesystem::exists(Opts.SymbolFilePath)) {
if (!fs::exists(Opts.SymbolFilePath)) {
throw CLI::ParseError(
fmt::format("Expected to find a state/symbol-store.json file in "
"'{}'; you need to generate it from Windows.",
Expand Down