Revision e4858974

b/Makefile.objs
379 379
trace-obj-y = trace.o
380 380
endif
381 381

  
382
trace-nested-$(CONFIG_TRACE_DEFAULT) += default.o
383

  
382 384
trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o
383 385
trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o
384 386

  
b/configure
3064 3064
;;
3065 3065
esac
3066 3066

  
3067
# use default implementation for tracing backend-specific routines
3068
trace_default=yes
3067 3069
echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak
3068 3070
if test "$trace_backend" = "nop"; then
3069 3071
  echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
3070 3072
fi
3071 3073
if test "$trace_backend" = "simple"; then
3072 3074
  echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak
3075
  trace_default=no
3073 3076
  # Set the appropriate trace file.
3074 3077
  trace_file="\"$trace_file-\" FMT_pid"
3075 3078
fi
......
3086 3089
  fi
3087 3090
fi
3088 3091
echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
3092
if test "$trace_default" = "yes"; then
3093
  echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
3094
fi
3089 3095

  
3090 3096
echo "TOOLS=$tools" >> $config_host_mak
3091 3097
echo "ROMS=$roms" >> $config_host_mak
b/qemu-config.c
303 303
    },
304 304
};
305 305

  
306
#ifdef CONFIG_TRACE_SIMPLE
307 306
static QemuOptsList qemu_trace_opts = {
308 307
    .name = "trace",
309 308
    .implied_opt_name = "trace",
......
316 315
        { /* end of list */ }
317 316
    },
