[commit] Turn on initial Ada support in GDB (Part 1)

Paul Hilfinger hilfingr@gnat.com
Fri Oct 1 18:13:00 GMT 2004


[Sorry; bounced the original.]

The following approved patches are committed.

PNH

2004-10-01  Paul N. Hilfinger  <Hilfinger@gnat.com>

	* symfile.c (init_filename_language_table): Add extensions for
	Ada.
	* defs.h (enum language): Add language_ada.
	* gdbtypes.h (TYPE_FLAG_FIXED_INSTANCE): Define.
	* ada-lang.c: Strip code that is conditionalized out by GNAT_GDB.
	(add_symbols_from_enclosing_procs): Make a no-op for now.
	(ada_unqualified_name,add_angle_brackets,function_name_from_pc)
	(extended_canonical_line_spec, find_sal_from_funcs_and_line)
	(find_line_in_linetable, find_next_line_in_linetable)
	(read_all_symtabs, is_plausible_func_for_line)
	(adjust_pc_past_prologue, error_breakpoint_runtime_sym_not_found)
	(is_runtime_sym_defined, check_size): Remove declaration.
	(function_name_from_pc, ada_translate_error_message)
	(ada_lookup_minimal_symbol): Remove definition.
	(ada_add_block_symbols): Remove useless label.
	* ada-lang.h (ada_maybe_exception_partial_symbol): Remove 
	useless declaration.
	(ada_is_exception_sym): Likewise.

Index: gdb/ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.54
diff -u -p -r1.54 ada-lang.c
--- gdb/ada-lang.c	18 Sep 2004 22:23:23 -0000	1.54
+++ gdb/ada-lang.c	1 Oct 2004 10:20:07 -0000
@@ -19,18 +19,6 @@ along with this program; if not, write t
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 
-/* Sections of code marked 
-
-     #ifdef GNAT_GDB 
-     ...
-     #endif
-
-   indicate sections that are used in sources distributed by 
-   ACT, Inc., but not yet integrated into the public tree (where
-   GNAT_GDB is not defined).  They are retained here nevertheless 
-   to minimize the problems of maintaining different versions 
-   of the source and to make the full source available. */
-
 #include "defs.h"
 #include <stdio.h>
 #include "gdb_string.h"
@@ -75,27 +63,8 @@ Foundation, Inc., 675 Mass Ave, Cambridg
 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
 #endif
 
-#ifdef GNAT_GDB
-/* A structure that contains a vector of strings.
-   The main purpose of this type is to group the vector and its
-   associated parameters in one structure.  This makes it easier
-   to handle and pass around.  */
-
-struct string_vector
-{
-  char **array; /* The vector itself.  */
-  int index;    /* Index of the next available element in the array.  */
-  size_t size;  /* The number of entries allocated in the array.  */
-};
-
-static struct string_vector xnew_string_vector (int initial_size);
-static void string_vector_append (struct string_vector *sv, char *str);
-#endif /* GNAT_GDB */
 
-static const char *ada_unqualified_name (const char *decoded_name);
-static char *add_angle_brackets (const char *str);
 static void extract_string (CORE_ADDR addr, char *buf);
-static char *function_name_from_pc (CORE_ADDR pc);
 
 static struct type *ada_create_fundamental_type (struct objfile *, int);
 
