* python/python.c (gdbpy_decode_line): Move cleanup creation out
[deliverable/binutils-gdb.git] / gdb / linespec.c
index 09d62e5154e0467c76c4ee17f2323739bd215514..1e9770ef7c8247ca4279c12346b8573484084f13 100644 (file)
@@ -321,6 +321,33 @@ cplusplus_error (const char *name, const char *fmt, ...)
   throw_error (NOT_FOUND_ERROR, "%s", message);
 }
 
+/* A callback function and the additional data to call it with.  */
+
+struct symbol_and_data_callback
+{
+  /* The callback to use.  */
+  symbol_found_callback_ftype *callback;
+
+  /* Data to be passed to the callback.  */
+  void *data;
+};
+
+/* A helper for iterate_over_all_matching_symtabs that is used to
+   restrict calls to another callback to symbols representing inline
+   symbols only.  */
+
+static int
+iterate_inline_only (struct symbol *sym, void *d)
+{
+  if (SYMBOL_INLINED (sym))
+    {
+      struct symbol_and_data_callback *cad = d;
+
+      return cad->callback (sym, cad->data);
+    }
+  return 1; /* Continue iterating.  */
+}
+
 /* Some data for the expand_symtabs_matching callback.  */
 
 struct symbol_matcher_data
@@ -348,14 +375,16 @@ iterate_name_matcher (const char *name, void *d)
 /* A helper that walks over all matching symtabs in all objfiles and
    calls CALLBACK for each symbol matching NAME.  If SEARCH_PSPACE is
    not NULL, then the search is restricted to just that program
-   space.  */
+   space.  If INCLUDE_INLINE is nonzero then symbols representing
+   inlined instances of functions will be included in the result.  */
 
 static void
 iterate_over_all_matching_symtabs (const char *name,
                                   const domain_enum domain,
                                   symbol_found_callback_ftype *callback,
                                   void *data,
-                                  struct program_space *search_pspace)
+                                  struct program_space *search_pspace,
+                                  int include_inline)
 {
   struct objfile *objfile;
   struct program_space *pspace;
@@ -394,6 +423,20 @@ iterate_over_all_matching_symtabs (const char *name,
 
              block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
              LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback, data);
+
+             if (include_inline)
+               {
+                 struct symbol_and_data_callback cad = { callback, data };
+                 int i;
+
+                 for (i = FIRST_LOCAL_BLOCK;
+                      i < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (symtab)); i++)
+                   {
+                     block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), i);
+                     LA_ITERATE_OVER_SYMBOLS (block, name, domain,
+                                              iterate_inline_only, &cad);
+                   }
+               }
            }
        }
     }
@@ -650,6 +693,11 @@ decode_line_2 (struct linespec_state *self,
       return;
     }
 
+  /* Sort the list of method names alphabetically.  */
+  qsort (VEC_address (const_char_ptr, item_names),
+        VEC_length (const_char_ptr, item_names),
+        sizeof (const_char_ptr), compare_strings);
+
   printf_unfiltered (_("[0] cancel\n[1] all\n"));
   for (i = 0; VEC_iterate (const_char_ptr, item_names, i, iter); ++i)
     printf_unfiltered ("[%d] %s\n", i + 2, iter);
@@ -903,7 +951,7 @@ decode_line_internal (struct linespec_state *self, char **argptr)
 
   /* Locate the end of the first half of the linespec.
      After the call, for instance, if the argptr string is "foo.c:123"
-     p will point at "123".  If there is only one part, like "foo", p
+     p will point at ":123".  If there is only one part, like "foo", p
      will point to "".  If this is a C++ name, like "A::B::foo", p will
      point to "::B::foo".  Argptr is not changed by this call.  */
 
@@ -912,9 +960,11 @@ decode_line_internal (struct linespec_state *self, char **argptr)
   /* First things first: if ARGPTR starts with a filename, get its
      symtab and strip the filename from ARGPTR.
      Avoid calling symtab_from_filename if we know can,
-     it can be expensive.  */
+     it can be expensive.  We know we can avoid the call if we see a
+     single word (e.g., "break NAME") or if we see a qualified C++
+     name ("break QUAL::NAME").  */
 
-  if (*p != '\0')
+  if (*p != '\0' && !(p[0] == ':' && p[1] == ':'))
     {
       TRY_CATCH (file_exception, RETURN_MASK_ERROR)
        {
@@ -1878,10 +1928,10 @@ lookup_prefix_sym (char **argptr, char *p, VEC (symtab_p) *file_symtabs,
        {
          iterate_over_all_matching_symtabs (copy, STRUCT_DOMAIN,
                                             collect_one_symbol, &collector,
-                                            NULL);
+                                            NULL, 0);
          iterate_over_all_matching_symtabs (copy, VAR_DOMAIN,
                                             collect_one_symbol, &collector,
-                                            NULL);
+                                            NULL, 0);
        }
       else
        {
@@ -2244,7 +2294,8 @@ find_function_symbols (char **argptr, char *p, int is_quote_enclosed,
     copy[p - *argptr] = 0;
 
   iterate_over_all_matching_symtabs (copy, VAR_DOMAIN,
-                                    collect_function_symbols, &result, NULL);
+                                    collect_function_symbols, &result, NULL,
+                                    0);
 
   if (VEC_empty (symbolp, result))
     VEC_free (symbolp, result);
@@ -2945,7 +2996,7 @@ add_matching_symbols_to_info (const char *name,
        {
          iterate_over_all_matching_symtabs (name, VAR_DOMAIN,
                                             collect_symbols, info,
-                                            pspace);
+                                            pspace, 1);
          search_minsyms_for_name (info, name, pspace);
        }
       else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt))
This page took 0.0258 seconds and 4 git commands to generate.