From patchwork Tue Feb 26 17:52:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 15101 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 22DCB23DFE for ; Tue, 26 Feb 2013 17:52:49 +0000 (UTC) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by fiordland.canonical.com (Postfix) with ESMTP id B0485A18B16 for ; Tue, 26 Feb 2013 17:52:48 +0000 (UTC) Received: by mail-ve0-f176.google.com with SMTP id cz10so3914253veb.21 for ; Tue, 26 Feb 2013 09:52:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=AE8TXu+k2dZ8GpkcjYWmCdRt5m43AE5FCPZEUA3K42M=; b=LFgrxqn/DuP3jgJu7e/jBtku3XDhzm4ZZw494ZeT3DJQEh5O+0gEkuIPTQ7G2vWnG8 PzoKYVw0lMC5Xf5KnHCYSTgqT3Jz5nqlfye7V+j7RTGIEhPXFT+Bp4bZcC9imhqn6hiB +Bh6G+RYAsmxiW7h3i/K75Yp9qybVIC+/EjUHdpwFwM/Iv7LIZk7eM141MaP8CF5C4do 5WHtlAlxCU25H0PG5fuucP/wX6yUpKPwytx49Bs6LIQkR5cptJkkaUSY6lrkxEFPx4nt pVGQ6quR1IG40b0+0RHj5x55H7GeIDAFFThGQsoR8YY0gIpxsSdoh9Pcsd/F2pqiYSpM IfKg== X-Received: by 10.52.88.237 with SMTP id bj13mr10529539vdb.75.1361901168095; Tue, 26 Feb 2013 09:52:48 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp126434veb; Tue, 26 Feb 2013 09:52:47 -0800 (PST) X-Received: by 10.194.87.229 with SMTP id bb5mr27737651wjb.32.1361901166270; Tue, 26 Feb 2013 09:52:46 -0800 (PST) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id ca7si781861wib.66.2013.02.26.09.52.45 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Feb 2013 09:52:46 -0800 (PST) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1UAOhk-0007To-RT; Tue, 26 Feb 2013 17:52:40 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Blue Swirl , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Stefan Hajnoczi , Markus Armbruster , Anthony Liguori Subject: [PATCH v3] qemu-log: default to stderr for logging output Date: Tue, 26 Feb 2013 17:52:40 +0000 Message-Id: <1361901160-28729-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQm90PJpvdP91kfj6nfqznTzmmfeUSG+GWPaZKnbE/isGNALA7UbISFLLt0o5m9c18YeXfp8 Switch the default for qemu_log logging output from "/tmp/qemu.log" to stderr. This is an incompatible change in some sense, but logging is mostly used for debugging purposes so it shouldn't affect production use. The previous behaviour can be obtained by adding "-D /tmp/qemu.log" to the command line. This change requires us to: * update all the documentation/help text (we take the opportunity to smooth out minor inconsistencies between the phrasing in linux-user/bsd-user/system help messages) * make linux-user and bsd-user defer to qemu-log for the default logging destination rather than overriding it themselves * ensure that all logfile closing is done via qemu_log_close() and that that function doesn't close stderr as well as the obvious change to the behaviour of do_qemu_set_log() when no logfile name has been specified. Signed-off-by: Peter Maydell Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster --- Changes v2->v3: * none, just rebased so patch applies cleanly Changes v1->v2: * dropped an unnecessary "if (log_file)" check from bsd-user * standardised the phrasing of the -d and -D help text for all of bsd-user, linux-user and system mode NB: if this is applied before the linux-user patch http://patchwork.ozlabs.org/patch/220481/ then the column formatting in linux-user's --help output will be slightly misaligned. Not a big deal... bsd-user/main.c | 18 ++++++++---------- hmp-commands.hx | 4 ++-- include/qemu/log.h | 8 ++++++-- linux-user/main.c | 16 +++++----------- qemu-doc.texi | 8 ++++---- qemu-log.c | 29 +++++++++++------------------ qemu-options.hx | 10 +++++----- tcg/tci/README | 2 +- 8 files changed, 42 insertions(+), 53 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 097fbfe..cc84981 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -34,8 +34,6 @@ #include "qemu/timer.h" #include "qemu/envlist.h" -#define DEBUG_LOGFILE "/tmp/qemu.log" - int singlestep; #if defined(CONFIG_USE_GUEST_BASE) unsigned long mmap_min_addr; @@ -691,11 +689,12 @@ static void usage(void) "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" "\n" "Debug options:\n" - "-d options activate log (default logfile=%s)\n" - "-D logfile override default logfile location\n" - "-p pagesize set the host page size to 'pagesize'\n" - "-singlestep always run in singlestep mode\n" - "-strace log system calls\n" + "-d item1[,...] enable logging of specified items\n" + " (use '-d help' for a list of log items)\n" + "-D logfile write logs to 'logfile' (default stderr)\n" + "-p pagesize set the host page size to 'pagesize'\n" + "-singlestep always run in singlestep mode\n" + "-strace log system calls\n" "\n" "Environment variables:\n" "QEMU_STRACE Print system calls and arguments similar to the\n" @@ -709,8 +708,7 @@ static void usage(void) , TARGET_ARCH, interp_prefix, - x86_stack_size, - DEBUG_LOGFILE); + x86_stack_size); exit(1); } @@ -733,7 +731,7 @@ int main(int argc, char **argv) { const char *filename; const char *cpu_model; - const char *log_file = DEBUG_LOGFILE; + const char *log_file = NULL; const char *log_mask = NULL; struct target_pt_regs regs1, *regs = ®s1; struct image_info info1, *info = &info1; diff --git a/hmp-commands.hx b/hmp-commands.hx index 64008a9..cef7708 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -295,14 +295,14 @@ ETEXI .name = "log", .args_type = "items:s", .params = "item1[,...]", - .help = "activate logging of the specified items to '/tmp/qemu.log'", + .help = "activate logging of the specified items", .mhandler.cmd = do_log, }, STEXI @item log @var{item1}[,...] @findex log -Activate logging of the specified items to @file{/tmp/qemu.log}. +Activate logging of the specified items. ETEXI { diff --git a/include/qemu/log.h b/include/qemu/log.h index 4527003..6b0db02 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -116,8 +116,12 @@ static inline void qemu_log_flush(void) /* Close the log file */ static inline void qemu_log_close(void) { - fclose(qemu_logfile); - qemu_logfile = NULL; + if (qemu_logfile) { + if (qemu_logfile != stderr) { + fclose(qemu_logfile); + } + qemu_logfile = NULL; + } } /* Set up a new log file */ diff --git a/linux-user/main.c b/linux-user/main.c index e515684..29845f9 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -35,8 +35,6 @@ #include "qemu/envlist.h" #include "elf.h" -#define DEBUG_LOGFILE "/tmp/qemu.log" - char *exec_path; int singlestep; @@ -3296,9 +3294,10 @@ static const struct qemu_argument arg_table[] = { "size", "reserve 'size' bytes for guest virtual address space"}, #endif {"d", "QEMU_LOG", true, handle_arg_log, - "options", "activate log"}, + "item[,...]", "enable logging of specified items " + "(use '-d help' for a list of items)"}, {"D", "QEMU_LOG_FILENAME", true, handle_arg_log_filename, - "logfile", "override default logfile location"}, + "logfile", "write logs to 'logfile' (default stderr)"}, {"p", "QEMU_PAGESIZE", true, handle_arg_pagesize, "pagesize", "set the host page size to 'pagesize'"}, {"singlestep", "QEMU_SINGLESTEP", false, handle_arg_singlestep, @@ -3351,11 +3350,9 @@ static void usage(void) printf("\n" "Defaults:\n" "QEMU_LD_PREFIX = %s\n" - "QEMU_STACK_SIZE = %ld byte\n" - "QEMU_LOG = %s\n", + "QEMU_STACK_SIZE = %ld byte\n", interp_prefix, - guest_stack_size, - DEBUG_LOGFILE); + guest_stack_size); printf("\n" "You can use -E and -U options or the QEMU_SET_ENV and\n" @@ -3439,7 +3436,6 @@ static int parse_args(int argc, char **argv) int main(int argc, char **argv, char **envp) { - const char *log_file = DEBUG_LOGFILE; struct target_pt_regs regs1, *regs = ®s1; struct image_info info1, *info = &info1; struct linux_binprm bprm; @@ -3482,8 +3478,6 @@ int main(int argc, char **argv, char **envp) cpudef_setup(); /* parse cpu definitions in target config file (TBD) */ #endif - /* init debug */ - qemu_set_log_filename(log_file); optind = parse_args(argc, argv); /* Zero out regs */ diff --git a/qemu-doc.texi b/qemu-doc.texi index 6d7f50d..747e052 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2642,8 +2642,8 @@ Pre-allocate a guest virtual address space of the given size (in bytes). Debug options: @table @option -@item -d -Activate log (logfile=/tmp/qemu.log) +@item -d item1,... +Activate logging of the specified items (use '-d help' for a list of log items) @item -p pagesize Act as if the host page size was 'pagesize' bytes @item -g port @@ -2781,8 +2781,8 @@ FreeBSD, NetBSD and OpenBSD (default). Debug options: @table @option -@item -d -Activate log (logfile=/tmp/qemu.log) +@item -d item1,... +Activate logging of the specified items (use '-d help' for a list of log items) @item -p pagesize Act as if the host page size was 'pagesize' bytes @item -singlestep diff --git a/qemu-log.c b/qemu-log.c index 2f47aaf..797f2af 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -20,12 +20,6 @@ #include "qemu-common.h" #include "qemu/log.h" -#ifdef WIN32 -#define DEFAULT_LOGFILENAME "qemu.log" -#else -#define DEFAULT_LOGFILENAME "/tmp/qemu.log" -#endif - static char *logfilename; FILE *qemu_logfile; int qemu_loglevel; @@ -56,14 +50,17 @@ void qemu_log_mask(int mask, const char *fmt, ...) /* enable or disable low levels log */ void do_qemu_set_log(int log_flags, bool use_own_buffers) { - const char *fname = logfilename ?: DEFAULT_LOGFILENAME; - qemu_loglevel = log_flags; if (qemu_loglevel && !qemu_logfile) { - qemu_logfile = fopen(fname, log_append ? "a" : "w"); - if (!qemu_logfile) { - perror(fname); - _exit(1); + if (logfilename) { + qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); + if (!qemu_logfile) { + perror(logfilename); + _exit(1); + } + } else { + /* Default to stderr if no log file specified */ + qemu_logfile = stderr; } /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ if (use_own_buffers) { @@ -81,8 +78,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) } } if (!qemu_loglevel && qemu_logfile) { - fclose(qemu_logfile); - qemu_logfile = NULL; + qemu_log_close(); } } @@ -90,10 +86,7 @@ void qemu_set_log_filename(const char *filename) { g_free(logfilename); logfilename = g_strdup(filename); - if (qemu_logfile) { - fclose(qemu_logfile); - qemu_logfile = NULL; - } + qemu_log_close(); qemu_set_log(qemu_loglevel); } diff --git a/qemu-options.hx b/qemu-options.hx index 2832d82..2b70432 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2515,21 +2515,21 @@ Shorthand for -gdb tcp::1234, i.e. open a gdbserver on TCP port 1234 ETEXI DEF("d", HAS_ARG, QEMU_OPTION_d, \ - "-d item1,... output log to /tmp/qemu.log (use '-d help' for a list of log items)\n", + "-d item1,... enable logging of specified items (use '-d help' for a list of log items)\n", QEMU_ARCH_ALL) STEXI -@item -d +@item -d @var{item1}[,...] @findex -d -Output log in /tmp/qemu.log +Enable logging of specified items. Use '-d help' for a list of log items. ETEXI DEF("D", HAS_ARG, QEMU_OPTION_D, \ - "-D logfile output log to logfile (instead of the default /tmp/qemu.log)\n", + "-D logfile output log to logfile (default stderr)\n", QEMU_ARCH_ALL) STEXI @item -D @var{logfile} @findex -D -Output log in @var{logfile} instead of /tmp/qemu.log +Output log in @var{logfile} instead of to stderr ETEXI DEF("L", HAS_ARG, QEMU_OPTION_L, \ diff --git a/tcg/tci/README b/tcg/tci/README index 6ac1ac9..dc57f07 100644 --- a/tcg/tci/README +++ b/tcg/tci/README @@ -52,7 +52,7 @@ The only difference from running QEMU with TCI to running without TCI should be speed. Especially during development of TCI, it was very useful to compare runs with and without TCI. Create /tmp/qemu.log by - qemu-system-i386 -d in_asm,op_opt,cpu -singlestep + qemu-system-i386 -d in_asm,op_opt,cpu -D /tmp/qemu.log -singlestep once with interpreter and once without interpreter and compare the resulting qemu.log files. This is also useful to see the effects of additional