* NEWS: Add entry for stdio gdbserver.
[deliverable/binutils-gdb.git] / gdb / infcall.c
index 48c183e39be88d7064c853640c3d82715b9db6bf..b8b7ff5d328f2a44a9199c12753a49b27e832a99 100644 (file)
@@ -88,7 +88,7 @@ show_coerce_float_to_double_p (struct ui_file *file, int from_tty,
    the stack and restore the context to what as it was before the
    call.
 
-   The default is to stop in the frame where the signal was received. */
+   The default is to stop in the frame where the signal was received.  */
 
 int unwind_on_signal_p = 0;
 static void
@@ -228,6 +228,21 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
   return value_cast (type, arg);
 }
 
+/* Return the return type of a function with its first instruction exactly at
+   the PC address.  Return NULL otherwise.  */
+
+static struct type *
+find_function_return_type (CORE_ADDR pc)
+{
+  struct symbol *sym = find_pc_function (pc);
+
+  if (sym != NULL && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) == pc
+      && SYMBOL_TYPE (sym) != NULL)
+    return TYPE_TARGET_TYPE (SYMBOL_TYPE (sym));
+
+  return NULL;
+}
+
 /* Determine a function's address and its return type from its value.
    Calls error() if the function is not valid for calling.  */
 
@@ -236,35 +251,45 @@ find_function_addr (struct value *function, struct type **retval_type)
 {
   struct type *ftype = check_typedef (value_type (function));
   struct gdbarch *gdbarch = get_type_arch (ftype);
-  enum type_code code = TYPE_CODE (ftype);
   struct type *value_type = NULL;
-  CORE_ADDR funaddr;
+  /* Initialize it just to avoid a GCC false warning.  */
+  CORE_ADDR funaddr = 0;
 
   /* If it's a member function, just look at the function
      part of it.  */
 
   /* Determine address to call.  */
-  if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
-    {
-      funaddr = value_address (function);
-      value_type = TYPE_TARGET_TYPE (ftype);
-    }
-  else if (code == TYPE_CODE_PTR)
+  if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
+      || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
+    funaddr = value_address (function);
+  else if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
     {
       funaddr = value_as_address (function);
       ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
       if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
          || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
+       funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
+                                                     &current_target);
+    }
+  if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
+      || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
+    {
+      value_type = TYPE_TARGET_TYPE (ftype);
+
+      if (TYPE_GNU_IFUNC (ftype))
        {
-         funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
-                                                       &current_target);
-         value_type = TYPE_TARGET_TYPE (ftype);
+         funaddr = gnu_ifunc_resolve_addr (gdbarch, funaddr);
+
+         /* Skip querying the function symbol if no RETVAL_TYPE has been
+            asked for.  */
+         if (retval_type)
+           value_type = find_function_return_type (funaddr);
        }
     }
