* gdb.base/start.c: New file.
[deliverable/binutils-gdb.git] / gdb / infcmd.c
index b58e4112064ad2788eb0cc69d9a4822e11fa5149..1a7f03e6c4891922e3f9b5b106c88b224d6a5e45 100644 (file)
@@ -1,6 +1,7 @@
 /* Memory-access and commands for "inferior" process, for GDB.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
+
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
+   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -434,7 +435,7 @@ run_command (char *args, int from_tty)
 
   if (!args)
     {
-      if (event_loop_p && target_can_async_p ())
+      if (target_can_async_p ())
        async_disable_stdin ();
     }
   else
@@ -443,12 +444,12 @@ run_command (char *args, int from_tty)
 
       /* If we get a request for running in the bg but the target
          doesn't support it, error out. */
-      if (event_loop_p && async_exec && !target_can_async_p ())
+      if (async_exec && !target_can_async_p ())
        error ("Asynchronous execution not supported on this target.");
 
       /* If we don't get a request of running in the bg, then we need
          to simulate synchronous (fg) execution. */
-      if (event_loop_p && !async_exec && target_can_async_p ())
+      if (!async_exec && target_can_async_p ())
        {
          /* Simulate synchronous execution */
          async_disable_stdin ();
@@ -526,12 +527,12 @@ continue_command (char *proc_count_exp, int from_tty)
 
   /* If we must run in the background, but the target can't do it,
      error out. */
-  if (event_loop_p && async_exec && !target_can_async_p ())
+  if (async_exec && !target_can_async_p ())
     error ("Asynchronous execution not supported on this target.");
 
   /* If we are not asked to run in the bg, then prepare to run in the
      foreground, synchronously. */
-  if (event_loop_p && !async_exec && target_can_async_p ())
+  if (!async_exec && target_can_async_p ())
     {
       /* Simulate synchronous execution */
       async_disable_stdin ();
@@ -620,12 +621,12 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
 
   /* If we get a request for running in the bg but the target
      doesn't support it, error out. */
-  if (event_loop_p && async_exec && !target_can_async_p ())
+  if (async_exec && !target_can_async_p ())
     error ("Asynchronous execution not supported on this target.");
 
   /* If we don't get a request of running in the bg, then we need
      to simulate synchronous (fg) execution. */
-  if (event_loop_p && !async_exec && target_can_async_p ())
+  if (!async_exec && target_can_async_p ())
     {
       /* Simulate synchronous execution */
       async_disable_stdin ();
@@ -636,14 +637,14 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
   if (!single_inst || skip_subroutines)                /* leave si command alone */
     {
       enable_longjmp_breakpoint ();
-      if (!event_loop_p || !target_can_async_p ())
+      if (!target_can_async_p ())
        cleanups = make_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
       else
         make_exec_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
     }
 
   /* In synchronous case, all is well, just use the regular for loop. */
-  if (!event_loop_p || !target_can_async_p ())
+  if (!target_can_async_p ())
     {
       for (; count > 0; count--)
        {
@@ -701,7 +702,7 @@ which has no line number information.\n", name);
      and handle them one at the time, through step_once(). */
   else
     {
-      if (event_loop_p && target_can_async_p ())
+      if (target_can_async_p ())
        step_once (skip_subroutines, single_inst, count);
     }
 }
@@ -828,12 +829,12 @@ jump_command (char *arg, int from_tty)
 
   /* If we must run in the background, but the target can't do it,
      error out. */
-  if (event_loop_p && async_exec && !target_can_async_p ())
+  if (async_exec && !target_can_async_p ())
     error ("Asynchronous execution not supported on this target.");
 
   /* If we are not asked to run in the bg, then prepare to run in the
      foreground, synchronously. */
-  if (event_loop_p && !async_exec && target_can_async_p ())
+  if (!async_exec && target_can_async_p ())
     {
       /* Simulate synchronous execution */
       async_disable_stdin ();
@@ -1024,12 +1025,12 @@ until_command (char *arg, int from_tty)
 
   /* If we must run in the background, but the target can't do it,
      error out. */
-  if (event_loop_p && async_exec && !target_can_async_p ())
+  if (async_exec && !target_can_async_p ())
     error ("Asynchronous execution not supported on this target.");
 
   /* If we are not asked to run in the bg, then prepare to run in the
      foreground, synchronously. */
-  if (event_loop_p && !async_exec && target_can_async_p ())
+  if (!async_exec && target_can_async_p ())
     {
       /* Simulate synchronous execution */
       async_disable_stdin ();
@@ -1058,12 +1059,12 @@ advance_command (char *arg, int from_tty)
 
   /* If we must run in the background, but the target can't do it,
      error out.  */
-  if (event_loop_p && async_exec && !target_can_async_p ())
+  if (async_exec && !target_can_async_p ())
     error ("Asynchronous execution not supported on this target.");
 
   /* If we are not asked to run in the bg, then prepare to run in the
      foreground, synchronously.  */
-  if (event_loop_p && !async_exec && target_can_async_p ())
+  if (!async_exec && target_can_async_p ())
     {
       /* Simulate synchronous execution.  */
       async_disable_stdin ();
@@ -1072,41 +1073,6 @@ advance_command (char *arg, int from_tty)
   until_break_command (arg, from_tty, 1);
 }
 \f
-
-static struct value *
-legacy_return_value (int struct_return, struct type *value_type)
-{
-  struct value *value;
-
-  if (!struct_return)
-    {
-      /* The return value can be found in the inferior's registers.  */
-      return register_value_being_returned (value_type, stop_registers);
-    }
-
-  if (DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS_P ())
-    {
-      CORE_ADDR addr;
-
-      addr = DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS (stop_registers);
-      if (!addr)
-       error ("Function return value unknown.");
-      return value_at (value_type, addr, NULL);
-    }
-
-  /* It is "struct return" yet the value is being extracted,
-     presumably from registers, using EXTRACT_RETURN_VALUE.  This
-     doesn't make sense.  Unfortunately, the legacy interfaces allowed
-     this behavior.  Sigh!  */
-  value = allocate_value (value_type);
-  CHECK_TYPEDEF (value_type);
-  /* If the function returns void, don't bother fetching the return
-     value.  */
-  EXTRACT_RETURN_VALUE (value_type, stop_registers,
-                       VALUE_CONTENTS_RAW (value));
-  return value;
-}
-
 /* Print the result of a function at the end of a 'finish' command.  */
 
 static void
@@ -1115,7 +1081,9 @@ print_return_value (int struct_return, struct type *value_type)
   struct gdbarch *gdbarch = current_gdbarch;
   struct cleanup *old_chain;
   struct ui_stream *stb;
-  struct value *value = NULL;
+  struct value *value;
+
+  gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
 
   /* FIXME: 2003-09-27: When returning from a nested inferior function
      call, it's possible (with no help from the architecture vector)
@@ -1124,24 +1092,21 @@ print_return_value (int struct_return, struct type *value_type)
      inferior function call code.  In fact, when inferior function
      calls are made async, this will likely be made the norm.  */
 
-  if (gdbarch_return_value_p (gdbarch))
+  switch (gdbarch_return_value (gdbarch, value_type, NULL, NULL, NULL))
     {
-      switch (gdbarch_return_value (gdbarch, value_type, NULL, NULL, NULL))
-       {
-       case RETURN_VALUE_REGISTER_CONVENTION:
-       case RETURN_VALUE_ABI_RETURNS_ADDRESS:
-         value = allocate_value (value_type);
-         CHECK_TYPEDEF (value_type);
-         gdbarch_return_value (current_gdbarch, value_type, stop_registers,
-                               VALUE_CONTENTS_RAW (value), NULL);
-         break;
-
-       case RETURN_VALUE_STRUCT_CONVENTION:
-         break;
-       }
+    case RETURN_VALUE_REGISTER_CONVENTION:
+    case RETURN_VALUE_ABI_RETURNS_ADDRESS:
+      value = allocate_value (value_type);
+      CHECK_TYPEDEF (value_type);
+      gdbarch_return_value (current_gdbarch, value_type, stop_registers,
+                           value_contents_raw (value), NULL);
+      break;
+    case RETURN_VALUE_STRUCT_CONVENTION:
+      value = NULL;
+      break;
+    default:
+      internal_error (__FILE__, __LINE__, "bad switch");
     }
-  else
-    value = legacy_return_value (struct_return, value_type);
 
   if (value)
     {
@@ -1235,12 +1200,12 @@ finish_command (char *arg, int from_tty)
 
   /* If we must run in the background, but the target can't do it,
      error out.  */
-  if (event_loop_p && async_exec && !target_can_async_p ())
+  if (async_exec && !target_can_async_p ())
     error ("Asynchronous execution not supported on this target.");
 
   /* If we are not asked to run in the bg, then prepare to run in the
      foreground, synchronously.  */
-  if (event_loop_p && !async_exec && target_can_async_p ())
+  if (!async_exec && target_can_async_p ())
     {
       /* Simulate synchronous execution.  */
       async_disable_stdin ();
@@ -1264,7 +1229,7 @@ finish_command (char *arg, int from_tty)
 
   breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
 
-  if (!event_loop_p || !target_can_async_p ())
+  if (!target_can_async_p ())
     old_chain = make_cleanup_delete_breakpoint (breakpoint);
   else
     old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
@@ -1278,14 +1243,14 @@ finish_command (char *arg, int from_tty)
   if (from_tty)
     {
       printf_filtered ("Run till exit from ");
-      print_stack_frame (get_selected_frame (), 1, LOCATION);
+      print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
     }
 
   /* If running asynchronously and the target support asynchronous
      execution, set things up for the rest of the finish command to be
      completed later on, when gdb has detected that the target has
      stopped, in fetch_inferior_event.  */
-  if (event_loop_p && target_can_async_p ())
+  if (target_can_async_p ())
     {
       arg1 =
        (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
@@ -1308,7 +1273,7 @@ finish_command (char *arg, int from_tty)
   /* Do this only if not running asynchronously or if the target
      cannot do async execution.  Otherwise, complete this command when
      the target actually stops, in fetch_inferior_event.  */
-  if (!event_loop_p || !target_can_async_p ())
+  if (!target_can_async_p ())
     {
       /* Did we stop at our breakpoint?  */
       if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
@@ -1353,7 +1318,7 @@ program_info (char *args, int from_tty)
 
   target_files_info ();
   printf_filtered ("Program stopped at %s.\n",
-                  local_hex_string ((unsigned long) stop_pc));
+                  hex_string ((unsigned long) stop_pc));
   if (stop_step)
     printf_filtered ("It stopped after being stepped.\n");
   else if (num != 0)
@@ -1550,12 +1515,6 @@ default_print_registers_info (struct gdbarch *gdbarch,
   const int numregs = NUM_REGS + NUM_PSEUDO_REGS;
   char buffer[MAX_REGISTER_SIZE];
 
-  if (DEPRECATED_DO_REGISTERS_INFO_P ())
-    {
-      DEPRECATED_DO_REGISTERS_INFO (regnum, print_all);
-      return;
-    }
-
   for (i = 0; i < numregs; i++)
     {
       /* Decide between printing all regs, non-float / vector regs, or
@@ -1604,13 +1563,13 @@ default_print_registers_info (struct gdbarch *gdbarch,
                     file, 0, 1, 0, Val_pretty_default);
 
          fprintf_filtered (file, "\t(raw 0x");
-         for (j = 0; j < DEPRECATED_REGISTER_RAW_SIZE (i); j++)
+         for (j = 0; j < register_size (current_gdbarch, i); j++)
            {
              int idx;
              if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
                idx = j;
              else
-               idx = DEPRECATED_REGISTER_RAW_SIZE (i) - 1 - j;
+               idx = register_size (current_gdbarch, i) - 1 - j;
              fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
            }
          fprintf_filtered (file, ")");
@@ -1818,15 +1777,32 @@ attach_command (char *args, int from_tty)
        error ("Not killed.");
     }
 
+  /* Clear out solib state. Otherwise the solib state of the previous
+     inferior might have survived and is entirely wrong for the new
+     target.  This has been observed on Linux using glibc 2.3. How to
+     reproduce:
+
+     bash$ ./foo&
+     [1] 4711
+     bash$ ./foo&
+     [1] 4712
+     bash$ gdb ./foo
+     [...]
+     (gdb) attach 4711
+     (gdb) detach
+     (gdb) attach 4712
+     Cannot access memory at address 0xdeadbeef
+  */
+#ifdef CLEAR_SOLIB
+      CLEAR_SOLIB ();
+#endif
+
   target_attach (args, from_tty);
 
   /* Set up the "saved terminal modes" of the inferior
      based on what modes we are starting it with.  */
   target_terminal_init ();
 
-  /* Install inferior's terminal modes.  */
-  target_terminal_inferior ();
-
   /* Set up execution context to know that we should return from
      wait_for_inferior as soon as the target reports a stop.  */
   init_wait_for_inferior ();
@@ -1885,6 +1861,9 @@ attach_command (char *args, int from_tty)
    */
   target_post_attach (PIDGET (inferior_ptid));
 
+  /* Install inferior's terminal modes.  */
+  target_terminal_inferior ();
+
   normal_stop ();
 
   if (deprecated_attach_hook)
@@ -1905,7 +1884,7 @@ attach_command (char *args, int from_tty)
 static void
 detach_command (char *args, int from_tty)
 {
-  dont_repeat ();              /* Not for the faint of heart */
+  dont_repeat ();              /* Not for the faint of heart */
   target_detach (args, from_tty);
 #if defined(SOLIB_RESTART)
   SOLIB_RESTART ();
@@ -1939,7 +1918,7 @@ disconnect_command (char *args, int from_tty)
 void
 interrupt_target_command (char *args, int from_tty)
 {
-  if (event_loop_p && target_can_async_p ())
+  if (target_can_async_p ())
     {
       dont_repeat ();          /* Not for the faint of heart */
       target_stop ();
@@ -1979,7 +1958,8 @@ No floating-point info available for this processor.\n");
 static void
 float_info (char *args, int from_tty)
 {
-  print_float_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
+  print_float_info (current_gdbarch, gdb_stdout, 
+                   deprecated_selected_frame, args);
 }
 \f
 static void
@@ -2006,7 +1986,7 @@ Follow this command with any number of args, to be passed to the program.",
                   &setlist);
   set_cmd_completer (c, filename_completer);
   set_cmd_sfunc (c, notice_args_set);
-  c = add_show_from_set (c, &showlist);
+  c = deprecated_add_show_from_set (c, &showlist);
   set_cmd_sfunc (c, notice_args_read);
 
   c = add_cmd
This page took 0.028375 seconds and 4 git commands to generate.