@@ -184,9 +153,6 @@ static int discrete_type_p (struct type 
 static struct type *ada_lookup_struct_elt_type (struct type *, char *,
                                                 int, int, int *);
 
-static char *extended_canonical_line_spec (struct symtab_and_line,
-                                           const char *);
-
 static struct value *evaluate_subexp (struct type *, struct expression *,
                                       int *, enum noside);
 
@@ -228,19 +194,6 @@ static int is_name_suffix (const char *)
 
 static int wild_match (const char *, int, const char *);
 
-static struct symtabs_and_lines
-find_sal_from_funcs_and_line (const char *, int,
-                              struct ada_symbol_info *, int);
-
-static int find_line_in_linetable (struct linetable *, int,
-                                   struct ada_symbol_info *, int, int *);
-
-static int find_next_line_in_linetable (struct linetable *, int, int, int);
-
-static void read_all_symtabs (const char *);
-
-static int is_plausible_func_for_line (struct symbol *, int);
-
 static struct value *ada_coerce_ref (struct value *);
 
 static LONGEST pos_atr (struct value *);
@@ -266,8 +219,6 @@ static struct value *ada_to_fixed_value_
 
 static struct value *ada_to_fixed_value (struct value *);
 
-static void adjust_pc_past_prologue (CORE_ADDR *);
-
 static int ada_resolve_function (struct ada_symbol_info *, int,
                                  struct value **, int, const char *,
                                  struct type *);
@@ -276,14 +227,8 @@ static struct value *ada_coerce_to_simpl
 
 static int ada_is_direct_array_type (struct type *);
 
-static void error_breakpoint_runtime_sym_not_found (const char *err_desc);
-
-static int is_runtime_sym_defined (const char *name, int allow_tramp);
-
 static void ada_language_arch_info (struct gdbarch *,
 				    struct language_arch_info *);
-
-static void check_size (const struct type *);
 
 
 
@@ -346,69 +291,6 @@ static struct obstack symbol_list_obstac
 
                         /* Utilities */
 
-#ifdef GNAT_GDB
-
-/* Create a new empty string_vector struct with an initial size of
-   INITIAL_SIZE.  */
-
-static struct string_vector
-xnew_string_vector (int initial_size)
-{
-  struct string_vector result;
-
-  result.array = (char **) xmalloc ((initial_size + 1) * sizeof (char *));
-  result.index = 0;
-  result.size = initial_size;
-
-  return result;
-}
-
-/* Add STR at the end of the given string vector SV.  If SV is already
-   full, its size is automatically increased (doubled).  */
-
-static void
-string_vector_append (struct string_vector *sv, char *str)
-{
-  if (sv->index >= sv->size)
-    GROW_VECT (sv->array, sv->size, sv->size * 2);
-
-  sv->array[sv->index] = str;
-  sv->index++;
-}
-
-/* Given DECODED_NAME a string holding a symbol name in its
-   decoded form (ie using the Ada dotted notation), returns
-   its unqualified name.  */
-
-static const char *
-ada_unqualified_name (const char *decoded_name)
-{
-  const char *result = strrchr (decoded_name, '.');
-
-  if (result != NULL)
-    result++;                   /* Skip the dot...  */
-  else
-    result = decoded_name;
-
-  return result;
-}
-
-/* Return a string starting with '<', followed by STR, and '>'.
-   The result is good until the next call.  */
-
-static char *
-add_angle_brackets (const char *str)
-{
-  static char *result = NULL;
-
-  xfree (result);
-  result = (char *) xmalloc ((strlen (str) + 3) * sizeof (char));
-
-  sprintf (result, "<%s>", str);
-  return result;
-}
-
-#endif /* GNAT_GDB */
 
 static char *
 ada_get_gdb_completer_word_break_characters (void)
@@ -435,20 +317,6 @@ extract_string (CORE_ADDR addr, char *bu
   while (buf[char_index - 1] != '\000');
 }
 
-/* Return the name of the function owning the instruction located at PC.
-   Return NULL if no such function could be found.  */
-
-static char *
-function_name_from_pc (CORE_ADDR pc)
-{
-  char *func_name;
-
-  if (!find_pc_partial_function (pc, &func_name, NULL, NULL))
-    return NULL;
-
-  return func_name;
-}
-
 /* Assuming *OLD_VECT points to an array of *SIZE objects of size
    ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
    updating *OLD_VECT and *SIZE as necessary.  */
@@ -617,15 +485,6 @@ lim_warning (const char *format, long ar
     warning (format, arg);
 }
 
-static const char *
-ada_translate_error_message (const char *string)
-{
-  if (strcmp (string, "Invalid cast.") == 0)
-    return "Invalid type conversion.";
-  else
-    return string;
-}
-
 /* Note: would have used MAX_OF_TYPE and MIN_OF_TYPE macros from
    gdbtypes.h, but some of the necessary definitions in that file
    seem to have gone missing. */
@@ -3713,107 +3572,9 @@ ada_convert_actuals (struct value *func,
       convert_actual (args[i], TYPE_FIELD_TYPE (VALUE_TYPE (func), i), sp);
 }
 
-                                /* Experimental Symbol Cache Module */
-
-/* This module may well have been OBE, due to improvements in the 
-   symbol-table module.  So until proven otherwise, it is disabled in
-   the submitted public code, and may be removed from all sources
-   in the future. */
-
-#ifdef GNAT_GDB
-
-/* This section implements a simple, fixed-sized hash table for those
-   Ada-mode symbols that get looked up in the course of executing the user's
-   commands.  The size is fixed on the grounds that there are not
-   likely to be all that many symbols looked up during any given
-   session, regardless of the size of the symbol table.  If we decide
-   to go to a resizable table, let's just use the stuff from libiberty
-   instead.  */
-
-#define HASH_SIZE 1009
-
-struct cache_entry
-{
-  const char *name;
-  domain_enum namespace;
-  struct symbol *sym;
-  struct symtab *symtab;
-  struct block *block;
-  struct cache_entry *next;
-};
-
-static struct obstack cache_space;
-
-static struct cache_entry *cache[HASH_SIZE];
-
-/* Clear all entries from the symbol cache.  */
-
-void
-clear_ada_sym_cache (void)
-{
-  obstack_free (&cache_space, NULL);
-  obstack_init (&cache_space);
-  memset (cache, '\000', sizeof (cache));
-}
-
-static struct cache_entry **
-find_entry (const char *name, domain_enum namespace)
-{
-  int h = msymbol_hash (name) % HASH_SIZE;
-  struct cache_entry **e;
-  for (e = &cache[h]; *e != NULL; e = &(*e)->next)
-    {
-      if (namespace == (*e)->namespace && strcmp (name, (*e)->name) == 0)
-        return e;
-    }
-  return NULL;
-}
-
-/* Return (in SYM) the last cached definition for global or static symbol NAME
-   in namespace DOMAIN.  Returns 1 if entry found, 0 otherwise.
-   If SYMTAB is non-NULL, store the symbol
-   table in which the symbol was found there, or NULL if not found.
-   *BLOCK is set to the block in which NAME is found.  */
-
-static int
-lookup_cached_symbol (const char *name, domain_enum namespace,
-                      struct symbol **sym, struct block **block,
-                      struct symtab **symtab)
-{
-  struct cache_entry **e = find_entry (name, namespace);
-  if (e == NULL)
-    return 0;
-  if (sym != NULL)
-    *sym = (*e)->sym;
-  if (block != NULL)
-    *block = (*e)->block;
-  if (symtab != NULL)
-    *symtab = (*e)->symtab;
-  return 1;
-}
-
-/* Set the cached definition of NAME in DOMAIN to SYM in block
-   BLOCK and symbol table SYMTAB.  */
-
-static void
-cache_symbol (const char *name, domain_enum namespace, struct symbol *sym,
-              struct block *block, struct symtab *symtab)
-{
-  int h = msymbol_hash (name) % HASH_SIZE;
-  char *copy;
-  struct cache_entry *e =
-    (struct cache_entry *) obstack_alloc (&cache_space, sizeof (*e));
-  e->next = cache[h];
-  cache[h] = e;
-  e->name = copy = obstack_alloc (&cache_space, strlen (name) + 1);
-  strcpy (copy, name);
-  e->sym = sym;
-  e->namespace = namespace;
-  e->symtab = symtab;
-  e->block = block;
-}
+/* Dummy definitions for an experimental caching module that is not
+ * used in the public sources. */
 
-#else
 static int
 lookup_cached_symbol (const char *name, domain_enum namespace,
                       struct symbol **sym, struct block **block,
@@ -3827,7 +3588,6 @@ cache_symbol (const char *name, domain_e
               struct block *block, struct symtab *symtab)
 {
 }
-#endif /* GNAT_GDB */
 
                                 /* Symbol Lookup */
 
@@ -4209,16 +3969,6 @@ ada_lookup_simple_minsym (const char *na
   return NULL;
 }
 
-/* Return up minimal symbol for NAME, folded and encoded according to 
-   Ada conventions, or NULL if none.  The last two arguments are ignored.  */
-
-static struct minimal_symbol *
-ada_lookup_minimal_symbol (const char *name, const char *sfile,
-                           struct objfile *objf)
-{
-  return ada_lookup_simple_minsym (ada_encode (name));
-}
-
 /* For all subprograms that statically enclose the subprogram of the
    selected frame, add symbols matching identifier NAME in DOMAIN
    and their blocks to the list of data in OBSTACKP, as for
@@ -4230,72 +3980,6 @@ add_symbols_from_enclosing_procs (struct
                                   const char *name, domain_enum namespace,
                                   int wild_match)
 {
-#ifdef HAVE_ADD_SYMBOLS_FROM_ENCLOSING_PROCS
-  /* Use a heuristic to find the frames of enclosing subprograms: treat the
-     pointer-sized value at location 0 from the local-variable base of a
-     frame as a static link, and then search up the call stack for a
-     frame with that same local-variable base.  */
-  static struct symbol static_link_sym;
-  static struct symbol *static_link;
-  struct value *target_link_val;
-
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-  struct frame_info *frame;
-
-  if (!target_has_stack)
-    return;
-
-  if (static_link == NULL)
-    {
-      /* Initialize the local variable symbol that stands for the
-         static link (when there is one).  */
-      static_link = &static_link_sym;
-      SYMBOL_LINKAGE_NAME (static_link) = "";
-      SYMBOL_LANGUAGE (static_link) = language_unknown;
-      SYMBOL_CLASS (static_link) = LOC_LOCAL;
-      SYMBOL_DOMAIN (static_link) = VAR_DOMAIN;
-      SYMBOL_TYPE (static_link) = lookup_pointer_type (builtin_type_void);
-      SYMBOL_VALUE (static_link) =
-        -(long) TYPE_LENGTH (SYMBOL_TYPE (static_link));
-    }
-
-  frame = get_selected_frame ();
-  if (frame == NULL || inside_main_func (get_frame_address_in_block (frame)))
-    return;
-
-  target_link_val = read_var_value (static_link, frame);
-  while (target_link_val != NULL
-         && num_defns_collected (obstackp) == 0
-         && frame_relative_level (frame) <= MAX_ENCLOSING_FRAME_LEVELS)
-    {
-      CORE_ADDR target_link = value_as_address (target_link_val);
-
-      frame = get_prev_frame (frame);
-      if (frame == NULL)
-        break;
-
-      if (get_frame_locals_address (frame) == target_link)
-        {
-          struct block *block;
-
-          QUIT;
-
-          block = get_frame_block (frame, 0);
-          while (block != NULL && block_function (block) != NULL
-                 && num_defns_collected (obstackp) == 0)
-            {
-              QUIT;
-
-              ada_add_block_symbols (obstackp, block, name, namespace,
-                                     NULL, NULL, wild_match);
-
-              block = BLOCK_SUPERBLOCK (block);
-            }
-        }
-    }
-
-  do_cleanups (old_chain);
-#endif
 }
 
 /* FIXME: The next two routines belong in symtab.c */
@@ -4758,8 +4442,6 @@ done:
    set to 0 and *SYMTAB is set to the symbol table in which the symbol
    was found (in both cases, these assignments occur only if the
    pointers are non-null).  */
-
-
 struct symbol *
 ada_lookup_symbol (const char *name, const struct block *block0,
                    domain_enum namespace, int *is_a_field_of_this,
@@ -5178,7 +4860,6 @@ ada_add_block_symbols (struct obstack *o
                   }
               }
           }
