]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/stack.c
sim: bfin: initial bf60x support
[thirdparty/binutils-gdb.git] / gdb / stack.c
index 7f7478ea32390762b18a55767028b4998eb2aae1..fad4b62c6f729f60ffc1f87238a249bff731ffc5 100644 (file)
@@ -97,7 +97,7 @@ static const char *const print_frame_info_choices[] =
 
 /* print_frame_info_print_what[i] maps a choice to the corresponding
    print_what enum.  */
-static const gdb::optional<enum print_what> print_frame_info_print_what[] =
+static const std::optional<enum print_what> print_frame_info_print_what[] =
   {{}, /* Empty value for "auto".  */
    SRC_LINE, LOCATION, SRC_AND_LOC, LOC_AND_ADDRESS, SHORT_LOCATION};
 
@@ -362,13 +362,11 @@ print_stack_frame (frame_info_ptr frame, int print_level,
   if (current_uiout->is_mi_like_p ())
     print_what = LOC_AND_ADDRESS;
 
-  frame.prepare_reinflate ();
   try
     {
       print_frame_info (user_frame_print_options,
                        frame, print_level, print_what, 1 /* print_args */,
                        set_current_sal);
-      frame.reinflate ();
       if (set_current_sal)
        set_current_sal_from_frame (frame);
     }
@@ -469,7 +467,7 @@ print_frame_arg (const frame_print_options &fp_opts,
                 because our standard indentation here is 4 spaces, and
                 val_print indents 2 for each recurse.  */ 
 
-             annotate_arg_value (value_type (arg->val));
+             annotate_arg_value (arg->val->type ());
 
              /* Use the appropriate language to display our symbol, unless the
                 user forced the language to a specific language.  */
@@ -552,7 +550,7 @@ read_frame_arg (const frame_print_options &fp_opts,
       && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
       && fp_opts.print_entry_values != print_entry_values_no
       && (fp_opts.print_entry_values != print_entry_values_if_needed
-         || !val || value_optimized_out (val)))
+         || !val || val->optimized_out ()))
     {
       try
        {
@@ -570,7 +568,7 @@ read_frame_arg (const frame_print_options &fp_opts,
            }
        }
 
-      if (entryval != NULL && value_optimized_out (entryval))
+      if (entryval != NULL && entryval->optimized_out ())
        entryval = NULL;
 
       if (fp_opts.print_entry_values == print_entry_values_compact
@@ -580,14 +578,14 @@ read_frame_arg (const frame_print_options &fp_opts,
 
          if (val && entryval && !current_uiout->is_mi_like_p ())
            {
-             struct type *type = value_type (val);
+             struct type *type = val->type ();
 
-             if (value_lazy (val))
-               value_fetch_lazy (val);
-             if (value_lazy (entryval))
-               value_fetch_lazy (entryval);
+             if (val->lazy ())
+               val->fetch_lazy ();
+             if (entryval->lazy ())
+               entryval->fetch_lazy ();
 
-             if (value_contents_eq (val, 0, entryval, 0, type->length ()))
+             if (val->contents_eq (0, entryval, 0, type->length ()))
                {
                  /* Initialize it just to avoid a GCC false warning.  */
                  struct value *val_deref = NULL, *entryval_deref;
@@ -601,20 +599,20 @@ read_frame_arg (const frame_print_options &fp_opts,
                      struct type *type_deref;
 
                      val_deref = coerce_ref (val);
-                     if (value_lazy (val_deref))
-                       value_fetch_lazy (val_deref);
-                     type_deref = value_type (val_deref);
+                     if (val_deref->lazy ())
+                       val_deref->fetch_lazy ();
+                     type_deref = val_deref->type ();
 
                      entryval_deref = coerce_ref (entryval);
-                     if (value_lazy (entryval_deref))
-                       value_fetch_lazy (entryval_deref);
+                     if (entryval_deref->lazy ())
+                       entryval_deref->fetch_lazy ();
 
                      /* If the reference addresses match but dereferenced
                         content does not match print them.  */
                      if (val != val_deref
-                         && value_contents_eq (val_deref, 0,
-                                               entryval_deref, 0,
-                                               type_deref->length ()))
+                         && val_deref->contents_eq (0,
+                                                    entryval_deref, 0,
+                                                    type_deref->length ()))
                        val_equal = 1;
                    }
                  catch (const gdb_exception_error &except)
@@ -674,16 +672,16 @@ read_frame_arg (const frame_print_options &fp_opts,
       if (fp_opts.print_entry_values == print_entry_values_only
          || fp_opts.print_entry_values == print_entry_values_both
          || (fp_opts.print_entry_values == print_entry_values_preferred
-             && (!val || value_optimized_out (val))))
+             && (!val || val->optimized_out ())))
        {
-         entryval = allocate_optimized_out_value (sym->type ());
+         entryval = value::allocate_optimized_out (sym->type ());
          entryval_error = NULL;
        }
     }
   if ((fp_opts.print_entry_values == print_entry_values_compact
        || fp_opts.print_entry_values == print_entry_values_if_needed
        || fp_opts.print_entry_values == print_entry_values_preferred)
-      && (!val || value_optimized_out (val)) && entryval != NULL)
+      && (!val || val->optimized_out ()) && entryval != NULL)
     {
       val = NULL;
       val_error = NULL;
@@ -744,24 +742,11 @@ print_frame_args (const frame_print_options &fp_opts,
     = (print_names
        && fp_opts.print_frame_arguments != print_frame_arguments_none);
 
-  /* If one of the arguments has a pretty printer that calls a
-     function of the inferior to print it, the pointer must be
-     reinflatable.  */
-  frame.prepare_reinflate ();
-
-  /* Temporarily change the selected frame to the given FRAME.
-     This allows routines that rely on the selected frame instead
-     of being given a frame as parameter to use the correct frame.  */
-  scoped_restore_selected_frame restore_selected_frame;
-  select_frame (frame);
-
   if (func)
     {
       const struct block *b = func->value_block ();
-      struct block_iterator iter;
-      struct symbol *sym;
 
-      ALL_BLOCK_SYMBOLS (b, iter, sym)
+      for (struct symbol *sym : block_iterator_range (b))
        {
          struct frame_arg arg, entryarg;
 
@@ -909,7 +894,6 @@ print_frame_args (const frame_print_options &fp_opts,
            }
 
          first = 0;
-         frame.reinflate ();
        }
     }
 
@@ -989,7 +973,7 @@ do_gdb_disassembly (struct gdbarch *gdbarch,
    Value not present indicates to the caller to use default values
    specific to the command being executed.  */
 
-static gdb::optional<enum print_what>
+static std::optional<enum print_what>
 print_frame_info_to_print_what (const char *print_frame_info)
 {
   for (int i = 0; print_frame_info_choices[i] != NULL; i++)
@@ -1020,7 +1004,7 @@ print_pc (struct ui_out *uiout, struct gdbarch *gdbarch, frame_info_ptr frame,
 /* See stack.h.  */
 
 void
-get_user_print_what_frame_info (gdb::optional<enum print_what> *what)
+get_user_print_what_frame_info (std::optional<enum print_what> *what)
 {
   *what
     = print_frame_info_to_print_what
@@ -1047,8 +1031,6 @@ print_frame_info (const frame_print_options &fp_opts,
   int location_print;
   struct ui_out *uiout = current_uiout;
 
-  frame.prepare_reinflate ();
-
   if (!current_uiout->is_mi_like_p ()
       && fp_opts.print_frame_info != print_frame_info_auto)
     {
@@ -1181,7 +1163,6 @@ print_frame_info (const frame_print_options &fp_opts,
 
          print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
        }
-      frame.reinflate ();
 
       /* If disassemble-next-line is set to on and there is line debug
         messages, output assembly codes for next line.  */
@@ -1439,7 +1420,7 @@ print_frame (const frame_print_options &fp_opts,
       {
        const char *lib
          = solib_name_from_address (get_frame_program_space (frame),
-                                    get_frame_pc (frame));
+                                    get_frame_address_in_block (frame));
 
        if (lib)
          {
@@ -1682,11 +1663,8 @@ info_frame_command_core (frame_info_ptr fi, bool selected_frame_p)
              gdb_printf (" %d args: ", numargs);
          }
 
-       fi.prepare_reinflate ();
        print_frame_args (user_frame_print_options,
                          func, fi, numargs, gdb_stdout);
-       fi.reinflate ();
-
        gdb_puts ("\n");
       }
   }
@@ -1722,32 +1700,31 @@ info_frame_command_core (frame_info_ptr fi, bool selected_frame_p)
        struct value *value = frame_unwind_register_value (fi, sp_regnum);
        gdb_assert (value != NULL);
 
-       if (!value_optimized_out (value) && value_entirely_available (value))
+       if (!value->optimized_out () && value->entirely_available ())
          {
-           if (VALUE_LVAL (value) == not_lval)
+           if (value->lval () == not_lval)
              {
                CORE_ADDR sp;
                enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
                int sp_size = register_size (gdbarch, sp_regnum);
 
                sp = extract_unsigned_integer
-                 (value_contents_all (value).data (), sp_size, byte_order);
+                 (value->contents_all ().data (), sp_size, byte_order);
 
                gdb_printf (" Previous frame's sp is ");
                gdb_puts (paddress (gdbarch, sp));
                gdb_printf ("\n");
              }
-           else if (VALUE_LVAL (value) == lval_memory)
+           else if (value->lval () == lval_memory)
              {
                gdb_printf (" Previous frame's sp at ");
-               gdb_puts (paddress (gdbarch, value_address (value)));
+               gdb_puts (paddress (gdbarch, value->address ()));
                gdb_printf ("\n");
              }
-           else if (VALUE_LVAL (value) == lval_register)
+           else if (value->lval () == lval_register)
              {
                gdb_printf (" Previous frame's sp in %s\n",
-                           gdbarch_register_name (gdbarch,
-                                                  VALUE_REGNUM (value)));
+                           gdbarch_register_name (gdbarch, value->regnum ()));
              }
 
            release_value (value);
@@ -1853,7 +1830,7 @@ select_frame_command_core (frame_info_ptr fi, bool ignored)
   frame_info_ptr prev_frame = get_selected_frame ();
   select_frame (fi);
   if (get_selected_frame () != prev_frame)
-    gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
+    notify_user_selected_context_changed (USER_SELECTED_FRAME);
 }
 
 /* The core of all the "frame" sub-commands.  Select frame FI, and if this
@@ -1866,7 +1843,7 @@ frame_command_core (frame_info_ptr fi, bool ignored)
   frame_info_ptr prev_frame = get_selected_frame ();
   select_frame (fi);
   if (get_selected_frame () != prev_frame)
-    gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
+    notify_user_selected_context_changed (USER_SELECTED_FRAME);
   else
     print_selected_thread_frame (current_uiout, USER_SELECTED_FRAME);
 }
@@ -2075,7 +2052,6 @@ backtrace_command_1 (const frame_print_options &fp_opts,
       for (fi = trailing; fi && count--; fi = get_prev_frame (fi))
        {
          QUIT;
-         fi.prepare_reinflate ();
 
          /* Don't use print_stack_frame; if an error() occurs it probably
             means further attempts to backtrace would fail (on the other
@@ -2087,7 +2063,6 @@ backtrace_command_1 (const frame_print_options &fp_opts,
            print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout);
 
          /* Save the last frame to check for error conditions.  */
-         fi.reinflate ();
          trailing = fi;
        }
 
@@ -2237,10 +2212,7 @@ static void
 iterate_over_block_locals (const struct block *b,
                           iterate_over_block_arg_local_vars_cb cb)
 {
-  struct block_iterator iter;
-  struct symbol *sym;
-
-  ALL_BLOCK_SYMBOLS (b, iter, sym)
+  for (struct symbol *sym : block_iterator_range (b))
     {
       switch (sym->aclass ())
        {
@@ -2288,8 +2260,8 @@ iterate_over_block_local_vars (const struct block *block,
 
 struct print_variable_and_value_data
 {
-  gdb::optional<compiled_regex> preg;
-  gdb::optional<compiled_regex> treg;
+  std::optional<compiled_regex> preg;
+  std::optional<compiled_regex> treg;
   struct frame_id frame_id;
   int num_tabs;
   struct ui_file *stream;
@@ -2334,7 +2306,7 @@ print_variable_and_value_data::operator() (const char *print_name,
    If REGEXP is NULL, it results in an empty regular expression.  */
 
 static void
-prepare_reg (const char *regexp, gdb::optional<compiled_regex> *reg)
+prepare_reg (const char *regexp, std::optional<compiled_regex> *reg)
 {
   if (regexp != NULL)
     {
@@ -2353,9 +2325,7 @@ prepare_reg (const char *regexp, gdb::optional<compiled_regex> *reg)
    If T_REGEXP is not NULL, only print local variables whose type
    matches T_REGEXP.
    If no local variables have been printed and !QUIET, prints a message
-   explaining why no local variables could be printed.
-
-   This function will invalidate FRAME.  */
+   explaining why no local variables could be printed.  */
 
 static void
 print_frame_local_vars (frame_info_ptr frame,
@@ -2486,10 +2456,7 @@ void
 iterate_over_block_arg_vars (const struct block *b,
                             iterate_over_block_arg_local_vars_cb cb)
 {
-  struct block_iterator iter;
-  struct symbol *sym, *sym2;
-
-  ALL_BLOCK_SYMBOLS (b, iter, sym)
+  for (struct symbol *sym : block_iterator_range (b))
     {
       /* Don't worry about things which aren't arguments.  */
       if (sym->is_argument ())
@@ -2505,8 +2472,9 @@ iterate_over_block_arg_vars (const struct block *b,
             float).  There are also LOC_ARG/LOC_REGISTER pairs which
             are not combined in symbol-reading.  */
 
-         sym2 = lookup_symbol_search_name (sym->search_name (),
-                                           b, VAR_DOMAIN).symbol;
+         struct symbol *sym2
+           = lookup_symbol_search_name (sym->search_name (),
+                                        b, VAR_DOMAIN).symbol;
          cb (sym->print_name (), sym2);
        }
     }
@@ -2519,9 +2487,7 @@ iterate_over_block_arg_vars (const struct block *b,
    If T_REGEXP is not NULL, only print argument variables whose type
    matches T_REGEXP.
    If no argument variables have been printed and !QUIET, prints a message
-   explaining why no argument variables could be printed.
-
-   This function will invalidate FRAME.  */
+   explaining why no argument variables could be printed.  */
 
 static void
 print_frame_arg_vars (frame_info_ptr frame,
@@ -2532,8 +2498,8 @@ print_frame_arg_vars (frame_info_ptr frame,
   struct print_variable_and_value_data cb_data;
   struct symbol *func;
   CORE_ADDR pc;
-  gdb::optional<compiled_regex> preg;
-  gdb::optional<compiled_regex> treg;
+  std::optional<compiled_regex> preg;
+  std::optional<compiled_regex> treg;
 
   if (!get_frame_pc_if_available (frame, &pc))
     {
@@ -2560,9 +2526,6 @@ print_frame_arg_vars (frame_info_ptr frame,
 
   iterate_over_block_arg_vars (func->value_block (), cb_data);
 
-  /* do_print_variable_and_value invalidates FRAME.  */
-  frame = NULL;
-
   if (!cb_data.values_printed && !quiet)
     {
       if (regexp == NULL && t_regexp == NULL)
@@ -2673,7 +2636,7 @@ static void
 up_command (const char *count_exp, int from_tty)
 {
   up_silently_base (count_exp);
-  gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
+  notify_user_selected_context_changed (USER_SELECTED_FRAME);
 }
 
 /* Select the frame down one or COUNT_EXP stack levels from the previously
@@ -2712,7 +2675,7 @@ static void
 down_command (const char *count_exp, int from_tty)
 {
   down_silently_base (count_exp);
-  gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
+  notify_user_selected_context_changed (USER_SELECTED_FRAME);
 }
 
 void
@@ -2745,7 +2708,7 @@ return_command (const char *retval_exp, int from_tty)
 
       /* Compute the return value.  Should the computation fail, this
         call throws an error.  */
-      return_value = evaluate_expression (retval_expr.get ());
+      return_value = retval_expr->evaluate ();
 
       /* Cast return value to the return type of the function.  Should
         the cast fail, this call throws an error.  */
@@ -2758,15 +2721,15 @@ return_command (const char *retval_exp, int from_tty)
            error (_("Return value type not available for selected "
                     "stack frame.\n"
                     "Please use an explicit cast of the value to return."));
-         return_type = value_type (return_value);
+         return_type = return_value->type ();
        }
       return_type = check_typedef (return_type);
       return_value = value_cast (return_type, return_value);
 
       /* Make sure the value is fully evaluated.  It may live in the
         stack frame we're about to pop.  */
-      if (value_lazy (return_value))
-       value_fetch_lazy (return_value);
+      if (return_value->lazy ())
+       return_value->fetch_lazy ();
 
       if (thisfun != NULL)
        function = read_var_value (thisfun, NULL, thisframe);
@@ -2781,7 +2744,7 @@ return_command (const char *retval_exp, int from_tty)
        return_value = NULL;
       else if (thisfun != NULL)
        {
-         if (is_nocall_function (check_typedef (value_type (function))))
+         if (is_nocall_function (check_typedef (function->type ())))
            {
              query_prefix =
                string_printf ("Function '%s' does not follow the target "
@@ -2833,14 +2796,15 @@ return_command (const char *retval_exp, int from_tty)
   /* Store RETURN_VALUE in the just-returned register set.  */
   if (return_value != NULL)
     {
-      struct type *return_type = value_type (return_value);
-      struct gdbarch *cache_arch = get_current_regcache ()->arch ();
+      struct type *return_type = return_value->type ();
+      regcache *regcache = get_thread_regcache (inferior_thread ());
+      struct gdbarch *cache_arch = regcache->arch ();
 
       gdb_assert (rv_conv != RETURN_VALUE_STRUCT_CONVENTION
                  && rv_conv != RETURN_VALUE_ABI_RETURNS_ADDRESS);
-      gdbarch_return_value (cache_arch, function, return_type,
-                           get_current_regcache (), NULL /*read*/,
-                           value_contents (return_value).data () /*write*/);
+      gdbarch_return_value_as_value
+       (cache_arch, function, return_type, regcache, NULL /*read*/,
+        return_value->contents ().data () /*write*/);
     }
 
   /* If we are at the end of a call dummy now, pop the dummy frame