2010-05-17 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / infcall.c
index 2d8bd2cecade786a4cb900d26729196ee27d8099..0c9a3af7b8848bab63fd2861505230186fc5cbcf 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "defs.h"
 #include "breakpoint.h"
+#include "tracepoint.h"
 #include "target.h"
 #include "regcache.h"
 #include "inferior.h"
@@ -267,10 +268,12 @@ find_function_addr (struct value *function, struct type **retval_type)
        {
          /* Handle function descriptors lacking debug info.  */
          int found_descriptor = 0;
+
          funaddr = 0;  /* pacify "gcc -Werror" */
          if (VALUE_LVAL (function) == lval_memory)
            {
              CORE_ADDR nfunaddr;
+
              funaddr = value_as_address (value_addr (function));
              nfunaddr = funaddr;
              funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
@@ -320,6 +323,7 @@ get_function_name (CORE_ADDR funaddr, char *buf, int buf_size)
 {
   {
     struct symbol *symbol = find_pc_function (funaddr);
+
     if (symbol)
       return SYMBOL_PRINT_NAME (symbol);
   }
@@ -327,6 +331,7 @@ 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);
+
     if (msymbol)
       return SYMBOL_PRINT_NAME (msymbol);
   }
@@ -334,6 +339,7 @@ get_function_name (CORE_ADDR funaddr, char *buf, int buf_size)
   {
     char *tmp = xstrprintf (_(RAW_FUNCTION_ADDRESS_FORMAT),
                             hex_string (funaddr));
+
     gdb_assert (strlen (tmp) + 1 <= buf_size);
     strcpy (buf, tmp);
     xfree (tmp);
@@ -402,6 +408,13 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
   return e;
 }
 
+/* A cleanup function that calls delete_std_terminate_breakpoint.  */
+static void
+cleanup_delete_std_terminate_breakpoint (void *ignore)
+{
+  delete_std_terminate_breakpoint ();
+}
+
 /* All this stuff with a dummy frame may seem unnecessarily complicated
    (why not just save registers in GDB?).  The purpose of pushing a dummy
    frame which looks just like a real frame is so that if you call a
@@ -439,12 +452,9 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   struct cleanup *args_cleanup;
   struct frame_info *frame;
   struct gdbarch *gdbarch;
-  struct breakpoint *terminate_bp = NULL;
-  struct minimal_symbol *tm;
-  struct cleanup *terminate_bp_cleanup = NULL;
+  struct cleanup *terminate_bp_cleanup;
   ptid_t call_thread_ptid;
   struct gdb_exception e;
-  const char *name;
   char name_buf[RAW_FUNCTION_ADDRESS_SIZE];
 
   if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
@@ -453,6 +463,9 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   if (!target_has_execution)
     noprocess ();
 
+  if (get_traceframe_number () >= 0)
+    error (_("May not call functions while looking at trace frames."));
+
   frame = get_current_frame ();
   gdbarch = get_frame_arch (frame);
 
@@ -475,6 +488,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   /* Ensure that the initial SP is correctly aligned.  */
   {
     CORE_ADDR old_sp = get_frame_sp (frame);
+
     if (gdbarch_frame_align_p (gdbarch))
       {
        sp = gdbarch_frame_align (gdbarch, old_sp);
@@ -633,6 +647,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
 
   {
     int i;
+
     for (i = nargs - 1; i >= 0; i--)
       {
        int prototyped;
@@ -667,6 +682,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   if (struct_return || lang_struct_return)
     {
       int len = TYPE_LENGTH (values_type);
+
       if (gdbarch_inner_than (gdbarch, 1, 2))
        {
          /* Stack grows downward.  Align STRUCT_ADDR and SP after
@@ -729,6 +745,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   {
     struct breakpoint *bpt;
     struct symtab_and_line sal;
+
     init_sal (&sal);           /* initialize to zeroes */
     sal.pspace = current_program_space;
     sal.pc = bp_addr;
@@ -753,13 +770,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
      call.  Place a momentary breakpoint in the std::terminate function
      and if triggered in the call, rewind.  */
   if (unwind_on_terminating_exception_p)
-     {
-       struct minimal_symbol *tm = lookup_minimal_symbol  ("std::terminate()",
-                                                          NULL, NULL);
-       if (tm != NULL)
-          terminate_bp = set_momentary_breakpoint_at_pc
-            (gdbarch, SYMBOL_VALUE_ADDRESS (tm),  bp_breakpoint);
-     }
+    set_std_terminate_breakpoint ();
 
   /* Everything's ready, push all the info needed to restore the
      caller (and identify the dummy-frame) onto the dummy-frame
@@ -772,8 +783,8 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
   discard_cleanups (inf_status_cleanup);
 
   /* Register a clean-up for unwind_on_terminating_exception_breakpoint.  */
-  if (terminate_bp)
-    terminate_bp_cleanup = make_cleanup_delete_breakpoint (terminate_bp);
+  terminate_bp_cleanup = make_cleanup (cleanup_delete_std_terminate_breakpoint,
+                                      NULL);
 
   /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP -
      If you're looking to implement asynchronous dummy-frames, then
@@ -874,7 +885,7 @@ When the function is done executing, GDB will silently stop."),
               name);
     }
 
-  if (stopped_by_random_signal || !stop_stack_dummy)
+  if (stopped_by_random_signal || stop_stack_dummy != STOP_STACK_DUMMY)
     {
       const char *name = get_function_name (funaddr,
                                            name_buf, sizeof (name_buf));
@@ -928,30 +939,17 @@ When the function is done executing, GDB will silently stop."),
            }
        }
 
-      if (!stop_stack_dummy)
+      if (stop_stack_dummy == STOP_STD_TERMINATE)
        {
+         /* We must get back to the frame we were before the dummy
+            call.  */
+         dummy_frame_pop (dummy_id);
 
-         /* Check if unwind on terminating exception behaviour is on.  */
-         if (unwind_on_terminating_exception_p)
-           {
-             /* Check that the breakpoint is our special std::terminate
-                breakpoint.  If it is, we do not want to kill the inferior
-                in an inferior function call. Rewind, and warn the
-                user.  */
-
-             if (terminate_bp != NULL
-                 && (inferior_thread ()->stop_bpstat->breakpoint_at->address
-                     == terminate_bp->loc->address))
-               {
-                 /* We must get back to the frame we were before the
-                    dummy call.  */
-                 dummy_frame_pop (dummy_id);
-
-                 /* We also need to restore inferior status to that before the
-                    dummy call.  */
-                 restore_inferior_status (inf_status);
-
-                 error (_("\
+         /* We also need to restore inferior status to that before
+            the dummy call.  */
+         restore_inferior_status (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\
@@ -959,9 +957,11 @@ 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);
+       }
+      else if (stop_stack_dummy == STOP_NONE)
+       {
+
          /* We hit a breakpoint inside the FUNCTION.
             Keep the dummy frame, the user may want to examine its state.
             Discard inferior status, we're not at the same point
@@ -988,10 +988,7 @@ When the function is done executing, GDB will silently stop."),
       internal_error (__FILE__, __LINE__, _("... should not be here"));
     }
 
-  /* If we get here and the std::terminate() breakpoint has been set,
-     it has to be cleaned manually.  */
-  if (terminate_bp)
-    do_cleanups (terminate_bp_cleanup);
+  do_cleanups (terminate_bp_cleanup);
 
   /* If we get here the called FUNCTION ran to completion,
      and the dummy frame has already been popped.  */
This page took 0.027014 seconds and 4 git commands to generate.