blob: b8680cce40639b7662ee281df8129ea272cd5881 [file] [log] [blame]
From 5fef0dd30c0f37198bf6f32f5e039617c05ce144 Mon Sep 17 00:00:00 2001
From: Alain Michaud <alainm@chromium.org>
Date: Mon, 6 Jul 2020 15:05:43 +0000
Subject: [PATCH] FROMLIST: Bluetooth: create CONFIG_BT_DEBUG_FEATURE_FUNC_NAME
Creates a CONFIG_BT_DEBUG_FEATURE_FUNC_NAME option to include function names in
debug statements.
Unlike other platforms __func__ isn't a string literal so it cannot be
automatically concatenated by the pre-processor. As a result, the
function name is passed as a parameter to the tracing function. Since
pr_debug is a function like macro, the normal expansion of BT_PREFIX_PARAM
does not work as it gets processed within the first parameter as well,
for this reason, BT_DBG is split into two versions.
This patch was built tested with all 4 possible combinations of
CONFIG_BT_DEBUG_FUNC_NAME and CONFIG_BT_FEATURE_DEBUG configurations.
Signed-off-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Archie Pusaka <apusaka@chromium.org>
(am from https://patchwork.kernel.org/patch/11649947/)
BUG=b:148227743
TEST=Built with and without CONFIG_BT_DEBUG_FUNC_NAME enabled and
validate the proper trace statement format is used.
Signed-off-by: Alain Michaud <alainm@chromium.org>
Change-Id: I82c636d3c7be67a4bc8fc22042b61efd6debd43a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2285367
Reviewed-by: Manish Mandlik <mmandlik@chromium.org>
[rebase510(groeck): Context conflicts (BT_ERR_RATELIMITED is gone)]
Signed-off-by: Guenter Roeck <groeck@chromium.org>
---
include/net/bluetooth/bluetooth.h | 29 +++++++++++++++++++++--------
net/bluetooth/Kconfig | 11 +++++++++++
2 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 6b48d9e2aab9..a5f7e4c3791e 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -188,22 +188,33 @@ void bt_dbg_set(bool enable);
bool bt_dbg_get(void);
__printf(1, 2)
void bt_dbg(const char *fmt, ...);
+#define BT_DBG_INT bt_dbg
+#else
+#define BT_DBG_INT pr_debug
#endif
__printf(1, 2)
void bt_warn_ratelimited(const char *fmt, ...);
__printf(1, 2)
void bt_err_ratelimited(const char *fmt, ...);
-#define BT_INFO(fmt, ...) bt_info(fmt "\n", ##__VA_ARGS__)
-#define BT_WARN(fmt, ...) bt_warn(fmt "\n", ##__VA_ARGS__)
-#define BT_ERR(fmt, ...) bt_err(fmt "\n", ##__VA_ARGS__)
-
-#if IS_ENABLED(CONFIG_BT_FEATURE_DEBUG)
-#define BT_DBG(fmt, ...) bt_dbg(fmt "\n", ##__VA_ARGS__)
+#if IS_ENABLED(CONFIG_BT_FEATURE_DEBUG_FUNC_NAMES)
+#define BT_PREFIX "%s() "
+#define BT_PREFIX_PARAM ,__func__
+#define BT_DBG(fmt, ...) \
+ BT_DBG_INT(BT_PREFIX fmt "\n", __func__, ##__VA_ARGS__)
#else
-#define BT_DBG(fmt, ...) pr_debug(fmt "\n", ##__VA_ARGS__)
+#define BT_PREFIX
+#define BT_PREFIX_PARAM
+#define BT_DBG(fmt, ...) BT_DBG_INT(fmt "\n", ##__VA_ARGS__)
#endif
+#define BT_INFO(fmt, ...) \
+ bt_info(BT_PREFIX fmt "\n" BT_PREFIX_PARAM, ##__VA_ARGS__)
+#define BT_WARN(fmt, ...) \
+ bt_warn(BT_PREFIX fmt "\n" BT_PREFIX_PARAM, ##__VA_ARGS__)
+#define BT_ERR(fmt, ...) \
+ bt_err(BT_PREFIX fmt "\n" BT_PREFIX_PARAM, ##__VA_ARGS__)
+
#define bt_dev_name(hdev) ((hdev) ? (hdev)->name : "null")
#define bt_dev_info(hdev, fmt, ...) \
@@ -216,7 +227,9 @@ void bt_err_ratelimited(const char *fmt, ...);
BT_DBG("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
#define bt_dev_warn_ratelimited(hdev, fmt, ...) \
- bt_warn_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
+ bt_warn_ratelimited("%s: " BT_PREFIX fmt, bt_dev_name(hdev) \
+ BT_PREFIX_PARAM, ##__VA_ARGS__)
+
#define bt_dev_err_ratelimited(hdev, fmt, ...) \
bt_err_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig
index e0ab4cd7afc3..69ab66672138 100644
--- a/net/bluetooth/Kconfig
+++ b/net/bluetooth/Kconfig
@@ -148,4 +148,15 @@ config BT_FEATURE_DEBUG
This provides an option to enable/disable debugging statements
at runtime via the experimental features interface.
+config BT_FEATURE_DEBUG_FUNC_NAMES
+ bool "Include function names in debugging statements"
+ depends on BT_FEATURE_DEBUG
+ default n
+ help
+ Provides an option to include function names in debugging
+ statements.
+
+ When enabled, trace statements will include the function name as a
+ prefix which may help identify the source code references.
+
source "drivers/bluetooth/Kconfig"
--
2.35.0