-      end_loop2:;
       }
 
       /* NOTE: This really shouldn't be needed for _ada_ symbols.
@@ -5192,1486 +4873,104 @@ ada_add_block_symbols (struct obstack *o
     }
 }
 
-#ifdef GNAT_GDB
-
-                                /* Symbol Completion */
+                                /* Field Access */
 
-/* If SYM_NAME is a completion candidate for TEXT, return this symbol
-   name in a form that's appropriate for the completion.  The result
-   does not need to be deallocated, but is only good until the next call.
-
-   TEXT_LEN is equal to the length of TEXT.
-   Perform a wild match if WILD_MATCH is set.
-   ENCODED should be set if TEXT represents the start of a symbol name
-   in its encoded form.  */
+/* True if field number FIELD_NUM in struct or union type TYPE is supposed
+   to be invisible to users.  */
 
-static const char *
-symbol_completion_match (const char *sym_name,
-                         const char *text, int text_len,
-                         int wild_match, int encoded)
+int
+ada_is_ignored_field (struct type *type, int field_num)
 {
-  char *result;
-  const int verbatim_match = (text[0] == '<');
-  int match = 0;
-
-  if (verbatim_match)
-    {
-      /* Strip the leading angle bracket.  */
-      text = text + 1;
-      text_len--;
-    }
-
-  /* First, test against the fully qualified name of the symbol.  */
-
-  if (strncmp (sym_name, text, text_len) == 0)
-    match = 1;
-
-  if (match && !encoded)
+  if (field_num < 0 || field_num > TYPE_NFIELDS (type))
+    return 1;
+  else
     {
-      /* One needed check before declaring a positive match is to verify
-         that iff we are doing a verbatim match, the decoded version
-         of the symbol name starts with '<'.  Otherwise, this symbol name
-         is not a suitable completion.  */
-      const char *sym_name_copy = sym_name;
-      int has_angle_bracket;
-
-      sym_name = ada_decode (sym_name);
-      has_angle_bracket = (sym_name[0] == '<');
-      match = (has_angle_bracket == verbatim_match);
-      sym_name = sym_name_copy;
+      const char *name = TYPE_FIELD_NAME (type, field_num);
+      return (name == NULL
+              || (name[0] == '_' && strncmp (name, "_parent", 7) != 0));
     }
+}
 
