Resolve more problems with readelf uncovered by fuzzing binary files.
[deliverable/binutils-gdb.git] / gdb / stack.c
index 16a03eb1e3fcbb6037063fe57a88740c9e5c6b2f..2834801f2cbe27178e3434180be08ebba217e7fb 100644 (file)
@@ -1,6 +1,6 @@
 /* Print and select stack frames for GDB, the GNU debugger.
 
-   Copyright (C) 1986-2013 Free Software Foundation, Inc.
+   Copyright (C) 1986-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -36,7 +36,6 @@
 #include "block.h"
 #include "stack.h"
 #include "dictionary.h"
-#include "exceptions.h"
 #include "reggroups.h"
 #include "regcache.h"
 #include "solib.h"
 #include "inline-frame.h"
 #include "linespec.h"
 #include "cli/cli-utils.h"
+#include "objfiles.h"
 
-#include "gdb_assert.h"
 #include <ctype.h>
-#include "gdb_string.h"
-
 #include "symfile.h"
-#include "python/python.h"
+#include "extension.h"
 
 void (*deprecated_selected_frame_level_changed_hook) (int);
 
@@ -154,7 +151,8 @@ frame_show_address (struct frame_info *frame,
 
 void
 print_stack_frame (struct frame_info *frame, int print_level,
-                  enum print_what print_what)
+                  enum print_what print_what,
+                  int set_current_sal)
 {
   volatile struct gdb_exception e;
 
@@ -164,10 +162,10 @@ print_stack_frame (struct frame_info *frame, int print_level,
 
   TRY_CATCH (e, RETURN_MASK_ERROR)
     {
-      int center = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
-
-      print_frame_info (frame, print_level, print_what, 1 /* print_args */);
-      set_current_sal_from_frame (frame, center);
+      print_frame_info (frame, print_level, print_what, 1 /* print_args */,
+                       set_current_sal);
+      if (set_current_sal)
+       set_current_sal_from_frame (frame);
     }
 }
 
@@ -383,9 +381,12 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
            {
              struct type *type = value_type (val);
 
-             if (!value_optimized_out (val)
-                 && value_available_contents_eq (val, 0, entryval, 0,
-                                                 TYPE_LENGTH (type)))
+             if (value_lazy (val))
+               value_fetch_lazy (val);
+             if (value_lazy (entryval))
+               value_fetch_lazy (entryval);
+
+             if (value_contents_eq (val, 0, entryval, 0, TYPE_LENGTH (type)))
                {
                  /* Initialize it just to avoid a GCC false warning.  */
                  struct value *val_deref = NULL, *entryval_deref;
@@ -411,9 +412,9 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
                      /* If the reference addresses match but dereferenced
                         content does not match print them.  */
                      if (val != val_deref
-                         && value_available_contents_eq (val_deref, 0,
-                                                         entryval_deref, 0,
-                                                     TYPE_LENGTH (type_deref)))
+                         && value_contents_eq (val_deref, 0,
+                                               entryval_deref, 0,
+                                               TYPE_LENGTH (type_deref)))
                        val_equal = 1;
                    }
 
@@ -536,7 +537,7 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
 
   if (func)
     {
-      struct block *b = SYMBOL_BLOCK_VALUE (func);
+      const struct block *b = SYMBOL_BLOCK_VALUE (func);
       struct block_iterator iter;
       struct symbol *sym;
 
@@ -712,17 +713,13 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
    line is in the center of the next 'list'.  */
 
 void
-set_current_sal_from_frame (struct frame_info *frame, int center)
+set_current_sal_from_frame (struct frame_info *frame)
 {
   struct symtab_and_line sal;
 
   find_frame_sal (frame, &sal);
-  if (sal.symtab)
-    {
-      if (center)
-        sal.line = max (sal.line - get_lines_to_list () / 2, 1);
-      set_current_source_symtab_and_line (&sal);
-    }
+  if (sal.symtab != NULL)
+    set_current_source_symtab_and_line (&sal);
 }
 
 /* If ON, GDB will display disassembly of the next source line when
@@ -780,7 +777,8 @@ do_gdb_disassembly (struct gdbarch *gdbarch,
 
 void
 print_frame_info (struct frame_info *frame, int print_level,
-                 enum print_what print_what, int print_args)
+                 enum print_what print_what, int print_args,
+                 int set_current_sal)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   struct symtab_and_line sal;
@@ -831,6 +829,13 @@ print_frame_info (struct frame_info *frame, int print_level,
       ui_out_text (uiout, "\n");
       annotate_frame_end ();
 
+      /* If disassemble-next-line is set to auto or on output the next
+        instruction.  */
+      if (disassemble_next_line == AUTO_BOOLEAN_AUTO
+         || disassemble_next_line == AUTO_BOOLEAN_TRUE)
+       do_gdb_disassembly (get_frame_arch (frame), 1,
+                           get_frame_pc (frame), get_frame_pc (frame) + 1);
+
       do_cleanups (uiout_cleanup);
       return;
     }
@@ -905,7 +910,7 @@ print_frame_info (struct frame_info *frame, int print_level,
        do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
     }
 
