From patchwork Wed Nov 29 19:20:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13473363 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 792EF5DF2C for ; Wed, 29 Nov 2023 19:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 8F79573222 for ; Wed, 29 Nov 2023 14:21:08 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:230d:b2c9:c388:f96b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 4689973232 for ; Wed, 29 Nov 2023 14:21:08 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 1/8] log: Refactor debugging preprocessor macros. Date: Wed, 29 Nov 2023 11:20:59 -0800 Message-ID: <20231129192106.1295868-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129192106.1295868-1-gerickson@nuovations.com> References: <20231128230847.1224497-1-gerickson@nuovations.com> <20231129192106.1295868-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This refactors the debugging / debug log preprocessor-related macros. In particular, it: * Introduces CONNMAN_DEBUG_DESC_INSTANTIATE which declares and instantiates an instance of 'connman_debug_desc'. * Replaces CONNMAN_DEBUG_DEFINE with CONNMAN_DEBUG_ALIAS which declares and instantiates an alias (that is, asserts the CONNMAN_DEBUG_FLAG_ALIAS flag) instance of 'connmand_debug_desc', using CONNMAN_DEBUG_DESC_INSTANTIATE. * Redefines 'DBG' against 'CONNMAN_DEBUG_DESC_INSTANTIATE' with '__func__' as the function parameter. --- include/log.h | 28 +++++++++++++++++----------- src/log.c | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/log.h b/include/log.h index 8b00e9dc979c..a9b0f17f392b 100644 --- a/include/log.h +++ b/include/log.h @@ -58,11 +58,17 @@ struct connman_debug_desc { unsigned int flags; } __attribute__((aligned(8))); -#define CONNMAN_DEBUG_DEFINE(name) \ - static struct connman_debug_desc __debug_alias_ ## name \ +#define CONNMAN_DEBUG_DESC_INSTANTIATE(symbol, _name, _file, _flags) \ + static struct connman_debug_desc symbol \ __attribute__((used, section("__debug"), aligned(8))) = { \ - #name, __FILE__, CONNMAN_DEBUG_FLAG_ALIAS \ - }; + .name = _name, .file = _file, .flags = _flags \ + } + +#define CONNMAN_DEBUG_ALIAS(suffix) \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__debug_alias_##suffix, \ + #suffix, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_ALIAS) /** * DBG: @@ -73,13 +79,13 @@ struct connman_debug_desc { * name it is called in. */ #define DBG(fmt, arg...) do { \ - static struct connman_debug_desc __connman_debug_desc \ - __attribute__((used, section("__debug"), aligned(8))) = { \ - .file = __FILE__, .flags = CONNMAN_DEBUG_FLAG_DEFAULT, \ - }; \ - if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ - connman_debug("%s:%s() " fmt, \ - __FILE__, __FUNCTION__ , ## arg); \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__connman_debug_desc, \ + 0, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_DEFAULT); \ + if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ + connman_debug("%s:%s() " fmt, \ + __FILE__, __func__, ##arg); \ } while (0) #ifdef __cplusplus diff --git a/src/log.c b/src/log.c index 554b046b07fa..f7483194b230 100644 --- a/src/log.c +++ b/src/log.c @@ -38,7 +38,7 @@ static const char *program_exec; static const char *program_path; /* This makes sure we always have a __debug section. */ -CONNMAN_DEBUG_DEFINE(dummy); +CONNMAN_DEBUG_ALIAS(dummy); /** * connman_info: