From 19048ed4bf839c29b515b80536ec932d55dcd4e0 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 20 Apr 2026 23:52:06 +0200 Subject: [PATCH] add run in gdb menu action --- charts/single_result.r | 1 + charts/single_scatter.r | 24 ++++++++ scripts/explore.pl | 3 + scripts/menu.pl | 99 ++++++++++++++++++++++++------- targets/wasm-module/sum0_base.cpp | 2 + 5 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 charts/single_scatter.r diff --git a/charts/single_result.r b/charts/single_result.r index 3f15441..e51dcfa 100644 --- a/charts/single_result.r +++ b/charts/single_result.r @@ -12,6 +12,7 @@ if (!file.exists(datafile)) { } data <- readr::read_csv(datafile) +tibble::glimpse(data) plot <- ggplot(data, aes(x = benchmark, y = faults, fill = resulttype)) + geom_col(position = "dodge") + diff --git a/charts/single_scatter.r b/charts/single_scatter.r new file mode 100644 index 0000000..a075092 --- /dev/null +++ b/charts/single_scatter.r @@ -0,0 +1,24 @@ +library(ggplot2) + +# Usage: Rscript single_scatter.r exp_abspath + +args <- commandArgs(trailingOnly = TRUE) +experiment <- args[1] +datafile <- paste(experiment, "/faults.csv", sep = "") + +if (!file.exists(datafile)) { + print(paste("Input file", datafile, "is missing")) + stop() +} + +data <- readr::read_csv(datafile) +data$fault_address <- strtoi(data$fault_address) +tibble::glimpse(data) + +plot <- ggplot(data, aes(x = fault_address, y = faults)) + + geom_point() + + scale_y_log10() + + labs(x = "Address", y = "Faults") + + theme_minimal() + +ggsave(paste(experiment, "/scatter.svg", sep = ""), plot = plot) diff --git a/scripts/explore.pl b/scripts/explore.pl index b976c9a..ce2154f 100644 --- a/scripts/explore.pl +++ b/scripts/explore.pl @@ -30,6 +30,9 @@ my $selected_experiment = $selected_experiments[0]; my $cui = TUI::init_cui(); +# TODO: Add a TextEditor panel below the markers for notes. +# Store notes in ./notes/benchmark-type-address.txt + # ============================================================================= # Data handling # ============================================================================= diff --git a/scripts/menu.pl b/scripts/menu.pl index 45dff39..569b260 100644 --- a/scripts/menu.pl +++ b/scripts/menu.pl @@ -13,6 +13,8 @@ use TUI; use feature 'say'; +my $local_wamr = '/home/christoph/Notes/TU/MastersThesis/05 WAMR'; +my $local_newlib = '/home/christoph/Notes/TU/MastersThesis/07 NewLib'; my $local_root = '/home/christoph/Notes/TU/MastersThesis/FailNix'; my $local_scripts_dir = "$local_root/scripts"; my $local_builds_dir = "$local_root/builds"; @@ -92,7 +94,79 @@ my %handlers = ( } }, - '06. Plot Results' => sub { + '10. Open Experiment In Explorer' => + sub { do "$local_scripts_dir/explore.pl" }, + + '11. Open Experiment in Ghidra' => sub { + + my @projects = + map { s/\.gpr//r } Util::find_files($local_ghidra_projects); + my @selected_projects = + TUI::select_from_list( "Select Project to Open in Ghidra", + 0, @projects ); + die "No project selected" unless @selected_projects; + my $project = $selected_projects[0]; + system( + join " ", + ( + "_JAVA_AWT_WM_NONREPARENTING=1", "ghidra", + "$local_ghidra_projects/$project.gpr", + ) + ); + }, + + '12. Open Experiment in Binsider' => sub { + my @experiments = Util::find_subdirs($local_archive_dir); + my @selected_experiments = + TUI::select_from_list( "Select Experiments to Plot", 0, + @experiments ); + die "No experiment selected" unless @selected_experiments; + my $selected_experiment = $selected_experiments[0]; + + system( 'binsider', + "$local_archive_dir/$selected_experiment/system.elf" ); + }, + + '13. Run Build in GDB' => sub { + my @builds = Util::find_subdirs($local_builds_dir); + my @selected_builds = + TUI::select_from_list( "Select Build to Run", 0, @builds ); + die "No experiment selected" unless @selected_builds; + my $selected_build = $selected_builds[0]; + + my $build_dir = "$local_builds_dir/$selected_build"; + my $build_name = $selected_build =~ s/.*-.*-.*:.*:.*?_(.*)-.*-.*/$1/r; + my $module_source = "$local_root/build-$build_name"; + + say "$build_name"; + + system( + 'gdb', + '--tui', + '-q', + "$build_dir/system.elf", + '-ex', + "set substitute-path '$module_source' '$build_dir'", + '-ex', + "set substitute-path '/build/source/core' '$local_wamr/core'", + '-ex', + 'break main', + '-ex', + 'break fail_start_trace', + '-ex', + 'break fail_stop_trace', + '-ex', + 'break fail_marker_positive', + '-ex', + 'break fail_marker_detected', + '-ex', + 'break fail_marker_negative', + '-ex', + 'run', + ); + }, + + '20. Plot Results' => sub { # Generate R ggplot2 charts my @experiments = Util::find_subdirs($local_archive_dir); @@ -129,28 +203,7 @@ my %handlers = ( } }, - '07. Open Experiment in Ghidra' => sub { - - my @projects = - map { s/\.gpr//r } Util::find_files($local_ghidra_projects); - my @selected_projects = - TUI::select_from_list( "Select Project to Open in Ghidra", - 0, @projects ); - die "No project selected" unless @selected_projects; - my $project = $selected_projects[0]; - system( - join " ", - ( - "_JAVA_AWT_WM_NONREPARENTING=1", "ghidra", - "$local_ghidra_projects/$project.gpr", - ) - ); - }, - - '08. Open Experiment In Explorer' => - sub { do "$local_scripts_dir/explore.pl" }, - - '95. Delete Builds (Local)' => sub { + '95. Delete Builds' => sub { # Delete old build files my @builds = Util::find_subdirs($local_builds_dir); diff --git a/targets/wasm-module/sum0_base.cpp b/targets/wasm-module/sum0_base.cpp index b4eefe7..262d7c2 100644 --- a/targets/wasm-module/sum0_base.cpp +++ b/targets/wasm-module/sum0_base.cpp @@ -25,9 +25,11 @@ extern "C" EXPORT("wasm_module") int wasm_module(void) { fail_stop_trace(); if (X == 100) { + HOST_PRINT("result correct.\n"); fail_marker_positive(); return 0; } else { + HOST_PRINT("result incorrect.\n"); fail_marker_negative(); return 1; }