Miscellaneous changes to aid in troubleshooting
cover Miscellaneous changes to aid in troubleshooting
These are pretty self-explanatory. They've been useful in debugging grub issues. Note that patch #2 and #3 are particularly synergistic.
Also a note about patch #4. It was used in a version of patch #3, though not any more. I decided to leave it in this patch series because it enhances grub_strword without any downsides (that I'm aware of).
Glenn
Glenn Washburn (4):
error: Add grub_errno to printed error message
misc: Add debug log condition to log output
misc: Allow selective disabling of debug conditionals
misc: Change grub_strword to return a string like grub_strstr
grub-core/kern/err.c | 2 +- grub-core/kern/misc.c | 22 +++++++++++++++++----- grub-core/loader/xnu.c | 7 ++++--- include/grub/misc.h | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/4 error: Add grub_errno to printed error message
--- grub-core/kern/err.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/err.c +1 -1
@@ -107,7 +107,7 @@ grub_print_error (void) {if (grub_errno !=GRUB_ERR_NONE ) { -grub_err_printf (_ ("error: %s.\n" ), grub_errmsg); +grub_err_printf (_ ("error: [%d] %s.\n" ), grub_errno, grub_errmsg); grub_err_printed_errors++; } }
Signature · 1 line
2.27.0
PATCH 2/4 misc: Add debug log condition to log output
In reply to Glenn WashburnWhen debugging using the "all" condition frequently gives way too much info. So selecting a subset of conditions is desirable. This change makes it easier to identify which conditions are desired. Before this change log messages needed to be looked up in the source code to find the condition used.
--- grub-core/kern/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/misc.c +1 -1
@@ -182,7 +182,7 @@ grub_real_dprintf (const char *file, const int line, const char *condition,if (grub_debug_enabled (condition)) { -grub_printf ("%s:%d: " , file, line); +grub_printf ("%s:%d:%s: " , file, line, condition);va_start (args, fmt);grub_vprintf (fmt, args);va_end (args);
Signature · 1 line
2.27.0
PATCH 3/4 misc: Allow selective disabling of debug conditionals
In reply to Glenn WashburnSometimes you know only know which debug logging conditionals you want to turn off. Now debug log messages can be excluded by specifying the conditional in the $debug string with a prepended dash. So say you want all debug logging on except for btrfs and scripting, then set debug=all,-btrfs,-scripting.
--- grub-core/kern/misc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
grub-core/kern/misc.c +13 -1
@@ -168,7 +168,19 @@ grub_debug_enabled (const char * condition)if (!debug)return 0 ; -if (grub_strword (debug,"all" ) ||grub_strword (debug, condition)) +if (grub_strword (debug,"all" )) + { +if (debug[3 ] =='\0' ) +return 1 ; +const char *ptr =NULL ; + ptr =grub_strstr (debug, condition); +if (ptr > debug && *(ptr-1 ) =='-' + && (*(ptr +grub_strlen (condition)) =='\0' + ||grub_iswordseparator (*(ptr +grub_strlen (condition))))) +return 0 ; +return 1 ; + } +else if (grub_strword (debug, condition))return 1 ;return 0 ;
Signature · 1 line
2.27.0
PATCH 4/4 misc: Change grub_strword to return a string like grub_strstr
In reply to Glenn WashburnThis makes grub_strword more versatile. All code as of this change using grub_strword uses it in a conditional or boolean operator context where its return value would be silently converted to a 1 or 0, so this does not affect current usage. A few lines in loader/xnu.c have been changed to enhance clarity there.
--- grub-core/kern/misc.c | 6 +++--- grub-core/loader/xnu.c | 7 ++++--- include/grub/misc.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-)
grub-core/kern/misc.c +3 -3
@@ -320,7 +320,7 @@ grub_strrchr (const char *s, int c)return p; } -int +char *grub_strword (const char *haystack,const char *needle) {const char *n_pos = needle;
@@ -343,7 +343,7 @@ grub_strword (const char *haystack, const char *needle)next word (or the end of string) and "reset" the needle. */ if ( (!*haystack ||grub_iswordseparator (*haystack)) && (!*n_pos ||grub_iswordseparator (*n_pos))) -return 1 ; +return (char *)(haystack - (n_pos - needle));else { n_pos = needle;
@@ -354,7 +354,7 @@ grub_strword (const char *haystack, const char *needle) } } -return 0 ; +return NULL ; }int
grub-core/loader/xnu.c +4 -3
@@ -975,7 +975,8 @@ grub_xnu_check_os_bundle_required (char *plistname,/* Set the return value for the case when no OSBundleRequired tag is found. */ if (osbundlereq) - ret =grub_strword (osbundlereq,"all" ) ||grub_strword (osbundlereq,"-" ); + ret =grub_strword (osbundlereq,"all" ) !=0 + ||grub_strword (osbundlereq,"-" ) !=0 ;else ret =1 ;
@@ -996,8 +997,8 @@ grub_xnu_check_os_bundle_required (char *plistname, {for (ptr2 = stringptr; *ptr2; ptr2++) *ptr2 =grub_tolower (*ptr2); - ret =grub_strword (osbundlereq, stringptr) - ||grub_strword (osbundlereq,"all" ); + ret =grub_strword (osbundlereq, stringptr) !=0 + ||grub_strword (osbundlereq,"all" ) !=0 ; }if (stringptr && binnamekeyfound && binname && depth ==4 ) {
include/grub/misc.h +1 -1
@@ -85,7 +85,7 @@ int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t n);char *EXPORT_FUNC (grub_strchr ) (const char *s,int c);char *EXPORT_FUNC (grub_strrchr ) (const char *s,int c); -int EXPORT_FUNC (grub_strword ) (const char *s,const char *w); +char *EXPORT_FUNC (grub_strword ) (const char *s,const char *w);/* Copied from gnulib. Written by Bruno Haible <[email protected]>, 2005. */
Signature · 1 line
2.27.0