Skip to contentSkip to conversation

Print out load addresses for .text and .data

PATCH Superseded Robbie Harwood 3 participants 12 messages Oct 11, 2021 – Oct 20, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Print out load addresses for .text and .data

Hi,

These patches display (in format that can be copy/pasted to gdb) the virtual addresses of grub-core/kernel.exec (and any modules it loads).

First patch is prep work - adds a print without numbering. The second patch is better with this call, since it makes copy/pasting easier.

(These have been downstream for just over six years now.)

Be well,
--Robbie

Peter Jones (2):
Add grub_qdprintf() - grub_dprintf() without the file+line number. Make a "gdb" dprintf that tells us load addresses.

 grub-core/kern/dl.c       | 50 +++++++++++++++++++++++++++++++++++++++
 grub-core/kern/efi/efi.c  |  4 ++--
 grub-core/kern/efi/init.c | 26 +++++++++++++++++++-
 grub-core/kern/misc.c     | 18 ++++++++++++++
 include/grub/efi/efi.h    |  2 +-
 include/grub/misc.h       |  2 ++
 6 files changed, 98 insertions(+), 4 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/2 Add grub_qdprintf() - grub_dprintf() without the file+line number.

From: Peter Jones <[email protected]>

This just makes copy+paste of our debug loading info easier.

---
 grub-core/kern/misc.c | 18 ++++++++++++++++++
 include/grub/misc.h   |  2 ++
 2 files changed, 20 insertions(+)
grub-core/kern/misc.c +18 -0
index 3af336ee2..633fb48ec 100644
@@ -190,6 +190,24 @@ grub_real_dprintf (const char *file, const int line, const char *condition,
     }
 }
 
+void
+grub_qdprintf (const char *condition, const char *fmt, ...)
+{
+  va_list args;
+  const char *debug = grub_env_get ("debug");
+
+  if (! debug)
+    return;
+
+  if (grub_strword (debug, "all") || grub_strword (debug, condition))
+    {
+      va_start (args, fmt);
+      grub_vprintf (fmt, args);
+      va_end (args);
+      grub_refresh ();
+    }
+}
+
 #define PREALLOC_SIZE 255
 
 int
include/grub/misc.h +2 -0
index 7d2b55196..b9b22b2ec 100644
@@ -345,6 +345,8 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file,
                                      const int line,
                                      const char *condition,
                                      const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5)));
+void EXPORT_FUNC(grub_qdprintf) (const char *condition,
+				 const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 2, 3)));
 int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
 int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...)
      __attribute__ ((format (GNU_PRINTF, 3, 4)));
Signature · 1 line
2.33.0
#2 lore raw

Re: [PATCH 1/2] Add grub_qdprintf() - grub_dprintf() without the file+line number.

Quoted 19 lines · On Mon, 11 Oct 2021 14:48:43 -0400 Robbie Harwood <[email protected]> wrote:

From: Peter Jones <[email protected]>

This just makes copy+paste of our debug loading info easier.

---
 grub-core/kern/misc.c | 18 ++++++++++++++++++
 include/grub/misc.h   |  2 ++
 2 files changed, 20 insertions(+)
grub-core/kern/misc.c +0 -0
index 3af336ee2..633fb48ec 100644
@@ -190,6 +190,24 @@ grub_real_dprintf (const char *file, const int line, const char *condition,
     }
 }
 

grub-core/kern/misc.c grub_real_dprintf (const char *file, const int line, const char *condition, · line 202

Quoted 10 lines
grub-core/kern/misc.c +10 -0
+void
+grub_qdprintf (const char *condition, const char *fmt, ...)
+{
+  va_list args;
+  const char *debug = grub_env_get ("debug");
+
+  if (! debug)
+    return;
+
+  if (grub_strword (debug, "all") || grub_strword (debug, condition))

Is there a good reason why this is done like this instead of using grub_debug_enabled as in grub_real_dprintf.

grub-core/kern/misc.c grub_real_dprintf (const char *file, const int line, const char *condition, · line 208

Quoted 6 lines
grub-core/kern/misc.c +6 -0
+    {
+      va_start (args, fmt);
+      grub_vprintf (fmt, args);
+      va_end (args);
+      grub_refresh ();
+    }

I don't particularly like, that this function is mostly a copy of grub_real_dprintf. What about modifying grub_real_dprintf to not print the file:line if file == NULL? Then have grub_qdprintf be a macro to grub_real_dprintf as grub_dprintf is. This would obviate the concern above.

Quoted 10 lines
grub-core/kern/misc.c +2 -0
+}
+
 #define PREALLOC_SIZE 255
 
 int
include/grub/misc.h +0 -0
index 7d2b55196..b9b22b2ec 100644

include/grub/misc.h void EXPORT_FUNC(grub_real_dprintf) (const char *file, · line 352

Quoted 8 lines
include/grub/misc.h +2 -0
@@ -345,6 +345,8 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file,
                                      const int line,
                                      const char *condition,
                                      const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5)));
