From patchwork Thu Jun 23 23:14:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 101702 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 0D074B6F84 for ; Fri, 24 Jun 2011 09:14:55 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6DCF7280A1; Fri, 24 Jun 2011 01:14:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BgFP1Mokj+JU; Fri, 24 Jun 2011 01:14:53 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1BF7B280A9; Fri, 24 Jun 2011 01:14:51 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5F8FC280A9 for ; Fri, 24 Jun 2011 01:14:48 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W6L0gIK++ugE for ; Fri, 24 Jun 2011 01:14:47 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtp-out.google.com (smtp-out.google.com [74.125.121.67]) by theia.denx.de (Postfix) with ESMTPS id 2EC09280A1 for ; Fri, 24 Jun 2011 01:14:45 +0200 (CEST) Received: from kpbe14.cbf.corp.google.com (kpbe14.cbf.corp.google.com [172.25.105.78]) by smtp-out.google.com with ESMTP id p5NNEh9Q023148; Thu, 23 Jun 2011 16:14:44 -0700 Received: from sglass.mtv.corp.google.com (sglass.mtv.corp.google.com [172.22.72.144]) by kpbe14.cbf.corp.google.com with ESMTP id p5NNEg23004143; Thu, 23 Jun 2011 16:14:42 -0700 Received: by sglass.mtv.corp.google.com (Postfix, from userid 121222) id E4865140CD5; Thu, 23 Jun 2011 16:14:41 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 23 Jun 2011 16:14:33 -0700 Message-Id: <1308870873-32540-1-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.3.1 X-System-Of-Record: true Subject: [U-Boot] [PATCH v2] Add assert() for debug assertions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de assert() is like BUG_ON() but compiles to nothing unless DEBUG is defined. This is useful when a condition is an error but a board reset is unlikely to fix it, so it is better to soldier on in hope. Assertion failures should be caught during development/test. It turns out that assert() is defined separately in a few places in U-Boot with various meanings. This patch cleans up some of these. Build errors exposed by this change (and defining DEBUG) are also fixed in this patch. Signed-off-by: Simon Glass Acked-by: Mike Frysinger --- V2: * Changed macros so that all code is compiled even if DEBUG is disabled --- common/dlmalloc.c | 7 ------- include/common.h | 19 +++++++++++++++++++ include/malloc.h | 8 -------- lib/qsort.c | 5 ----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index e9bab09..f2080c6 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -286,13 +286,6 @@ extern "C" { */ -#ifdef DEBUG -#include -#else -#define assert(x) ((void)0) -#endif - - /* INTERNAL_SIZE_T is the word-size used for internal bookkeeping of chunk sizes. On a 64-bit machine, you can reduce malloc diff --git a/include/common.h b/include/common.h index 1e21b7a..6181e07 100644 --- a/include/common.h +++ b/include/common.h @@ -124,6 +124,25 @@ typedef volatile unsigned char vu_char; #define debugX(level,fmt,args...) #endif /* DEBUG */ +#ifdef DEBUG +# define _DEBUG 1 +#else +# define _DEBUG 0 +#endif + +/* + * An assertion is run-time check done in debug mode only. If DEBUG is not + * defined then it is skipped. It does not BUG or halt U-Boot, but tries to + * continue execution in any case. It is hoped that all failing assertions + * are found before release, and after release it is hoped that they don't + * matter. But in any case these failing assertions cannot be fixed with a + * BUG-type reset (which may just do the same assertion again). + */ +#define assert(x) \ + ({ if (!(x) && _DEBUG) \ + printf("Assertion failure '%s' %s line %d\n", \ + #x, __FILE__, __LINE__); }) + #define error(fmt, args...) do { \ printf("ERROR: " fmt "\nat %s:%d/%s()\n", \ ##args, __FILE__, __LINE__, __func__); \ diff --git a/include/malloc.h b/include/malloc.h index 3e145ad..ecf3c67 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -285,14 +285,6 @@ extern "C" { */ -#ifdef DEBUG -/* #include */ -#define assert(x) ((void)0) -#else -#define assert(x) ((void)0) -#endif - - /* INTERNAL_SIZE_T is the word-size used for internal bookkeeping of chunk sizes. On a 64-bit machine, you can reduce malloc diff --git a/lib/qsort.c b/lib/qsort.c index 1cc0d31..86c392c 100644 --- a/lib/qsort.c +++ b/lib/qsort.c @@ -17,11 +17,6 @@ #include #include -#if 0 -#include -#else -#define assert(arg) -#endif void qsort(void *base, size_t nel,