From patchwork Sat Apr 1 13:52:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danil Antonov X-Patchwork-Id: 9657931 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 4040060353 for ; Sat, 1 Apr 2017 13:53:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3567C285C2 for ; Sat, 1 Apr 2017 13:53:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A41328610; Sat, 1 Apr 2017 13:53:27 +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 921FE285C2 for ; Sat, 1 Apr 2017 13:53:26 +0000 (UTC) Received: from localhost ([::1]:51412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJT3-0003Od-OY for patchwork-qemu-devel@patchwork.kernel.org; Sat, 01 Apr 2017 09:53:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJSM-0003Kl-5k for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:52:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuJSJ-0002Nb-1o for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:52:42 -0400 Received: from mail-oi0-x241.google.com ([2607:f8b0:4003:c06::241]:35714) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuJSI-0002NM-QN for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:52:38 -0400 Received: by mail-oi0-x241.google.com with SMTP id d2so5864131oig.2 for ; Sat, 01 Apr 2017 06:52:38 -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=0g31vRm6ky839cL1PLh+ZO2Aib3RV7k4DOQrAXTNoQM=; b=t5Ivxshqh4oZfBI+LQk7siYuxzRT7xAaK6LxCcZZ6j/VbL4aYr4qpZGl8nKUYCf3oJ ySooeohUhUU7pyVGxsJ1sJVcQt9KCBIwlxKTZBz8+Iw5JVVd7B90sOqSlrmDYoG8GZe1 HjNKhpLWXCEwis0Yvbzb7dxMlfE/AjSTErFA/7JB3u3mFSwN536TSrxhPWQM+KxbtKiN B404tBeEt0Or+whNMAAi1gjVfJSnnafuo7SSqez5EzjTIVMuSaiuHphVSYOav274JO4B GBXZUtctURMleY7yOtAIwjmbdB9JMG3nIRI02f7lGJbkKXhqgmw15ZXZQlIuo3R0egIe 7MRw== 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=0g31vRm6ky839cL1PLh+ZO2Aib3RV7k4DOQrAXTNoQM=; b=kOHQrsIfRd6fD4wx8L3v0KymjNvjRTsKtJ53TMvegLOf+XkqF5G/jEG1CcF/0u4ZNO F3qvKI8TRsTJYCPaRN7ArftDB1uk9HvVdLJcmRzU3pYcPXyT5K0wR2YxJ+7pg17nhzkc J4r9BeAyhLRNDmpByj5PiMxIsBftVh1O+lWxvjvbeW4KLNnXLcCDaRfLLCLPryFKooUS /pyNNRPJGnnVrklkxtemMT19GkuqhYiegJovZS1cvzp17V8qf+ocMm5k9xwYo7rFObmi 5dBFWxU03Q96w4Uw3Fz0lz3DRjaSg8jWZ/+q8Oqc7xXpRS6m04D4dvGAayVHHfel9pui gMdQ== X-Gm-Message-State: AFeK/H0za5aiwkHSP5moIIcNHu2fZlY5Kpo3ccZVB8m9EysjOwnLyrWB6/dyBQN9QOEnHIYg6taKXzgpr4od8Q== X-Received: by 10.157.6.7 with SMTP id 7mr5473245otn.246.1491054758122; Sat, 01 Apr 2017 06:52:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.32.234 with HTTP; Sat, 1 Apr 2017 06:52:37 -0700 (PDT) From: Danil Antonov Date: Sat, 1 Apr 2017 16:52:37 +0300 Message-ID: To: qemu-devel@nongnu.org, jasowang@redhat.com, huth@tuxfamily.org, peter.maydell@linaro.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::241 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] [PATCH 17/43] net: 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 d01cd76d0b20ee8fa67c07da64b0e2301e510247 Mon Sep 17 00:00:00 2001 From: Danil Antonov Date: Wed, 29 Mar 2017 12:30:42 +0300 Subject: [PATCH 17/43] net: 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/net/dp8393x.c | 15 ++++++++++----- hw/net/lan9118.c | 20 ++++++++++++++------ hw/net/mcf_fec.c | 18 +++++++++++------- hw/net/stellaris_enet.c | 28 ++++++++++++++++++---------- 4 files changed, 53 insertions(+), 28 deletions(-) #define SE_INT_RX 0x01 #define SE_INT_TXER 0x02 diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index efa33ad..1236990 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -25,13 +25,13 @@ #include "qemu/timer.h" #include -//#define DEBUG_SONIC +#ifndef DEBUG_SONIC +#define DEBUG_SONIC 0 +#endif #define SONIC_PROM_SIZE 0x1000 #ifdef DEBUG_SONIC -#define DPRINTF(fmt, ...) \ -do { printf("sonic: " fmt , ## __VA_ARGS__); } while (0) static const char* reg_names[] = { "CR", "DCR", "RCR", "TCR", "IMR", "ISR", "UTDA", "CTDA", "TPS", "TFC", "TSA0", "TSA1", "TFS", "URDA", "CRDA", "CRBA0", @@ -41,10 +41,15 @@ static const char* reg_names[] = { "SR", "WT0", "WT1", "RSC", "CRCT", "FAET", "MPT", "MDT", "0x30", "0x31", "0x32", "0x33", "0x34", "0x35", "0x36", "0x37", "0x38", "0x39", "0x3a", "0x3b", "0x3c", "0x3d", "0x3e", "DCR2" }; -#else -#define DPRINTF(fmt, ...) do {} while (0) #endif +#define DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_SONIC) { \ + fprintf(stderr, "sonic: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) + #define SONIC_ERROR(fmt, ...) \ do { printf("sonic ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0) diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c index 3db8937..427160a 100644 --- a/hw/net/lan9118.c +++ b/hw/net/lan9118.c @@ -22,17 +22,25 @@ //#define DEBUG_LAN9118 +#ifndef DEBUG_LAN9118 +#define DEBUG_LAN9118 0 +#endif + #ifdef DEBUG_LAN9118 -#define DPRINTF(fmt, ...) \ -do { printf("lan9118: " fmt , ## __VA_ARGS__); } while (0) #define BADF(fmt, ...) \ do { hw_error("lan9118: error: " fmt , ## __VA_ARGS__);} while (0) #else -#define DPRINTF(fmt, ...) do {} while(0) #define BADF(fmt, ...) \ do { fprintf(stderr, "lan9118: error: " fmt , ## __VA_ARGS__);} while (0) #endif +#define DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_LAN9118) { \ + fprintf(stderr, "lan9118: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) + #define CSR_ID_REV 0x50 #define CSR_IRQ_CFG 0x54 #define CSR_INT_STS 0x58 @@ -1033,7 +1041,7 @@ static void lan9118_writel(void *opaque, hwaddr offset, s->int_sts |= val & SW_INT; break; case CSR_FIFO_INT: - DPRINTF("FIFO INT levels %08x\n", val); + DPRINTF("FIFO INT levels %08x\n", (int)val); s->fifo_int = val; break; case CSR_RX_CFG: @@ -1114,9 +1122,9 @@ static void lan9118_writel(void *opaque, hwaddr offset, if (val & 0x80000000) { if (val & 0x40000000) { s->mac_data = do_mac_read(s, val & 0xf); - DPRINTF("MAC read %d = 0x%08x\n", val & 0xf, s->mac_data); + DPRINTF("MAC read %lx = 0x%08x\n", val & 0xf, s->mac_data); } else { - DPRINTF("MAC write %d = 0x%08x\n", val & 0xf, s->mac_data); + DPRINTF("MAC write %lx = 0x%08x\n", val & 0xf, s->mac_data); do_mac_write(s, val & 0xf, s->mac_data); } } diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c index bfa6b4b..b1430ee 100644 --- a/hw/net/mcf_fec.c +++ b/hw/net/mcf_fec.c @@ -18,12 +18,16 @@ //#define DEBUG_FEC 1 -#ifdef DEBUG_FEC -#define DPRINTF(fmt, ...) \ -do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#endif +#ifndef DEBUG_FEC +#define DEBUG_FEC 0 +#endif + +#define DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_FEC) { \ + fprintf(stderr, "mcf_fec: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) #define FEC_MAX_DESC 1024 #define FEC_MAX_FRAME_SIZE 2032 @@ -557,7 +561,7 @@ static ssize_t mcf_fec_receive(NetClientState *nc, const uint8_t *buf, size_t si unsigned int buf_len; size_t retsize; - DPRINTF("do_rx len %d\n", size); + DPRINTF("do_rx len %lx\n", size); if (!s->rx_enabled) { return -1; } diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index 04bd10a..e6f5e28 100644 --- a/hw/net/stellaris_enet.c +++ b/hw/net/stellaris_enet.c @@ -13,16 +13,24 @@ //#define DEBUG_STELLARIS_ENET 1 -#ifdef DEBUG_STELLARIS_ENET -#define DPRINTF(fmt, ...) \ -do { printf("stellaris_enet: " fmt , ## __VA_ARGS__); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "stellaris_enet: error: " fmt , ## __VA_ARGS__); exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "stellaris_enet: error: " fmt , ## __VA_ARGS__);} while (0) -#endif +#ifndef DEBUG_STELLARIS_ENET +#define DEBUG_STELLARIS_ENET 0 +#endif + +#define DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_STELLARIS_ENET) { \ + fprintf(stderr, "stellaris_enet: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) + +#define BADF(fmt, ...) \ + do { \ + fprintf(stderr, "stellaris_enet: error: " fmt , ## __VA_ARGS__); \ + if (DEBUG_STELLARIS_ENET) { \ + exit(1); \ + } \ + } while (0)