+void EXPORT_FUNC(grub_qdprintf) (const char *condition,
+				 const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 2, 3)));
 int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
 int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...)
      __attribute__ ((format (GNU_PRINTF, 3, 4)));

Glenn

#3 lore raw

PATCH 2/2 Make a "gdb" dprintf that tells us load addresses.

In reply to Robbie Harwood

From: Peter Jones <[email protected]>

This makes a grub_dprintf() call during platform init and during module loading that tells us the virtual addresses of the .text and .data sections of grub-core/kernel.exec and any modules it loads.

Specifically, it displays them in the gdb "add-symbol-file" syntax, with the presumption that there's a variable $grubdir that reflects the path to any such binaries.

---
 grub-core/kern/dl.c       | 50 +++++++++++++++++++++++++++++++++++++++
 grub-core/kern/efi/efi.c  |  4 ++--
 grub-core/kern/efi/init.c | 26 +++++++++++++++++++-
 include/grub/efi/efi.h    |  2 +-
 4 files changed, 78 insertions(+), 4 deletions(-)
grub-core/kern/dl.c +50 -0
index 48f8a7907..44a1f4ca3 100644
@@ -447,6 +447,23 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name)
       return s;
   return NULL;
 }
+static long
+grub_dl_find_section_index (Elf_Ehdr *e, const char *name)
+{
+  Elf_Shdr *s;
+  const char *str;
+  unsigned i;
+
+  s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize);
+  str = (char *) e + s->sh_offset;
+
+  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
+       i < e->e_shnum;
+       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
+    if (grub_strcmp (str + s->sh_name, name) == 0)
+      return (long)i;
+  return -1;
+}
 
 /* Me, Vladimir Serbinenko, hereby I add this module check as per new
    GNU module policy. Note that this license check is informative only.
@@ -599,6 +616,37 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
 
   return GRUB_ERR_NONE;
 }
+static void
+grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e)
+{
+  void *text, *data = NULL;
+  long idx;
+
+  idx = grub_dl_find_section_index (e, ".text");
+  if (idx < 0)
+    return;
+
+  text = grub_dl_get_section_addr (mod, idx);
+  if (!text)
+    return;
+
+  idx = grub_dl_find_section_index (e, ".data");
+  if (idx >= 0)
+    data = grub_dl_get_section_addr (mod, idx);
+
+  if (data)
+    grub_qdprintf ("gdb", "add-symbol-file \\\n"
+		          "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug "
+			  "\\\n %p -s .data %p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM,
+		  mod->name, text, data);
+  else
+    grub_qdprintf ("gdb", "add-symbol-file \\\n"
+			   "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug "
+			   "\\\n%p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM,
+		  mod->name, text);
+}
 
 /* Load a module from core memory.  */
 grub_dl_t
@@ -658,6 +706,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size)
   grub_dprintf ("modules", "module name: %s\n", mod->name);
   grub_dprintf ("modules", "init function: %p\n", mod->init);
 
