All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] GDB script fixes
@ 2023-02-21 18:28 Glenn Washburn
  2023-02-21 18:28 ` [PATCH 1/3] gdb: Fix redirection issue in dump_module_sections Glenn Washburn
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Glenn Washburn @ 2023-02-21 18:28 UTC (permalink / raw)
  To: grub-devel, Daniel Kiper; +Cc: 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

 grub-core/gdb_grub.in | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] gdb: Fix redirection issue in dump_module_sections
  2023-02-21 18:28 [PATCH 0/3] GDB script fixes Glenn Washburn
@ 2023-02-21 18:28 ` Glenn Washburn
  2023-02-21 18:28 ` [PATCH 2/3] gdb: Prevent wrapping when writing to .segments.tmp Glenn Washburn
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Glenn Washburn @ 2023-02-21 18:28 UTC (permalink / raw)
  To: grub-devel, Daniel Kiper; +Cc: Glenn Washburn

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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/gdb_grub.in | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in
index e322d3dc10..4e45ad5622 100644
--- a/grub-core/gdb_grub.in
+++ b/grub-core/gdb_grub.in
@@ -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
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] gdb: Prevent wrapping when writing to .segments.tmp
  2023-02-21 18:28 [PATCH 0/3] GDB script fixes Glenn Washburn
  2023-02-21 18:28 ` [PATCH 1/3] gdb: Fix redirection issue in dump_module_sections Glenn Washburn
@ 2023-02-21 18:28 ` Glenn Washburn
  2023-02-21 18:28 ` [PATCH 3/3] gdb: If no modules have been loaded, do not try to load module symbols Glenn Washburn
  2023-02-23 14:21 ` [PATCH 0/3] GDB script fixes Daniel Kiper
  3 siblings, 0 replies; 5+ messages in thread
From: Glenn Washburn @ 2023-02-21 18:28 UTC (permalink / raw)
  To: grub-devel, Daniel Kiper; +Cc: 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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/gdb_grub.in | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in
index 4e45ad5622..edb5a8872c 100644
--- a/grub-core/gdb_grub.in
+++ b/grub-core/gdb_grub.in
@@ -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
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] gdb: If no modules have been loaded, do not try to load module symbols
  2023-02-21 18:28 [PATCH 0/3] GDB script fixes Glenn Washburn
  2023-02-21 18:28 ` [PATCH 1/3] gdb: Fix redirection issue in dump_module_sections Glenn Washburn
  2023-02-21 18:28 ` [PATCH 2/3] gdb: Prevent wrapping when writing to .segments.tmp Glenn Washburn
@ 2023-02-21 18:28 ` Glenn Washburn
  2023-02-23 14:21 ` [PATCH 0/3] GDB script fixes Daniel Kiper
  3 siblings, 0 replies; 5+ messages in thread
From: Glenn Washburn @ 2023-02-21 18:28 UTC (permalink / raw)
  To: grub-devel, Daniel Kiper; +Cc: 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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/gdb_grub.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in
index edb5a8872c..fc17e3d899 100644
--- a/grub-core/gdb_grub.in
+++ b/grub-core/gdb_grub.in
@@ -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.
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] GDB script fixes
  2023-02-21 18:28 [PATCH 0/3] GDB script fixes Glenn Washburn
                   ` (2 preceding siblings ...)
  2023-02-21 18:28 ` [PATCH 3/3] gdb: If no modules have been loaded, do not try to load module symbols Glenn Washburn
@ 2023-02-23 14:21 ` Daniel Kiper
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Kiper @ 2023-02-23 14:21 UTC (permalink / raw)
  To: Glenn Washburn; +Cc: grub-devel

On Tue, Feb 21, 2023 at 12:28:45PM -0600, Glenn Washburn wrote:
> 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 <daniel.kiper@oracle.com>...

Daniel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-02-23 14:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-21 18:28 [PATCH 0/3] GDB script fixes Glenn Washburn
2023-02-21 18:28 ` [PATCH 1/3] gdb: Fix redirection issue in dump_module_sections Glenn Washburn
2023-02-21 18:28 ` [PATCH 2/3] gdb: Prevent wrapping when writing to .segments.tmp Glenn Washburn
2023-02-21 18:28 ` [PATCH 3/3] gdb: If no modules have been loaded, do not try to load module symbols Glenn Washburn
2023-02-23 14:21 ` [PATCH 0/3] GDB script fixes Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.