* breakpoint.c (do_enable_breakpoint): Use update_watchpoint for
[binutils-gdb.git] / gdb / symtab.c
index 1a0dcbad1d278cb6498572ec0f9d0a21d1a51bff..b9befedf339897cbca50716fb8e37433d3f2fc28 100644 (file)
@@ -1,7 +1,7 @@
 /* Symbol table lookup for the GNU debugger, GDB.
 
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -58,6 +58,8 @@
 #include "observer.h"
 #include "gdb_assert.h"
 #include "solist.h"
+#include "macrotab.h"
+#include "macroscope.h"
 
 /* Prototypes for local functions */
 
@@ -857,11 +859,11 @@ find_pc_sect_psymtab (CORE_ADDR pc, struct obj_section *section)
      not include the data ranges.  */
   msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
   if (msymbol
-      && (msymbol->type == mst_data
-         || msymbol->type == mst_bss
-         || msymbol->type == mst_abs
-         || msymbol->type == mst_file_data
-         || msymbol->type == mst_file_bss))
+      && (MSYMBOL_TYPE (msymbol) == mst_data
+         || MSYMBOL_TYPE (msymbol) == mst_bss
+         || MSYMBOL_TYPE (msymbol) == mst_abs
+         || MSYMBOL_TYPE (msymbol) == mst_file_data
+         || MSYMBOL_TYPE (msymbol) == mst_file_bss))
     return NULL;
 
   /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
@@ -1991,11 +1993,11 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section)
      on the partial_symtab's texthigh and textlow.  */
   msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
   if (msymbol
-      && (msymbol->type == mst_data
-         || msymbol->type == mst_bss
-         || msymbol->type == mst_abs
-         || msymbol->type == mst_file_data
-         || msymbol->type == mst_file_bss))
+      && (MSYMBOL_TYPE (msymbol) == mst_data
+         || MSYMBOL_TYPE (msymbol) == mst_bss
+         || MSYMBOL_TYPE (msymbol) == mst_abs
+         || MSYMBOL_TYPE (msymbol) == mst_file_data
+         || MSYMBOL_TYPE (msymbol) == mst_file_bss))
     return NULL;
 
   /* Search all symtabs for the one whose file contains our address, and which
@@ -2987,7 +2989,6 @@ sort_search_symbols (struct symbol_search *prevtail, int nfound)
    Only symbols of KIND are searched:
    FUNCTIONS_DOMAIN - search all functions
    TYPES_DOMAIN     - search all type names
-   METHODS_DOMAIN   - search all methods NOT IMPLEMENTED
    VARIABLES_DOMAIN - search all symbols, excluding functions, type names,
    and constants (enums)
 
@@ -3128,8 +3129,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
                    && ((kind == VARIABLES_DOMAIN && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
                         && SYMBOL_CLASS (*psym) != LOC_BLOCK)
                        || (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (*psym) == LOC_BLOCK)
-                       || (kind == TYPES_DOMAIN && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
-                       || (kind == METHODS_DOMAIN && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
+                       || (kind == TYPES_DOMAIN && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))))
              {
                PSYMTAB_TO_SYMTAB (ps);
                keep_going = 0;
@@ -3204,8 +3204,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
                           && SYMBOL_CLASS (sym) != LOC_BLOCK
                           && SYMBOL_CLASS (sym) != LOC_CONST)
                          || (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (sym) == LOC_BLOCK)
-                         || (kind == TYPES_DOMAIN && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
-                         || (kind == METHODS_DOMAIN && SYMBOL_CLASS (sym) == LOC_BLOCK))))
+                         || (kind == TYPES_DOMAIN && SYMBOL_CLASS (sym) == LOC_TYPEDEF))))
                {
                  /* match */
                  psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
@@ -3640,6 +3639,29 @@ language_search_unquoted_string (char *text, char *p)
   return p;
 }
 