-  else if (code == TYPE_CODE_INT)
+  else if (TYPE_CODE (ftype) == TYPE_CODE_INT)
     {
       /* Handle the case of functions lacking debugging info.
-         Their values are characters since their addresses are char */
+         Their values are characters since their addresses are char */
       if (TYPE_LENGTH (ftype) == 1)
        funaddr = value_as_address (value_addr (function));
       else
@@ -362,10 +387,8 @@ static struct gdb_exception
 run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
 {
   volatile struct gdb_exception e;
-  int saved_async = 0;
   int saved_in_infcall = call_thread->control.in_infcall;
   ptid_t call_thread_ptid = call_thread->ptid;
-  char *saved_target_shortname = xstrdup (target_shortname);
 
   call_thread->control.in_infcall = 1;
 
@@ -373,25 +396,27 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
 
   disable_watchpoints_before_interactive_call_start ();
 
-  /* We want stop_registers, please... */
+  /* We want stop_registers, please...  */
   call_thread->control.proceed_to_finish = 1;
 
-  if (target_can_async_p ())
-    saved_async = target_async_mask (0);
-
   TRY_CATCH (e, RETURN_MASK_ALL)
-    proceed (real_pc, TARGET_SIGNAL_0, 0);
+    {
+      proceed (real_pc, TARGET_SIGNAL_0, 0);
+
+      /* Inferior function calls are always synchronous, even if the
+        target supports asynchronous execution.  Do here what
+        `proceed' itself does in sync mode.  */
+      if (target_can_async_p () && is_running (inferior_ptid))
+       {
+         wait_for_inferior ();
+         normal_stop ();
+       }
+    }
 
   /* At this point the current thread may have changed.  Refresh
      CALL_THREAD as it could be invalid if its thread has exited.  */
   call_thread = find_thread_ptid (call_thread_ptid);
 
-  /* Don't restore the async mask if the target has changed,
-     saved_async is for the original target.  */
-  if (saved_async
-      && strcmp (saved_target_shortname, target_shortname) == 0)
-    target_async_mask (saved_async);
-
   enable_watchpoints_after_interactive_call_stop ();
 
   /* Call breakpoint_auto_delete on the current contents of the bpstat
@@ -408,8 +433,6 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
   if (call_thread != NULL)
     call_thread->control.in_infcall = saved_in_infcall;
 
-  xfree (saved_target_shortname);
-
   return e;
 }
 
@@ -436,7 +459,7 @@ cleanup_delete_std_terminate_breakpoint (void *ignore)
    May fail to return, if a breakpoint or signal is hit
    during the execution of the function.
 
-   ARGS is modified to contain coerced values. */
+   ARGS is modified to contain coerced values.  */
 
 struct value *
 call_function_by_hand (struct value *function, int nargs, struct value **args)
@@ -470,6 +493,9 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   if (get_traceframe_number () >= 0)
     error (_("May not call functions while looking at trace frames."));
 
+  if (execution_direction == EXEC_REVERSE)
+    error (_("Cannot call functions in reverse mode."));
+
   frame = get_current_frame ();
   gdbarch = get_frame_arch (frame);
 
@@ -549,7 +575,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
         If the generic dummy frame ends up empty (because nothing is
         pushed) GDB won't be able to correctly perform back traces.
         If a target is having trouble with backtraces, first thing to
-        do is add FRAME_ALIGN() to the architecture vector. If that
+        do is add FRAME_ALIGN() to the architecture vector.  If that
         fails, try dummy_id().
 
          If the ABI specifies a "Red Zone" (see the doco) the code
@@ -682,7 +708,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
 
   /* Reserve space for the return structure to be written on the
      stack, if necessary.  Make certain that the value is correctly
-     aligned. */
+     aligned.  */
 
   if (struct_return || lang_struct_return)
     {
@@ -700,7 +726,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
       else
        {
          /* Stack grows upward.  Align the frame, allocate space, and
-             then again, re-align the frame??? */
+             then again, re-align the frame???  */
          if (gdbarch_frame_align_p (gdbarch))
            sp = gdbarch_frame_align (gdbarch, sp);
          struct_addr = sp;
@@ -825,12 +851,11 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
       switch (e.reason)
        {
        case RETURN_ERROR:
-         throw_error (e.error,
-                      _("%s\nAn error occurred while in a "
-                        "function called from GDB.\n Evaluation "
-                        "of the expression containing the function\n   "
-                        "(%s) will be abandoned.\nWhen the function "
-                        "is done executing, GDB will silently stop."),
+         throw_error (e.error, _("%s\n\
+An error occurred while in a function called from GDB.\n\
+Evaluation of the expression containing the function\n\
+(%s) will be abandoned.\n\
+When the function is done executing, GDB will silently stop."),
                       e.message, name);
        case RETURN_QUIT:
        default:
@@ -874,18 +899,19 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
       /* Keep the dummy frame record, if the user switches back to the
         thread with the hand-call, we'll need it.  */
       if (stopped_by_random_signal)
-       error (_("The program received a signal in another thread while\n"
-                "making a function call from GDB.\nEvaluation "
-                "of the expression containing the function\n"
-                "(%s) will be abandoned.\nWhen the function "
-                "is done executing, GDB will silently stop."),
+       error (_("\
+The program received a signal in another thread while\n\
+making a function call from GDB.\n\
+Evaluation of the expression containing the function\n\
+(%s) will be abandoned.\n\
+When the function is done executing, GDB will silently stop."),
               name);
       else
-       error (_("The program stopped in another thread while making "
-                "a function call from GDB.\nEvaluation "
-                "of the expression containing the function\n"
-                "(%s) will be abandoned.\nWhen the function "
-                "is done executing, GDB will silently stop."),
+       error (_("\
+The program stopped in another thread while making a function call from GDB.\n\
+Evaluation of the expression containing the function\n\
+(%s) will be abandoned.\n\
+When the function is done executing, GDB will silently stop."),
               name);
     }
 
@@ -898,11 +924,11 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
        {
          /* We stopped inside the FUNCTION because of a random
             signal.  Further execution of the FUNCTION is not
-            allowed. */
+            allowed.  */
 
          if (unwind_on_signal_p)
            {
-             /* The user wants the context restored. */
+             /* The user wants the context restored.  */
 
              /* We must get back to the frame we were before the
                 dummy call.  */
@@ -914,12 +940,12 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
 
              /* FIXME: Insert a bunch of wrap_here; name can be very
                 long if it's a C++ name with arguments and stuff.  */
-             error (_("The program being debugged was signaled while "
-                      "in a function called from GDB.\nGDB has restored "
-                      "the context to what it was before the call.\n "
-                      "To change this behavior use \"set unwindonsignal "
-                      "off\".\nEvaluation of the expression containing "
-                      "the function\n(%s) will be abandoned."),
+             error (_("\
+The program being debugged was signaled while in a function called from GDB.\n\
+GDB has restored the context to what it was before the call.\n\
+To change this behavior use \"set unwindonsignal off\".\n\
+Evaluation of the expression containing the function\n\
+(%s) will be abandoned."),
                     name);
            }
          else
@@ -932,14 +958,13 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
 
              /* FIXME: Insert a bunch of wrap_here; name can be very
                 long if it's a C++ name with arguments and stuff.  */
-             error (_("The program being debugged was signaled while "
-                      "in a function called from GDB.\nGDB remains in "
-                      "the frame where the signal was received.\nTo change "
-                      "this behavior use \"set unwindonsignal on\".\n"
-                      "Evaluation of the expression containing the "
-                      "function\n(%s) will be abandoned.\n"
-                      "When the function is done executing, GDB will "
-                      "silently stop."),
+             error (_("\
+The program being debugged was signaled while in a function called from GDB.\n\
+GDB remains in the frame where the signal was received.\n\
+To change this behavior use \"set unwindonsignal on\".\n\
+Evaluation of the expression containing the function\n\
+(%s) will be abandoned.\n\
+When the function is done executing, GDB will silently stop."),
                     name);
            }
        }
@@ -954,18 +979,14 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
             the dummy call.  */
          restore_infcall_control_state (inf_status);
 
-         error (_("The program being debugged entered a "
-                  "std::terminate call, most likely\n"
-                  "caused by an unhandled C++ exception.  "
-                  "GDB blocked this call in order\n"
-                  "to prevent the program from being "
-                  "terminated, and has restored the\n"
-                  "context to its original state before the call.\n"
-                  "To change this behaviour use \"set "
-                  "unwind-on-terminating-exception off\".\n"
-                  "Evaluation of the expression "
-                  "containing the function (%s)\n"
-                  "will be abandoned."),
+         error (_("\
+The program being debugged entered a std::terminate call, most likely\n\
+caused by an unhandled C++ exception.  GDB blocked this call in order\n\
+to prevent the program from being terminated, and has restored the\n\
+context to its original state before the call.\n\
+To change this behaviour use \"set unwind-on-terminating-exception off\".\n\
+Evaluation of the expression containing the function (%s)\n\
+will be abandoned."),
                 name);
        }
       else if (stop_stack_dummy == STOP_NONE)
@@ -985,13 +1006,11 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
             someday this will be implemented (it would not be easy).  */
          /* FIXME: Insert a bunch of wrap_here; name can be very long if it's
             a C++ name with arguments and stuff.  */
-         error (_("The program being debugged stopped "
-                  "while in a function called from GDB.\n"
-                  "Evaluation of the expression "
-                  "containing the function\n"
-                  "(%s) will be abandoned.\n"
-                  "When the function is done executing, "
-                  "GDB will silently stop."),
+         error (_("\
+The program being debugged stopped while in a function called from GDB.\n\
+Evaluation of the expression containing the function\n\
+(%s) will be abandoned.\n\
+When the function is done executing, GDB will silently stop."),
                 name);
        }
 
@@ -1017,29 +1036,29 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
     restore_infcall_control_state (inf_status);
 
     /* Figure out the value returned by the function.  */
+    retval = allocate_value (values_type);
 
     if (lang_struct_return)
-      retval = value_at (values_type, struct_addr);
-    else if (TYPE_CODE (target_values_type) == TYPE_CODE_VOID)
+      read_value_memory (retval, 0, 1, struct_addr,
+                        value_contents_raw (retval),
+                        TYPE_LENGTH (values_type));
+    else if (TYPE_CODE (target_values_type) != TYPE_CODE_VOID)
       {
        /* If the function returns void, don't bother fetching the
           return value.  */
-       retval = allocate_value (values_type);
-      }
-    else
-      {
        switch (gdbarch_return_value (gdbarch, value_type (function),
                                      target_values_type, NULL, NULL, NULL))
          {
          case RETURN_VALUE_REGISTER_CONVENTION:
          case RETURN_VALUE_ABI_RETURNS_ADDRESS:
          case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
-           retval = allocate_value (values_type);
            gdbarch_return_value (gdbarch, value_type (function), values_type,
                                  retbuf, value_contents_raw (retval), NULL);
            break;
          case RETURN_VALUE_STRUCT_CONVENTION:
-           retval = value_at (values_type, struct_addr);
+           read_value_memory (retval, 0, 1, struct_addr,
+                              value_contents_raw (retval),
+                              TYPE_LENGTH (values_type));
            break;
          }
       }
This page took 0.029775 seconds and 4 git commands to generate.