From patchwork Sat Apr 1 14:03:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danil Antonov X-Patchwork-Id: 9658015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF66360349 for ; Sat, 1 Apr 2017 14:04:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D615728481 for ; Sat, 1 Apr 2017 14:04:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C864728616; Sat, 1 Apr 2017 14:04:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 68D8028481 for ; Sat, 1 Apr 2017 14:04:59 +0000 (UTC) Received: from localhost ([::1]:51511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJeE-0002hO-Fh for patchwork-qemu-devel@patchwork.kernel.org; Sat, 01 Apr 2017 10:04:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJcs-0002W2-77 for qemu-devel@nongnu.org; Sat, 01 Apr 2017 10:03:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuJcq-0007lH-W8 for qemu-devel@nongnu.org; Sat, 01 Apr 2017 10:03:34 -0400 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]:36089) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuJcq-0007ky-Om for qemu-devel@nongnu.org; Sat, 01 Apr 2017 10:03:32 -0400 Received: by mail-oi0-x244.google.com with SMTP id b187so13231837oif.3 for ; Sat, 01 Apr 2017 07:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=g12Nhv7mzL7UGL8IhZzd17HJC70cyTKB3jx26rmnpNk=; b=YuwOpC6iI8G3gmsSt65RyP1sNO7Z3abWedFpZqTlJWWzzpzJiKwjyNLYrrNhKkl9tH skVjGcgCJDATL0U9Nhw72bNwmp9gwCJPu455PQtpG7v8itiULXYWoNfQZuNyLAhPIe0Q ahAEhqFYszOYILYLDdSHSRvmvZ9eQnVPS7njtu7YdF8rhyl6y1pT6pzLpdq8bPNuU0Wg f9LKWWthU3wVKHUv378H3Ryyo41wew4laHpyCukAE51YJBOkPhd53l14dvL00axzC5Bm oSMAHoVbhh3cb+2uDwp5x4iCGTSSzzXOk+MFPlZPlT65Hrd6fv2uzuMFYeohKLJFynUh 4i5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=g12Nhv7mzL7UGL8IhZzd17HJC70cyTKB3jx26rmnpNk=; b=W+AxweJF8AfD1rzcl3VDgq/cbtmkPMhpVhOHHZXf9kVC9+NgBjmE2VMi4lbeg9uNdS N94NGy3qygUQkiXjhNxBQx/5urds2zTcxJpDodxzZu0HHP5UepvvDYjlrYQVRnQT0DYC s5GMM6f95D4MmOH+T2VuvkBQW3rWuRrWzHAep644hWRydIRNyo0WprJ5d2bOBI/9t7+I QfAKQPJ8k8O3AWtZMOTinBwj+QSvtW032TNABfIma45rrXM92MCob41nDlViGqSUaX6C cJw1X80A7bFB9ckR0wu/kZHn4lMo/VPp6PmqcGN0u86xoqkkmriV9RQanKcXe7BNFydO bykg== X-Gm-Message-State: AFeK/H1qBiyFt8/73CsEp4REQ+JCyfQG7eAXwbR7g5ILnzeNoxuRqbXlT+6x8LAVJELmdGwjvczp2PWnMB64Gg== X-Received: by 10.157.27.44 with SMTP id l41mr4988256otl.103.1491055411838; Sat, 01 Apr 2017 07:03:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.32.234 with HTTP; Sat, 1 Apr 2017 07:03:31 -0700 (PDT) From: Danil Antonov Date: Sat, 1 Apr 2017 17:03:31 +0300 Message-ID: To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::244 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] [PATCH 32/43] char: made printf always compile in debug output X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From 9147a39cc2dabe76e7c1b38e801069390d5a3321 Mon Sep 17 00:00:00 2001 From: Danil Antonov Date: Wed, 29 Mar 2017 12:40:02 +0300 Subject: [PATCH 32/43] char: made printf always compile in debug output Wrapped printf calls inside debug macros (DPRINTF) in `if` statement. This will ensure that printf function will always compile even if debug output is turned off and, in turn, will prevent bitrot of the format strings. Signed-off-by: Danil Antonov --- hw/char/ipoctal232.c | 24 +++++++++++++----------- hw/char/serial.c | 16 +++++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c index 93929c2..180d8f7 100644 --- a/hw/char/ipoctal232.c +++ b/hw/char/ipoctal232.c @@ -13,14 +13,16 @@ #include "qemu/bitops.h" #include "sysemu/char.h" -/* #define DEBUG_IPOCTAL */ -#ifdef DEBUG_IPOCTAL -#define DPRINTF2(fmt, ...) \ - do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) -#else -#define DPRINTF2(fmt, ...) do { } while (0) -#endif +#ifndef DEBUG_IPOCTAL +#define DEBUG_IPOCTAL 0 +#endif + +#define DPRINTF2(fmt, ...) do { \ + if (DEBUG_IPOCTAL) { \ + fprintf(stderr, fmt, ## __VA_ARGS__); \ + } \ +} while (0); #define DPRINTF(fmt, ...) DPRINTF2("IP-Octal: " fmt, ## __VA_ARGS__) @@ -504,11 +506,11 @@ static void hostdev_event(void *opaque, int event) SCC2698Channel *ch = opaque; switch (event) { case CHR_EVENT_OPENED: - DPRINTF("Device %s opened\n", ch->dev->label); + DPRINTF("Device %s opened\n", ch->dev.chr->label); break; case CHR_EVENT_BREAK: { uint8_t zero = 0; - DPRINTF("Device %s received break\n", ch->dev->label); + DPRINTF("Device %s received break\n", ch->dev.chr->label); if (!(ch->sr & SR_BREAK)) { IPOctalState *dev = ch->ipoctal; @@ -528,7 +530,7 @@ static void hostdev_event(void *opaque, int event) } break; default: - DPRINTF("Device %s received event %d\n", ch->dev->label, event); + DPRINTF("Device %s received event %d\n", ch->dev.chr->label, event); } } @@ -546,7 +548,7 @@ static void ipoctal_realize(DeviceState *dev, Error **errp) qemu_chr_fe_set_handlers(&ch->dev, hostdev_can_receive, hostdev_receive, hostdev_event, ch, NULL, true); - DPRINTF("Redirecting channel %u to %s\n", i, ch->dev->label); + DPRINTF("Redirecting channel %u to %s\n", i, ch->dev.chr->label); } else { DPRINTF("Could not redirect channel %u, no chardev set\n", i); } diff --git a/hw/char/serial.c b/hw/char/serial.c index 03d890c..9421c7a 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -97,13 +97,15 @@ #define MAX_XMIT_RETRY 4 -#ifdef DEBUG_SERIAL -#define DPRINTF(fmt, ...) \ -do { fprintf(stderr, "serial: " fmt , ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) \ -do {} while (0) -#endif +#ifndef DEBUG_SERIAL +#define DEBUG_SERIAL 0 +#endif + +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_SERIAL) { \ + fprintf(stderr, "serial: " fmt , ## __VA_ARGS__); \ + } \ +} while (0); static void serial_receive1(void *opaque, const uint8_t *buf, int size); static void serial_xmit(SerialState *s);