Fix xmethod Python so that it works with Python3.
[deliverable/binutils-gdb.git] / gdb / infcall.c
index e3171d7051f3329bf70d06b63ae592f7263abce3..e60d1d476beadd891429fea8b8a7cd4bc95b0594 100644 (file)
@@ -1,8 +1,6 @@
 /* Perform an inferior function call, for GDB, the GNU debugger.
 
-   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1986-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "target.h"
 #include "regcache.h"
 #include "inferior.h"
-#include "gdb_assert.h"
+#include "infrun.h"
 #include "block.h"
 #include "gdbcore.h"
 #include "language.h"
 #include "objfiles.h"
 #include "gdbcmd.h"
 #include "command.h"
-#include "gdb_string.h"
 #include "infcall.h"
 #include "dummy-frame.h"
 #include "ada-lang.h"
 #include "gdbthread.h"
 #include "exceptions.h"
+#include "event-top.h"
 
 /* If we can't find a function's name from its address,
    we print this instead.  */
@@ -90,7 +88,7 @@ show_coerce_float_to_double_p (struct ui_file *file, int from_tty,
 
    The default is to stop in the frame where the signal was received.  */
 
-int unwind_on_signal_p = 0;
+static int unwind_on_signal_p = 0;
 static void
 show_unwind_on_signal_p (struct ui_file *file, int from_tty,
                         struct cmd_list_element *c, const char *value)
@@ -161,7 +159,7 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
        struct value *new_value;
 
        if (TYPE_CODE (arg_type) == TYPE_CODE_REF)
-         return value_cast_pointers (type, arg);
+         return value_cast_pointers (type, arg, 0);
 
        /* Cast the value to the reference's target type, and then
           convert it back to a reference.  This will issue an error
@@ -215,7 +213,6 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
     case TYPE_CODE_SET:
     case TYPE_CODE_RANGE:
     case TYPE_CODE_STRING:
-    case TYPE_CODE_BITSTRING:
     case TYPE_CODE_ERROR:
     case TYPE_CODE_MEMBERPTR:
     case TYPE_CODE_METHODPTR:
@@ -358,10 +355,10 @@ get_function_name (CORE_ADDR funaddr, char *buf, int buf_size)
 
   {
     /* Try the minimal symbols.  */
-    struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr);
+    struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (funaddr);
 
-    if (msymbol)
-      return SYMBOL_PRINT_NAME (msymbol);
+    if (msymbol.minsym)
+      return MSYMBOL_PRINT_NAME (msymbol.minsym);
   }
 
   {
@@ -389,10 +386,15 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
   volatile struct gdb_exception e;
   int saved_in_infcall = call_thread->control.in_infcall;
   ptid_t call_thread_ptid = call_thread->ptid;
+  int saved_sync_execution = sync_execution;
+
+  /* Infcalls run synchronously, in the foreground.  */
+  if (target_can_async_p ())
+    sync_execution = 1;
 
   call_thread->control.in_infcall = 1;
 
-  clear_proceed_status ();
+  clear_proceed_status (0);
 
   disable_watchpoints_before_interactive_call_start ();
 
@@ -401,15 +403,24 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
 
   TRY_CATCH (e, RETURN_MASK_ALL)
     {
-      proceed (real_pc, TARGET_SIGNAL_0, 0);
+      int was_sync = sync_execution;
+
+      proceed (real_pc, GDB_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))
+      if (target_can_async_p ())
        {
          wait_for_inferior ();
          normal_stop ();
+         /* If GDB was previously in sync execution mode, then ensure
+            that it remains so.  normal_stop calls
+            async_enable_stdin, so reset it again here.  In other
+            cases, stdin will be re-enabled by
+            inferior_event_handler, when an exception is thrown.  */
+         if (was_sync)
+           async_disable_stdin ();
        }
     }
 
@@ -433,6 +444,8 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
   if (call_thread != NULL)
     call_thread->control.in_infcall = saved_in_infcall;
 
+  sync_execution = saved_sync_execution;
+
   return e;
 }
 