-  if (print_what != LOCATION)
+  if (set_current_sal)
     {
       CORE_ADDR pc;
 
@@ -1072,14 +1077,14 @@ find_frame_funname (struct frame_info *frame, char **funname,
        memset (&msymbol, 0, sizeof (msymbol));
 
       if (msymbol.minsym != NULL
-         && (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
+         && (BMSYMBOL_VALUE_ADDRESS (msymbol)
              > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
        {
          /* We also don't know anything about the function besides
             its address and name.  */
          func = 0;
-         *funname = xstrdup (SYMBOL_PRINT_NAME (msymbol.minsym));
-         *funlang = SYMBOL_LANGUAGE (msymbol.minsym);
+         *funname = xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym));
+         *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
        }
       else
        {
@@ -1115,8 +1120,8 @@ find_frame_funname (struct frame_info *frame, char **funname,
       msymbol = lookup_minimal_symbol_by_pc (pc);
       if (msymbol.minsym != NULL)
        {
-         *funname = xstrdup (SYMBOL_PRINT_NAME (msymbol.minsym));
-         *funlang = SYMBOL_LANGUAGE (msymbol.minsym);
+         *funname = xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym));
+         *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
        }
     }
 }
@@ -1403,7 +1408,9 @@ frame_info (char *addr_exp, int from_tty)
   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
   CORE_ADDR frame_pc;
   int frame_pc_p;
-  CORE_ADDR caller_pc;
+  /* Initialize it to avoid "may be used uninitialized" warning.  */
+  CORE_ADDR caller_pc = 0;
+  volatile struct gdb_exception ex;
 
   fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
   gdbarch = get_frame_arch (fi);
@@ -1453,8 +1460,8 @@ frame_info (char *addr_exp, int from_tty)
       msymbol = lookup_minimal_symbol_by_pc (frame_pc);
       if (msymbol.minsym != NULL)
        {
-         funname = SYMBOL_PRINT_NAME (msymbol.minsym);
-         funlang = SYMBOL_LANGUAGE (msymbol.minsym);
+         funname = MSYMBOL_PRINT_NAME (msymbol.minsym);
+         funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
        }
     }
   calling_frame_info = get_prev_frame (fi);
@@ -1489,11 +1496,29 @@ frame_info (char *addr_exp, int from_tty)
                     sal.line);
   puts_filtered ("; ");
   wrap_here ("    ");
-  printf_filtered ("saved %s ", pc_regname);
-  if (frame_unwind_caller_pc_if_available (fi, &caller_pc))
-    fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
+  printf_filtered ("saved %s = ", pc_regname);
+
+  TRY_CATCH (ex, RETURN_MASK_ERROR)
+    {
+      caller_pc = frame_unwind_caller_pc (fi);
+    }
+  if (ex.reason < 0)
+    {
+      switch (ex.error)
+       {
+       case NOT_AVAILABLE_ERROR:
+         val_print_unavailable (gdb_stdout);
+         break;
+       case OPTIMIZED_OUT_ERROR:
+         val_print_not_saved (gdb_stdout);
+         break;
+       default:
+         fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
+         break;
+       }
+    }
   else
-    fputs_filtered ("<unavailable>", gdb_stdout);
+    fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
   printf_filtered ("\n");
 
   if (calling_frame_info == NULL)
@@ -1503,7 +1528,7 @@ frame_info (char *addr_exp, int from_tty)
       reason = get_frame_unwind_stop_reason (fi);
       if (reason != UNWIND_NO_REASON)
        printf_filtered (_(" Outermost frame: %s\n"),
-                        frame_stop_reason_string (reason));
+                        frame_stop_reason_string (fi));
     }
   else if (get_frame_type (fi) == TAILCALL_FRAME)
     puts_filtered (" tail call frame");
@@ -1684,7 +1709,7 @@ backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
   int i;
   struct frame_info *trailing;
   int trailing_level, py_start = 0, py_end = 0;
-  enum py_bt_status result = PY_BT_ERROR;
+  enum ext_lang_bt_status result = EXT_LANG_BT_ERROR;
 
   if (!target_has_stack)
     error (_("No stack."));
@@ -1751,14 +1776,14 @@ backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
 
          QUIT;
          pc = get_frame_address_in_block (fi);
-         find_pc_sect_symtab_via_partial (pc, find_pc_mapped_section (pc));
+         expand_symtab_containing_pc (pc, find_pc_mapped_section (pc));
        }
     }
 
   if (! no_filters)
     {
       int flags = PRINT_LEVEL | PRINT_FRAME_INFO | PRINT_ARGS;
-      enum py_frame_args arg_type;
+      enum ext_lang_frame_args arg_type;
 
       if (show_locals)
        flags |= PRINT_LOCALS;
@@ -1770,13 +1795,14 @@ backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
       else
        arg_type = NO_VALUES;
 
-      result = apply_frame_filter (get_current_frame (), flags, arg_type,
-                                  current_uiout, py_start, py_end);
-
+      result = apply_ext_lang_frame_filter (get_current_frame (), flags,
+                                           arg_type, current_uiout,
+                                           py_start, py_end);
     }