-  if (match && !verbatim_match)
-    {
-      /* When doing non-verbatim match, another check that needs to
-         be done is to verify that the potentially matching symbol name
-         does not include capital letters, because the ada-mode would
-         not be able to understand these symbol names without the
-         angle bracket notation.  */
-      const char *tmp;
+/* True iff TYPE has a tag field.  If REFOK, then TYPE may also be a
+   pointer or reference type whose ultimate target has a tag field. */
 
-      for (tmp = sym_name; *tmp != '\0' && !isupper (*tmp); tmp++);
-      if (*tmp != '\0')
-        match = 0;
-    }
+int
+ada_is_tagged_type (struct type *type, int refok)
+{
+  return (ada_lookup_struct_elt_type (type, "_tag", refok, 1, NULL) != NULL);
+}
 
-  /* Second: Try wild matching...  */
+/* True iff TYPE represents the type of X'Tag */
 
-  if (!match && wild_match)
+int
+ada_is_tag_type (struct type *type)
+{
+  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR)
+    return 0;
+  else
     {
-      /* Since we are doing wild matching, this means that TEXT
-         may represent an unqualified symbol name.  We therefore must
-         also compare TEXT against the unqualified name of the symbol.  */
-      sym_name = ada_unqualified_name (ada_decode (sym_name));
-
-      if (strncmp (sym_name, text, text_len) == 0)
-        match = 1;
+      const char *name = ada_type_name (TYPE_TARGET_TYPE (type));
+      return (name != NULL
+              && strcmp (name, "ada__tags__dispatch_table") == 0);
     }
-
-  /* Finally: If we found a mach, prepare the result to return.  */
-
-  if (!match)
-    return NULL;
-
-  if (verbatim_match)
-    sym_name = add_angle_brackets (sym_name);
-
-  if (!encoded)
-    sym_name = ada_decode (sym_name);
-
-  return sym_name;
 }
 