@@ -466,7 +479,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
 {
   CORE_ADDR sp;
   struct type *values_type, *target_values_type;
-  unsigned char struct_return = 0, lang_struct_return = 0;
+  unsigned char struct_return = 0, hidden_first_param_p = 0;
   CORE_ADDR struct_addr = 0;
   struct infcall_control_state *inf_status;
   struct cleanup *inf_status_cleanup;
@@ -600,9 +613,9 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
      the first argument is passed in out0 but the hidden structure
      return pointer would normally be passed in r8.  */
 
-  if (language_pass_by_reference (values_type))
+  if (gdbarch_return_in_first_hidden_param_p (gdbarch, values_type))
     {
-      lang_struct_return = 1;
+      hidden_first_param_p = 1;
 
       /* Tell the target specific argument pushing routine not to
         expect a value.  */
@@ -610,8 +623,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
     }
   else
     {
-      struct_return = using_struct_return (gdbarch,
-                                          value_type (function), values_type);
+      struct_return = using_struct_return (gdbarch, function, values_type);
       target_values_type = values_type;
     }
 
@@ -621,68 +633,51 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
      not just the breakpoint but also an extra word containing the
      size (?) of the structure being passed.  */
 
-  /* The actual breakpoint (at BP_ADDR) is inserted separatly so there
-     is no need to write that out.  */
-
   switch (gdbarch_call_dummy_location (gdbarch))
     {
     case ON_STACK:
-      sp = push_dummy_code (gdbarch, sp, funaddr,
-                               args, nargs, target_values_type,
-                               &real_pc, &bp_addr, get_current_regcache ());
-      break;
-    case AT_SYMBOL:
-      /* Some executables define a symbol __CALL_DUMMY_ADDRESS whose
-        address is the location where the breakpoint should be
-        placed.  Once all targets are using the overhauled frame code
-        this can be deleted - ON_STACK is a better option.  */
       {
-       struct minimal_symbol *sym;
-       CORE_ADDR dummy_addr;
-
-       sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
-       real_pc = funaddr;
-       if (sym)
-         {
-           dummy_addr = SYMBOL_VALUE_ADDRESS (sym);
-           /* Make certain that the address points at real code, and not
-              a function descriptor.  */
-           dummy_addr = gdbarch_convert_from_func_ptr_addr (gdbarch,
-                                                            dummy_addr,
-                                                            &current_target);
-           /* A call dummy always consists of just a single breakpoint,
-              so its address is the same as the address of the dummy.  */
-           bp_addr = dummy_addr;
-           break;
-         }
+       const gdb_byte *bp_bytes;
+       CORE_ADDR bp_addr_as_address;
+       int bp_size;
+
+       /* Be careful BP_ADDR is in inferior PC encoding while
+          BP_ADDR_AS_ADDRESS is a plain memory address.  */
+
+       sp = push_dummy_code (gdbarch, sp, funaddr, args, nargs,
+                             target_values_type, &real_pc, &bp_addr,
+                             get_current_regcache ());
+
+       /* Write a legitimate instruction at the point where the infcall
+          breakpoint is going to be inserted.  While this instruction
+          is never going to be executed, a user investigating the
+          memory from GDB would see this instruction instead of random
+          uninitialized bytes.  We chose the breakpoint instruction
+          as it may look as the most logical one to the user and also
+          valgrind 3.7.0 needs it for proper vgdb inferior calls.
+
+          If software breakpoints are unsupported for this target we
+          leave the user visible memory content uninitialized.  */
+
+       bp_addr_as_address = bp_addr;
+       bp_bytes = gdbarch_breakpoint_from_pc (gdbarch, &bp_addr_as_address,
+                                              &bp_size);
+       if (bp_bytes != NULL)
+         write_memory (bp_addr_as_address, bp_bytes, bp_size);
       }
-      /* FALLTHROUGH */
+      break;
     case AT_ENTRY_POINT:
       {
        CORE_ADDR dummy_addr;
-       int bp_len;
 
        real_pc = funaddr;
        dummy_addr = entry_point_address ();
 
-       /* If the inferior call throws an uncaught C++ exception,
-          the inferior unwinder tries to unwind all frames, including
-          our dummy frame.  The unwinder determines the address of
-          the calling instruction by subtracting 1 to the return
-          address.  So, using the entry point's address as the return
-          address would lead the unwinder to use the unwinding
-          information of the code immediately preceding the entry
-          point.  This information, if found, is invalid for the dummy
-          frame, and can potentially crash the inferior's unwinder.
-          Therefore, we adjust the return address by the length of
-          a breakpoint, guaranteeing that the unwinder finds the
-          correct function as the caller.  */
-
-       gdbarch_breakpoint_from_pc (gdbarch, &dummy_addr, &bp_len);
-       dummy_addr += bp_len;
-
        /* A call dummy always consists of just a single breakpoint, so
-          its address is the same as the address of the dummy.  */
+          its address is the same as the address of the dummy.
+
+          The actual breakpoint is inserted separatly so there is no need to
+          write that out.  */
        bp_addr = dummy_addr;
        break;
       }
@@ -727,15 +722,13 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
      stack, if necessary.  Make certain that the value is correctly
      aligned.  */
 
-  if (struct_return || lang_struct_return)
+  if (struct_return || hidden_first_param_p)
     {
-      int len = TYPE_LENGTH (values_type);
-
       if (gdbarch_inner_than (gdbarch, 1, 2))
        {
          /* Stack grows downward.  Align STRUCT_ADDR and SP after
              making space for the return value.  */
-         sp -= len;
+         sp -= TYPE_LENGTH (values_type);
          if (gdbarch_frame_align_p (gdbarch))
            sp = gdbarch_frame_align (gdbarch, sp);
          struct_addr = sp;
@@ -747,13 +740,13 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
          if (gdbarch_frame_align_p (gdbarch))
            sp = gdbarch_frame_align (gdbarch, sp);
          struct_addr = sp;
-         sp += len;
+         sp += TYPE_LENGTH (values_type);
          if (gdbarch_frame_align_p (gdbarch))
            sp = gdbarch_frame_align (gdbarch, sp);
        }
     }
 
-  if (lang_struct_return)
+  if (hidden_first_param_p)
     {
       struct value **new_args;
 
@@ -791,7 +784,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
      inferior.  That way it breaks when it returns.  */
 
   {
-    struct breakpoint *bpt;
+    struct breakpoint *bpt, *longjmp_b;
     struct symtab_and_line sal;
 
     init_sal (&sal);           /* initialize to zeroes */
@@ -802,7 +795,22 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
        PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by
        dummy_id to form the frame ID's stack address.  */
     bpt = set_momentary_breakpoint (gdbarch, sal, dummy_id, bp_call_dummy);
+
+    /* set_momentary_breakpoint invalidates FRAME.  */
+    frame = NULL;
+
     bpt->disposition = disp_del;
+    gdb_assert (bpt->related_breakpoint == bpt);
+
+    longjmp_b = set_longjmp_breakpoint_for_call_dummy ();
+    if (longjmp_b)
+      {
+       /* Link BPT into the chain of LONGJMP_B.  */
+       bpt->related_breakpoint = longjmp_b;
+       while (longjmp_b->related_breakpoint != bpt->related_breakpoint)
+         longjmp_b = longjmp_b->related_breakpoint;
+       longjmp_b->related_breakpoint = bpt;
+      }
   }
 
   /* Create a breakpoint in std::terminate.
@@ -823,7 +831,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   /* Everything's ready, push all the info needed to restore the
      caller (and identify the dummy-frame) onto the dummy-frame
      stack.  */
-  dummy_frame_push (caller_state, &dummy_id);
+  dummy_frame_push (caller_state, &dummy_id, inferior_ptid);
 
   /* Discard both inf_status and caller_state cleanups.
      From this point on we explicitly restore the associated state
@@ -949,7 +957,7 @@ When the function is done executing, GDB will silently stop."),
 
              /* We must get back to the frame we were before the
                 dummy call.  */
-             dummy_frame_pop (dummy_id);
+             dummy_frame_pop (dummy_id, call_thread_ptid);
 
              /* We also need to restore inferior status to that before the
                 dummy call.  */
@@ -990,7 +998,7 @@ When the function is done executing, GDB will silently stop."),
        {
          /* We must get back to the frame we were before the dummy
             call.  */
-         dummy_frame_pop (dummy_id);
+         dummy_frame_pop (dummy_id, call_thread_ptid);
 
          /* We also need to restore inferior status to that before
             the dummy call.  */
@@ -1055,7 +1063,7 @@ When the function is done executing, GDB will silently stop."),
     /* Figure out the value returned by the function.  */
     retval = allocate_value (values_type);
 
-    if (lang_struct_return)
+    if (hidden_first_param_p)
       read_value_memory (retval, 0, 1, struct_addr,
                         value_contents_raw (retval),
                         TYPE_LENGTH (values_type));
@@ -1063,13 +1071,13 @@ When the function is done executing, GDB will silently stop."),
       {
        /* If the function returns void, don't bother fetching the
           return value.  */
-       switch (gdbarch_return_value (gdbarch, value_type (function),
-                                     target_values_type, NULL, NULL, NULL))
+       switch (gdbarch_return_value (gdbarch, function, target_values_type,
+                                     NULL, NULL, NULL))
          {
          case RETURN_VALUE_REGISTER_CONVENTION:
          case RETURN_VALUE_ABI_RETURNS_ADDRESS:
          case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
-           gdbarch_return_value (gdbarch, value_type (function), values_type,
+           gdbarch_return_value (gdbarch, function, values_type,
                                  retbuf, value_contents_raw (retval), NULL);
            break;
          case RETURN_VALUE_STRUCT_CONVENTION:
This page took 0.029459 seconds and 4 git commands to generate.