[PATCH v4 15/39] dyndbg: update selection of trace destination

From: Łukasz Bartosik
Date: Sat Feb 10 2024 - 18:54:02 EST


If callsite's current trace destination is '0' and user provided T flag
without trace destination name then set callsite's trace destination to
default trace destination. If a user provided trace destination name
:trace_dest_name with or without T flag then set callsite's trace
destination to the provided name. Otherwise keep callsite's current
trace destination.

The change main purpose is to preserve trace destination names (different
from '0') set previously by a user which can be later enabled with
'label' keyword.

Signed-off-by: Łukasz Bartosik <ukaszb@xxxxxxxxxxxx>
---
lib/dynamic_debug.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index f91c51234456..172497954e00 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -480,6 +480,27 @@ void update_tr_dst(const struct _ddebug *desc, const struct dd_ctrl *nctrl)
trc_tbl.buf[ndst].use_cnt++;
}

+
+/*
+ * Selects trace destination. If callsite's current trace destination is '0'
+ * and user provided T flag without trace destination name then set callsite's
+ * trace destination to default trace destination. If a user provided trace
+ * destination name :trace_dest_name with or without T flag then set callsite's
+ * trace destination to the provided name. Otherwise keep callsite's current
+ * trace destination.
+ */
+static int select_tr_dst(struct flag_settings *modifiers, int cur_dst)
+{
+ if (!cur_dst && modifiers->flags & _DPRINTK_FLAGS_TRACE &&
+ modifiers->trace_dst == DST_NOT_SET)
+ return trc_tbl.default_dst;
+
+ if (modifiers->trace_dst >= 0)
+ return modifiers->trace_dst;
+
+ return cur_dst;
+}
+
static int ddebug_parse_cmd(char *words[], int nwords)
{
if (nwords != 1)
@@ -590,8 +611,7 @@ static int ddebug_change(const struct ddebug_query *query,
nfound++;

nctrl.flags = (get_flags(dp) & modifiers->mask) | modifiers->flags;
- nctrl.trace_dst = modifiers->trace_dst == DST_NOT_SET ?
- get_trace_dst(dp) : modifiers->trace_dst;
+ nctrl.trace_dst = select_tr_dst(modifiers, get_trace_dst(dp));
if (!memcmp(&nctrl, get_ctrl(dp), sizeof(nctrl)))
continue;
#ifdef CONFIG_JUMP_LABEL
@@ -881,10 +901,6 @@ static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
break;
}

- if (modifiers->flags & _DPRINTK_FLAGS_TRACE &&
- modifiers->trace_dst == DST_NOT_SET)
- modifiers->trace_dst = trc_tbl.default_dst;
-
v3pr_info("flags=0x%x mask=0x%x, trace_dest=0x%x\n",
modifiers->flags, modifiers->mask, modifiers->trace_dst);

--
2.43.0.687.g38aa6559b0-goog