Revision 989b697d

b/bsd-user/main.c
34 34
#include "qemu/timer.h"
35 35
#include "qemu/envlist.h"
36 36

  
37
#define DEBUG_LOGFILE "/tmp/qemu.log"
38

  
39 37
int singlestep;
40 38
#if defined(CONFIG_USE_GUEST_BASE)
41 39
unsigned long mmap_min_addr;
......
691 689
           "-bsd type         select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n"
692 690
           "\n"
693 691
           "Debug options:\n"
694
           "-d options   activate log (default logfile=%s)\n"
695
           "-D logfile   override default logfile location\n"
696
           "-p pagesize  set the host page size to 'pagesize'\n"
697
           "-singlestep  always run in singlestep mode\n"
698
           "-strace      log system calls\n"
692
           "-d item1[,...]    enable logging of specified items\n"
693
           "                  (use '-d help' for a list of log items)\n"
694
           "-D logfile        write logs to 'logfile' (default stderr)\n"
695
           "-p pagesize       set the host page size to 'pagesize'\n"
696
           "-singlestep       always run in singlestep mode\n"
697
           "-strace           log system calls\n"
699 698
           "\n"
700 699
           "Environment variables:\n"
701 700
           "QEMU_STRACE       Print system calls and arguments similar to the\n"
......
709 708
           ,
710 709
           TARGET_ARCH,
711 710
           interp_prefix,
712
           x86_stack_size,
713
           DEBUG_LOGFILE);
711
           x86_stack_size);
714 712
    exit(1);
715 713
}
716 714

  
......
733 731
{
734 732
    const char *filename;
735 733
    const char *cpu_model;
736
    const char *log_file = DEBUG_LOGFILE;
734
    const char *log_file = NULL;
737 735
    const char *log_mask = NULL;
738 736
    struct target_pt_regs regs1, *regs = &regs1;
739 737
    struct image_info info1, *info = &info1;
b/hmp-commands.hx
295 295
        .name       = "log",
296 296
        .args_type  = "items:s",
297 297
        .params     = "item1[,...]",
298
        .help       = "activate logging of the specified items to '/tmp/qemu.log'",
298
        .help       = "activate logging of the specified items",
299 299
        .mhandler.cmd = do_log,
300 300
    },
301 301

  
302 302
STEXI
303 303
@item log @var{item1}[,...]
304 304
@findex log
305
Activate logging of the specified items to @file{/tmp/qemu.log}.
305
Activate logging of the specified items.
306 306
ETEXI
307 307

  
308 308
    {
b/include/qemu/log.h
116 116
/* Close the log file */
117 117
static inline void qemu_log_close(void)
118 118
{
119
    fclose(qemu_logfile);
120
    qemu_logfile = NULL;
119
    if (qemu_logfile) {
120
        if (qemu_logfile != stderr) {
121
            fclose(qemu_logfile);
122
        }
123
        qemu_logfile = NULL;
124
    }
121 125
}
122 126

  
123 127
/* Set up a new log file */
b/linux-user/main.c
35 35
#include "qemu/envlist.h"
36 36
#include "elf.h"
37 37

  
38
#define DEBUG_LOGFILE "/tmp/qemu.log"
39

  
40 38
char *exec_path;
41 39

  
42 40
int singlestep;
......
3296 3294
     "size",       "reserve 'size' bytes for guest virtual address space"},
3297 3295
#endif
3298 3296
    {"d",          "QEMU_LOG",         true,  handle_arg_log,
3299
     "options",    "activate log"},
3297
     "item[,...]", "enable logging of specified items "
3298
     "(use '-d help' for a list of items)"},
3300 3299
    {"D",          "QEMU_LOG_FILENAME", true, handle_arg_log_filename,
3301
     "logfile",     "override default logfile location"},
3300
     "logfile",     "write logs to 'logfile' (default stderr)"},
3302 3301
    {"p",          "QEMU_PAGESIZE",    true,  handle_arg_pagesize,
3303 3302
     "pagesize",   "set the host page size to 'pagesize'"},
3304 3303
    {"singlestep", "QEMU_SINGLESTEP",  false, handle_arg_singlestep,
......
3351 3350
    printf("\n"
3352 3351
           "Defaults:\n"
3353 3352
           "QEMU_LD_PREFIX  = %s\n"
3354
           "QEMU_STACK_SIZE = %ld byte\n"
3355
           "QEMU_LOG        = %s\n",
3353
           "QEMU_STACK_SIZE = %ld byte\n",
3356 3354
           interp_prefix,
3357
           guest_stack_size,
3358
           DEBUG_LOGFILE);
3355
           guest_stack_size);
