public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED
Date: Wed, 23 Mar 2022 13:13:33 -0700	[thread overview]
Message-ID: <20220323201341.3596128-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20220323201341.3596128-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This introduces DBG_IS_ENABLE macro which can be used to check if
BTD_DEBUG_FLAG_PRINT has been enabled for the current file.
---
 src/log.c | 12 ++++++++++++
 src/log.h | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/src/log.c b/src/log.c
index 0155a6bba..1157859ef 100644
--- a/src/log.c
+++ b/src/log.c
@@ -179,6 +179,18 @@ void __btd_log_init(const char *debug, int detach)
 	info("Bluetooth daemon %s", VERSION);
 }
 
+bool __btd_log_is_enabled(const char *file)
+{
+	struct btd_debug_desc *desc;
+
+	for (desc = __start___debug; desc < __stop___debug; desc++) {
+		if (desc->file && g_pattern_match_simple(file, desc->file))
+			return desc->flags & BTD_DEBUG_FLAG_PRINT;
+	}
+
+	return false;
+}
+
 void __btd_log_cleanup(void)
 {
 	closelog();
diff --git a/src/log.h b/src/log.h
index 74941beb2..e35238870 100644
--- a/src/log.h
+++ b/src/log.h
@@ -9,6 +9,7 @@
  */
 
 #include <stdint.h>
+#include <stdbool.h>
 
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
@@ -27,6 +28,7 @@ void btd_debug(uint16_t index, const char *format, ...)
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
 void __btd_toggle_debug(void);
+bool __btd_log_is_enabled(const char *file);
 
 struct btd_debug_desc {
 	const char *file;
@@ -38,6 +40,15 @@ struct btd_debug_desc {
 void __btd_enable_debug(struct btd_debug_desc *start,
 					struct btd_debug_desc *stop);
 
+/* DBG_IS_ENABLED:
+ *
+ * Simple macro that can be used to check if debug has been enabled for the
+ * __FILE__.
+ * Note: This does a lookup thus why it was not used by the likes of
+ * DBG/DBG_IDX which loads it directly from section("__debug").
+ */
+#define DBG_IS_ENABLED() __btd_log_is_enabled(__FILE__)
+
 /**
  * DBG:
  * @fmt: format string
-- 
2.35.1


  reply	other threads:[~2022-03-23 20:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 20:13 [PATCH BlueZ v3 1/9] log: Don't log __FILE__ and __func__ with DBG_IDX Luiz Augusto von Dentz
2022-03-23 20:13 ` Luiz Augusto von Dentz [this message]
2022-03-24  1:53   ` [BlueZ,v2,1/9] log: Introduce DBG_IS_ENABLED bluez.test.bot
2022-03-24 19:50   ` [PATCH BlueZ v2 1/9] " patchwork-bot+bluetooth
2022-03-23 20:13 ` [PATCH BlueZ v3 2/9] mgmt: Add DBG macro Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 3/9] mgmt: Introduce mgmt_set_verbose Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 4/9] adapter: Don't use DBG in mgmt_debug Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 5/9] att: Log file and function names Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 6/9] gatt-client: Add DBG macro Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 7/9] gatt-server: " Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 8/9] att: Rename att_debug and att_verbose to DBG and VERBOSE Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 9/9] device: Don't use DBG in gatt_debug Luiz Augusto von Dentz
2022-03-23 21:48 ` [BlueZ,v3,1/9] log: Don't log __FILE__ and __func__ with DBG_IDX bluez.test.bot
  -- strict thread matches above, loose matches on Subject: below --
2022-03-23  0:06 [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED Luiz Augusto von Dentz
2022-03-23 10:35 ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220323201341.3596128-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox