summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-02 22:08:23 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-02 22:08:23 (GMT)
commit63c47828b196e6740d98cc150992ecc7aba0dc79 (patch)
treebffa5692315d3ecf3d94fa34fe31b3a246a59ace /main
parente7c21fc83758b9431bce474c5ba12eec2e20ac10 (diff)
downloadeeshow-63c47828b196e6740d98cc150992ecc7aba0dc79.zip
eeshow-63c47828b196e6740d98cc150992ecc7aba0dc79.tar.gz
eeshow-63c47828b196e6740d98cc150992ecc7aba0dc79.tar.bz2
main/common.c: split gdb launcher off main.c (beginning of big main.c split)
Diffstat (limited to 'main')
-rw-r--r--main/common.c38
-rw-r--r--main/common.h18
2 files changed, 56 insertions, 0 deletions
diff --git a/main/common.c b/main/common.c
new file mode 100644
index 0000000..50cee63
--- /dev/null
+++ b/main/common.c
@@ -0,0 +1,38 @@
+/*
+ * main/common.c - Functions common to more than one form of invocation
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "misc/util.h"
+#include "main/common.h"
+
+
+void run_under_gdb(int argc, char *const *argv)
+{
+ char **args;
+
+ if (argc < 1 || strcmp(argv[1], "gdb"))
+ return;
+
+ args = alloc_type_n(char *, argc + 2);
+ args[0] = "gdb";
+ args[1] = "--args";
+ args[2] = *argv;
+ memcpy(args + 3, argv + 2, sizeof(char *) * (argc - 1));
+ execvp("gdb", args);
+ perror(*argv);
+ exit(1);
+}
diff --git a/main/common.h b/main/common.h
new file mode 100644
index 0000000..05af4f1
--- /dev/null
+++ b/main/common.h
@@ -0,0 +1,18 @@
+/*
+ * main/common.h - Functions common to more than one form of invocation
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef MAIN_COMMON_H
+#define MAIN_COMMON_H
+
+void run_under_gdb(int argc, char *const *argv);
+
+#endif /* !MAIN_COMMON_H */