-/* A companion function to ada_make_symbol_completion_list().
-   Check if SYM_NAME represents a symbol which name would be suitable
-   to complete TEXT (TEXT_LEN is the length of TEXT), in which case
-   it is appended at the end of the given string vector SV.
-
-   ORIG_TEXT is the string original string from the user command
-   that needs to be completed.  WORD is the entire command on which
-   completion should be performed.  These two parameters are used to
-   determine which part of the symbol name should be added to the
-   completion vector.
-   if WILD_MATCH is set, then wild matching is performed.
-   ENCODED should be set if TEXT represents a symbol name in its
-   encoded formed (in which case the completion should also be
-   encoded).  */
-
-static void
-symbol_completion_add (struct string_vector *sv,
-                       const char *sym_name,
-                       const char *text, int text_len,
-                       const char *orig_text, const char *word,
-                       int wild_match, int encoded)
-{
-  const char *match = symbol_completion_match (sym_name, text, text_len,
-                                               wild_match, encoded);
-  char *completion;
-
-  if (match == NULL)
-    return;
+/* The type of the tag on VAL.  */
 
-  /* We found a match, so add the appropriate completion to the given
-     string vector.  */
+struct type *
+ada_tag_type (struct value *val)
+{
+  return ada_lookup_struct_elt_type (VALUE_TYPE (val), "_tag", 1, 0, NULL);
+}
 
-  if (word == orig_text)
-    {
-      completion = xmalloc (strlen (match) + 5);
-      strcpy (completion, match);
-    }
-  else if (word > orig_text)
-    {
-      /* Return some portion of sym_name.  */
-      completion = xmalloc (strlen (match) + 5);
-      strcpy (completion, match + (word - orig_text));
-    }
-  else
-    {
-      /* Return some of ORIG_TEXT plus sym_name.  */
-      completion = xmalloc (strlen (match) + (orig_text - word) + 5);
-      strncpy (completion, word, orig_text - word);
-      completion[orig_text - word] = '\0';
-      strcat (completion, match);
-    }
+/* The value of the tag on VAL.  */
 
-  string_vector_append (sv, completion);
+struct value *
+ada_value_tag (struct value *val)
+{
+  return ada_value_struct_elt (val, "_tag", "record");
 }
 
-/* Return a list of possible symbol names completing TEXT0.  The list
-   is NULL terminated.  WORD is the entire command on which completion
-   is made.  */
+/* The value of the tag on the object of type TYPE whose contents are
+   saved at VALADDR, if it is non-null, or is at memory address
+   ADDRESS. */
 
-char **
-ada_make_symbol_completion_list (const char *text0, const char *word)
+static struct value *
+value_tag_from_contents_and_address (struct type *type, char *valaddr,
+                                     CORE_ADDR address)
 {
-  /* Note: This function is almost a copy of make_symbol_completion_list(),
-     except it has been adapted for Ada.  It is somewhat of a shame to
-     duplicate so much code, but we don't really have the infrastructure
-     yet to develop a language-aware version of he symbol completer...  */
-  char *text;
-  int text_len;
-  int wild_match;
-  int encoded;
-  struct string_vector result = xnew_string_vector (128);
-  struct symbol *sym;
-  struct symtab *s;
-  struct partial_symtab *ps;
-  struct minimal_symbol *msymbol;
-  struct objfile *objfile;
-  struct block *b, *surrounding_static_block = 0;
-  int i;
-  struct dict_iterator iter;
-
-  if (text0[0] == '<')
-    {
-      text = xstrdup (text0);
-      make_cleanup (xfree, text);
-      text_len = strlen (text);
-      wild_match = 0;
-      encoded = 1;
-    }
-  else
+  int tag_byte_offset, dummy1, dummy2;
+  struct type *tag_type;
+  if (find_struct_field ("_tag", type, 0, &tag_type, &tag_byte_offset,
+                         &dummy1, &dummy2))
     {
-      text = xstrdup (ada_encode (text0));
-      make_cleanup (xfree, text);
-      text_len = strlen (text);
-      for (i = 0; i < text_len; i++)
-        text[i] = tolower (text[i]);
+      char *valaddr1 = (valaddr == NULL) ? NULL : valaddr + tag_byte_offset;
+      CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset;
 
-      /* FIXME: brobecker/2003-09-17: When we get rid of ADA_RETAIN_DOTS,
-         we can restrict the wild_match check to searching "__" only.  */
-      wild_match = (strstr (text0, "__") == NULL
-                    && strchr (text0, '.') == NULL);
-      encoded = (strstr (text0, "__") != NULL);
+      return value_from_contents_and_address (tag_type, valaddr1, address1);
     }
+  return NULL;
+}
 
-  /* First, look at the partial symtab symbols.  */
-  ALL_PSYMTABS (objfile, ps)
-  {
-    struct partial_symbol **psym;
+static struct type *
+type_from_tag (struct value *tag)
+{
+  const char *type_name = ada_tag_name (tag);
+  if (type_name != NULL)
+    return ada_find_any_type (ada_encode (type_name));
+  return NULL;
+}
 
-    /* If the psymtab's been read in we'll get it when we search
-       through the blockvector.  */
-    if (ps->readin)
-      continue;
+struct tag_args
+{
+  struct value *tag;
+  char *name;
+};
 
-    for (psym = objfile->global_psymbols.list + ps->globals_offset;
-         psym < (objfile->global_psymbols.list + ps->globals_offset
-                 + ps->n_global_syms); psym++)
-      {
-        QUIT;
-        symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (*psym),
-                               text, text_len, text0, word,
-                               wild_match, encoded);
-      }
-
-    for (psym = objfile->static_psymbols.list + ps->statics_offset;
-         psym < (objfile->static_psymbols.list + ps->statics_offset
-                 + ps->n_static_syms); psym++)
-      {
-        QUIT;
-        symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (*psym),
-                               text, text_len, text0, word,
-                               wild_match, encoded);
-      }
-  }
-
-  /* At this point scan through the misc symbol vectors and add each
-     symbol you find to the list.  Eventually we want to ignore
-     anything that isn't a text symbol (everything else will be
-     handled by the psymtab code above).  */
-
-  ALL_MSYMBOLS (objfile, msymbol)
-  {
-    QUIT;
-    symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (msymbol),
-                           text, text_len, text0, word, wild_match, encoded);
-  }
-
-  /* Search upwards from currently selected frame (so that we can
-     complete on local vars.  */
-
-  for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
-    {
-      if (!BLOCK_SUPERBLOCK (b))
-        surrounding_static_block = b;   /* For elmin of dups */
-
-      ALL_BLOCK_SYMBOLS (b, iter, sym)
-      {
-        symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym),
-                               text, text_len, text0, word,
-                               wild_match, encoded);
-      }
-    }
-
-  /* Go through the symtabs and check the externs and statics for
-     symbols which match.  */
-
-  ALL_SYMTABS (objfile, s)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
-    ALL_BLOCK_SYMBOLS (b, iter, sym)
-    {
-      symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym),
-                             text, text_len, text0, word,
-                             wild_match, encoded);
-    }
-  }
-
-  ALL_SYMTABS (objfile, s)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
-    /* Don't do this block twice.  */
-    if (b == surrounding_static_block)
-      continue;
-    ALL_BLOCK_SYMBOLS (b, iter, sym)
-    {
-      symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym),
-                             text, text_len, text0, word,
-                             wild_match, encoded);
-    }
-  }
-
-  /* Append the closing NULL entry.  */
-  string_vector_append (&result, NULL);
-
-  return (result.array);
-}
-
-#endif /* GNAT_GDB */
-
-#ifdef GNAT_GDB
-                                /* Breakpoint-related */
-
-/* Assuming that LINE is pointing at the beginning of an argument to
-   'break', return a pointer to the delimiter for the initial segment
-   of that name.  This is the first ':', ' ', or end of LINE.  */
-
-char *
-ada_start_decode_line_1 (char *line)
-{
-  /* NOTE: strpbrk would be more elegant, but I am reluctant to be
-     the first to use such a library function in GDB code.  */
-  char *p;
-  for (p = line; *p != '\000' && *p != ' ' && *p != ':'; p += 1)
-    ;
-  return p;
-}
-
-/* *SPEC points to a function and line number spec (as in a break
-   command), following any initial file name specification.
-
-   Return all symbol table/line specfications (sals) consistent with the
-   information in *SPEC and FILE_TABLE in the following sense:
-     + FILE_TABLE is null, or the sal refers to a line in the file
-       named by FILE_TABLE.
-     + If *SPEC points to an argument with a trailing ':LINENUM',
-       then the sal refers to that line (or one following it as closely as
-       possible).
-     + If *SPEC does not start with '*', the sal is in a function with
-       that name.
-
-   Returns with 0 elements if no matching non-minimal symbols found.
-
-   If *SPEC begins with a function name of the form <NAME>, then NAME
-   is taken as a literal name; otherwise the function name is subject
-   to the usual encoding.
-
-   *SPEC is updated to point after the function/line number specification.
-
-   FUNFIRSTLINE is non-zero if we desire the first line of real code
-   in each function.
-
-   If CANONICAL is non-NULL, and if any of the sals require a
-   'canonical line spec', then *CANONICAL is set to point to an array
-   of strings, corresponding to and equal in length to the returned
-   list of sals, such that (*CANONICAL)[i] is non-null and contains a
-   canonical line spec for the ith returned sal, if needed.  If no
-   canonical line specs are required and CANONICAL is non-null,
-   *CANONICAL is set to NULL.
-
-   A 'canonical line spec' is simply a name (in the format of the
-   breakpoint command) that uniquely identifies a breakpoint position,
-   with no further contextual information or user selection.  It is
-   needed whenever the file name, function name, and line number
-   information supplied is insufficient for this unique
-   identification.  Currently overloaded functions, the name '*',
-   or static functions without a filename yield a canonical line spec.
-   The array and the line spec strings are allocated on the heap; it
-   is the caller's responsibility to free them.  */
-
-struct symtabs_and_lines
-ada_finish_decode_line_1 (char **spec, struct symtab *file_table,
-                          int funfirstline, char ***canonical)
-{
-  struct ada_symbol_info *symbols;
-  const struct block *block;
-  int n_matches, i, line_num;
-  struct symtabs_and_lines selected;
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-  char *name;
-  int is_quoted;
-
-  int len;
-  char *lower_name;
-  char *unquoted_name;
-
-  if (file_table == NULL)
-    block = block_static_block (get_selected_block (0));
-  else
-    block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_table), STATIC_BLOCK);
-
-  if (canonical != NULL)
-    *canonical = (char **) NULL;
-
-  is_quoted = (**spec && strchr (get_gdb_completer_quote_characters (),
-                                 **spec) != NULL);
-
-  name = *spec;
-  if (**spec == '*')
-    *spec += 1;
-  else
-    {
-      if (is_quoted)
-        *spec = skip_quoted (*spec);
-      while (**spec != '\000'
-             && !strchr (ada_completer_word_break_characters, **spec))
-        *spec += 1;
-    }
-  len = *spec - name;
-
-  line_num = -1;
-  if (file_table != NULL && (*spec)[0] == ':' && isdigit ((*spec)[1]))
-    {
-      line_num = strtol (*spec + 1, spec, 10);
-      while (**spec == ' ' || **spec == '\t')
-        *spec += 1;
-    }
-
-  if (name[0] == '*')
-    {
-      if (line_num == -1)
-        error ("Wild-card function with no line number or file name.");
-
-      return ada_sals_for_line (file_table->filename, line_num,
-                                funfirstline, canonical, 0);
-    }
-
-  if (name[0] == '\'')
-    {
-      name += 1;
-      len -= 2;
-    }
-
-  if (name[0] == '<')
-    {
-      unquoted_name = (char *) alloca (len - 1);
-      memcpy (unquoted_name, name + 1, len - 2);
-      unquoted_name[len - 2] = '\000';
-      lower_name = NULL;
-    }
-  else
-    {
-      unquoted_name = (char *) alloca (len + 1);
-      memcpy (unquoted_name, name, len);
-      unquoted_name[len] = '\000';
-      lower_name = (char *) alloca (len + 1);
-      for (i = 0; i < len; i += 1)
-        lower_name[i] = tolower (name[i]);
-      lower_name[len] = '\000';
-    }
-
-  n_matches = 0;
-  if (lower_name != NULL)
-    n_matches = ada_lookup_symbol_list (ada_encode (lower_name), block,
-                                        VAR_DOMAIN, &symbols);
-  if (n_matches == 0)
-    n_matches = ada_lookup_symbol_list (unquoted_name, block,
-                                        VAR_DOMAIN, &symbols);
-  if (n_matches == 0 && line_num >= 0)
-    error ("No line number information found for %s.", unquoted_name);
-  else if (n_matches == 0)
-    {
-#ifdef HPPA_COMPILER_BUG
-      /* FIXME: See comment in symtab.c::decode_line_1 */
-#undef volatile
-      volatile struct symtab_and_line val;
-#define volatile                /*nothing */
-#else
-      struct symtab_and_line val;
-#endif
-      struct minimal_symbol *msymbol;
-
-      init_sal (&val);
-
-      msymbol = NULL;
-      if (lower_name != NULL)
-        msymbol = ada_lookup_simple_minsym (ada_encode (lower_name));
-      if (msymbol == NULL)
-        msymbol = ada_lookup_simple_minsym (unquoted_name);
-      if (msymbol != NULL)
-        {
-          val.pc = SYMBOL_VALUE_ADDRESS (msymbol);
-          val.section = SYMBOL_BFD_SECTION (msymbol);
-          if (funfirstline)
-            {
-              val.pc = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
-							   val.pc,
-							   &current_target);
-              SKIP_PROLOGUE (val.pc);
-            }
-          selected.sals = (struct symtab_and_line *)
-            xmalloc (sizeof (struct symtab_and_line));
-          selected.sals[0] = val;
-          selected.nelts = 1;
-          return selected;
-        }
-
-      if (!have_full_symbols ()
-          && !have_partial_symbols () && !have_minimal_symbols ())
-        error ("No symbol table is loaded.  Use the \"file\" command.");
-
-      error ("Function \"%s\" not defined.", unquoted_name);
-      return selected;          /* for lint */
-    }
-
-  if (line_num >= 0)
-    {
-      struct symtabs_and_lines best_sal =
-        find_sal_from_funcs_and_line (file_table->filename, line_num,
-                                      symbols, n_matches);
-      if (funfirstline)
-        adjust_pc_past_prologue (&best_sal.sals[0].pc);
-      return best_sal;
-    }
-  else
-    {
-      selected.nelts = user_select_syms (symbols, n_matches, n_matches);
-    }
-
-  selected.sals = (struct symtab_and_line *)
-    xmalloc (sizeof (struct symtab_and_line) * selected.nelts);
-  memset (selected.sals, 0, selected.nelts * sizeof (selected.sals[i]));
-  make_cleanup (xfree, selected.sals);
-
-  i = 0;
-  while (i < selected.nelts)
-    {
-      if (SYMBOL_CLASS (symbols[i].sym) == LOC_BLOCK)
-        selected.sals[i]
-          = find_function_start_sal (symbols[i].sym, funfirstline);
-      else if (SYMBOL_LINE (symbols[i].sym) != 0)
-        {
-          selected.sals[i].symtab =
-            symbols[i].symtab
-            ? symbols[i].symtab : symtab_for_sym (symbols[i].sym);
-          selected.sals[i].line = SYMBOL_LINE (symbols[i].sym);
-        }
-      else if (line_num >= 0)
-        {
-          /* Ignore this choice */
-          symbols[i] = symbols[selected.nelts - 1];
-          selected.nelts -= 1;
-          continue;
-        }
-      else
-        error ("Line number not known for symbol \"%s\"", unquoted_name);
-      i += 1;
-    }
-
-  if (canonical != NULL && (line_num >= 0 || n_matches > 1))
-    {
-      *canonical = (char **) xmalloc (sizeof (char *) * selected.nelts);
-      for (i = 0; i < selected.nelts; i += 1)
-        (*canonical)[i] =
-          extended_canonical_line_spec (selected.sals[i],
-                                        SYMBOL_PRINT_NAME (symbols[i].sym));
-    }
-
-  discard_cleanups (old_chain);
-  return selected;
-}
-
-/* The (single) sal corresponding to line LINE_NUM in a symbol table
-   with file name FILENAME that occurs in one of the functions listed
-   in the symbol fields of SYMBOLS[0 .. NSYMS-1].  */
-
-static struct symtabs_and_lines
-find_sal_from_funcs_and_line (const char *filename, int line_num,
-                              struct ada_symbol_info *symbols, int nsyms)
-{
-  struct symtabs_and_lines sals;
-  int best_index, best;
-  struct linetable *best_linetable;
-  struct objfile *objfile;
-  struct symtab *s;
-  struct symtab *best_symtab;
-
-  read_all_symtabs (filename);
-
-  best_index = 0;
-  best_linetable = NULL;
-  best_symtab = NULL;
-  best = 0;
-  ALL_SYMTABS (objfile, s)
-  {
-    struct linetable *l;
-    int ind, exact;
-
-    QUIT;
-
-    if (strcmp (filename, s->filename) != 0)
-      continue;
-    l = LINETABLE (s);
-    ind = find_line_in_linetable (l, line_num, symbols, nsyms, &exact);
-    if (ind >= 0)
-      {
-        if (exact)
-          {
-            best_index = ind;
-            best_linetable = l;
-            best_symtab = s;
-            goto done;
-          }
-        if (best == 0 || l->item[ind].line < best)
-          {
-            best = l->item[ind].line;
-            best_index = ind;
-            best_linetable = l;
-            best_symtab = s;
-          }
-      }
-  }
-
-  if (best == 0)
-    error ("Line number not found in designated function.");
-
-done:
-
-  sals.nelts = 1;
-  sals.sals = (struct symtab_and_line *) xmalloc (sizeof (sals.sals[0]));
-
-  init_sal (&sals.sals[0]);
-
-  sals.sals[0].line = best_linetable->item[best_index].line;
-  sals.sals[0].pc = best_linetable->item[best_index].pc;
-  sals.sals[0].symtab = best_symtab;
-
-  return sals;
-}
-
-/* Return the index in LINETABLE of the best match for LINE_NUM whose
-   pc falls within one of the functions denoted by the symbol fields
-   of SYMBOLS[0..NSYMS-1].  Set *EXACTP to 1 if the match is exact, 
-   and 0 otherwise.  */
-
-static int
-find_line_in_linetable (struct linetable *linetable, int line_num,
-                        struct ada_symbol_info *symbols, int nsyms,
-                        int *exactp)
-{
-  int i, len, best_index, best;
-
-  if (line_num <= 0 || linetable == NULL)
-    return -1;
-
-  len = linetable->nitems;
-  for (i = 0, best_index = -1, best = 0; i < len; i += 1)
-    {
-      int k;
-      struct linetable_entry *item = &(linetable->item[i]);
-
-      for (k = 0; k < nsyms; k += 1)
-        {
-          if (symbols[k].sym != NULL
-              && SYMBOL_CLASS (symbols[k].sym) == LOC_BLOCK
-              && item->pc >= BLOCK_START (SYMBOL_BLOCK_VALUE (symbols[k].sym))
-              && item->pc < BLOCK_END (SYMBOL_BLOCK_VALUE (symbols[k].sym)))
-            goto candidate;
-        }
-      continue;
-
-    candidate:
-
-      if (item->line == line_num)
-        {
-          *exactp = 1;
-          return i;
-        }
-
-      if (item->line > line_num && (best == 0 || item->line < best))
-        {
-          best = item->line;
-          best_index = i;
-        }
-    }
-
-  *exactp = 0;
-  return best_index;
-}
-
-/* Find the smallest k >= LINE_NUM such that k is a line number in
-   LINETABLE, and k falls strictly within a named function that begins at
-   or before LINE_NUM.  Return -1 if there is no such k.  */
-
-static int
-nearest_line_number_in_linetable (struct linetable *linetable, int line_num)
-{
-  int i, len, best;
-
-  if (line_num <= 0 || linetable == NULL || linetable->nitems == 0)
-    return -1;
-  len = linetable->nitems;
-
-  i = 0;
-  best = INT_MAX;
-  while (i < len)
-    {
-      struct linetable_entry *item = &(linetable->item[i]);
-
-      if (item->line >= line_num && item->line < best)
-        {
-          char *func_name;
-          CORE_ADDR start, end;
-
-          func_name = NULL;
-          find_pc_partial_function (item->pc, &func_name, &start, &end);
-
-          if (func_name != NULL && item->pc < end)
-            {
-              if (item->line == line_num)
-                return line_num;
-              else
-                {
-                  struct symbol *sym =
-                    standard_lookup (func_name, NULL, VAR_DOMAIN);
-                  if (is_plausible_func_for_line (sym, line_num))
-                    best = item->line;
-                  else
-                    {
-                      do
-                        i += 1;
-                      while (i < len && linetable->item[i].pc < end);
-                      continue;
-                    }
-                }
-            }
-        }
-
-      i += 1;
-    }
-
-  return (best == INT_MAX) ? -1 : best;
-}
-
-
-/* Return the next higher index, k, into LINETABLE such that k > IND,
-   entry k in LINETABLE has a line number equal to LINE_NUM, k
-   corresponds to a PC that is in a function different from that
-   corresponding to IND, and falls strictly within a named function
-   that begins at a line at or preceding STARTING_LINE.
-   Return -1 if there is no such k.
-   IND == -1 corresponds to no function.  */
-
-static int
-find_next_line_in_linetable (struct linetable *linetable, int line_num,
-                             int starting_line, int ind)
-{
-  int i, len;
-
-  if (line_num <= 0 || linetable == NULL || ind >= linetable->nitems)
-    return -1;
-  len = linetable->nitems;
-
-  if (ind >= 0)
-    {
-      CORE_ADDR start, end;
-
-      if (find_pc_partial_function (linetable->item[ind].pc,
-                                    (char **) NULL, &start, &end))
-        {
-          while (ind < len && linetable->item[ind].pc < end)
-            ind += 1;
-        }
-      else
-        ind += 1;
-    }
-  else
-    ind = 0;
-
-  i = ind;
-  while (i < len)
-    {
-      struct linetable_entry *item = &(linetable->item[i]);
-
-      if (item->line >= line_num)
-        {
-          char *func_name;
-          CORE_ADDR start, end;
-
-          func_name = NULL;
-          find_pc_partial_function (item->pc, &func_name, &start, &end);
-
-          if (func_name != NULL && item->pc < end)
-            {
-              if (item->line == line_num)
-                {
-                  struct symbol *sym =
-                    standard_lookup (func_name, NULL, VAR_DOMAIN);
-                  if (is_plausible_func_for_line (sym, starting_line))
-                    return i;
-                  else
-                    {
-                      while ((i + 1) < len && linetable->item[i + 1].pc < end)
-                        i += 1;
-                    }
-                }
-            }
-        }
-      i += 1;
-    }
-
-  return -1;
-}
-
-/* True iff function symbol SYM starts somewhere at or before line #
-   LINE_NUM.  */
-
-static int
-is_plausible_func_for_line (struct symbol *sym, int line_num)
-{
-  struct symtab_and_line start_sal;
-
-  if (sym == NULL)
-    return 0;
-
-  start_sal = find_function_start_sal (sym, 0);
-
-  return (start_sal.line != 0 && line_num >= start_sal.line);
-}
-
-/* Read in all symbol tables corresponding to partial symbol tables
-   with file name FILENAME.  */
-
-static void
-read_all_symtabs (const char *filename)
-{
-  struct partial_symtab *ps;
-  struct objfile *objfile;
-
-  ALL_PSYMTABS (objfile, ps)
-  {
-    QUIT;
-
-    if (strcmp (filename, ps->filename) == 0)
-      PSYMTAB_TO_SYMTAB (ps);
-  }
-}
-
-/* All sals corresponding to line LINE_NUM in a symbol table from file
-   FILENAME, as filtered by the user.  Filter out any lines that
-   reside in functions with "suppressed" names (not corresponding to
-   explicit Ada functions), if there is at least one in a function
-   with a non-suppressed name.  If CANONICAL is not null, set
-   it to a corresponding array of canonical line specs.
-   If ONE_LOCATION_ONLY is set and several matches are found for
-   the given location, then automatically select the first match found
-   instead of asking the user which instance should be returned.  */
-
-struct symtabs_and_lines
-ada_sals_for_line (const char *filename, int line_num,
-                   int funfirstline, char ***canonical, int one_location_only)
-{
-  struct symtabs_and_lines result;
-  struct objfile *objfile;
-  struct symtab *s;
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-  size_t len;
-
-  read_all_symtabs (filename);
-
-  result.sals =
-    (struct symtab_and_line *) xmalloc (4 * sizeof (result.sals[0]));
-  result.nelts = 0;
-  len = 4;
-  make_cleanup (free_current_contents, &result.sals);
-
-  ALL_SYMTABS (objfile, s)
-  {
-    int ind, target_line_num;
-
-    QUIT;
-
-    if (strcmp (s->filename, filename) != 0)
-      continue;
-
-    target_line_num =
-      nearest_line_number_in_linetable (LINETABLE (s), line_num);
-    if (target_line_num == -1)
-      continue;
-
-    ind = -1;
-    while (1)
-      {
-        ind =
-          find_next_line_in_linetable (LINETABLE (s),
-                                       target_line_num, line_num, ind);
-
-        if (ind < 0)
-          break;
-
-        GROW_VECT (result.sals, len, result.nelts + 1);
-        init_sal (&result.sals[result.nelts]);
-        result.sals[result.nelts].line = line_num;
-        result.sals[result.nelts].pc = LINETABLE (s)->item[ind].pc;
-        result.sals[result.nelts].symtab = s;
-
-        if (funfirstline)
-          adjust_pc_past_prologue (&result.sals[result.nelts].pc);
-
-        result.nelts += 1;
-      }
-  }
-
-  if (canonical != NULL || result.nelts > 1)
-    {
-      int k, j, n;
-      char **func_names = (char **) alloca (result.nelts * sizeof (char *));
-      int first_choice = (result.nelts > 1) ? 2 : 1;
-      int *choices = (int *) alloca (result.nelts * sizeof (int));
-
-      for (k = 0; k < result.nelts; k += 1)
-        {
-          find_pc_partial_function (result.sals[k].pc, &func_names[k],
-                                    (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
-          if (func_names[k] == NULL)
-            error ("Could not find function for one or more breakpoints.");
-        }
-
-      /* Remove suppressed names, unless all are suppressed.  */
-      for (j = 0; j < result.nelts; j += 1)
-        if (!is_suppressed_name (func_names[j]))
-          {
-            /* At least one name is unsuppressed, so remove all
-               suppressed names.  */
-            for (k = n = 0; k < result.nelts; k += 1)
-              if (!is_suppressed_name (func_names[k]))
-                {
-                  func_names[n] = func_names[k];
-                  result.sals[n] = result.sals[k];
-                  n += 1;
-                }
-            result.nelts = n;
-            break;
-          }
-
-      if (result.nelts > 1)
-        {
-          if (one_location_only)
-            {
-              /* Automatically select the first of all possible choices.  */
-              n = 1;
-              choices[0] = 0;
-            }
-          else
-            {
-              printf_unfiltered ("[0] cancel\n");
-              if (result.nelts > 1)
-                printf_unfiltered ("[1] all\n");
-              for (k = 0; k < result.nelts; k += 1)
-                printf_unfiltered ("[%d] %s\n", k + first_choice,
-                                   ada_decode (func_names[k]));
-
-              n = get_selections (choices, result.nelts, result.nelts,
-                                  result.nelts > 1, "instance-choice");
-            }
-
-          for (k = 0; k < n; k += 1)
-            {
-              result.sals[k] = result.sals[choices[k]];
-              func_names[k] = func_names[choices[k]];
-            }
-          result.nelts = n;
-        }
-
-      if (canonical != NULL && result.nelts == 0)
-        *canonical = NULL;
-      else if (canonical != NULL)
-        {
-          *canonical = (char **) xmalloc (result.nelts * sizeof (char **));
-          make_cleanup (xfree, *canonical);
-          for (k = 0; k < result.nelts; k += 1)
-            {
-              (*canonical)[k] =
-                extended_canonical_line_spec (result.sals[k], func_names[k]);
-              if ((*canonical)[k] == NULL)
-                error ("Could not locate one or more breakpoints.");
-              make_cleanup (xfree, (*canonical)[k]);




More information about the Gdb-patches mailing list