318 317
};
319
#endif
320 318

  
321 319
static QemuOptsList qemu_cpudef_opts = {
322 320
    .name = "cpudef",
......
517 515
    &qemu_global_opts,
518 516
    &qemu_mon_opts,
519 517
    &qemu_cpudef_opts,
520
#ifdef CONFIG_TRACE_SIMPLE
521 518
    &qemu_trace_opts,
522
#endif
523 519
    &qemu_option_rom_opts,
524 520
    &qemu_machine_opts,
525 521
    &qemu_boot_opts,
b/qemu-options.hx
2436 2436
@var{sysconfdir}/target-@var{ARCH}.conf on startup.  The @code{-nodefconfig}
2437 2437
option will prevent QEMU from loading these configuration files at startup.
2438 2438
ETEXI
2439
#ifdef CONFIG_TRACE_SIMPLE
2440 2439
DEF("trace", HAS_ARG, QEMU_OPTION_trace,
2441 2440
    "-trace\n"
2442 2441
    "                Specify a trace file to log traces to\n",
2443 2442
    QEMU_ARCH_ALL)
2444 2443
STEXI
2444
HXCOMM This line is not accurate, as the option is backend-specific but HX does
2445
HXCOMM not support conditional compilation of text.
2445 2446
@item -trace
2446 2447
@findex -trace
2447 2448
Specify a trace file to log output traces to.
2449

  
2450
This option is available only when using the @var{simple} tracing backend.
2448 2451
ETEXI
2449
#endif
2450 2452

  
2451 2453
HXCOMM This is the last statement. Insert new options before this line!
2452 2454
STEXI
b/trace/control.h
1
/*
2
 * Interface for configuring and controlling the state of tracing events.
3
 *
4
 * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
5
 *
6
 * This work is licensed under the terms of the GNU GPL, version 2.  See
7
 * the COPYING file in the top-level directory.
8
 */
9

  
10
#ifndef TRACE_CONTROL_H
11
#define TRACE_CONTROL_H
12

  
13
#include <stdbool.h>
14

  
15

  
16
/** Initialize the tracing backend.
17
 *
18
 * @file Name of trace output file; may be NULL.
19
 *       Corresponds to commandline option "-trace file=...".
20
 * @return Whether the backend could be successfully initialized.
21
 */
22
bool trace_backend_init(const char *file);
23

  
24
#endif  /* TRACE_CONTROL_H */
b/trace/default.c
1
/*
2
 * Default implementation for backend initialization from commandline.
3
 *
4
 * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
5
 *
6
 * This work is licensed under the terms of the GNU GPL, version 2.  See
7
 * the COPYING file in the top-level directory.
8
 */
9

  
10
#include "trace/control.h"
11

  
12

  
13
bool trace_backend_init(const char *file)
14
{
15
    if (file) {
16
        fprintf(stderr, "error: -trace file=...: "
17
                "option not supported by the selected tracing backend\n");
18
        return false;
19
    }
20
    return true;
21
}
b/trace/simple.c
16 16
#include <pthread.h>
17 17
#include "qemu-timer.h"
18 18
#include "trace.h"
19
#include "trace/control.h"
19 20

  
20 21
/** Trace file header event ID */
21 22
#define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceEventIDs */
......
330 331
    flush_trace_file(true);
331 332
}
332 333

  
333
bool st_init(const char *file)
334
bool trace_backend_init(const char *file)
334 335
{
335 336
    pthread_t thread;
336 337
    pthread_attr_t attr;
......
346 347
    pthread_sigmask(SIG_SETMASK, &oldset, NULL);
347 348

  
348 349
    if (ret != 0) {
349
        return false;
350
        fprintf(stderr, "warning: unable to initialize simple trace backend\n");
351
    } else {
352
        atexit(st_flush_trace_buffer);
353
        st_set_trace_file(file);
350 354
    }
351 355

  
352
    atexit(st_flush_trace_buffer);
353
    st_set_trace_file(file);
354 356
    return true;
355 357
}
b/trace/simple.h
15 15
#include <stdbool.h>
16 16
#include <stdio.h>
17 17

  
18
#ifdef CONFIG_TRACE_SIMPLE
19 18
typedef uint64_t TraceEventID;
20 19

  
21 20
typedef struct {
......
37 36
void st_set_trace_file_enabled(bool enable);
38 37
bool st_set_trace_file(const char *file);
39 38
void st_flush_trace_buffer(void);
40
bool st_init(const char *file);
41
#else
42
static inline bool st_init(const char *file)
43
{
44
    return true;
45
}
46
#endif /* !CONFIG_TRACE_SIMPLE */
47 39

  
48 40
#endif /* TRACE_SIMPLE_H */
b/vl.c
156 156
#include "slirp/libslirp.h"
157 157

  
158 158
#include "trace.h"
159
#include "trace/simple.h"
159
#include "trace/control.h"
160 160
#include "qemu-queue.h"
161 161
#include "cpus.h"
162 162
#include "arch_init.h"
......
2130 2130
    int show_vnc_port = 0;
2131 2131
#endif
2132 2132
    int defconfig = 1;
2133
    const char *trace_file = NULL;
2134 2133
    const char *log_mask = NULL;
2135 2134
    const char *log_file = NULL;
2136 2135
    GMemVTable mem_trace = {
......
2138 2137
        .realloc = realloc_and_trace,
2139 2138
        .free = free_and_trace,
2140 2139
    };
2140
    const char *trace_file = NULL;
2141 2141

  
2142 2142
    atexit(qemu_run_exit_notifiers);
2143 2143
    error_set_progname(argv[0]);
......
2928 2928
                }
2929 2929
                xen_mode = XEN_ATTACH;
2930 2930
                break;
2931
#ifdef CONFIG_TRACE_SIMPLE
2932 2931
            case QEMU_OPTION_trace:
2932
            {
2933 2933
                opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2934
                if (opts) {
2935
                    trace_file = qemu_opt_get(opts, "file");
2934
                if (!opts) {
2935
                    exit(1);
2936 2936
                }
2937
                trace_file = qemu_opt_get(opts, "file");
2937 2938
                break;
2938
#endif
2939
            }
2939 2940
            case QEMU_OPTION_readconfig:
2940 2941
                {
2941 2942
                    int ret = qemu_read_config_file(optarg);
......
2993 2994
        set_cpu_log(log_mask);
2994 2995
    }
2995 2996

  
2996
    if (!st_init(trace_file)) {
2997
        fprintf(stderr, "warning: unable to initialize simple trace backend\n");
2997
    if (!trace_backend_init(trace_file)) {
2998
        exit(1);
2998 2999
    }
2999 3000

  
3000 3001
    /* If no data_dir is specified then try to find it relative to the

Also available in: Unified diff