3359 3356

  
3360 3357
    printf("\n"
3361 3358
           "You can use -E and -U options or the QEMU_SET_ENV and\n"
......
3439 3436

  
3440 3437
int main(int argc, char **argv, char **envp)
3441 3438
{
3442
    const char *log_file = DEBUG_LOGFILE;
3443 3439
    struct target_pt_regs regs1, *regs = &regs1;
3444 3440
    struct image_info info1, *info = &info1;
3445 3441
    struct linux_binprm bprm;
......
3482 3478
    cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
3483 3479
#endif
3484 3480

  
3485
    /* init debug */
3486
    qemu_set_log_filename(log_file);
3487 3481
    optind = parse_args(argc, argv);
3488 3482

  
3489 3483
    /* Zero out regs */
b/qemu-doc.texi
2642 2642
Debug options:
2643 2643

  
2644 2644
@table @option
2645
@item -d
2646
Activate log (logfile=/tmp/qemu.log)
2645
@item -d item1,...
2646
Activate logging of the specified items (use '-d help' for a list of log items)
2647 2647
@item -p pagesize
2648 2648
Act as if the host page size was 'pagesize' bytes
2649 2649
@item -g port
......
2781 2781
Debug options:
2782 2782

  
2783 2783
@table @option
2784
@item -d
2785
Activate log (logfile=/tmp/qemu.log)
2784
@item -d item1,...
2785
Activate logging of the specified items (use '-d help' for a list of log items)
2786 2786
@item -p pagesize
2787 2787
Act as if the host page size was 'pagesize' bytes
2788 2788
@item -singlestep
b/qemu-log.c
20 20
#include "qemu-common.h"
21 21
#include "qemu/log.h"
22 22

  
23
#ifdef WIN32
24
#define DEFAULT_LOGFILENAME "qemu.log"
25
#else
26
#define DEFAULT_LOGFILENAME "/tmp/qemu.log"
27
#endif
28

  
29 23
static char *logfilename;
30 24
FILE *qemu_logfile;
31 25
int qemu_loglevel;
......
56 50
/* enable or disable low levels log */
57 51
void do_qemu_set_log(int log_flags, bool use_own_buffers)
58 52
{
59
    const char *fname = logfilename ?: DEFAULT_LOGFILENAME;
60

  
61 53
    qemu_loglevel = log_flags;
62 54
    if (qemu_loglevel && !qemu_logfile) {
63
        qemu_logfile = fopen(fname, log_append ? "a" : "w");
64
        if (!qemu_logfile) {
65
            perror(fname);
66
            _exit(1);
55
        if (logfilename) {
56
            qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
57
            if (!qemu_logfile) {
58
                perror(logfilename);
59
                _exit(1);
60
            }
61
        } else {
62
            /* Default to stderr if no log file specified */
63
            qemu_logfile = stderr;
67 64
        }
68 65
        /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
69 66
        if (use_own_buffers) {
......
81 78
        }
82 79
    }
83 80
    if (!qemu_loglevel && qemu_logfile) {
84
        fclose(qemu_logfile);
85
        qemu_logfile = NULL;
81
        qemu_log_close();
86 82
    }
87 83
}
88 84

  
......
90 86
{
91 87
    g_free(logfilename);
92 88
    logfilename = g_strdup(filename);
93
    if (qemu_logfile) {
94
        fclose(qemu_logfile);
95
        qemu_logfile = NULL;
96
    }
89
    qemu_log_close();
97 90
    qemu_set_log(qemu_loglevel);
98 91
}
99 92

  
b/qemu-options.hx
2517 2517
ETEXI
2518 2518

  
2519 2519
DEF("d", HAS_ARG, QEMU_OPTION_d, \
2520
    "-d item1,...    output log to /tmp/qemu.log (use '-d help' for a list of log items)\n",
2520
    "-d item1,...    enable logging of specified items (use '-d help' for a list of log items)\n",
2521 2521
    QEMU_ARCH_ALL)
2522 2522
STEXI
2523
@item -d
2523
@item -d @var{item1}[,...]
2524 2524
@findex -d
2525
Output log in /tmp/qemu.log
2525
Enable logging of specified items. Use '-d help' for a list of log items.
2526 2526
ETEXI
2527 2527

  
2528 2528
DEF("D", HAS_ARG, QEMU_OPTION_D, \
2529
    "-D logfile      output log to logfile (instead of the default /tmp/qemu.log)\n",
2529
    "-D logfile      output log to logfile (default stderr)\n",
2530 2530
    QEMU_ARCH_ALL)
2531 2531
STEXI
2532 2532
@item -D @var{logfile}
2533 2533
@findex -D
2534
Output log in @var{logfile} instead of /tmp/qemu.log
2534
Output log in @var{logfile} instead of to stderr
2535 2535
ETEXI
2536 2536

  
2537 2537
DEF("L", HAS_ARG, QEMU_OPTION_L, \
b/tcg/tci/README
52 52
should be speed. Especially during development of TCI, it was very
53 53
useful to compare runs with and without TCI. Create /tmp/qemu.log by
54 54

  
55
        qemu-system-i386 -d in_asm,op_opt,cpu -singlestep
55
        qemu-system-i386 -d in_asm,op_opt,cpu -D /tmp/qemu.log -singlestep
56 56

  
57 57
once with interpreter and once without interpreter and compare the resulting
58 58
qemu.log files. This is also useful to see the effects of additional

Also available in: Unified diff