trace: [bsd-user] Commandline arguments to control tracing

[Changed const char *trace_file to char *trace_file since it's a
heap-allocated string that needs to be freed.  This type is also
returned by trace_opt_parse() and used in vl.c.

Also fixed coding style on for(;;) and else statement as suggested by
Eric Blake <eblake@redhat.com> since the patch modifies these lines or
close enough.
--Stefan]

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Message-id: 146860252322.30668.18276041739086338328.stgit@fimbulvetr.bsc.es
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Lluís Vilanova 2016-07-15 19:08:43 +02:00 committed by Stefan Hajnoczi
parent 6533dd6e11
commit 6913e79c36

View file

@ -21,6 +21,7 @@
#include "qapi/error.h" #include "qapi/error.h"
#include "qemu.h" #include "qemu.h"
#include "qemu/config-file.h"
#include "qemu/path.h" #include "qemu/path.h"
#include "qemu/help_option.h" #include "qemu/help_option.h"
/* For tb_lock */ /* For tb_lock */
@ -30,6 +31,8 @@
#include "qemu/timer.h" #include "qemu/timer.h"
#include "qemu/envlist.h" #include "qemu/envlist.h"
#include "exec/log.h" #include "exec/log.h"
#include "trace/control.h"
#include "glib-compat.h"
int singlestep; int singlestep;
unsigned long mmap_min_addr; unsigned long mmap_min_addr;
@ -687,6 +690,8 @@ static void usage(void)
"-p pagesize set the host page size to 'pagesize'\n" "-p pagesize set the host page size to 'pagesize'\n"
"-singlestep always run in singlestep mode\n" "-singlestep always run in singlestep mode\n"
"-strace log system calls\n" "-strace log system calls\n"
"-trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
" specify tracing options\n"
"\n" "\n"
"Environment variables:\n" "Environment variables:\n"
"QEMU_STRACE Print system calls and arguments similar to the\n" "QEMU_STRACE Print system calls and arguments similar to the\n"
@ -735,6 +740,7 @@ int main(int argc, char **argv)
int gdbstub_port = 0; int gdbstub_port = 0;
char **target_environ, **wrk; char **target_environ, **wrk;
envlist_t *envlist = NULL; envlist_t *envlist = NULL;
char *trace_file = NULL;
bsd_type = target_openbsd; bsd_type = target_openbsd;
if (argc <= 1) if (argc <= 1)
@ -754,6 +760,8 @@ int main(int argc, char **argv)
cpu_model = NULL; cpu_model = NULL;
qemu_add_opts(&qemu_trace_opts);
optind = 1; optind = 1;
for (;;) { for (;;) {
if (optind >= argc) if (optind >= argc)
@ -840,8 +848,10 @@ int main(int argc, char **argv)
singlestep = 1; singlestep = 1;
} else if (!strcmp(r, "strace")) { } else if (!strcmp(r, "strace")) {
do_strace = 1; do_strace = 1;
} else } else if (!strcmp(r, "trace")) {
{ g_free(trace_file);
trace_file = trace_opt_parse(optarg);
} else {
usage(); usage();
} }
} }
@ -865,6 +875,11 @@ int main(int argc, char **argv)
} }
filename = argv[optind]; filename = argv[optind];
if (!trace_init_backends()) {
exit(1);
}
trace_init_file(trace_file);
/* Zero out regs */ /* Zero out regs */
memset(regs, 0, sizeof(struct target_pt_regs)); memset(regs, 0, sizeof(struct target_pt_regs));