[1/2] gdb/readline: new 'maint info readline' command

Message ID d5223f45826d25dd8419dd6d8ae7a3f6541dfaaf.1730303479.git.aburgess@redhat.com
State New
Headers
Series Fis for readline eof and secondary prompt issue |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Andrew Burgess Oct. 30, 2024, 3:53 p.m. UTC
  When debugging readline issues I'd like an easy way to know (for sure)
what version of readline GDB is using.  This could also be useful when
writing readline tests, knowing the precise readline version will
allow us to know if we expect a test to pass or not.

Add a new 'maintenance info readline' command which will display the
readline version string and a suffix indicating if we are using the
system readline, or the statically linked in readline.

Example usage (statically linked in readline):

  (gdb) maintenance info readline
  version: 8.1	(internal)

Or (using older system readline):

  (gdb) maintenance info readline
  version: 8.0	(system)
---
 gdb/NEWS                         |  3 +++
 gdb/doc/gdb.texinfo              | 16 ++++++++++++++++
 gdb/event-top.c                  | 27 +++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/maint.exp |  3 +++
 4 files changed, 49 insertions(+)
  

Comments

Eli Zaretskii Oct. 30, 2024, 4:52 p.m. UTC | #1
> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>
> Date: Wed, 30 Oct 2024 15:53:34 +0000
> 
> When debugging readline issues I'd like an easy way to know (for sure)
> what version of readline GDB is using.  This could also be useful when
> writing readline tests, knowing the precise readline version will
> allow us to know if we expect a test to pass or not.
> 
> Add a new 'maintenance info readline' command which will display the
> readline version string and a suffix indicating if we are using the
> system readline, or the statically linked in readline.
> 
> Example usage (statically linked in readline):
> 
>   (gdb) maintenance info readline
>   version: 8.1	(internal)
> 
> Or (using older system readline):
> 
>   (gdb) maintenance info readline
>   version: 8.0	(system)
> ---
>  gdb/NEWS                         |  3 +++
>  gdb/doc/gdb.texinfo              | 16 ++++++++++++++++
>  gdb/event-top.c                  | 27 +++++++++++++++++++++++++++
>  gdb/testsuite/gdb.base/maint.exp |  3 +++
>  4 files changed, 49 insertions(+)

Thanks, the documentation parts are approved.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  
Tom de Vries Oct. 30, 2024, 8:06 p.m. UTC | #2
On 10/30/24 16:53, Andrew Burgess wrote:
> When debugging readline issues I'd like an easy way to know (for sure)
> what version of readline GDB is using.  This could also be useful when
> writing readline tests, knowing the precise readline version will
> allow us to know if we expect a test to pass or not.
> 

Hi Andrew,

that's a great idea, thanks.

> Add a new 'maintenance info readline' command which will display the
> readline version string and a suffix indicating if we are using the
> system readline, or the statically linked in readline.

I gave it a try, the output looked correct, so LGTM.

Approved-By: Tom de Vries <tdevries@suse.de>

Thanks,
- Tom