+/* Type of the user_data argument passed to add_macro_name.  The
+   contents are simply whatever is needed by
+   completion_list_add_name.  */
+struct add_macro_name_data
+{
+  char *sym_text;
+  int sym_text_len;
+  char *text;
+  char *word;
+};
+
+/* A callback used with macro_for_each and macro_for_each_in_scope.
+   This adds a macro's name to the current completion list.  */
+static void
+add_macro_name (const char *name, const struct macro_definition *ignore,
+               void *user_data)
+{
+  struct add_macro_name_data *datum = (struct add_macro_name_data *) user_data;
+  completion_list_add_name ((char *) name,
+                           datum->sym_text, datum->sym_text_len,
+                           datum->text, datum->word);
+}
+
 char **
 default_make_symbol_completion_list (char *text, char *word)
 {
@@ -3826,6 +3848,35 @@ default_make_symbol_completion_list (char *text, char *word)
       }
   }
 
+  if (current_language->la_macro_expansion == macro_expansion_c)
+    {
+      struct macro_scope *scope;
+      struct add_macro_name_data datum;
+
+      datum.sym_text = sym_text;
+      datum.sym_text_len = sym_text_len;
+      datum.text = text;
+      datum.word = word;
+
+      /* Add any macros visible in the default scope.  Note that this
+        may yield the occasional wrong result, because an expression
+        might be evaluated in a scope other than the default.  For
+        example, if the user types "break file:line if <TAB>", the
+        resulting expression will be evaluated at "file:line" -- but
+        at there does not seem to be a way to detect this at
+        completion time.  */
+      scope = default_macro_scope ();
+      if (scope)
+       {
+         macro_for_each_in_scope (scope->file, scope->line,
+                                  add_macro_name, &datum);
+         xfree (scope);
+       }
+
+      /* User-defined macros are always visible.  */
+      macro_for_each (macro_user_macros, add_macro_name, &datum);
+    }
+
   return (return_val);
 }
 
@@ -4198,6 +4249,7 @@ skip_prologue_using_sal (CORE_ADDR func_addr)
   struct symtab_and_line prologue_sal;
   CORE_ADDR start_pc;
   CORE_ADDR end_pc;
+  struct block *bl;
 
   /* Get an initial range for the function.  */
   find_pc_partial_function (func_addr, NULL, &start_pc, &end_pc);
@@ -4206,11 +4258,35 @@ skip_prologue_using_sal (CORE_ADDR func_addr)
   prologue_sal = find_pc_line (start_pc, 0);
   if (prologue_sal.line != 0)
     {
+      /* For langauges other than assembly, treat two consecutive line
+        entries at the same address as a zero-instruction prologue.
+        The GNU assembler emits separate line notes for each instruction
+        in a multi-instruction macro, but compilers generally will not
+        do this.  */
+      if (prologue_sal.symtab->language != language_asm)
+       {
+         struct linetable *linetable = LINETABLE (prologue_sal.symtab);
+         int exact;
+         int idx = 0;
+
+         /* Skip any earlier lines, and any end-of-sequence marker
+            from a previous function.  */
+         while (linetable->item[idx].pc != prologue_sal.pc
+                || linetable->item[idx].line == 0)
+           idx++;
+
+         if (idx+1 < linetable->nitems
+             && linetable->item[idx+1].line != 0
+             && linetable->item[idx+1].pc == start_pc)
+           return start_pc;
+       }
+
       /* If there is only one sal that covers the entire function,
         then it is probably a single line function, like
         "foo(){}". */
       if (prologue_sal.end >= end_pc)
        return 0;
+
       while (prologue_sal.end < end_pc)
        {
          struct symtab_and_line sal;
@@ -4232,7 +4308,14 @@ skip_prologue_using_sal (CORE_ADDR func_addr)
          prologue_sal = sal;
        }
     }
-  return prologue_sal.end;
+
+  if (prologue_sal.end < end_pc)
+    /* Return the end of this line, or zero if we could not find a
+       line.  */
+    return prologue_sal.end;
+  else
+    /* Don't return END_PC, which is past the end of the function.  */
+    return prologue_sal.pc;
 }
 \f
 struct symtabs_and_lines