about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--README.md3
-rw-r--r--cover.c44
-rw-r--r--fix.m48
4 files changed, 51 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index d677d39..a9994cf 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ BIN_PREFIX ::= $(DESTDIR)$(PREFIX)/bin/taosc-
 DATA_DIR ::= $(DESTDIR)$(PREFIX)/share/taosc
 
 BIN ::= fix measure-stack scout synth trace-call
-DATA ::= collect jump patch
+DATA ::= collect cover jump patch
 
 all: $(BIN) $(DATA)
 
diff --git a/README.md b/README.md
index 33051f7..260cad8 100644
--- a/README.md
+++ b/README.md
@@ -16,8 +16,7 @@ To install taosc to `$prefix`, you'll also need `install(1p)`:
 
 ## Usage
 
-    taosc-fix executable address workdir option...
-    taosc-fix-lib executable library address workdir option...
+    taosc-fix WORKDIR EXECUTABLE OPTION...
 
 ## Copying
 
diff --git a/cover.c b/cover.c
new file mode 100644
index 0000000..3061646
--- /dev/null
+++ b/cover.c
@@ -0,0 +1,44 @@
+/*
+ * Live variable collector
+ * Copyright (C) 2024-2025  Nguyễn Gia Phong
+ *
+ * This file is part of taosc.
+ *
+ * Taosc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Taosc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with taosc.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "stdlib.c"
+
+static int output_file = -1;
+
+void init(int argc, const char *const *argv, char **envp)
+{
+	environ = envp;
+	const char *const path = getenv("TAOSC_OUTPUT");
+	if (path != NULL)
+		output_file = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
+	if (output_file == -1) {
+		const char *msg = "cannot open $TAOSC_OUTPUT for writing\n";
+		write(2, msg, strlen(msg));
+		fsync(2);
+		exit(128);
+	}
+	write(output_file, "\n", 1);
+	fsync(output_file);
+}
+
+void report(void)
+{
+	ftruncate(output_file, 0);
+}
diff --git a/fix.m4 b/fix.m4
index de4e446..065f91e 100644
--- a/fix.m4
+++ b/fix.m4
@@ -28,7 +28,7 @@ save_exit_code() {
 
 if test $# -lt 3
 then
-  echo Usage: taosc-fix workdir binary option...
+  echo Usage: taosc-fix WORKDIR EXECUTABLE OPTION...
   exit 1
 fi
 wd="$(realpath $1)"
@@ -84,8 +84,10 @@ test -s "$wd/patch-location"
 test -s "$wd/destinations"
 
 patch_loc=0x$(< "$wd/patch-location")
-e9tool -M addr=$patch_loc -P 'log(state)@collect' -o "$bin.collect" "$binary"
-e9tool -M addr=$patch_loc -P 'if dest(state)@patch goto'\
+e9tool -100 -M addr=$patch_loc -P 'report()@cover' -o "$bin.covered" "$binary"
+e9tool -100 -M addr=$patch_loc -P 'log(state)@collect'\
+  -o "$bin.collect" "$binary"
+e9tool -100 -M addr=$patch_loc -P 'if dest(state)@patch goto'\
   -o "$bin.patched" "$binary"
 exit
 stack_size=$(taosc-measure-stack "$binary" < "$wd/patch-location")