From patchwork Tue Feb 13 14:00:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 128236 Delivered-To: patches@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4280619ljc; Tue, 13 Feb 2018 06:00:31 -0800 (PST) X-Google-Smtp-Source: AH8x225ZTDbnaOhZ4u6O3NgL9Y7fP62asvPoUZnYGS7lNNZEdFG23mW2czXqC99yb8ELJwMXs5xF X-Received: by 10.28.53.138 with SMTP id c132mr1312836wma.108.1518530431661; Tue, 13 Feb 2018 06:00:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518530431; cv=none; d=google.com; s=arc-20160816; b=mWKInVRi0NJ/437K/6PIEJoZf8nZ4wuwRFYf1L25XA/r4AGhuclaWP3AfiPwC/WB7c c0G9Wykcw05bEnxLamm3ypS7PUxgxA5JCpuTJimnbpagE1WNt2Pq06RH47OW8iL1eoQG 2pxLcX6T9P6NtThnyqnS97kwXCSfbJ64SBv8aE2K0/0amvuPXhCiX2ShmPrDnPgWN1PN 0fHNVCvv60B/rLjVmIpsv9LIGS9ufVMoZCr5WPkecIGU121Ot2KT5WYo8+FcVcQgrN9Y JI+FWBrv2tMEDszDns79uGdSDw9Y3olfSk3LQOO4DFc0kELIVIcIJKgKC2czc88uL7qj hqow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=ZAqpwvTkYrylmKsQOYPvjR4+l9COBJh5XHzz4RyZDVo=; b=Wl2sYu4+5+gfH4z+2BMuM8U90ngBwdo2D/aeG6l2Y+NNSqOenXb58gXea6ppViFFTf GtS4rGe0YQYQo7vJatQJQ3cHicU9yhgnjrkowcC+RV5ljrB/OJ6ISzxHGPsYzHGlWZtf fT3IQB8voKkJyvXHdM4id3XfYGEH/TnVLuqx5T7r0xXeWOW/Daydedpn6K8LmtUBd/5/ kTscTnfuNmijcSI7MvlJa8swS1NzcDdQMWwr5XZaigUoSzPbta9nJFTU4RRKRvtW5FtS tHybByRrbB0Gk0TQj2CwsDnqkhhPfm8GwLq1p5zQZjgXfdDHRORFu48hd1BqHcfgwlPg s3xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id l17si6605992wrg.119.2018.02.13.06.00.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Feb 2018 06:00:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1elb8I-0008HF-5r; Tue, 13 Feb 2018 14:00:30 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Stefan Hajnoczi Subject: [PATCH] log-for-trace.h: Split out parts of log.h used by trace.h Date: Tue, 13 Feb 2018 14:00:29 +0000 Message-Id: <20180213140029.8308-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.1 A persistent build problem we see is where a source file accidentally omits the #include of log.h. This slips through local developer testing because if you configure with the default (log) trace backend trace.h will pull in log.h for you. Compilation fails only if some other backend is selected. To make this error cause a compile failure regardless of the configured trace backend, split out the parts of log.h that trace.h requires into a new log-for-trace.h header. Since almost all manual uses of the log.h functions will use constants or functions which aren't in log-for-trace.h, this will let us catch missing #include "qemu/log.h" more consistently. Signed-off-by: Peter Maydell --- include/qemu/log-for-trace.h | 35 +++++++++++++++++++++++++++++++++++ include/qemu/log.h | 18 ++++-------------- scripts/tracetool/backend/log.py | 13 ++++++------- 3 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 include/qemu/log-for-trace.h -- 2.16.1 Reviewed-by: Eric Blake Reviewed-by: Richard Henderson diff --git a/include/qemu/log-for-trace.h b/include/qemu/log-for-trace.h new file mode 100644 index 0000000000..2f0a5b080e --- /dev/null +++ b/include/qemu/log-for-trace.h @@ -0,0 +1,35 @@ +/* log-for-trace.h: logging basics required by the trace.h generated + * by the log trace backend. + * + * This should not be included directly by any .c file: if you + * need to use the logging functions include "qemu/log.h". + * + * The purpose of splitting these parts out into their own header + * is to catch the easy mistake where a .c file includes trace.h + * but forgets to include qemu/log.h. Without this split, that + * would result in the .c file compiling fine when the default + * trace backend is in use but failing to compile with any other + * backend. + * + * This code is licensed under the GNU General Public License, + * version 2 or (at your option) any later version. + */ + +#ifndef QEMU_LOG_FOR_TRACE_H +#define QEMU_LOG_FOR_TRACE_H + +/* Private global variable, don't use */ +extern int qemu_loglevel; + +#define LOG_TRACE (1 << 15) + +/* Returns true if a bit is set in the current loglevel mask */ +static inline bool qemu_loglevel_mask(int mask) +{ + return (qemu_loglevel & mask) != 0; +} + +/* main logging function */ +int GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); + +#endif diff --git a/include/qemu/log.h b/include/qemu/log.h index a50e994c21..ff92a8b86a 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -1,10 +1,11 @@ #ifndef QEMU_LOG_H #define QEMU_LOG_H +/* A small part of this API is split into its own header */ +#include "qemu/log-for-trace.h" -/* Private global variables, don't use */ +/* Private global variable, don't use */ extern FILE *qemu_logfile; -extern int qemu_loglevel; /* * The new API: @@ -41,16 +42,9 @@ 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) +/* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1 << 16) -/* Returns true if a bit is set in the current loglevel mask - */ -static inline bool qemu_loglevel_mask(int mask) -{ - return (qemu_loglevel & mask) != 0; -} - /* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we * assume that qemu_loglevel_mask has already been tested, and that @@ -69,10 +63,6 @@ static inline void qemu_log_unlock(void) /* Logging functions: */ -/* main logging function - */ -int GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); - /* vfprintf-like logging function */ static inline void GCC_FMT_ATTR(1, 0) diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py index da86f6b882..78933d03ad 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -20,7 +20,7 @@ PUBLIC = True def generate_h_begin(events, group): - out('#include "qemu/log.h"', + out('#include "qemu/log-for-trace.h"', '') @@ -35,14 +35,13 @@ def generate_h(event, group): else: cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) - out(' if (%(cond)s) {', + out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {', ' struct timeval _now;', ' gettimeofday(&_now, NULL);', - ' 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);', + ' qemu_log("%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",', + ' getpid(),', + ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', + ' %(argnames)s);', ' }', cond=cond, name=event.name,