Skip to contentSkip to conversation

misc: Allow selective disabling of debug facility names

PATCH In review Glenn Washburn 2 participants 2 messages Jan 2, 2022 – Jan 13, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 misc: Allow selective disabling of debug facility names

Sometimes you only know which debug logging facility names you want to turn off, not necessarily all the ones you want enabled. This patch allows the debug string to contain facility names in the $debug variable which are prefixed with a "-" to disable debug log messages for that conditional. Say you want all debug logging on except for btrfs and scripting, then do:
"set debug=all,-btrfs,-scripting"

Note, that only the last occurence of the facility name with or without a leading "-" is considered. So simply appending ",-facilityname" to the $debug variable will disable that conditional. To illustrate, the command "set debug=all,-btrfs,-scripting,btrfs" will enable btrfs.

Also, add documentation explaining this new behavior.

---
Range-diff against v3:
1: 31439a7fb ! 1: b5165ba45 misc: Allow selective disabling of debug facility names
@@ Metadata
## Commit message ##
misc: Allow selective disabling of debug facility names

- Sometimes you know only know which debug logging facility names you want to
+ Sometimes you only know which debug logging facility names you want to
turn off, not necessarily all the ones you want enabled. This patch allows the debug string to contain facility names in the $debug variable which are prefixed with a "-" to disable debug log messages for that conditional. Say
@@ docs/grub.texi: processed by commands @command{configfile} (@pxref{configfile})
-whitespace or @samp{,}, or @samp{all} to enable all available debugging -output. The facility names are the first argument to grub_dprintf. Consult +of GRUB. The value is an ordered list of debug facility names separated by
-+whitespace or @samp{,}. If the special facility names @samp{all} is present ++whitespace or @samp{,}. If the special facility named @samp{all} is present
+then debugging output of all facility names is enabled at the start of +processing the value of this variable. A facility's debug output can then be +disabled by prefixing its name with a @samp{-}. The last occurence facility
@@ grub-core/kern/misc.c: __attribute__ ((alias("grub_printf")));
+ continue;
+
+ /*
-+ * If found condition is at the start of debug, then enable debug. Else
-+ * if found condition is prefixed with '-' and the start is on a word
-+ * boundary, then disable debug. Otherwise, if the start is on a word
-+ * boundary, enable debug. If none of these cases, ignore.
++ * If found condition is at the start of debug or the start is on a word
++ * boundary, then enable debug. Else if found condition is prefixed with
++ * '-' and the start is on a word boundary, then disable debug. If none
++ * of these cases, ignore.
+ */
-+ if (found == debug)
++ if (found == debug || *(found - 1) == ',' || grub_isspace (*(found - 1)))
+ ret = 1;
-+ else if (*(found-1) == '-' && ((found == debug + 1) || (*(found-2) == ','
-+ || grub_isspace (*(found-2)))))
++ else if (*(found - 1) == '-' && ((found == debug + 1) || (*(found - 2) == ','
++ || grub_isspace (*(found - 2)))))
+ ret = 0;
-+ else if (*(found-1) == ',' || grub_isspace (*(found-1)))
-+ ret = 1;
+ }
+
+ return ret;

 docs/grub.texi        | 13 ++++++++++---
 grub-core/kern/misc.c | 41 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 47 insertions(+), 7 deletions(-)
docs/grub.texi +10 -3
index 99d0a0149..22efbd297 100644
@@ -3388,9 +3388,16 @@ processed by commands @command{configfile} (@pxref{configfile}) or @command{norm
 @subsection debug
 
 This variable may be set to enable debugging output from various components
-of GRUB.  The value is a list of debug facility names separated by
-whitespace or @samp{,}, or @samp{all} to enable all available debugging
-output. The facility names are the first argument to grub_dprintf. Consult
+of GRUB. The value is an ordered list of debug facility names separated by
+whitespace or @samp{,}. If the special facility named @samp{all} is present
+then debugging output of all facility names is enabled at the start of
+processing the value of this variable. A facility's debug output can then be
+disabled by prefixing its name with a @samp{-}. The last occurence facility
+name with or without a leading @samp{-} takes precendent over any previous
+occurence. This allows the easy enabling or disabling of facilities by
+appending a @samp{,} and then the facility name with or without the leading
+@samp{-}, which will preserve the state of the rest of the facilities.
+The facility names are the first argument to grub_dprintf. Consult the
 source for more details.
 
 
grub-core/kern/misc.c +37 -4

53 lines not on this page · raw message

Signature · 1 line
2.27.0
Reviewed-by on v4 1/1
#1 lore raw
Quoted 7 lines · Glenn Washburn

Sometimes you only know which debug logging facility names you want to turn off, not necessarily all the ones you want enabled. This patch allows the debug string to contain facility names in the $debug variable which are prefixed with a "-" to disable debug log messages for that conditional. Say you want all debug logging on except for btrfs and scripting, then do:
"set debug=all,-btrfs,-scripting"

Quoted 8 lines

Note, that only the last occurence of the facility name with or without a leading "-" is considered. So simply appending ",-facilityname" to the $debug variable will disable that conditional. To illustrate, the command "set debug=all,-btrfs,-scripting,btrfs" will enable btrfs.

Also, add documentation explaining this new behavior.

Daniel