feat: find image file relative to config option image_path

This commit is contained in:
xinyangli 2024-08-08 17:06:59 +08:00
parent 13ded9c314
commit 407216b17c
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
6 changed files with 25 additions and 6 deletions

View file

@ -9,5 +9,6 @@ dut = "/home/xin/repo/spike-diff/build/lib/libspike-diff.so"
dut-prefix = "spike_"
listen = "/tmp/gdbstub-diffu.sock"
# listen = "127.0.0.1:1234"
memory = "/nix/store/37986mdgsqm5m8w74k0f5llzqhxgsbnv-am-kernel-riscv32-none-elf-2024-07-10/share/am-kernels/string.bin"
# memory = "/nix/store/37986mdgsqm5m8w74k0f5llzqhxgsbnv-am-kernel-riscv32-none-elf-2024-07-10/share/am-kernels/string.bin"
memory = "./add.bin"
# g = true

View file

@ -5,6 +5,7 @@
#include <vector>
struct Config {
std::filesystem::path images_path = "./";
std::filesystem::path memory_file;
std::vector<std::filesystem::path> refs;
std::vector<std::string> refs_prefix;

View file

@ -6,9 +6,16 @@
int Config::cli_parse(int argc, char **argv) {
CLI::App app;
app.add_option("-m,--memory", memory_file, "Content of memory")
->required()
->check(CLI::ExistingFile);
app.add_option(
"--images-path", images_path,
"Directory containing image files. Search image files in this path.")
->envname("DIFFU_IMAGES_PATH")
->check(CLI::ExistingPath);
app.add_option("-m,--memory", memory_file,
"Image file used to fill up the memory. Relative path to "
"--images-path")
->required();
app.add_option("--ref", refs, "Reference dynamic library")
->required()

View file

@ -20,6 +20,7 @@ Difftest::Difftest(Target &&dut, std::vector<Target> &&refs) {
void Difftest::setup(const std::filesystem::path &memory_file) {
std::ifstream is = std::ifstream(memory_file, std::ios::binary);
spdlog::debug("Reading image file: {}", memory_file.c_str());
// Seek to the end to determine the file size
is.seekg(0, std::ios::end);
std::streampos memsize = is.tellg();

View file

@ -11,7 +11,9 @@ Target::Target(const std::string &name, const std::string &func_prefix,
.libpath = path,
.dlhandle = dlopen(path.c_str(), RTLD_NOW)};
spdlog::info("Library handle: {}", meta.dlhandle);
spdlog::info("Found dlopen API handle for {} at {}", meta.name,
meta.dlhandle);
if (!meta.dlhandle) {
throw std::runtime_error(dlerror());
}

View file

@ -1,7 +1,9 @@
#include "api.hpp"
#include "config.hpp"
#include "difftest.hpp"
#include <filesystem>
#include <spdlog/cfg/env.h>
#include <spdlog/spdlog.h>
int gdbstub_loop(Difftest *, std::string);
@ -26,7 +28,12 @@ int main(int argc, char **argv) {
Difftest difftest{std::move(*dut), std::move(refs)};
difftest.setup(config.memory_file);
std::filesystem::path image_file = config.images_path / config.memory_file;
if (!std::filesystem::exists(image_file)) {
spdlog::error("Cannot find {} in {}.", config.memory_file.c_str(),
config.images_path.c_str());
}
difftest.setup(image_file);
if (config.use_debugger) {
gdbstub_loop(&difftest, config.gdbstub_addr);