aboutsummaryrefslogtreecommitdiff
path: root/linux-user/main.c
diff options
context:
space:
mode:
authorJosh Kunz <jkz@google.com>2020-02-03 18:54:14 -0800
committerLaurent Vivier <laurent@vivier.eu>2020-02-19 11:17:40 +0100
commit4b25a50674de41e72f6b3003e3c8c74ca95503d3 (patch)
tree1eaf91a8753f29fab83f0e7f7d29405f2b1a0cb9 /linux-user/main.c
parent39be535008f120452d3bda2a50798774a5f1f963 (diff)
downloadqemu-4b25a50674de41e72f6b3003e3c8c74ca95503d3.zip
qemu-4b25a50674de41e72f6b3003e3c8c74ca95503d3.tar.gz
qemu-4b25a50674de41e72f6b3003e3c8c74ca95503d3.tar.bz2
linux-user: Use `qemu_log' for strace
This change switches linux-user strace logging to use the newer `qemu_log` logging subsystem rather than the older `gemu_log` (notice the "g") logger. `qemu_log` has several advantages, namely that it allows logging to a file, and provides a more unified interface for configuration of logging (via the QEMU_LOG environment variable or options). This change introduces a new log mask: `LOG_STRACE` which is used for logging of user-mode strace messages. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Josh Kunz <jkz@google.com> Message-Id: <20200204025416.111409-3-jkz@google.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'linux-user/main.c')
-rw-r--r--linux-user/main.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/linux-user/main.c b/linux-user/main.c
index fba833a..8f1d07c 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -61,6 +61,19 @@ unsigned long guest_base;
int have_guest_base;
/*
+ * Used to implement backwards-compatibility for the `-strace`, and
+ * QEMU_STRACE options. Without this, the QEMU_LOG can be overwritten by
+ * -strace, or vice versa.
+ */
+static bool enable_strace;
+
+/*
+ * The last log mask given by the user in an environment variable or argument.
+ * Used to support command line arguments overriding environment variables.
+ */
+static int last_log_mask;
+
+/*
* When running 32-on-64 we should make sure we can fit all of the possible
* guest address space into a contiguous chunk of virtual host memory.
*
@@ -223,15 +236,11 @@ static void handle_arg_help(const char *arg)
static void handle_arg_log(const char *arg)
{
- int mask;
-
- mask = qemu_str_to_log_mask(arg);
- if (!mask) {
+ last_log_mask = qemu_str_to_log_mask(arg);
+ if (!last_log_mask) {
qemu_print_log_usage(stdout);
exit(EXIT_FAILURE);
}
- qemu_log_needs_buffers();
- qemu_set_log(mask);
}
static void handle_arg_dfilter(const char *arg)
@@ -375,7 +384,7 @@ static void handle_arg_singlestep(const char *arg)
static void handle_arg_strace(const char *arg)
{
- do_strace = 1;
+ enable_strace = true;
}
static void handle_arg_version(const char *arg)
@@ -629,6 +638,7 @@ int main(int argc, char **argv, char **envp)
int i;
int ret;
int execfd;
+ int log_mask;
unsigned long max_reserved_va;
error_init(argv[0]);
@@ -661,6 +671,12 @@ int main(int argc, char **argv, char **envp)
optind = parse_args(argc, argv);
+ log_mask = last_log_mask | (enable_strace ? LOG_STRACE : 0);
+ if (log_mask) {
+ qemu_log_needs_buffers();
+ qemu_set_log(log_mask);
+ }
+
if (!trace_init_backends()) {
exit(1);
}