+  grub_dl_print_gdb_info (mod, e);
+
   if (grub_dl_add (mod))
     {
       grub_dl_unload (mod);
grub-core/kern/efi/efi.c +2 -2
index 8cff7be02..f12fd5893 100644
@@ -291,7 +291,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
 /* Search the mods section from the PE32/PE32+ image. This code uses
    a PE32 header, but should work with PE32+ as well.  */
 grub_addr_t
-grub_efi_modules_addr (void)
+grub_efi_section_addr (const char *section_name)
 {
   grub_efi_loaded_image_t *image;
   struct grub_pe32_header *header;
@@ -316,7 +316,7 @@ grub_efi_modules_addr (void)
        i < coff_header->num_sections;
        i++, section++)
     {
-      if (grub_strcmp (section->name, "mods") == 0)
+      if (grub_strcmp (section->name, section_name) == 0)
 	break;
     }
 
grub-core/kern/efi/init.c +25 -1
index 7facacf09..da7be3b12 100644
@@ -82,10 +82,33 @@ stack_protector_init (void)
 
 grub_addr_t grub_modbase;
 
+static void
+grub_efi_print_gdb_info (void)
+{
+  grub_addr_t text;
+  grub_addr_t data;
+
+  text = grub_efi_section_addr (".text");
+  if (!text)
+    return;
+
+  data = grub_efi_section_addr (".data");
+  if (data)
+    grub_qdprintf ("gdb",
+		  "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/"
+		  "kernel.exec %p -s .data %p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text, (void *)data);
+  else
+    grub_qdprintf ("gdb",
+		  "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/"
+		  "kernel.exec %p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text);
+}
+
 void
 grub_efi_init (void)
 {
-  grub_modbase = grub_efi_modules_addr ();
+  grub_modbase = grub_efi_section_addr ("mods");
   /* First of all, initialize the console so that GRUB can display
      messages.  */
   grub_console_init ();
@@ -108,6 +131,7 @@ grub_efi_init (void)
   efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
 	      0, 0, 0, NULL);
 
+  grub_efi_print_gdb_info ();
   grub_efidisk_init ();
 }
 
include/grub/efi/efi.h +1 -1
index 83d958f99..73b754177 100644
@@ -105,7 +105,7 @@ grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
                                            char *args);
 #endif
 
-grub_addr_t grub_efi_modules_addr (void);
+grub_addr_t grub_efi_section_addr (const char *section);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);
Signature · 1 line
2.33.0
#4 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

Quoted 72 lines · On Mon, 11 Oct 2021 14:48:44 -0400 Robbie Harwood <[email protected]> wrote:

From: Peter Jones <[email protected]>

This makes a grub_dprintf() call during platform init and during module loading that tells us the virtual addresses of the .text and .data sections of grub-core/kernel.exec and any modules it loads.

Specifically, it displays them in the gdb "add-symbol-file" syntax, with the presumption that there's a variable $grubdir that reflects the path to any such binaries.

---
 grub-core/kern/dl.c       | 50 +++++++++++++++++++++++++++++++++++++++
 grub-core/kern/efi/efi.c  |  4 ++--
 grub-core/kern/efi/init.c | 26 +++++++++++++++++++-
 include/grub/efi/efi.h    |  2 +-
 4 files changed, 78 insertions(+), 4 deletions(-)
grub-core/kern/dl.c +38 -0
index 48f8a7907..44a1f4ca3 100644
@@ -447,6 +447,23 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name)
       return s;
   return NULL;
 }
+static long
+grub_dl_find_section_index (Elf_Ehdr *e, const char *name)
+{
+  Elf_Shdr *s;
+  const char *str;
+  unsigned i;
+
+  s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize);
+  str = (char *) e + s->sh_offset;
+
+  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
+       i < e->e_shnum;
+       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
+    if (grub_strcmp (str + s->sh_name, name) == 0)
+      return (long)i;
+  return -1;
+}
 
 /* Me, Vladimir Serbinenko, hereby I add this module check as per new
    GNU module policy. Note that this license check is informative only.
@@ -599,6 +616,37 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
 
   return GRUB_ERR_NONE;
 }
+static void
+grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e)
+{
+  void *text, *data = NULL;
+  long idx;
+
+  idx = grub_dl_find_section_index (e, ".text");
+  if (idx < 0)
+    return;
+
+  text = grub_dl_get_section_addr (mod, idx);
+  if (!text)
+    return;
+
+  idx = grub_dl_find_section_index (e, ".data");
+  if (idx >= 0)
+    data = grub_dl_get_section_addr (mod, idx);
+
+  if (data)
+    grub_qdprintf ("gdb", "add-symbol-file \\\n"
+		          "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug "

grub-core/kern/dl.c grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) · line 649

Quoted 10 lines
grub-core/kern/dl.c +10 -0
+			  "\\\n %p -s .data %p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM,
+		  mod->name, text, data);
+  else
+    grub_qdprintf ("gdb", "add-symbol-file \\\n"
+			   "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug "
+			   "\\\n%p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM,
+		  mod->name, text);
+}

I don't agree with suppressing file:line for debug output. I have some changes in the pipeline which will allow selectively disabling conditions when also using "deubg=all". Suppressing file:line makes it harder to figure out where the debug output is coming from to find the condition to disable it. I think solution that we both might find agree able is to prepend "\n" to your format string. That way "add-symbol-file" will still start on a new-line, which seems to be what you're after.

Quoted 55 lines
grub-core/kern/dl.c +2 -0
 /* Load a module from core memory.  */
 grub_dl_t
