PR22348, conflicting global vars in crx and cr16
[deliverable/binutils-gdb.git] / gdb / infcall.c
index 9e434a9df41e6b299456000a601097d835731cdf..03749f3dc2e1aa8caecc763730a29d16210d00f7 100644 (file)
@@ -340,6 +340,20 @@ push_dummy_code (struct gdbarch *gdbarch,
                                  regcache);
 }
 
+/* See infcall.h.  */
+
+void
+error_call_unknown_return_type (const char *func_name)
+{
+  if (func_name != NULL)
+    error (_("'%s' has unknown return type; "
+            "cast the call to its declared return type"),
+          func_name);
+  else
+    error (_("function has unknown return type; "
+            "cast the call to its declared return type"));
+}
+
 /* Fetch the name of the function at FUNADDR.
    This is used in printing an error message for call_function_by_hand.
    BUF is used to print FUNADDR in hex if the function name cannot be
@@ -530,7 +544,7 @@ call_thread_fsm_should_stop (struct thread_fsm *self,
 
       /* Break out of wait_sync_command_done.  */
       scoped_restore save_ui = make_scoped_restore (&current_ui, f->waiting_ui);
-      target_terminal_ours ();
+      target_terminal::ours ();
       f->waiting_ui->prompt_state = PROMPT_NEEDED;
     }
 
@@ -673,9 +687,12 @@ cleanup_delete_std_terminate_breakpoint (void *ignore)
 /* See infcall.h.  */
 
 struct value *
-call_function_by_hand (struct value *function, int nargs, struct value **args)
+call_function_by_hand (struct value *function,
+                      type *default_return_type,
+                      int nargs, struct value **args)
 {
-  return call_function_by_hand_dummy (function, nargs, args, NULL, NULL);
+  return call_function_by_hand_dummy (function, default_return_type,
+                                     nargs, args, NULL, NULL);
 }
 
 /* All this stuff with a dummy frame may seem unnecessarily complicated
@@ -698,6 +715,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
 
 struct value *
 call_function_by_hand_dummy (struct value *function,
+                            type *default_return_type,
                             int nargs, struct value **args,
                             dummy_frame_dtor_ftype *dummy_dtor,
                             void *dummy_dtor_data)
@@ -850,8 +868,16 @@ call_function_by_hand_dummy (struct value *function,
   }
 
   funaddr = find_function_addr (function, &values_type);
-  if (!values_type)
-    values_type = builtin_type (gdbarch)->builtin_int;
+  if (values_type == NULL)
+    values_type = default_return_type;
+  if (values_type == NULL)
+    {
+      const char *name = get_function_name (funaddr,
+                                           name_buf, sizeof (name_buf));
+      error (_("'%s' has unknown return type; "
+              "cast the call to its declared return type"),
+            name);
+    }
 
   values_type = check_typedef (values_type);
 
@@ -955,6 +981,21 @@ call_function_by_hand_dummy (struct value *function,
           prototyped.  Can we respect TYPE_VARARGS?  Probably not.  */
        if (TYPE_CODE (ftype) == TYPE_CODE_METHOD)
          prototyped = 1;
+       if (TYPE_TARGET_TYPE (ftype) == NULL && TYPE_NFIELDS (ftype) == 0
+           && default_return_type != NULL)
+         {
+           /* Calling a no-debug function with the return type
+              explicitly cast.  Assume the function is prototyped,
+              with a prototype matching the types of the arguments.
+              E.g., with:
+                float mult (float v1, float v2) { return v1 * v2; }
+              This:
+                (gdb) p (float) mult (2.0f, 3.0f)
+              Is a simpler alternative to:
+                (gdb) p ((float (*) (float, float)) mult) (2.0f, 3.0f)
+            */
+           prototyped = 1;
+         }
        else if (i < TYPE_NFIELDS (ftype))
          prototyped = TYPE_PROTOTYPED (ftype);
        else
@@ -1267,10 +1308,8 @@ When the function is done executing, GDB will silently stop."),
 
     {
       /* Make a copy as NAME may be in an objfile freed by dummy_frame_pop.  */
-      char *name = xstrdup (get_function_name (funaddr,
-                                              name_buf, sizeof (name_buf)));
-      make_cleanup (xfree, name);
-
+      std::string name = get_function_name (funaddr, name_buf,
+                                           sizeof (name_buf));
 
       if (stopped_by_random_signal)
        {
@@ -1298,7 +1337,7 @@ 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);
+                    name.c_str ());
            }
          else
            {
@@ -1317,7 +1356,7 @@ 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);
+                    name.c_str ());
            }
        }
 
@@ -1339,7 +1378,7 @@ 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);
+                name.c_str ());
        }
       else if (stop_stack_dummy == STOP_NONE)
        {
@@ -1363,7 +1402,7 @@ 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);
+                name.c_str ());
        }
 
     }
@@ -1371,10 +1410,6 @@ When the function is done executing, GDB will silently stop."),
   /* The above code errors out, so ...  */
   gdb_assert_not_reached ("... should not be here");
 }
-\f
-
-/* Provide a prototype to silence -Wmissing-prototypes.  */
-void _initialize_infcall (void);
 
 void
 _initialize_infcall (void)
This page took 0.030527 seconds and 4 git commands to generate.