Skip to contentSkip to conversation

GDB script fixes

PATCH In review Glenn Washburn 2 participants 5 messages Feb 21, 2023 – Feb 23, 2023

lore
Share & tools
lore
#0 lore raw

cover GDB script fixes

This series is the first 3 patches of the previous series "GDB script fixes and improvements", which I think it better to break into separate logical series. These are (most of) the fixes from that that series that stand alone.

Glenn

Glenn Washburn (3):
gdb: Fix redirection issue in dump_module_sections
gdb: Prevent wrapping when writing to .segments.tmp
gdb: If no modules have been loaded, do not try to load module symbols

 grub-core/gdb_grub.in | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 gdb: Fix redirection issue in dump_module_sections

An error in any GDB command causes it to immediately abort with an error, this includes any command that calls that command. This leads to an issue in dump_module_sections where an error causes the command to exit without turning off file redirection. The user then ends up with a GDB command line where commands output nothing to the console.

Instead do the work of dump_module_sections in the command dump_module_sections_helper and run the command using GDB's pipe command which does the redirection and undoes the redirection when it finishes regardless of any errors in the command.

Also, remove .segments.tmp file prior to loading modules in case one was left from a previous run.

---
 grub-core/gdb_grub.in | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
grub-core/gdb_grub.in +5 -10
index e322d3dc10..4e45ad5622 100644
@@ -10,15 +10,8 @@
 ###
 
 # Add section numbers and addresses to .segments.tmp
-define dump_module_sections
+define dump_module_sections_helper
 	set $mod = $arg0
-
-	# FIXME: save logging status
-	set logging file .segments.tmp
-	set logging redirect on
-	set logging overwrite off
-	set logging on
-
 	printf "%s", $mod->name
 	set $segment = $mod->segment
 	while ($segment)
@@ -26,9 +19,10 @@ define dump_module_sections
 		set $segment = $segment->next
 	end
 	printf "\n"
+end
 
-	set logging off
-	# FIXME: restore logging status
+define dump_module_sections
+	pipe dump_module_sections_helper $arg0 | sh -c 'cat >>.segments.tmp'
 end
 document dump_module_sections
 	Gather information about module whose mod structure was
@@ -59,6 +53,7 @@ document load_module
 end
 
 define load_all_modules
+	shell rm -f .segments.tmp
 	set $this = grub_dl_head
 	while ($this != 0)
 		dump_module_sections $this
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/3 gdb: Prevent wrapping when writing to .segments.tmp

In reply to Glenn Washburn

GDB logging is redirected to write .segments.tmp, which means that GDB will wrap lines longer than what it thinks is the screen width (typically 80 characters). When wrapping does occur it causes gmodule.pl to misbehave. So disable line wrapping by using GDB's "with" command so that its guaranteed to return the width to the previous value upon command completion.

Also disable command tracing when dumping the module sections because that output will go to .segments.tmp and thus cause gmodule.pl to misbehave.

---
 grub-core/gdb_grub.in | 4 ++++
 1 file changed, 4 insertions(+)
grub-core/gdb_grub.in +4 -0
index 4e45ad5622..edb5a8872c 100644
@@ -22,6 +22,10 @@ define dump_module_sections_helper
 end
 
 define dump_module_sections
+	# Set unlimited width so that lines don't get wrapped writing
+	# to .segments.tmp
+	with width 0 -- \
+	with trace-commands off -- \
 	pipe dump_module_sections_helper $arg0 | sh -c 'cat >>.segments.tmp'
 end
 document dump_module_sections
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/3 gdb: If no modules have been loaded, do not try to load module symbols

In reply to Glenn Washburn

This prevents load_all_modules from failing when called before any modules have been loaded. Failures in GDB user-defined functions cause any function which called them to also fail.

---
 grub-core/gdb_grub.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
grub-core/gdb_grub.in +3 -1
index edb5a8872c..fc17e3d899 100644
@@ -63,7 +63,9 @@ define load_all_modules
 		dump_module_sections $this
 		set $this = $this->next
 	end
-	match_and_load_symbols
+	if (grub_dl_head != 0)
+		match_and_load_symbols
+	end
 end
 document load_all_modules
 	Load debugging information for all loaded modules.
Signature · 1 line
2.34.1
#4 lore raw
In reply to Glenn Washburn
Quoted 10 lines · Glenn Washburn

This series is the first 3 patches of the previous series "GDB script fixes and improvements", which I think it better to break into separate logical series. These are (most of) the fixes from that that series that stand alone.

Glenn

Glenn Washburn (3):
gdb: Fix redirection issue in dump_module_sections
gdb: Prevent wrapping when writing to .segments.tmp
gdb: If no modules have been loaded, do not try to load module symbols

For all the patches Reviewed-by: Daniel Kiper <[email protected]>...

Daniel