+
   /* Run the inbuilt backtrace if there are no filters registered, or
      "no-filters" has been specified from the command.  */
-  if (no_filters ||  result == PY_BT_NO_FILTERS)
+  if (no_filters ||  result == EXT_LANG_BT_NO_FILTERS)
     {
       for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
        {
@@ -1787,7 +1813,7 @@ backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
             hand, perhaps the code does or could be fixed to make sure
             the frame->prev field gets set to NULL in that case).  */
 
-         print_frame_info (fi, 1, LOCATION, 1);
+         print_frame_info (fi, 1, LOCATION, 1, 0);
          if (show_locals)
            {
              struct frame_id frame_id = get_frame_id (fi);
@@ -1821,7 +1847,7 @@ backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
          reason = get_frame_unwind_stop_reason (trailing);
          if (reason >= UNWIND_FIRST_ERROR)
            printf_filtered (_("Backtrace stopped: %s\n"),
-                            frame_stop_reason_string (reason));
+                            frame_stop_reason_string (trailing));
        }
     }
 }
@@ -1901,7 +1927,7 @@ backtrace_full_command (char *arg, int from_tty)
    CB_DATA.  */
 
 static void
-iterate_over_block_locals (struct block *b,
+iterate_over_block_locals (const struct block *b,
                           iterate_over_block_arg_local_vars_cb cb,
                           void *cb_data)
 {
@@ -1984,7 +2010,7 @@ print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
    superblocks, stopping when the top-level block is reached.  */
 
 void
-iterate_over_block_local_vars (struct block *block,
+iterate_over_block_local_vars (const struct block *block,
                               iterate_over_block_arg_local_vars_cb cb,
                               void *cb_data)
 {
@@ -2046,7 +2072,7 @@ print_frame_local_vars (struct frame_info *frame, int num_tabs,
                        struct ui_file *stream)
 {
   struct print_variable_and_value_data cb_data;
-  struct block *block;
+  const struct block *block;
   CORE_ADDR pc;
 
   if (!get_frame_pc_if_available (frame, &pc))
@@ -2091,7 +2117,7 @@ locals_info (char *args, int from_tty)
    Returns 1 if any argument was walked; 0 otherwise.  */
 
 void
-iterate_over_block_arg_vars (struct block *b,
+iterate_over_block_arg_vars (const struct block *b,
                             iterate_over_block_arg_local_vars_cb cb,
                             void *cb_data)
 {
@@ -2184,7 +2210,7 @@ select_and_print_frame (struct frame_info *frame)
 {
   select_frame (frame);
   if (frame)
-    print_stack_frame (frame, 1, SRC_AND_LOC);
+    print_stack_frame (frame, 1, SRC_AND_LOC, 1);
 }
 \f
 /* Return the symbol-block in which the selected frame is executing.
@@ -2194,7 +2220,7 @@ select_and_print_frame (struct frame_info *frame)
    code address within the block returned.  We use this to decide
    which macros are in scope.  */
 
-struct block *
+const struct block *
 get_selected_block (CORE_ADDR *addr_in_block)
 {
   if (!has_stack_frames ())
@@ -2262,7 +2288,7 @@ static void
 frame_command (char *level_exp, int from_tty)
 {
   select_frame_command (level_exp, from_tty);
-  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
+  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
 /* The XDB Compatibility command to print the current frame.  */
@@ -2270,14 +2296,14 @@ frame_command (char *level_exp, int from_tty)
 static void
 current_frame_command (char *level_exp, int from_tty)
 {
-  print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC);
+  print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC, 1);
 }
 
 /* Select the frame up one or COUNT_EXP stack levels from the
    previously selected frame, and print it briefly.  */
 
 static void
-up_silently_base (char *count_exp)
+up_silently_base (const char *count_exp)
 {
   struct frame_info *frame;
   int count = 1;
@@ -2301,14 +2327,14 @@ static void
 up_command (char *count_exp, int from_tty)
 {
   up_silently_base (count_exp);
-  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
+  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
 /* Select the frame down one or COUNT_EXP stack levels from the previously
    selected frame, and print it briefly.  */
 
 static void
-down_silently_base (char *count_exp)
+down_silently_base (const char *count_exp)
 {
   struct frame_info *frame;
   int count = -1;
@@ -2340,7 +2366,7 @@ static void
 down_command (char *count_exp, int from_tty)
 {
   down_silently_base (count_exp);
-  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
+  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 \f
 
@@ -2543,7 +2569,6 @@ get_frame_language (void)
     {
       volatile struct gdb_exception ex;
       CORE_ADDR pc = 0;
-      struct symtab *s;
 
       /* We determine the current frame language by looking up its
          associated symtab.  To retrieve this symtab, we use the frame
@@ -2565,9 +2590,10 @@ get_frame_language (void)
        }
       else
        {
-         s = find_pc_symtab (pc);
-         if (s != NULL)
-           return s->language;
+         struct compunit_symtab *cust = find_pc_compunit_symtab (pc);
+
+         if (cust != NULL)
+           return compunit_language (cust);
        }
     }
 
This page took 0.030754 seconds and 4 git commands to generate.