> Example usage (statically linked in readline):
> 
>    (gdb) maintenance info readline
>    version: 8.1	(internal)
> 
> Or (using older system readline):
> 
>    (gdb) maintenance info readline
>    version: 8.0	(system)
> ---
>   gdb/NEWS                         |  3 +++
>   gdb/doc/gdb.texinfo              | 16 ++++++++++++++++
>   gdb/event-top.c                  | 27 +++++++++++++++++++++++++++
>   gdb/testsuite/gdb.base/maint.exp |  3 +++
>   4 files changed, 49 insertions(+)
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 42b8a88fd8a..a8f8f2c8265 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -83,6 +83,9 @@ maintenance info blocks [ADDRESS]
>     are listed starting at the inner global block out to the most inner
>     block.
>   
> +maintenance info readline
> +  Displays the version of readline that GDB is using.
> +
>   * Changed commands
>   
>   remove-symbol-file
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index eb2aff974bb..3409382e54b 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -27520,6 +27520,10 @@
>   next line relative to the current line from the history for editing.
>   Any argument is ignored.
>   
> +It is possible to discover which version of readline @value{GDBN} is
> +using with the @kbd{maint info readline} command (@pxref{maint info
> +readline}).
> +
>   @node Command History
>   @section Command History
>   @cindex command history
> @@ -42449,6 +42453,18 @@
>   Print various characteristics of the screen, such as various notions
>   of width and height.
>   
> +@anchor{maint info readline}
> +@kindex maint info readline
> +@cindex readline version, showing
> +@item maint info readline
> +Print the version number of the readline library @value{GDBN} is
> +using.
> +
> +After the version number will appear either @samp{(system)} indicating
> +@value{GDBN} is using the shared system readline library, or
> +@samp{(internal)} indicating @value{GDBN} is using a statically linked
> +in version of the readline library.
> +
>   @kindex maint space
>   @cindex memory used by commands
>   @item maint space @var{value}
> diff --git a/gdb/event-top.c b/gdb/event-top.c
> index d3cf144958a..0d46dec1774 100644
> --- a/gdb/event-top.c
> +++ b/gdb/event-top.c
> @@ -1454,6 +1454,24 @@ show_debug_event_loop_command (struct ui_file *file, int from_tty,
>     gdb_printf (file, _("Event loop debugging is %s.\n"), value);
>   }
>   
> +/* Handle 'maint info readline' command.  Print the version of readline
> +   that GDB is using.  */
> +
> +static void
> +maintenance_info_readline (const char *arg, int from_tty)
> +{
> +  /* Is GDB using the system readline, or our own internal copy?  */
> +  const char *suffix
> +#ifdef HAVE_READLINE_READLINE_H
> +    = "\t(system)"
> +#else
> +    = "\t(internal)"
> +#endif
> +    ;
> +
> +  gdb_printf ("version: %s%s\n", rl_library_version, suffix);
> +}
> +
>   void _initialize_event_top ();
>   void
>   _initialize_event_top ()
> @@ -1481,4 +1499,13 @@ crashes within GDB, not a mechanism for debugging inferiors."),
>   			   show_bt_on_fatal_signal,
>   			   &maintenance_set_cmdlist,
>   			   &maintenance_show_cmdlist);
> +
> +  add_cmd ("readline", class_maintenance, maintenance_info_readline, _("\
> +Display information about version of readline being used.\n\
> +\n\
> +Displays which version of the readline library GDB is using\n\
> +followed by either '(system)' or '(internal)' to indicate if\n\
> +GDB is using the shared system library or a statically linked\n\
> +in version of the library."),
> +	   &maintenanceinfolist);
>   }
> diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
> index d6aa22321f1..d540783f5cb 100644
> --- a/gdb/testsuite/gdb.base/maint.exp
> +++ b/gdb/testsuite/gdb.base/maint.exp
> @@ -381,6 +381,9 @@ gdb_test "maint" \
>       "List.*unambiguous\\..*" \
>       "maint w/o args"
>   
> +gdb_test "maint info readline" \
> +    "^version: \[^\r\n\]+"
> +
>   # Test that "main info line-table" w/o a file name shows the symtab for
>   # $srcfile.
>   set saw_srcfile 0
  
Tom Tromey Nov. 1, 2024, 2:33 p.m. UTC | #3
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> Add a new 'maintenance info readline' command which will display the
Andrew> readline version string and a suffix indicating if we are using the
Andrew> system readline, or the statically linked in readline.

I don't mind this approach but why not add this info to 'show
configuration'?

Tom
  
Andrew Burgess Nov. 1, 2024, 3:53 p.m. UTC | #4
Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> Add a new 'maintenance info readline' command which will display the
> Andrew> readline version string and a suffix indicating if we are using the
> Andrew> system readline, or the statically linked in readline.
>
> I don't mind this approach but why not add this info to 'show
> configuration'?