@@ -658,6 +706,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size)
   grub_dprintf ("modules", "module name: %s\n", mod->name);
   grub_dprintf ("modules", "init function: %p\n", mod->init);
 
+  grub_dl_print_gdb_info (mod, e);
+
   if (grub_dl_add (mod))
     {
       grub_dl_unload (mod);
grub-core/kern/efi/efi.c +2 -2
index 8cff7be02..f12fd5893 100644
@@ -291,7 +291,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
 /* Search the mods section from the PE32/PE32+ image. This code uses
    a PE32 header, but should work with PE32+ as well.  */
 grub_addr_t
-grub_efi_modules_addr (void)
+grub_efi_section_addr (const char *section_name)
 {
   grub_efi_loaded_image_t *image;
   struct grub_pe32_header *header;
@@ -316,7 +316,7 @@ grub_efi_modules_addr (void)
        i < coff_header->num_sections;
        i++, section++)
     {
-      if (grub_strcmp (section->name, "mods") == 0)
+      if (grub_strcmp (section->name, section_name) == 0)
 	break;
     }
 
grub-core/kern/efi/init.c +13 -0
index 7facacf09..da7be3b12 100644
@@ -82,10 +82,33 @@ stack_protector_init (void)
 
 grub_addr_t grub_modbase;
 
+static void
+grub_efi_print_gdb_info (void)
+{
+  grub_addr_t text;
+  grub_addr_t data;
+
+  text = grub_efi_section_addr (".text");
+  if (!text)
+    return;
+
+  data = grub_efi_section_addr (".data");
+  if (data)
+    grub_qdprintf ("gdb",

grub-core/kern/efi/init.c stack_protector_init (void) · line 107

Quoted 10 lines
grub-core/kern/efi/init.c +10 -0
+		  "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/"
+		  "kernel.exec %p -s .data %p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text, (void *)data);
+  else
+    grub_qdprintf ("gdb",
+		  "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/"
+		  "kernel.exec %p\n",
+		  GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text);
+}
+

ditto.

Quoted 21 lines
grub-core/kern/efi/init.c +2 -1
 void
 grub_efi_init (void)
 {
-  grub_modbase = grub_efi_modules_addr ();
+  grub_modbase = grub_efi_section_addr ("mods");
   /* First of all, initialize the console so that GRUB can display
      messages.  */
   grub_console_init ();
@@ -108,6 +131,7 @@ grub_efi_init (void)
   efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
 	      0, 0, 0, NULL);
 
+  grub_efi_print_gdb_info ();
   grub_efidisk_init ();
 }
 
include/grub/efi/efi.h +0 -0
index 83d958f99..73b754177 100644

include/grub/efi/efi.h grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, · line 111

Quoted 8 lines
include/grub/efi/efi.h +1 -1
@@ -105,7 +105,7 @@ grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
                                            char *args);
 #endif
 
-grub_addr_t grub_efi_modules_addr (void);
+grub_addr_t grub_efi_section_addr (const char *section);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);

Glenn

#5 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

Quoted 5 lines · Glenn Washburn

I don't agree with suppressing file:line for debug output. I have some changes in the pipeline which will allow selectively disabling conditions when also using "deubg=all". Suppressing file:line makes it harder to figure out where the debug output is coming from to find the condition to disable it.

Grep for add-symbol-file or /usr/lib/debug etc. will get there.

Quoted 3 lines

I think solution that we both might find agree able is to prepend "\n" to your format string. That way "add-symbol-file" will still start on a new-line, which seems to be what you're after.

During a boot with this enabled, you don't get just one line - you get one for each module (plus the initial one for kernel.exec). So if nothing intersperses, you can do set confirm off, then copy/paste the block.

Be well,
--Robbie

#6 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

