aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2016-02-03 19:00:33 +0000
committerPeter Maydell <peter.maydell@linaro.org>2016-02-03 19:00:33 +0000
commit382d34ff9fcc534db32d54eb82590de7c04f9b33 (patch)
treeb8b23b009ff6dba3650a5d16143a919c90436df5
parent87574621b18f86eab295a2c207e0b42c77b5dfa0 (diff)
parentc84ea00dc29b2084a62bd31f498ed0f245d3848e (diff)
Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging
# gpg: Signature made Wed 03 Feb 2016 15:47:34 GMT using RSA key ID 81AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" * remotes/stefanha/tags/tracing-pull-request: log: add "-d trace:PATTERN" trace: switch default backend to "log" trace: convert stderr backend to log log: move qemu-log.c into util/ directory log: do not unnecessarily include qom/cpu.h trace: add "-trace help" trace: add "-trace enable=..." trace: no need to call trace_backend_init in different branches now trace: split trace_init_file out of trace_init_backends trace: split trace_init_events out of trace_init_backends trace: fix documentation trace: track enabled events in a separate array trace: count number of enabled events Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--.travis.yml2
-rw-r--r--Makefile.objs1
-rw-r--r--bsd-user/main.c1
-rwxr-xr-xconfigure6
-rw-r--r--cpu-exec.c1
-rw-r--r--exec.c1
-rw-r--r--hw/acpi/cpu_hotplug.c1
-rw-r--r--hw/timer/a9gtimer.c1
-rw-r--r--include/exec/log.h60
-rw-r--r--include/qemu/log.h60
-rw-r--r--linux-user/main.c1
-rw-r--r--qemu-io.c2
-rw-r--r--qemu-options.hx22
-rw-r--r--qom/cpu.c1
-rw-r--r--scripts/tracetool/backend/log.py (renamed from scripts/tracetool/backend/stderr.py)9
-rw-r--r--scripts/tracetool/format/events_c.py2
-rw-r--r--target-alpha/translate.c1
-rw-r--r--target-arm/translate-a64.c1
-rw-r--r--target-arm/translate.c1
-rw-r--r--target-cris/translate.c1
-rw-r--r--target-i386/seg_helper.c1
-rw-r--r--target-i386/smm_helper.c1
-rw-r--r--target-i386/translate.c1
-rw-r--r--target-lm32/helper.c1
-rw-r--r--target-lm32/translate.c1
-rw-r--r--target-m68k/translate.c1
-rw-r--r--target-microblaze/helper.c1
-rw-r--r--target-microblaze/translate.c1
-rw-r--r--target-mips/helper.c1
-rw-r--r--target-mips/translate.c1
-rw-r--r--target-moxie/translate.c1
-rw-r--r--target-openrisc/translate.c1
-rw-r--r--target-ppc/mmu-hash32.c1
-rw-r--r--target-ppc/mmu-hash64.c1
-rw-r--r--target-ppc/mmu_helper.c1
-rw-r--r--target-ppc/translate.c1
-rw-r--r--target-s390x/translate.c1
-rw-r--r--target-sh4/helper.c1
-rw-r--r--target-sh4/translate.c1
-rw-r--r--target-sparc/int32_helper.c1
-rw-r--r--target-sparc/int64_helper.c1
-rw-r--r--target-sparc/translate.c1
-rw-r--r--target-tilegx/translate.c1
-rw-r--r--target-tricore/translate.c1
-rw-r--r--target-unicore32/translate.c1
-rw-r--r--target-xtensa/translate.c1
-rw-r--r--tcg/tcg.c1
-rw-r--r--trace/control-internal.h15
-rw-r--r--trace/control.c98
-rw-r--r--trace/control.h44
-rw-r--r--trace/event-internal.h2
-rw-r--r--trace/simple.c6
-rw-r--r--trace/simple.h4
-rw-r--r--translate-all.c1
-rw-r--r--util/Makefile.objs1
-rw-r--r--util/log.c (renamed from qemu-log.c)19
-rw-r--r--vl.c38
57 files changed, 293 insertions, 137 deletions
diff --git a/.travis.yml b/.travis.yml
index 6ca0260941..0428aed0ec 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -78,7 +78,7 @@ matrix:
compiler: gcc
# All the trace backends (apart from dtrace)
- env: TARGETS=i386-softmmu,x86_64-softmmu
- EXTRA_CONFIG="--enable-trace-backends=stderr"
+ EXTRA_CONFIG="--enable-trace-backends=log"
compiler: gcc
- env: TARGETS=i386-softmmu,x86_64-softmmu
EXTRA_CONFIG="--enable-trace-backends=simple"
diff --git a/Makefile.objs b/Makefile.objs
index 06b95c72d0..fbcaa7471f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -89,7 +89,6 @@ endif
#######################################################################
# Target-independent parts used in system and user emulation
-common-obj-y += qemu-log.o
common-obj-y += tcg-runtime.o
common-obj-y += hw/
common-obj-y += qom/
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 1ecaeb50e5..fefcfc1ccf 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -33,6 +33,7 @@
#include "tcg.h"
#include "qemu/timer.h"
#include "qemu/envlist.h"
+#include "exec/log.h"
int singlestep;
unsigned long mmap_min_addr;
diff --git a/configure b/configure
index 297bfc7997..d4411a1314 100755
--- a/configure
+++ b/configure
@@ -303,7 +303,7 @@ pkgversion=""
pie=""
zero_malloc=""
qom_cast_debug="yes"
-trace_backends="nop"
+trace_backends="log"
trace_file="trace"
spice=""
rbd=""
@@ -5445,8 +5445,8 @@ if have_backend "simple"; then
# Set the appropriate trace file.
trace_file="\"$trace_file-\" FMT_pid"
fi
-if have_backend "stderr"; then
- echo "CONFIG_TRACE_STDERR=y" >> $config_host_mak
+if have_backend "log"; then
+ echo "CONFIG_TRACE_LOG=y" >> $config_host_mak
fi
if have_backend "ust"; then
echo "CONFIG_TRACE_UST=y" >> $config_host_mak
diff --git a/cpu-exec.c b/cpu-exec.c
index c4593646ff..fd92452f16 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -27,6 +27,7 @@
#include "exec/address-spaces.h"
#include "qemu/rcu.h"
#include "exec/tb-hash.h"
+#include "exec/log.h"
#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
#include "hw/i386/apic.h"
#endif
diff --git a/exec.c b/exec.c
index 9e076bc323..ab373604d7 100644
--- a/exec.c
+++ b/exec.c
@@ -52,6 +52,7 @@
#include "exec/memory-internal.h"
#include "exec/ram_addr.h"
+#include "exec/log.h"
#include "qemu/range.h"
#ifndef _WIN32
diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 2f99ec5455..5a410a5287 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -12,6 +12,7 @@
#include "qemu/osdep.h"
#include "hw/hw.h"
#include "hw/acpi/cpu_hotplug.h"
+#include "qom/cpu.h"
static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
{
diff --git a/hw/timer/a9gtimer.c b/hw/timer/a9gtimer.c
index c11a7bc75b..fa4602ca04 100644
--- a/hw/timer/a9gtimer.c
+++ b/hw/timer/a9gtimer.c
@@ -25,6 +25,7 @@
#include "qemu/timer.h"
#include "qemu/bitops.h"
#include "qemu/log.h"
+#include "qom/cpu.h"
#ifndef A9_GTIMER_ERR_DEBUG
#define A9_GTIMER_ERR_DEBUG 0
diff --git a/include/exec/log.h b/include/exec/log.h
new file mode 100644
index 0000000000..ba1c9b5682
--- /dev/null
+++ b/include/exec/log.h
@@ -0,0 +1,60 @@
+#ifndef QEMU_EXEC_LOG_H
+#define QEMU_EXEC_LOG_H
+
+#include "qemu/log.h"
+#include "qom/cpu.h"
+#include "disas/disas.h"
+
+/* cpu_dump_state() logging functions: */
+/**
+ * log_cpu_state:
+ * @cpu: The CPU whose state is to be logged.
+ * @flags: Flags what to log.
+ *
+ * Logs the output of cpu_dump_state().
+ */
+static inline void log_cpu_state(CPUState *cpu, int flags)
+{
+ if (qemu_log_enabled()) {
+ cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
+ }
+}
+
+/**
+ * log_cpu_state_mask:
+ * @mask: Mask when to log.
+ * @cpu: The CPU whose state is to be logged.
+ * @flags: Flags what to log.
+ *
+ * Logs the output of cpu_dump_state() if loglevel includes @mask.
+ */
+static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
+{
+ if (qemu_loglevel & mask) {
+ log_cpu_state(cpu, flags);
+ }
+}
+
+#ifdef NEED_CPU_H
+/* disas() and target_disas() to qemu_logfile: */
+static inline void log_target_disas(CPUState *cpu, target_ulong start,
+ target_ulong len, int flags)
+{
+ target_disas(qemu_logfile, cpu, start, len, flags);
+}
+
+static inline void log_disas(void *code, unsigned long size)
+{
+ disas(qemu_logfile, code, size);
+}
+
+#if defined(CONFIG_USER_ONLY)
+/* page_dump() output to the log file: */
+static inline void log_page_dump(void)
+{
+ page_dump(qemu_logfile);
+}
+#endif
+#endif
+
+#endif
diff --git a/include/qemu/log.h b/include/qemu/log.h
index d837d90e77..30817f7b42 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -5,10 +5,6 @@
#include <stdbool.h>
#include <stdio.h>
#include "qemu/compiler.h"
-#include "qom/cpu.h"
-#ifdef NEED_CPU_H
-#include "disas/disas.h"
-#endif
/* Private global variables, don't use */
extern FILE *qemu_logfile;
@@ -49,6 +45,7 @@ static inline bool qemu_log_separate(void)
#define CPU_LOG_MMU (1 << 12)
#define CPU_LOG_TB_NOCHAIN (1 << 13)
#define CPU_LOG_PAGE (1 << 14)
+#define LOG_TRACE (1 << 15)
/* Returns true if a bit is set in the current loglevel mask
*/
@@ -78,61 +75,6 @@ qemu_log_vprintf(const char *fmt, va_list va)
void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
-/* Special cases: */
-
-/* cpu_dump_state() logging functions: */
-/**
- * log_cpu_state:
- * @cpu: The CPU whose state is to be logged.
- * @flags: Flags what to log.
- *
- * Logs the output of cpu_dump_state().
- */
-static inline void log_cpu_state(CPUState *cpu, int flags)
-{
- if (qemu_log_enabled()) {
- cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
- }
-}
-
-/**
- * log_cpu_state_mask:
- * @mask: Mask when to log.
- * @cpu: The CPU whose state is to be logged.
- * @flags: Flags what to log.
- *
- * Logs the output of cpu_dump_state() if loglevel includes @mask.
- */
-static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
-{
- if (qemu_loglevel & mask) {
- log_cpu_state(cpu, flags);
- }
-}
-
-#ifdef NEED_CPU_H
-/* disas() and target_disas() to qemu_logfile: */
-static inline void log_target_disas(CPUState *cpu, target_ulong start,
- target_ulong len, int flags)
-{
- target_disas(qemu_logfile, cpu, start, len, flags);
-}
-
-static inline void log_disas(void *code, unsigned long size)
-{
- disas(qemu_logfile, code, size);
-}
-
-#if defined(CONFIG_USER_ONLY)
-/* page_dump() output to the log file: */
-static inline void log_page_dump(void)
-{
- page_dump(qemu_logfile);
-}
-#endif
-#endif
-
-
/* Maintenance: */
/* fflush() the log file */
diff --git a/linux-user/main.c b/linux-user/main.c
index f8d45778c8..e719a2da02 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -28,6 +28,7 @@
#include "qemu/timer.h"
#include "qemu/envlist.h"
#include "elf.h"
+#include "exec/log.h"
char *exec_path;
diff --git a/qemu-io.c b/qemu-io.c
index d593f19642..83c48f4149 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -435,7 +435,7 @@ int main(int argc, char **argv)
}
break;
case 'T':
- if (!trace_init_backends(optarg, NULL)) {
+ if (!trace_init_backends()) {
exit(1); /* error message will have been printed */
}
break;
diff --git a/qemu-options.hx b/qemu-options.hx
index f31a240bed..733a1949e9 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3544,7 +3544,7 @@ config files on @var{sysconfdir}, but won't make it skip the QEMU-provided confi
files from @var{datadir}.
ETEXI
DEF("trace", HAS_ARG, QEMU_OPTION_trace,
- "-trace [events=<file>][,file=<file>]\n"
+ "-trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
" specify tracing options\n",
QEMU_ARCH_ALL)
STEXI
@@ -3556,15 +3556,25 @@ HXCOMM HX does not support conditional compilation of text.
Specify tracing options.
@table @option
+@item [enable=]@var{pattern}
+Immediately enable events matching @var{pattern}.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too. This option is only
+available if QEMU has been compiled with the @var{simple}, @var{stderr}
+or @var{ftrace} tracing backend. To specify multiple events or patterns,
+specify the @option{-trace} option multiple times.
+
+Use @code{-trace help} to print a list of names of trace points.
+
@item events=@var{file}
Immediately enable events listed in @var{file}.
-The file must contain one event name (as listed in the @var{trace-events} file)
-per line.
-This option is only available if QEMU has been compiled with
-either @var{simple} or @var{stderr} tracing backend.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too. This option is only
+available if QEMU has been compiled with the @var{simple}, @var{stderr} or
+@var{ftrace} tracing backend.
+
@item file=@var{file}
Log output traces to @var{file}.
-
This option is only available if QEMU has been compiled with
the @var{simple} tracing backend.
@end table
diff --git a/qom/cpu.c b/qom/cpu.c
index 8f537a470f..38dc713ce2 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -23,6 +23,7 @@
#include "sysemu/kvm.h"
#include "qemu/notify.h"
#include "qemu/log.h"
+#include "exec/log.h"
#include "qemu/error-report.h"
#include "sysemu/sysemu.h"
diff --git a/scripts/tracetool/backend/stderr.py b/scripts/tracetool/backend/log.py
index ca58054621..a62c310705 100644
--- a/scripts/tracetool/backend/stderr.py
+++ b/scripts/tracetool/backend/log.py
@@ -25,6 +25,7 @@ def generate_h_begin(events):
'#include <sys/types.h>',
'#include <unistd.h>',
'#include "trace/control.h"',
+ '#include "qemu/log.h"',
'')
@@ -36,10 +37,10 @@ def generate_h(event):
out(' if (trace_event_get_state(%(event_id)s)) {',
' struct timeval _now;',
' gettimeofday(&_now, NULL);',
- ' fprintf(stderr, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
- ' getpid(),',
- ' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
- ' %(argnames)s);',
+ ' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
+ ' getpid(),',
+ ' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
+ ' %(argnames)s);',
' }',
event_id="TRACE_" + event.name.upper(),
name=event.name,
diff --git a/scripts/tracetool/format/events_c.py b/scripts/tracetool/format/events_c.py
index 2d97fa310a..2717ea3a0b 100644
--- a/scripts/tracetool/format/events_c.py
+++ b/scripts/tracetool/format/events_c.py
@@ -27,7 +27,7 @@ def generate(events, backend):
out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {')
for e in events:
- out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },',
+ out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s },',
id = "TRACE_" + e.name.upper(),
name = e.name,
sstate = "TRACE_%s_ENABLED" % e.name.upper())
diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index 7d419d9972..c96adbb6c7 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -28,6 +28,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#undef ALPHA_DEBUG_DISAS
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
index 80f6c2058c..2af7d860a5 100644
--- a/target-arm/translate-a64.c
+++ b/target-arm/translate-a64.c
@@ -31,6 +31,7 @@
#include "exec/helper-proto.h"
#include "exec/helper-gen.h"
+#include "exec/log.h"
#include "trace-tcg.h"
diff --git a/target-arm/translate.c b/target-arm/translate.c
index cff511b9c6..3ec758ad6f 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -32,6 +32,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define ENABLE_ARCH_4T arm_dc_feature(s, ARM_FEATURE_V4T)
diff --git a/target-cris/translate.c b/target-cris/translate.c
index 295005f141..0350cb59c0 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -35,6 +35,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define DISAS_CRIS 0
diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c
index 4c7cab79ff..4f269416a5 100644
--- a/target-i386/seg_helper.c
+++ b/target-i386/seg_helper.c
@@ -23,6 +23,7 @@
#include "qemu/log.h"
#include "exec/helper-proto.h"
#include "exec/cpu_ldst.h"
+#include "exec/log.h"
//#define DEBUG_PCALL
diff --git a/target-i386/smm_helper.c b/target-i386/smm_helper.c
index b930421724..e7bb5be521 100644
--- a/target-i386/smm_helper.c
+++ b/target-i386/smm_helper.c
@@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/helper-proto.h"
+#include "exec/log.h"
/* SMM support */
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 957a92d591..73a45c872e 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -28,6 +28,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define PREFIX_REPZ 0x01
diff --git a/target-lm32/helper.c b/target-lm32/helper.c
index 3ebec68cba..655248f81a 100644
--- a/target-lm32/helper.c
+++ b/target-lm32/helper.c
@@ -22,6 +22,7 @@
#include "qemu/host-utils.h"
#include "sysemu/sysemu.h"
#include "exec/semihost.h"
+#include "exec/log.h"
int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
int mmu_idx)
diff --git a/target-lm32/translate.c b/target-lm32/translate.c
index 477d4285a5..52fe562737 100644
--- a/target-lm32/translate.c
+++ b/target-lm32/translate.c
@@ -29,6 +29,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define DISAS_LM32 1
diff --git a/target-m68k/translate.c b/target-m68k/translate.c
index 342c040559..a402bd847a 100644
--- a/target-m68k/translate.c
+++ b/target-m68k/translate.c
@@ -29,6 +29,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
//#define DEBUG_DISPATCH 1
diff --git a/target-microblaze/helper.c b/target-microblaze/helper.c
index 3b0fae8072..4de6bdbf83 100644
--- a/target-microblaze/helper.c
+++ b/target-microblaze/helper.c
@@ -21,6 +21,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "qemu/host-utils.h"
+#include "exec/log.h"
#define D(x)
diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c
index 2e1293d953..40be4ec805 100644
--- a/target-microblaze/translate.c
+++ b/target-microblaze/translate.c
@@ -28,6 +28,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define SIM_COMPAT 0
diff --git a/target-mips/helper.c b/target-mips/helper.c
index f9c4c11eb9..1004edee05 100644
--- a/target-mips/helper.c
+++ b/target-mips/helper.c
@@ -21,6 +21,7 @@
#include "cpu.h"
#include "sysemu/kvm.h"
#include "exec/cpu_ldst.h"
+#include "exec/log.h"
enum {
TLBRET_XI = -6,
diff --git a/target-mips/translate.c b/target-mips/translate.c
index 383d4b5118..791866bf2d 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -33,6 +33,7 @@
#include "exec/semihost.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define MIPS_DEBUG_DISAS 0
diff --git a/target-moxie/translate.c b/target-moxie/translate.c
index 229ce3b64d..04ab278ea2 100644
--- a/target-moxie/translate.c
+++ b/target-moxie/translate.c
@@ -31,6 +31,7 @@
#include "exec/helper-proto.h"
#include "exec/helper-gen.h"
+#include "exec/log.h"
/* This is the state at translation time. */
typedef struct DisasContext {
diff --git a/target-openrisc/translate.c b/target-openrisc/translate.c
index 62890c21ed..b766b27405 100644
--- a/target-openrisc/translate.c
+++ b/target-openrisc/translate.c
@@ -32,6 +32,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define OPENRISC_DISAS
diff --git a/target-ppc/mmu-hash32.c b/target-ppc/mmu-hash32.c
index b076d8006f..39abb2fd39 100644
--- a/target-ppc/mmu-hash32.c
+++ b/target-ppc/mmu-hash32.c
@@ -24,6 +24,7 @@
#include "sysemu/kvm.h"
#include "kvm_ppc.h"
#include "mmu-hash32.h"
+#include "exec/log.h"
//#define DEBUG_BAT
diff --git a/target-ppc/mmu-hash64.c b/target-ppc/mmu-hash64.c
index 6d110ee342..9c58fbf009 100644
--- a/target-ppc/mmu-hash64.c
+++ b/target-ppc/mmu-hash64.c
@@ -25,6 +25,7 @@
#include "qemu/error-report.h"
#include "kvm_ppc.h"
#include "mmu-hash64.h"
+#include "exec/log.h"
//#define DEBUG_SLB
diff --git a/target-ppc/mmu_helper.c b/target-ppc/mmu_helper.c
index de4e286eee..e5ec8d6169 100644
--- a/target-ppc/mmu_helper.c
+++ b/target-ppc/mmu_helper.c
@@ -24,6 +24,7 @@
#include "mmu-hash64.h"
#include "mmu-hash32.h"
#include "exec/cpu_ldst.h"
+#include "exec/log.h"
//#define DEBUG_MMU
//#define DEBUG_BATS
diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index 7db3145cff..0057bdaf37 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -29,6 +29,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define CPU_SINGLE_STEP 0x1
diff --git a/target-s390x/translate.c b/target-s390x/translate.c
index 811928b1c3..3087692aa7 100644
--- a/target-s390x/translate.c
+++ b/target-s390x/translate.c
@@ -44,6 +44,7 @@ static TCGv_ptr cpu_env;
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
/* Information that (most) every instruction needs to manipulate. */
diff --git a/target-sh4/helper.c b/target-sh4/helper.c
index 9d8b61cce6..6438338f24 100644
--- a/target-sh4/helper.c
+++ b/target-sh4/helper.c
@@ -19,6 +19,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
+#include "exec/log.h"
#if !defined(CONFIG_USER_ONLY)
#include "hw/sh4/sh_intc.h"
diff --git a/target-sh4/translate.c b/target-sh4/translate.c
index 9de5659cf7..3e4164b78f 100644
--- a/target-sh4/translate.c
+++ b/target-sh4/translate.c
@@ -29,6 +29,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
typedef struct DisasContext {
diff --git a/target-sparc/int32_helper.c b/target-sparc/int32_helper.c
index d4d6a4b8a5..09afe136e5 100644
--- a/target-sparc/int32_helper.c
+++ b/target-sparc/int32_helper.c
@@ -21,6 +21,7 @@
#include "cpu.h"
#include "trace.h"
#include "sysemu/sysemu.h"
+#include "exec/log.h"
#define DEBUG_PCALL
diff --git a/target-sparc/int64_helper.c b/target-sparc/int64_helper.c
index ddef66b569..aa876cd8ba 100644
--- a/target-sparc/int64_helper.c
+++ b/target-sparc/int64_helper.c
@@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/helper-proto.h"
+#include "exec/log.h"
#include "trace.h"
#define DEBUG_PCALL
diff --git a/target-sparc/translate.c b/target-sparc/translate.c
index 747f94d60e..67268604ba 100644
--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -29,6 +29,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
#define DEBUG_DISAS
diff --git a/target-tilegx/translate.c b/target-tilegx/translate.c
index 2088f8796b..a5bb8d4aba 100644
--- a/target-tilegx/translate.c
+++ b/target-tilegx/translate.c
@@ -21,6 +21,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "qemu/log.h"
+#include "exec/log.h"
#include "disas/disas.h"
#include "tcg-op.h"
#include "exec/cpu_ldst.h"
diff --git a/target-tricore/translate.c b/target-tricore/translate.c
index 2b07b86694..e385fc71f7 100644
--- a/target-tricore/translate.c
+++ b/target-tricore/translate.c
@@ -28,6 +28,7 @@
#include "exec/helper-gen.h"
#include "tricore-opcodes.h"
+#include "exec/log.h"
/*
* TCG registers
diff --git a/target-unicore32/translate.c b/target-unicore32/translate.c
index 5db8f94931..7dbfe3bd03 100644
--- a/target-unicore32/translate.c
+++ b/target-unicore32/translate.c
@@ -20,6 +20,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
/* internal defines */
diff --git a/target-xtensa/translate.c b/target-xtensa/translate.c
index a8c1113489..435ee035d5 100644
--- a/target-xtensa/translate.c
+++ b/target-xtensa/translate.c
@@ -43,6 +43,7 @@
#include "exec/helper-gen.h"
#include "trace-tcg.h"
+#include "exec/log.h"
typedef struct DisasContext {
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 3ce02dcd08..be765ad3a8 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -60,6 +60,7 @@
#endif
#include "elf.h"
+#include "exec/log.h"
/* Forward declarations for functions declared in tcg-target.c and used here. */
static void tcg_target_init(TCGContext *s);
diff --git a/trace/control-internal.h b/trace/control-internal.h
index 5a8df28c58..07cb1c1685 100644
--- a/trace/control-internal.h
+++ b/trace/control-internal.h
@@ -14,6 +14,8 @@
extern TraceEvent trace_events[];
+extern bool trace_events_dstate[];
+extern int trace_events_enabled_count;
static inline TraceEventID trace_event_count(void)
@@ -51,17 +53,24 @@ static inline bool trace_event_get_state_static(TraceEvent *ev)
return ev->sstate;
}
+static inline bool trace_event_get_state_dynamic_by_id(int id)
+{
+ return unlikely(trace_events_enabled_count) && trace_events_dstate[id];
+}
+
static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
{
- assert(ev != NULL);
- return ev->dstate;
+ int id = trace_event_get_id(ev);
+ return trace_event_get_state_dynamic_by_id(id);
}
static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
{
+ int id = trace_event_get_id(ev);
assert(ev != NULL);
assert(trace_event_get_state_static(ev));
- ev->dstate = state;
+ trace_events_enabled_count += state - trace_events_dstate[id];
+ trace_events_dstate[id] = state;
}
#endif /* TRACE__CONTROL_INTERNAL_H */
diff --git a/trace/control.c b/trace/control.c
index 995beb384c..84ea840892 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -14,8 +14,14 @@
#ifdef CONFIG_TRACE_FTRACE
#include "trace/ftrace.h"
#endif
+#ifdef CONFIG_TRACE_LOG
+#include "qemu/log.h"
+#endif
#include "qemu/error-report.h"
+int trace_events_enabled_count;
+bool trace_events_dstate[TRACE_EVENT_COUNT];
+
TraceEvent *trace_event_name(const char *name)
{
assert(name != NULL);
@@ -85,7 +91,52 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
return NULL;
}
-static void trace_init_events(const char *fname)
+void trace_list_events(void)
+{
+ int i;
+ for (i = 0; i < trace_event_count(); i++) {
+ TraceEvent *res = trace_event_id(i);
+ fprintf(stderr, "%s\n", trace_event_get_name(res));
+ }
+}
+
+static void do_trace_enable_events(const char *line_buf)
+{
+ const bool enable = ('-' != line_buf[0]);
+ const char *line_ptr = enable ? line_buf : line_buf + 1;
+
+ if (trace_event_is_pattern(line_ptr)) {
+ TraceEvent *ev = NULL;
+ while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) {
+ if (trace_event_get_state_static(ev)) {
+ trace_event_set_state_dynamic(ev, enable);
+ }
+ }
+ } else {
+ TraceEvent *ev = trace_event_name(line_ptr);
+ if (ev == NULL) {
+ error_report("WARNING: trace event '%s' does not exist",
+ line_ptr);
+ } else if (!trace_event_get_state_static(ev)) {
+ error_report("WARNING: trace event '%s' is not traceable",
+ line_ptr);
+ } else {
+ trace_event_set_state_dynamic(ev, enable);
+ }
+ }
+}
+
+void trace_enable_events(const char *line_buf)
+{
+ if (is_help_option(line_buf)) {
+ trace_list_events();
+ exit(0);
+ } else {
+ do_trace_enable_events(line_buf);
+ }
+}
+
+void trace_init_events(const char *fname)
{
Location loc;
FILE *fp;
@@ -111,27 +162,7 @@ static void trace_init_events(const char *fname)
if ('#' == line_buf[0]) { /* skip commented lines */
continue;
}
- const bool enable = ('-' != line_buf[0]);
- char *line_ptr = enable ? line_buf : line_buf + 1;
- if (trace_event_is_pattern(line_ptr)) {
- TraceEvent *ev = NULL;
- while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) {
- if (trace_event_get_state_static(ev)) {
- trace_event_set_state_dynamic(ev, enable);
- }
- }
- } else {
- TraceEvent *ev = trace_event_name(line_ptr);
- if (ev == NULL) {
- error_report("WARNING: trace event '%s' does not exist",
- line_ptr);
- } else if (!trace_event_get_state_static(ev)) {
- error_report("WARNING: trace event '%s' is not traceable",
- line_ptr);
- } else {
- trace_event_set_state_dynamic(ev, enable);
- }
- }
+ trace_enable_events(line_buf);
}
}
if (fclose(fp) != 0) {
@@ -142,17 +173,31 @@ static void trace_init_events(const char *fname)
loc_pop(&loc);
}
-bool trace_init_backends(const char *events, const char *file)
+void trace_init_file(const char *file)
{
#ifdef CONFIG_TRACE_SIMPLE
- if (!st_init(file)) {
- fprintf(stderr, "failed to initialize simple tracing backend.\n");
- return false;
+ st_set_trace_file(file);
+#elif defined CONFIG_TRACE_LOG
+ /* If both the simple and the log backends are enabled, "-trace file"
+ * only applies to the simple backend; use "-D" for the log backend.
+ */
+ if (file) {
+ qemu_set_log_filename(file);
}
#else
if (file) {
fprintf(stderr, "error: -trace file=...: "
"option not supported by the selected tracing backends\n");
+ exit(1);
+ }
+#endif
+}
+
+bool trace_init_backends(void)
+{
+#ifdef CONFIG_TRACE_SIMPLE
+ if (!st_init()) {
+ fprintf(stderr, "failed to initialize simple tracing backend.\n");
return false;
}
#endif
@@ -164,6 +209,5 @@ bool trace_init_backends(const char *events, const char *file)
}
#endif
- trace_init_events(events);
return true;
}
diff --git a/trace/control.h b/trace/control.h
index da9bb6b774..d5bc86e5f1 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -104,7 +104,7 @@ static const char * trace_event_get_name(TraceEvent *ev);
* As a down side, you must always use an immediate #TraceEventID value.
*/
#define trace_event_get_state(id) \
- ((id ##_ENABLED) && trace_event_get_state_dynamic(trace_event_id(id)))
+ ((id ##_ENABLED) && trace_event_get_state_dynamic_by_id(id))
/**
* trace_event_get_state_static:
@@ -150,8 +150,6 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
/**
* trace_init_backends:
- * @events: Name of file with events to be enabled at startup; may be NULL.
- * Corresponds to commandline option "-trace events=...".
* @file: Name of trace output file; may be NULL.
* Corresponds to commandline option "-trace file=...".
*
@@ -159,7 +157,45 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
*
* Returns: Whether the backends could be successfully initialized.
*/
-bool trace_init_backends(const char *events, const char *file);
+bool trace_init_backends(void);
+
+/**
+ * trace_init_events:
+ * @events: Name of file with events to be enabled at startup; may be NULL.
+ * Corresponds to commandline option "-trace events=...".
+ *
+ * Read the list of enabled tracing events.
+ *
+ * Returns: Whether the backends could be successfully initialized.
+ */
+void trace_init_events(const char *file);
+
+/**
+ * trace_init_file:
+ * @file: Name of trace output file; may be NULL.
+ * Corresponds to commandline option "-trace file=...".
+ *
+ * Record the name of the output file for the tracing backend.
+ * Exits if no selected backend does not support specifying the
+ * output file, and a non-NULL file was passed.
+ */
+void trace_init_file(const char *file);
+
+/**
+ * trace_list_events:
+ *
+ * List all available events.
+ */
+void trace_list_events(void);
+
+/**
+ * trace_enable_events:
+ * @line_buf: A string with a glob pattern of events to be enabled or,
+ * if the string starts with '-', disabled.
+ *
+ * Enable or disable matching events.
+ */
+void trace_enable_events(const char *line_buf);
#include "trace/control-internal.h"
diff --git a/trace/event-internal.h b/trace/event-internal.h
index b2310d9bea..86f6a511be 100644
--- a/trace/event-internal.h
+++ b/trace/event-internal.h
@@ -18,7 +18,6 @@
* @id: Unique event identifier.
* @name: Event name.
* @sstate: Static tracing state.
- * @dstate: Dynamic tracing state.
*
* Opaque generic description of a tracing event.
*/
@@ -26,7 +25,6 @@ typedef struct TraceEvent {
TraceEventID id;
const char * name;
const bool sstate;
- bool dstate;
} TraceEvent;
diff --git a/trace/simple.c b/trace/simple.c
index 56a624cac8..e8594cd00d 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -322,7 +322,7 @@ void st_set_trace_file_enabled(bool enable)
* @file The trace file name or NULL for the default name-<pid> set at
* config time
*/
-bool st_set_trace_file(const char *file)
+void st_set_trace_file(const char *file)
{
st_set_trace_file_enabled(false);
@@ -336,7 +336,6 @@ bool st_set_trace_file(const char *file)
}
st_set_trace_file_enabled(true);
- return true;
}
void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...))
@@ -374,7 +373,7 @@ static GThread *trace_thread_create(GThreadFunc fn)
return thread;
}
-bool st_init(const char *file)
+bool st_init(void)
{
GThread *thread;
@@ -387,6 +386,5 @@ bool st_init(const char *file)
}
atexit(st_flush_trace_buffer);
- st_set_trace_file(file);
return true;
}
diff --git a/trace/simple.h b/trace/simple.h
index 6997996855..8d1a32eba0 100644
--- a/trace/simple.h
+++ b/trace/simple.h
@@ -20,8 +20,8 @@
void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
void st_set_trace_file_enabled(bool enable);
-bool st_set_trace_file(const char *file);
-bool st_init(const char *file);
+void st_set_trace_file(const char *file);
+bool st_init(void);
void st_flush_trace_buffer(void);
typedef struct {
diff --git a/translate-all.c b/translate-all.c
index ab61fac66c..e9f409b762 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -55,6 +55,7 @@
#include "translate-all.h"
#include "qemu/bitmap.h"
#include "qemu/timer.h"
+#include "exec/log.h"
//#define DEBUG_TB_INVALIDATE
//#define DEBUG_FLUSH
diff --git a/util/Makefile.objs b/util/Makefile.objs
index 8620a80b45..a8a777ec40 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -31,3 +31,4 @@ util-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
util-obj-y += buffer.o
util-obj-y += timed-average.o
util-obj-y += base64.o
+util-obj-y += log.o
diff --git a/qemu-log.c b/util/log.c
index 901b93087d..46c88c93e2 100644
--- a/qemu-log.c
+++ b/util/log.c
@@ -19,6 +19,7 @@
#include "qemu-common.h"
#include "qemu/log.h"
+#include "trace/control.h"
static char *logfilename;
FILE *qemu_logfile;
@@ -51,6 +52,9 @@ void qemu_log_mask(int mask, const char *fmt, ...)
void do_qemu_set_log(int log_flags, bool use_own_buffers)
{
qemu_loglevel = log_flags;
+#ifdef CONFIG_TRACE_LOG
+ qemu_loglevel |= LOG_TRACE;
+#endif
if (qemu_loglevel && !qemu_logfile) {
if (logfilename) {
qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
@@ -151,6 +155,11 @@ int qemu_str_to_log_mask(const char *str)
for (item = qemu_log_items; item->mask != 0; item++) {
mask |= item->mask;
}
+#ifdef CONFIG_TRACE_LOG
+ } else if (strncmp(p, "trace:", 6) == 0 && p + 6 != p1) {
+ trace_enable_events(p + 6);
+ mask |= LOG_TRACE;
+#endif
} else {
for (item = qemu_log_items; item->mask != 0; item++) {
if (cmp1(p, p1 - p, item->name)) {
@@ -158,9 +167,9 @@ int qemu_str_to_log_mask(const char *str)
}
}
return 0;
+ found:
+ mask |= item->mask;
}
- found:
- mask |= item->mask;
if (*p1 != ',') {
break;
}
@@ -174,6 +183,10 @@ void qemu_print_log_usage(FILE *f)
const QEMULogItem *item;
fprintf(f, "Log items (comma separated):\n");
for (item = qemu_log_items; item->mask != 0; item++) {
- fprintf(f, "%-10s %s\n", item->name, item->help);
+ fprintf(f, "%-15s %s\n", item->name, item->help);
}
+#ifdef CONFIG_TRACE_LOG
+ fprintf(f, "trace:PATTERN enable trace events\n");
+ fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n");
+#endif
}
diff --git a/vl.c b/vl.c
index f043009f67..a7d7c39c34 100644
--- a/vl.c
+++ b/vl.c
@@ -270,10 +270,14 @@ static QemuOptsList qemu_sandbox_opts = {
static QemuOptsList qemu_trace_opts = {
.name = "trace",
- .implied_opt_name = "trace",
+ .implied_opt_name = "enable",
.head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
.desc = {
{
+ .name = "enable",
+ .type = QEMU_OPT_STRING,
+ },
+ {
.name = "events",
.type = QEMU_OPT_STRING,
},{
@@ -2988,8 +2992,7 @@ int main(int argc, char **argv, char **envp)
bool userconfig = true;
const char *log_mask = NULL;
const char *log_file = NULL;
- const char *trace_events = NULL;
- const char *trace_file = NULL;
+ char *trace_file = NULL;
ram_addr_t maxram_size;
uint64_t ram_slots = 0;
FILE *vmstate_dump_file = NULL;
@@ -3901,12 +3904,19 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_trace:
{
opts = qemu_opts_parse_noisily(qemu_find_opts("trace"),
- optarg, false);
+ optarg, true);
if (!opts) {
exit(1);
}
- trace_events = qemu_opt_get(opts, "events");
- trace_file = qemu_opt_get(opts, "file");
+ if (qemu_opt_get(opts, "enable")) {
+ trace_enable_events(qemu_opt_get(opts, "enable"));
+ }
+ trace_init_events(qemu_opt_get(opts, "events"));
+ if (trace_file) {
+ g_free(trace_file);
+ }
+ trace_file = g_strdup(qemu_opt_get(opts, "file"));
+ qemu_opts_del(opts);
break;
}
case QEMU_OPTION_readconfig:
@@ -4089,6 +4099,8 @@ int main(int argc, char **argv, char **envp)
exit(0);
}
+ trace_init_file(trace_file);
+
/* Open the logfile at this point and set the log mask if necessary.
*/
if (log_file) {
@@ -4103,12 +4115,12 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
qemu_set_log(mask);
+ } else {
+ qemu_set_log(0);
}
- if (!is_daemonized()) {
- if (!trace_init_backends(trace_events, trace_file)) {
- exit(1);
- }
+ if (!trace_init_backends()) {
+ exit(1);
}
/* If no data_dir is specified then try to find it relative to the
@@ -4652,12 +4664,6 @@ int main(int argc, char **argv, char **envp)
os_setup_post();
- if (is_daemonized()) {
- if (!trace_init_backends(trace_events, trace_file)) {
- exit(1);
- }
- }
-
main_loop();
replay_disable_events();