@@ -18,7 +18,6 @@
#include <errno.h>
#include <signal.h>
#include <ucontext.h>
-#include <getopt.h>
#include <setjmp.h>
#include <assert.h>
#include <sys/stat.h>
@@ -27,7 +26,6 @@
#include <string.h>
#include "config.h"
-
#include "risu.h"
void *memblock;
@@ -287,7 +285,7 @@ void usage(void)
}
}
-struct option * setup_options(char **short_opts)
+static struct option * setup_options(char **short_opts)
{
static struct option default_longopts[] = {
{"help", no_argument, 0, '?'},
@@ -303,20 +301,19 @@ struct option * setup_options(char **short_opts)
if (arch_long_opts) {
const size_t osize = sizeof(struct option);
- const int default_count = ARRAY_SIZE(default_longopts);
- struct option *dptr;
- int extra_count = 0;
+ const int default_count = ARRAY_SIZE(default_longopts) - 1;
+ int arch_count;
/* count additional opts */
- dptr = arch_long_opts;
- do {} while (dptr[extra_count++].name);
+ for (arch_count = 0; arch_long_opts[arch_count].name; arch_count++) {
+ continue;
+ }
- lopts = calloc(default_count + extra_count, osize);
+ lopts = calloc(default_count + arch_count + 1, osize);
/* Copy default opts + extra opts */
memcpy(lopts, default_longopts, default_count * osize);
- dptr = &lopts[default_count - 1];
- memcpy(dptr, arch_long_opts, extra_count * osize);
+ memcpy(lopts + default_count, arch_long_opts, arch_count * osize);
}
return lopts;
@@ -343,34 +340,26 @@ int main(int argc, char **argv)
switch (c) {
case 0:
- {
/* flag set by getopt_long, do nothing */
break;
- }
case 't':
- {
trace_fn = optarg;
trace = 1;
break;
- }
case 'h':
- {
hostname = optarg;
break;
- }
case 'p':
- {
/* FIXME err handling */
port = strtol(optarg, 0, 10);
break;
- }
case '?':
- {
usage();
exit(1);
- }
default:
- abort();
+ assert(c >= FIRST_ARCH_OPT);
+ process_arch_opt(c, optarg);
+ break;
}
}
@@ -16,10 +16,13 @@
#include <stdint.h>
#include <ucontext.h>
#include <stdio.h>
+#include <getopt.h>
/* Extra option processing for architectures */
-extern void *arch_long_opts;
-extern char *arch_extra_help;
+extern const struct option * const arch_long_opts;
+extern const char * const arch_extra_help;
+void process_arch_opt(int opt, const char *arg);
+#define FIRST_ARCH_OPT 0x100
/* GCC computed include to pull in the correct risu_reginfo_*.h for
* the architecture.
@@ -14,12 +14,18 @@
#include <ucontext.h>
#include <string.h>
#include <signal.h> /* for FPSIMD_MAGIC */
+#include <stdlib.h>
#include "risu.h"
#include "risu_reginfo_aarch64.h"
-void *arch_long_opts;
-char *arch_extra_help;
+const struct option * const arch_long_opts;
+const char * const arch_extra_help;
+
+void process_arch_opt(int opt, const char *arg)
+{
+ abort();
+}
/* reginfo_init: initialize with a ucontext */
void reginfo_init(struct reginfo *ri, ucontext_t *uc)
@@ -13,7 +13,7 @@
#include <stdio.h>
#include <ucontext.h>
#include <string.h>
-#include <getopt.h>
+#include <stdlib.h>
#include "risu.h"
#include "risu_reginfo_arm.h"
@@ -22,13 +22,19 @@ extern int insnsize(ucontext_t *uc);
/* Should we test for FP exception status bits? */
static int test_fp_exc;
-static struct option extra_opts[] = {
+static const struct option extra_opts[] = {
{"test-fp-exc", no_argument, &test_fp_exc, 1},
{0, 0, 0, 0}
};
-void *arch_long_opts = &extra_opts[0];
-char *arch_extra_help = " --test-fp-exc Check FP exception bits when comparing\n";
+const struct option * const arch_long_opts = &extra_opts[0];
+const char * const arch_extra_help =
+ " --test-fp-exc Check FP exception bits when comparing\n";
+
+void process_arch_opt(int opt, const char *arg)
+{
+ abort();
+}
static void reginfo_init_vfp(struct reginfo *ri, ucontext_t *uc)
{
@@ -10,12 +10,18 @@
#include <ucontext.h>
#include <string.h>
#include <math.h>
+#include <stdlib.h>
#include "risu.h"
#include "risu_reginfo_m68k.h"
-void *arch_long_opts;
-char *arch_extra_help;
+const struct option * const arch_long_opts;
+const char * const arch_extra_help;
+
+void process_arch_opt(int opt, const char *arg)
+{
+ abort();
+}
/* reginfo_init: initialize with a ucontext */
void reginfo_init(struct reginfo *ri, ucontext_t *uc)
@@ -15,6 +15,7 @@
#include <ucontext.h>
#include <string.h>
#include <math.h>
+#include <stdlib.h>
#include "risu.h"
#include "risu_reginfo_ppc64.h"
@@ -22,8 +23,13 @@
#define XER 37
#define CCR 38
-void *arch_long_opts;
-char *arch_extra_help;
+const struct option * const arch_long_opts;
+const char * const arch_extra_help;
+
+void process_arch_opt(int opt, const char *arg)
+{
+ abort();
+}
/* reginfo_init: initialize with a ucontext */
void reginfo_init(struct reginfo *ri, ucontext_t *uc)