Uniquefy gdb.threads/attach-into-signal.exp
[deliverable/binutils-gdb.git] / gdb / completer.c
index bfd2788ecce5a6873ee6e083ad5941f52f783ecd..d1ebf67f08c5b3001ef349efbfc1f44edc957acb 100644 (file)
@@ -26,6 +26,7 @@
 #include "target.h"
 #include "reggroups.h"
 #include "user-regs.h"
+#include "arch-utils.h"
 
 #include "cli/cli-decode.h"
 
@@ -343,7 +344,7 @@ add_struct_fields (struct type *type, VEC (char_ptr) **output,
   int computed_type_name = 0;
   const char *type_name = NULL;
 
-  CHECK_TYPEDEF (type);
+  type = check_typedef (type);
   for (i = 0; i < TYPE_NFIELDS (type); ++i)
     {
       if (i < TYPE_N_BASECLASSES (type))
@@ -395,23 +396,26 @@ expression_completer (struct cmd_list_element *ignore,
   struct type *type = NULL;
   char *fieldname;
   const char *p;
-  volatile struct gdb_exception except;
   enum type_code code = TYPE_CODE_UNDEF;
 
   /* Perform a tentative parse of the expression, to see whether a
      field completion is required.  */
   fieldname = NULL;
-  TRY_CATCH (except, RETURN_MASK_ERROR)
+  TRY
     {
       type = parse_expression_for_completion (text, &fieldname, &code);
     }
-  if (except.reason < 0)
-    return NULL;
+  CATCH (except, RETURN_MASK_ERROR)
+    {
+      return NULL;
+    }
+  END_CATCH
+
   if (fieldname && type)
     {
       for (;;)
        {
-         CHECK_TYPEDEF (type);
+         type = check_typedef (type);
          if (TYPE_CODE (type) != TYPE_CODE_PTR
              && TYPE_CODE (type) != TYPE_CODE_REF)
            break;
@@ -860,14 +864,7 @@ throw_max_completions_reached_error (void)
 /* Generate completions all at once.  Returns a vector of unique strings
    allocated with xmalloc.  Returns NULL if there are no completions
    or if max_completions is 0.  If max_completions is non-negative, this will
-   return at most max_completions + 1 strings.
-
-   If max_completions strings are collected, an extra string is added which
-   is a text message to inform the user that the list may be truncated.
-   This extra string serves two purposes:
-   1) Inform the user.
-   2) Prevent readline from being able to find a common prefix to advance
-      point to, since it's working with an incomplete list.
+   return at most max_completions strings.
 
    TEXT is the caller's idea of the "word" we are looking at.
 
@@ -951,7 +948,7 @@ signal_completer (struct cmd_list_element *ignore,
 {
   VEC (char_ptr) *return_val = NULL;
   size_t len = strlen (word);
-  enum gdb_signal signum;
+  int signum;
   const char *signame;
 
   for (signum = GDB_SIGNAL_FIRST; signum != GDB_SIGNAL_LAST; ++signum)
@@ -960,7 +957,7 @@ signal_completer (struct cmd_list_element *ignore,
       if (signum == GDB_SIGNAL_0)
        continue;
 
-      signame = gdb_signal_to_name (signum);
+      signame = gdb_signal_to_name ((enum gdb_signal) signum);
 
       /* Ignore the unknown signal case.  */
       if (!signame || strcmp (signame, "?") == 0)
@@ -973,44 +970,82 @@ signal_completer (struct cmd_list_element *ignore,
   return return_val;
 }
 
-/* Complete on a register or reggroup.  */
+/* Bit-flags for selecting what the register and/or register-group
+   completer should complete on.  */
 
-VEC (char_ptr) *
-reg_or_group_completer (struct cmd_list_element *ignore,
-                       const char *text, const char *word)
+enum reg_completer_targets
+  {
+    complete_register_names = 0x1,
+    complete_reggroup_names = 0x2
+  };
+
+/* Complete register names and/or reggroup names based on the value passed
+   in TARGETS.  At least one bit in TARGETS must be set.  */
+
+static VEC (char_ptr) *
+reg_or_group_completer_1 (struct cmd_list_element *ignore,
+                         const char *text, const char *word,
+                         enum reg_completer_targets targets)
 {
   VEC (char_ptr) *result = NULL;
   size_t len = strlen (word);
   struct gdbarch *gdbarch;
-  struct reggroup *group;
   const char *name;
-  int i;
-
-  if (!target_has_registers)
-    return result;
 
-  gdbarch = get_frame_arch (get_selected_frame (NULL));
+  gdb_assert ((targets & (complete_register_names
+                         | complete_reggroup_names)) != 0);
+  gdbarch = get_current_arch ();
 
-  for (i = 0;
-       (name = user_reg_map_regnum_to_name (gdbarch, i)) != NULL;
-       i++)
+  if ((targets & complete_register_names) != 0)
     {
-      if (*name != '\0' && strncmp (word, name, len) == 0)
-       VEC_safe_push (char_ptr, result, xstrdup (name));
+      int i;
+
+      for (i = 0;
+          (name = user_reg_map_regnum_to_name (gdbarch, i)) != NULL;
+          i++)
+       {
+         if (*name != '\0' && strncmp (word, name, len) == 0)
+           VEC_safe_push (char_ptr, result, xstrdup (name));
+       }
     }
 
-  for (group = reggroup_next (gdbarch, NULL);
-       group != NULL;
-       group = reggroup_next (gdbarch, group))
+  if ((targets & complete_reggroup_names) != 0)
     {
-      name = reggroup_name (group);
-      if (strncmp (word, name, len) == 0)
-       VEC_safe_push (char_ptr, result, xstrdup (name));
+      struct reggroup *group;
+
+      for (group = reggroup_next (gdbarch, NULL);
+          group != NULL;
+          group = reggroup_next (gdbarch, group))
+       {
+         name = reggroup_name (group);
+         if (strncmp (word, name, len) == 0)
+           VEC_safe_push (char_ptr, result, xstrdup (name));
+       }
     }
 
   return result;
 }
 
+/* Perform completion on register and reggroup names.  */
+
+VEC (char_ptr) *
+reg_or_group_completer (struct cmd_list_element *ignore,
+                       const char *text, const char *word)
+{
+  return reg_or_group_completer_1 (ignore, text, word,
+                                  (complete_register_names
+                                   | complete_reggroup_names));
+}
+
+/* Perform completion on reggroup names.  */
+
+VEC (char_ptr) *
+reggroup_completer (struct cmd_list_element *ignore,
+                   const char *text, const char *word)
+{
+  return reg_or_group_completer_1 (ignore, text, word,
+                                  complete_reggroup_names);
+}
 
 /* Get the list of chars that are considered as word breaks
    for the current command.  */
@@ -1555,6 +1590,12 @@ gdb_complete_get_screenwidth (const struct match_list_displayer *displayer)
   return displayer->width;
 }
 
+extern int _rl_completion_prefix_display_length;
+extern int _rl_print_completions_horizontally;
+
+EXTERN_C int _rl_qsort_string_compare (const void *, const void *);
+typedef int QSFUNC (const void *, const void *);
+
 /* GDB version of readline/complete.c:rl_display_match_list.
    See gdb_display_match_list for a description of MATCHES, LEN, MAX.
    Returns non-zero if all matches are displayed.  */
@@ -1567,10 +1608,6 @@ gdb_display_match_list_1 (char **matches, int len, int max,
   int i, j, k, l, common_length, sind;
   char *temp, *t;
   int page_completions = displayer->height != INT_MAX && pagination_enabled;
-  extern int _rl_completion_prefix_display_length;
-  extern int _rl_qsort_string_compare (const void *, const void *);
-  extern int _rl_print_completions_horizontally;
-  typedef int QSFUNC (const void *, const void *);
 
   /* Find the length of the prefix common to all items: length as displayed
      characters (common_length) and as a byte index into the matches (sind) */
This page took 0.026515 seconds and 4 git commands to generate.