* gdb.base/ptype.exp: Accept char[0] as well as char[] for "ptype
[deliverable/binutils-gdb.git] / gdb / core.c
index 4c60fb7e04e3a26345b10588f00d7425cc6c598f..974e55c1859de6cdf1f8ae1ef42a01e868b2be1e 100644 (file)
@@ -1,5 +1,6 @@
 /* Core dump and executable file functions above target vector, for GDB.
-   Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994
+   Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -18,6 +19,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "defs.h"
+#include <string.h>
 #include <errno.h>
 #include <signal.h>
 #include <fcntl.h>
@@ -30,6 +32,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "target.h"
 #include "gdbcore.h"
 #include "dis-asm.h"
+#include "language.h"
 
 extern char registers[];
 
@@ -135,17 +138,24 @@ memory_error (status, memaddr)
      int status;
      CORE_ADDR memaddr;
 {
-
   if (status == EIO)
     {
       /* Actually, address between memaddr and memaddr + len
         was out of bounds. */
-      error ("Cannot access memory at address %s.", local_hex_string(memaddr));
+      error_begin ();
+      printf_filtered ("Cannot access memory at address ");
+      print_address_numeric (memaddr, 1, gdb_stdout);
+      printf_filtered (".\n");
+      return_to_top_level (RETURN_ERROR);
     }
   else
     {
-      error ("Error accessing memory address %s: %s.",
-            local_hex_string (memaddr), safe_strerror (status));
+      error_begin ();
+      printf_filtered ("Error accessing memory address ");
+      print_address_numeric (memaddr, 1, gdb_stdout);
+      printf_filtered (": %s.\n",
+                        safe_strerror (status));
+      return_to_top_level (RETURN_ERROR);
     }
 }
 
@@ -214,9 +224,8 @@ read_memory_integer (memaddr, len)
      CORE_ADDR memaddr;
      int len;
 {
-  char *buf;
+  char buf[sizeof (LONGEST)];
 
-  buf = alloca (len);
   read_memory (memaddr, buf, len);
   return extract_signed_integer (buf, len);
 }
@@ -226,13 +235,85 @@ read_memory_unsigned_integer (memaddr, len)
      CORE_ADDR memaddr;
      int len;
 {
-  char *buf;
+  char buf[sizeof (unsigned LONGEST)];
 
-  buf = alloca (len);
   read_memory (memaddr, buf, len);
   return extract_unsigned_integer (buf, len);
 }
 \f
+#if 0
+/* Enable after 4.12.  It is not tested.  */
+
+/* Search code.  Targets can just make this their search function, or
+   if the protocol has a less general search function, they can call this
+   in the cases it can't handle.  */
+void
+generic_search (len, data, mask, startaddr, increment, lorange, hirange
+               addr_found, data_found)
+     int len;
+     char *data;
+     char *mask;
+     CORE_ADDR startaddr;
+     int increment;
+     CORE_ADDR lorange;
+     CORE_ADDR hirange;
+     CORE_ADDR *addr_found;
+     char *data_found;
+{
+  int i;
+  CORE_ADDR curaddr = startaddr;
+
+  while (curaddr >= lorange && curaddr < hirange)
+    {
+      read_memory (curaddr, data_found, len);
+      for (i = 0; i < len; ++i)
+       if ((data_found[i] & mask[i]) != data[i])
+         goto try_again;
+      /* It matches.  */
+      *addr_found = curaddr;
+      return;
+
+    try_again:
+      curaddr += increment;
+    }
+  *addr_found = (CORE_ADDR)0;
+  return;
+}
+#endif /* 0 */
+\f
+/* The current default bfd target.  Points to storage allocated for
+   gnutarget_string.  */
+char *gnutarget;
+
+/* Same thing, except it is "auto" not NULL for the default case.  */
+static char *gnutarget_string;
+
+static void set_gnutarget_command
+  PARAMS ((char *, int, struct cmd_list_element *));
+
+static void
+set_gnutarget_command (ignore, from_tty, c)
+     char *ignore;
+     int from_tty;
+     struct cmd_list_element *c;
+{
+  if (STREQ (gnutarget_string, "auto"))
+    gnutarget = NULL;
+  else
+    gnutarget = gnutarget_string;
+}
+
+/* Set the gnutarget.  */
+void
+set_gnutarget (newtarget)
+     char *newtarget;
+{
+  if (gnutarget_string != NULL)
+    free (gnutarget_string);
+  gnutarget_string = savestring (newtarget, strlen (newtarget));
+  set_gnutarget_command (NULL, 0, NULL);
+}
+
 void
 _initialize_core()
 {
@@ -242,4 +323,17 @@ _initialize_core()
 No arg means have no core file.  This command has been superseded by the\n\
 `target core' and `detach' commands.", &cmdlist);
   c->completer = filename_completer;
+
+  c = add_set_cmd ("gnutarget", class_files, var_string_noescape,
+                 (char *) &gnutarget_string,
+                 "Set the current BFD target.\n\
+Use `set gnutarget auto' to specify automatic detection.",
+                 &setlist);
+  c->function.sfunc = set_gnutarget_command;
+  add_show_from_set (c, &showlist);
+
+  if (getenv ("GNUTARGET"))
+    set_gnutarget (getenv ("GNUTARGET"));
+  else
+    set_gnutarget ("auto");
 }
This page took 0.024591 seconds and 4 git commands to generate.