Quoted 9 lines · On Thu, 14 Oct 2021 13:09:21 -0400 Robbie Harwood <[email protected]> wrote:
Quoted 5 lines · Glenn Washburn

I don't agree with suppressing file:line for debug output. I have some changes in the pipeline which will allow selectively disabling conditions when also using "debug=all". Suppressing file:line makes it harder to figure out where the debug output is coming from to find the condition to disable it.

Grep for add-symbol-file or /usr/lib/debug etc. will get there.

I'm not following. Are you suggesting grepping for "add-symbol-file" in the source? If so, I don't find that an acceptable answer to the sysadmin trying to figure out hwo to disable that log message.

Quoted 8 lines
Quoted 3 lines

I think solution that we both might find agree able is to prepend "\n" to your format string. That way "add-symbol-file" will still start on a new-line, which seems to be what you're after.

During a boot with this enabled, you don't get just one line - you get one for each module (plus the initial one for kernel.exec). So if nothing intersperses, you can do set confirm off, then copy/paste the block.

Yes I understood this is per module, and I'm also confused here as to why this is your response because it doesn't address what its supposedly responding to. You're just talking about how to use the functionality that this patch provides. With the change that I suggest the actions in your response would be the same.

Quoted 2 lines

Be well,
--Robbie

Glenn

#7 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

Quoted 9 lines · Glenn Washburn
Quoted 8 lines · Robbie Harwood
Quoted 5 lines · Glenn Washburn

I don't agree with suppressing file:line for debug output. I have some changes in the pipeline which will allow selectively disabling conditions when also using "debug=all". Suppressing file:line makes it harder to figure out where the debug output is coming from to find the condition to disable it.

Quoted 5 lines
Quoted 1 line

Grep for add-symbol-file or /usr/lib/debug etc. will get there.

I'm not following. Are you suggesting grepping for "add-symbol-file" in the source? If so, I don't find that an acceptable answer to the sysadmin trying to figure out hwo to disable that log message.

I don't understand your target audience - they have access to the source, but can't search it? Do I have that right?

If so, it seems unlikely that we're going to agree.

Be well,
--Robbie

#8 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

Quoted 11 lines · On Fri, 15 Oct 2021 16:55:17 -0400 Robbie Harwood <[email protected]> wrote:
Quoted 9 lines · Glenn Washburn
Quoted 8 lines · Robbie Harwood
Quoted 5 lines · Glenn Washburn

I don't agree with suppressing file:line for debug output. I have some changes in the pipeline which will allow selectively disabling conditions when also using "debug=all". Suppressing file:line makes it harder to figure out where the debug output is coming from to find the condition to disable it.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Grep for add-symbol-file or /usr/lib/debug etc. will get there.

I'm not following. Are you suggesting grepping for "add-symbol-file" in the source? If so, I don't find that an acceptable answer to the sysadmin trying to figure out hwo to disable that log message.

I don't understand your target audience - they have access to the source, but can't search it? Do I have that right?

No, my target audience is a sysadmin trying to debug why grub is failing in some way. They might not even be a programmer. But they can read documentation and make intuitive guesses, but they likely don't know how to use gdb. Say they are trying to debug an issue, but they don't know exactly where things are going wrong, but it is reproducible. This is on a system where all they have is a keyboard and a monitor. So when the output scrolls off the top of the screen its gone.

They turn on debug=all because they don't know in what conditional(s) would give them useful debug information. This will spew a lot of debug messages to the screen, including the messages output by this patch. The sysadmin may not see anything of value in the output, but will see lots of messages of no apparent value. It would be nice to using this output to be able to selectively disable it at runtime.

I forgot to mention that I have another patch that adds the conditional used to the message to file:line:conditional is prepended. That combined with a patch that allows selective disabling of debug log message by conditional, allows the user to iteratively pare down debug log messages so that the ones of value have a greater likelihood of being on the limited screen realestate. This would look like, for example:

set debug=all,-gdb,-disk,-lexer,-alloc

Now the patch as is does not show the file:line prefix, and wouldn't show the conditional after my patch. So the user has no way of knowing what conditional should be used to disable the gdb output. And may actually be confused because all debug messages are currently prefixed the file:line, even multiline messages. So the user may thing that the gdb message is a multiline message that comes from the debug log message that preceeded it, leading them to disable potentially the wrong conditional.

