qemu-log: default to stderr for logging output

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 <peter.maydell@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1361901160-28729-1-git-send-email-peter.maydell@linaro.org
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Peter Maydell 2013-02-26 17:52:40 +00:00 committed by Anthony Liguori
parent ab4004495c
commit 989b697ddd
8 changed files with 42 additions and 53 deletions

View File

@ -34,8 +34,6 @@
#include "qemu/timer.h" #include "qemu/timer.h"
#include "qemu/envlist.h" #include "qemu/envlist.h"
#define DEBUG_LOGFILE "/tmp/qemu.log"
int singlestep; int singlestep;
#if defined(CONFIG_USE_GUEST_BASE) #if defined(CONFIG_USE_GUEST_BASE)
unsigned long mmap_min_addr; unsigned long mmap_min_addr;
@ -691,11 +689,12 @@ static void usage(void)
"-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n"
"\n" "\n"
"Debug options:\n" "Debug options:\n"
"-d options activate log (default logfile=%s)\n" "-d item1[,...] enable logging of specified items\n"
"-D logfile override default logfile location\n" " (use '-d help' for a list of log items)\n"
"-p pagesize set the host page size to 'pagesize'\n" "-D logfile write logs to 'logfile' (default stderr)\n"
"-singlestep always run in singlestep mode\n" "-p pagesize set the host page size to 'pagesize'\n"
"-strace log system calls\n" "-singlestep always run in singlestep mode\n"
"-strace log system calls\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"
@ -709,8 +708,7 @@ static void usage(void)
, ,
TARGET_ARCH, TARGET_ARCH,
interp_prefix, interp_prefix,
x86_stack_size, x86_stack_size);
DEBUG_LOGFILE);
exit(1); exit(1);
} }
@ -733,7 +731,7 @@ int main(int argc, char **argv)
{ {
const char *filename; const char *filename;
const char *cpu_model; const char *cpu_model;
const char *log_file = DEBUG_LOGFILE; const char *log_file = NULL;
const char *log_mask = NULL; const char *log_mask = NULL;
struct target_pt_regs regs1, *regs = &regs1; struct target_pt_regs regs1, *regs = &regs1;
struct image_info info1, *info = &info1; struct image_info info1, *info = &info1;

View File

@ -295,14 +295,14 @@ ETEXI
.name = "log", .name = "log",
.args_type = "items:s", .args_type = "items:s",
.params = "item1[,...]", .params = "item1[,...]",
.help = "activate logging of the specified items to '/tmp/qemu.log'", .help = "activate logging of the specified items",
.mhandler.cmd = do_log, .mhandler.cmd = do_log,
}, },
STEXI STEXI
@item log @var{item1}[,...] @item log @var{item1}[,...]
@findex log @findex log
Activate logging of the specified items to @file{/tmp/qemu.log}. Activate logging of the specified items.
ETEXI ETEXI
{ {

View File

@ -116,8 +116,12 @@ static inline void qemu_log_flush(void)
/* Close the log file */ /* Close the log file */
static inline void qemu_log_close(void) static inline void qemu_log_close(void)
{ {
fclose(qemu_logfile); if (qemu_logfile) {
qemu_logfile = NULL; if (qemu_logfile != stderr) {
fclose(qemu_logfile);
}
qemu_logfile = NULL;
}
} }
/* Set up a new log file */ /* Set up a new log file */

View File

@ -35,8 +35,6 @@
#include "qemu/envlist.h" #include "qemu/envlist.h"
#include "elf.h" #include "elf.h"
#define DEBUG_LOGFILE "/tmp/qemu.log"
char *exec_path; char *exec_path;
int singlestep; int singlestep;
@ -3296,9 +3294,10 @@ static const struct qemu_argument arg_table[] = {
"size", "reserve 'size' bytes for guest virtual address space"}, "size", "reserve 'size' bytes for guest virtual address space"},
#endif #endif
{"d", "QEMU_LOG", true, handle_arg_log, {"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, {"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, {"p", "QEMU_PAGESIZE", true, handle_arg_pagesize,
"pagesize", "set the host page size to 'pagesize'"}, "pagesize", "set the host page size to 'pagesize'"},
{"singlestep", "QEMU_SINGLESTEP", false, handle_arg_singlestep, {"singlestep", "QEMU_SINGLESTEP", false, handle_arg_singlestep,
@ -3351,11 +3350,9 @@ static void usage(void)
printf("\n" printf("\n"
"Defaults:\n" "Defaults:\n"
"QEMU_LD_PREFIX = %s\n" "QEMU_LD_PREFIX = %s\n"
"QEMU_STACK_SIZE = %ld byte\n" "QEMU_STACK_SIZE = %ld byte\n",
"QEMU_LOG = %s\n",
interp_prefix, interp_prefix,
guest_stack_size, guest_stack_size);
DEBUG_LOGFILE);
printf("\n" printf("\n"
"You can use -E and -U options or the QEMU_SET_ENV and\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) int main(int argc, char **argv, char **envp)
{ {
const char *log_file = DEBUG_LOGFILE;
struct target_pt_regs regs1, *regs = &regs1; struct target_pt_regs regs1, *regs = &regs1;
struct image_info info1, *info = &info1; struct image_info info1, *info = &info1;
struct linux_binprm bprm; 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) */ cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
#endif #endif
/* init debug */
qemu_set_log_filename(log_file);
optind = parse_args(argc, argv); optind = parse_args(argc, argv);
/* Zero out regs */ /* Zero out regs */

View File

@ -2642,8 +2642,8 @@ Pre-allocate a guest virtual address space of the given size (in bytes).
Debug options: Debug options:
@table @option @table @option
@item -d @item -d item1,...
Activate log (logfile=/tmp/qemu.log) Activate logging of the specified items (use '-d help' for a list of log items)
@item -p pagesize @item -p pagesize
Act as if the host page size was 'pagesize' bytes Act as if the host page size was 'pagesize' bytes
@item -g port @item -g port
@ -2781,8 +2781,8 @@ FreeBSD, NetBSD and OpenBSD (default).
Debug options: Debug options:
@table @option @table @option
@item -d @item -d item1,...
Activate log (logfile=/tmp/qemu.log) Activate logging of the specified items (use '-d help' for a list of log items)
@item -p pagesize @item -p pagesize
Act as if the host page size was 'pagesize' bytes Act as if the host page size was 'pagesize' bytes
@item -singlestep @item -singlestep

View File

@ -20,12 +20,6 @@
#include "qemu-common.h" #include "qemu-common.h"
#include "qemu/log.h" #include "qemu/log.h"
#ifdef WIN32
#define DEFAULT_LOGFILENAME "qemu.log"
#else
#define DEFAULT_LOGFILENAME "/tmp/qemu.log"
#endif
static char *logfilename; static char *logfilename;
FILE *qemu_logfile; FILE *qemu_logfile;
int qemu_loglevel; int qemu_loglevel;
@ -56,14 +50,17 @@ void qemu_log_mask(int mask, const char *fmt, ...)
/* enable or disable low levels log */ /* enable or disable low levels log */
void do_qemu_set_log(int log_flags, bool use_own_buffers) void do_qemu_set_log(int log_flags, bool use_own_buffers)
{ {
const char *fname = logfilename ?: DEFAULT_LOGFILENAME;
qemu_loglevel = log_flags; qemu_loglevel = log_flags;
if (qemu_loglevel && !qemu_logfile) { if (qemu_loglevel && !qemu_logfile) {
qemu_logfile = fopen(fname, log_append ? "a" : "w"); if (logfilename) {
if (!qemu_logfile) { qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
perror(fname); if (!qemu_logfile) {
_exit(1); 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" */ /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
if (use_own_buffers) { 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) { if (!qemu_loglevel && qemu_logfile) {
fclose(qemu_logfile); qemu_log_close();
qemu_logfile = NULL;
} }
} }
@ -90,10 +86,7 @@ void qemu_set_log_filename(const char *filename)
{ {
g_free(logfilename); g_free(logfilename);
logfilename = g_strdup(filename); logfilename = g_strdup(filename);
if (qemu_logfile) { qemu_log_close();
fclose(qemu_logfile);
qemu_logfile = NULL;
}
qemu_set_log(qemu_loglevel); qemu_set_log(qemu_loglevel);
} }

View File

@ -2517,21 +2517,21 @@ Shorthand for -gdb tcp::1234, i.e. open a gdbserver on TCP port 1234
ETEXI ETEXI
DEF("d", HAS_ARG, QEMU_OPTION_d, \ 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) QEMU_ARCH_ALL)
STEXI STEXI
@item -d @item -d @var{item1}[,...]
@findex -d @findex -d
Output log in /tmp/qemu.log Enable logging of specified items. Use '-d help' for a list of log items.
ETEXI ETEXI
DEF("D", HAS_ARG, QEMU_OPTION_D, \ 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) QEMU_ARCH_ALL)
STEXI STEXI
@item -D @var{logfile} @item -D @var{logfile}
@findex -D @findex -D
Output log in @var{logfile} instead of /tmp/qemu.log Output log in @var{logfile} instead of to stderr
ETEXI ETEXI
DEF("L", HAS_ARG, QEMU_OPTION_L, \ DEF("L", HAS_ARG, QEMU_OPTION_L, \

View File

@ -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 should be speed. Especially during development of TCI, it was very
useful to compare runs with and without TCI. Create /tmp/qemu.log by 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 once with interpreter and once without interpreter and compare the resulting
qemu.log files. This is also useful to see the effects of additional qemu.log files. This is also useful to see the effects of additional