[v2,4/5] gdb: Tab-complete registers in expressions

Message ID 20240828014916.162446-5-nt8r@protonmail.com
State New
Headers
Series Tab complete convenience variables |

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-aarch64 fail Test failed

Commit Message

Antonio Rische Aug. 28, 2024, 1:50 a.m. UTC
  ---
 gdb/completer.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
  

Comments

Keith Seitz Aug. 30, 2024, 7:34 p.m. UTC | #1
On 8/27/24 6:50 PM, Antonio Rische wrote:

Please add a commit message. Since you're adding new functionality,
it would be nice to include an example of it here.

> ---
>   gdb/completer.c | 18 +++++++++++++++++-
>   1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/completer.c b/gdb/completer.c
> index 3c9f01c84..bff975b36 100644
> --- a/gdb/completer.c
> +++ b/gdb/completer.c
> @@ -52,6 +52,9 @@ static const char *completion_find_completion_word (completion_tracker &tracker,
>   
>   static void set_rl_completer_word_break_characters (const char *break_chars);
>   
> +static void complete_register (completion_tracker &tracker,
> +			       const char *text, const char *word);
> +
>   /* See completer.h.  */
>   
>   class completion_tracker::completion_hash_entry
> @@ -1105,7 +1108,10 @@ complete_expression (completion_tracker &tracker,
>   	  tracker.advance_custom_word_point_by (1);
>   	  /* We don't support completion of history indices.  */
>   	  if (!isdigit (word[0]))
> -	    complete_internalvar (tracker, word);
> +	    {
> +	      complete_internalvar (tracker, word);
> +	      complete_register (tracker, text, word);

This seems odd to me. Wouldn't this produce incorrect output if a user
typed something nonsensical like "p $crea$ecTAB"?

In this case, we should output no matches, I think.

> +	    }
>   	  tracker.advance_custom_word_point_by (-1);
>   	  return;
>   	}
> @@ -1872,6 +1878,16 @@ reggroup_completer (struct cmd_list_element *ignore,
>   			    complete_reggroup_names);
>   }
>   
> +/* Perform completion on register names.  */
> +
> +void
> +complete_register (completion_tracker &tracker,
> +		    const char *text, const char *word)
> +{
> +  reg_or_group_completer_1 (tracker, text, word,
> +			    complete_register_names);
> +}
> +
>   /* The default completer_handle_brkchars implementation.  */
>   
>   static void

Keith
  

Patch

diff --git a/gdb/completer.c b/gdb/completer.c
index 3c9f01c84..bff975b36 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -52,6 +52,9 @@  static const char *completion_find_completion_word (completion_tracker &tracker,
 
 static void set_rl_completer_word_break_characters (const char *break_chars);
 
+static void complete_register (completion_tracker &tracker,
+			       const char *text, const char *word);
+
 /* See completer.h.  */
 
 class completion_tracker::completion_hash_entry
@@ -1105,7 +1108,10 @@  complete_expression (completion_tracker &tracker,
 	  tracker.advance_custom_word_point_by (1);
 	  /* We don't support completion of history indices.  */
 	  if (!isdigit (word[0]))
-	    complete_internalvar (tracker, word);
+	    {
+	      complete_internalvar (tracker, word);
+	      complete_register (tracker, text, word);
+	    }
 	  tracker.advance_custom_word_point_by (-1);
 	  return;
 	}
@@ -1872,6 +1878,16 @@  reggroup_completer (struct cmd_list_element *ignore,
 			    complete_reggroup_names);
 }
 
+/* Perform completion on register names.  */
+
+void
+complete_register (completion_tracker &tracker,
+		    const char *text, const char *word)
+{
+  reg_or_group_completer_1 (tracker, text, word,
+			    complete_register_names);
+}
+
 /* The default completer_handle_brkchars implementation.  */
 
 static void