So, no, I think it should remain the standard that log messages enabled via the debug variable always have a file:line prefix.

On the otherhand, since you're able to copy paste, I'm guessing you're on a serial line or VM and not on in the situation I'm describing. In which case, without the proposed "\n" modification, having the file:line prefix is an extremely minor inconvenience (you'll have to find the start of the add-symbol-file, which won't be at the beginning of the line). And you can copy-paste, you likely can search that output anyway. The person in the scenario I describe doesn't have that luxury.

Why do I care? I've been that guy trying to figure out a boot issue with too much noise in the debug log messages pushing the messages I needed to see off the screen (and the source wasn't readily available). And no pager is not always an option if you have hundreds of pages of log messages to scroll through, it takes forever.

Quoted 1 line

If so, it seems unlikely that we're going to agree.

I don't think we need to agree (that is for you to agree that the issue I'm describing is something to be concerned about). However, like I said, I think we can both be satisfied by not leaving out the file:line and to prepend "\n" to "add-symbol-file" so that it will start on a new line. So I'll ask again. Is my proposal an acceptable modification for the need that you have?

Quoted 2 lines

Be well,
--Robbie

Cheers,
Glenn

#9 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

Quoted 6 lines · Glenn Washburn

I don't think we need to agree (that is for you to agree that the issue I'm describing is something to be concerned about). However, like I said, I think we can both be satisfied by not leaving out the file:line and to prepend "\n" to "add-symbol-file" so that it will start on a new line. So I'll ask again. Is my proposal an acceptable modification for the need that you have?

No, this is what I was trying to explain. There's one add-symbol-file line per module. If there's no file:line, you get something like this:

    add-symbol-file ...
    add-symbol-file ...
    add-symbol-file ...

This can be directly pasted into gdb.

Your proposal results in something like:

    dl.c:694:
    add-symbol-file ...
    dl.c:694:
    add-symbol-file ...
    dl.c:694:
    add-symbol-file ...

You can't easily copy-paste that into gdb. It needs to be processed to remove the file:line stuff.

Be well,
--Robbie

#10 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

Quoted 9 lines · On Tue, 19 Oct 2021 17:08:59 -0400 Robbie Harwood <[email protected]> wrote:
Quoted 6 lines · Glenn Washburn

I don't think we need to agree (that is for you to agree that the issue I'm describing is something to be concerned about). However, like I said, I think we can both be satisfied by not leaving out the file:line and to prepend "\n" to "add-symbol-file" so that it will start on a new line. So I'll ask again. Is my proposal an acceptable modification for the need that you have?

Quoted 8 lines

No, this is what I was trying to explain. There's one add-symbol-file line per module. If there's no file:line, you get something like this:

    add-symbol-file ...
    add-symbol-file ...
    add-symbol-file ...

This can be directly pasted into gdb.

Thank you for clarifying that for me. Technically the patch prints a multiline debug message, so you don't get one line per module. However, I see that doesn't matter for your use case because the line continuation makes it appear as one line in gdb.

Quoted 10 lines

Your proposal results in something like:

    dl.c:694:
    add-symbol-file ...
    dl.c:694:
    add-symbol-file ...
    dl.c:694:
    add-symbol-file ...
Quoted 2 lines

You can't easily copy-paste that into gdb. It needs to be processed to remove the file:line stuff.

Ok, I see now why removing the prefix is important for you. And my objection still stands. At worst just copy into a file and run grep -v or sed. There have been alternatives proposed on this thread which may be preferable.

Glenn

#11 lore raw

Re: [PATCH 2/2] Make a "gdb" dprintf that tells us load addresses.

In reply to Robbie Harwood

Hi,

Quoted 9 lines · Robbie Harwood
    dl.c:694:
    add-symbol-file ...
    dl.c:694:
    add-symbol-file ...
    dl.c:694:
    add-symbol-file ...

You can't easily copy-paste that into gdb. It needs to be processed to remove the file:line stuff.

How about hiding the "dl.c" lines behind a "#" ?

    # dl.c:694:
    add-symbol-file ...

I don't find the current gdb documentation online from GNU, but
https://sourceware.org/gdb/current/onlinedocs/gdb/Command-Syntax.html#Command-Syntax
looks young and promises
"Any text from a # to the end of the line is a comment; it does nothing."
(All gdbs i ever saw fulfill this promise.)

Have a nice day :)

Thomas