Because `show configuration` shows GDB's configure line, and the
readline version isn't part of the configure command.  There is one
extra sentence printed:

  ("Relocatable" means the directory can be moved with the GDB installation
  tree, and GDB will still find it.)

but that just explains a term that is part of the configure command.

That's why I didn't add this there.

But I could for sure add this at the end of this output if you think
that would be better.  I don't really have strong feelings where the
information is printed, just so long as I can get it somewhere.

Thanks,
Andrew
  
Tom Tromey Nov. 1, 2024, 6:15 p.m. UTC | #5
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> But I could for sure add this at the end of this output if you think
Andrew> that would be better.  I don't really have strong feelings where the
Andrew> information is printed, just so long as I can get it somewhere.

Either way is fine by me.

Tom
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 42b8a88fd8a..a8f8f2c8265 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -83,6 +83,9 @@  maintenance info blocks [ADDRESS]
   are listed starting at the inner global block out to the most inner
   block.
 
+maintenance info readline
+  Displays the version of readline that GDB is using.
+
 * Changed commands
 
 remove-symbol-file
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index eb2aff974bb..3409382e54b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -27520,6 +27520,10 @@ 
 next line relative to the current line from the history for editing.
 Any argument is ignored.
 
+It is possible to discover which version of readline @value{GDBN} is
+using with the @kbd{maint info readline} command (@pxref{maint info
+readline}).
+
 @node Command History
 @section Command History
 @cindex command history
@@ -42449,6 +42453,18 @@ 
 Print various characteristics of the screen, such as various notions
 of width and height.
 
+@anchor{maint info readline}
+@kindex maint info readline
+@cindex readline version, showing
+@item maint info readline
+Print the version number of the readline library @value{GDBN} is
+using.
+
+After the version number will appear either @samp{(system)} indicating
+@value{GDBN} is using the shared system readline library, or
+@samp{(internal)} indicating @value{GDBN} is using a statically linked
+in version of the readline library.
+
 @kindex maint space
 @cindex memory used by commands
 @item maint space @var{value}
diff --git a/gdb/event-top.c b/gdb/event-top.c
index d3cf144958a..0d46dec1774 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -1454,6 +1454,24 @@  show_debug_event_loop_command (struct ui_file *file, int from_tty,
   gdb_printf (file, _("Event loop debugging is %s.\n"), value);
 }
 
+/* Handle 'maint info readline' command.  Print the version of readline
+   that GDB is using.  */
+
+static void
+maintenance_info_readline (const char *arg, int from_tty)
+{
+  /* Is GDB using the system readline, or our own internal copy?  */
+  const char *suffix
+#ifdef HAVE_READLINE_READLINE_H
+    = "\t(system)"
+#else
+    = "\t(internal)"
+#endif
+    ;
+
+  gdb_printf ("version: %s%s\n", rl_library_version, suffix);
+}
+
 void _initialize_event_top ();
 void
 _initialize_event_top ()
@@ -1481,4 +1499,13 @@  crashes within GDB, not a mechanism for debugging inferiors."),
 			   show_bt_on_fatal_signal,
 			   &maintenance_set_cmdlist,
 			   &maintenance_show_cmdlist);
+
+  add_cmd ("readline", class_maintenance, maintenance_info_readline, _("\
+Display information about version of readline being used.\n\
+\n\
+Displays which version of the readline library GDB is using\n\
+followed by either '(system)' or '(internal)' to indicate if\n\
+GDB is using the shared system library or a statically linked\n\
+in version of the library."),
+	   &maintenanceinfolist);
 }
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index d6aa22321f1..d540783f5cb 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -381,6 +381,9 @@  gdb_test "maint" \
     "List.*unambiguous\\..*" \
     "maint w/o args"
 
+gdb_test "maint info readline" \
+    "^version: \[^\r\n\]+"
+
 # Test that "main info line-table" w/o a file name shows the symtab for
 # $srcfile.
 set saw_srcfile 0