target_read_memory&co: no longer return target_xfer_status
authorPedro Alves <palves@redhat.com>
Tue, 27 Oct 2015 17:25:09 +0000 (17:25 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 27 Oct 2015 17:25:09 +0000 (17:25 +0000)
Years ago, these functions used to return errno/EIO.  Later, through a
series of changes that intended to remove native/remote differences,
they ended up returning a target_xfer_status in disguise.

Unlike target_xfer_partial&co, the point of target_read_memory&co is
to either fully succeed or fail.  On error, they always return
TARGET_XFER_E_IO.  So there's no real point in casting the return of
target_read_memory to a target_xfer_status to pass it to memory_error.
Instead, it results in clearer code to simply decouple
target_read_memory&co's return from target_xfer_status.

This fixes build errors like this in C++ mode:

 ../../src/gdb/corefile.c: In function ‘void read_stack(CORE_ADDR, gdb_byte*, ssize_t)’:
 ../../src/gdb/corefile.c:276:34: error: invalid conversion from ‘int’ to ‘target_xfer_status’ [-fpermissive]
      memory_error (status, memaddr);
   ^
 ../../src/gdb/corefile.c:216:1: error:   initializing argument 1 of ‘void memory_error(target_xfer_status, CORE_ADDR)’ [-fpermissive]

gdb/ChangeLog:
2015-10-27  Pedro Alves  <palves@redhat.com>

* alpha-tdep.c (alpha_read_insn): Always pass TARGET_XFER_E_IO to
memory_error.  Rename local 'status' to 'res'.
* c-lang.c (c_get_string): Always pass TARGET_XFER_E_IO to
memory_error.
* corefile.c (read_stack, read_code, write_memory): Always pass
TARGET_XFER_E_IO to memory_error.
* disasm.c (dis_asm_memory_error): Always pass TARGET_XFER_E_IO to
memory_error.  Rename parameter 'status' to 'err'.
(dump_insns): Rename local 'status' to 'err'.
* mips-tdep.c (mips_fetch_instruction): Rename parameter 'statusp'
to 'errp'.  Rename local 'status' to 'err'.  Always pass
TARGET_XFER_E_IO to memory_error.
(mips_breakpoint_from_pc): Rename local 'status' to 'err'.
* target.c (target_read_memory, target_read_raw_memory)
(target_read_stack, target_read_code, target_write_memory)
(target_write_raw_memory): Return -1 on error instead of
TARGET_XFER_E_IO.
* valprint.c (val_print_string): Rename local 'errcode' to 'err'.
Always pass TARGET_XFER_E_IO to memory_error.  Update comment.

gdb/ChangeLog
gdb/alpha-tdep.c
gdb/c-lang.c
gdb/corefile.c
gdb/disasm.c
gdb/mips-tdep.c
gdb/target.c
gdb/valprint.c

index e84a227148c39f51fd38f3df481e3b2acf25a346..d7266e5f5d987366aa4f99c2ec128529e8ce7e88 100644 (file)
@@ -1,3 +1,25 @@
+2015-10-27  Pedro Alves  <palves@redhat.com>
+
+       * alpha-tdep.c (alpha_read_insn): Always pass TARGET_XFER_E_IO to
+       memory_error.  Rename local 'status' to 'res'.
+       * c-lang.c (c_get_string): Always pass TARGET_XFER_E_IO to
+       memory_error.
+       * corefile.c (read_stack, read_code, write_memory): Always pass
+       TARGET_XFER_E_IO to memory_error.
+       * disasm.c (dis_asm_memory_error): Always pass TARGET_XFER_E_IO to
+       memory_error.  Rename parameter 'status' to 'err'.
+       (dump_insns): Rename local 'status' to 'err'.
+       * mips-tdep.c (mips_fetch_instruction): Rename parameter 'statusp'
+       to 'errp'.  Rename local 'status' to 'err'.  Always pass
+       TARGET_XFER_E_IO to memory_error.
+       (mips_breakpoint_from_pc): Rename local 'status' to 'err'.
+       * target.c (target_read_memory, target_read_raw_memory)
+       (target_read_stack, target_read_code, target_write_memory)
+       (target_write_raw_memory): Return -1 on error instead of
+       TARGET_XFER_E_IO.
+       * valprint.c (val_print_string): Rename local 'errcode' to 'err'.
+       Always pass TARGET_XFER_E_IO to memory_error.  Update comment.
+
 2015-10-27  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * guile/guile-internal.h (gdbscm_with_guile): Change return
index 0696b6e67b07669a029128f7b4e7200dc906963c..ca0e10990b0b559d0bf4ac1cf2b97e2588ef374c 100644 (file)
@@ -682,11 +682,11 @@ alpha_read_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[ALPHA_INSN_SIZE];
-  int status;
+  int res;
 
-  status = target_read_memory (pc, buf, sizeof (buf));
-  if (status)
-    memory_error (status, pc);
+  res = target_read_memory (pc, buf, sizeof (buf));
+  if (res != 0)
+    memory_error (TARGET_XFER_E_IO, pc);
   return extract_unsigned_integer (buf, sizeof (buf), byte_order);
 }
 
index 6731b43d21dbefd382306c7e259e701a9c8cd95e..384783cb167a71d387c8000602388789fe7e3fde 100644 (file)
@@ -327,10 +327,10 @@ c_get_string (struct value *value, gdb_byte **buffer,
 
       err = read_string (addr, *length, width, fetchlimit,
                         byte_order, buffer, length);
-      if (err)
+      if (err != 0)
        {
          xfree (*buffer);
-         memory_error (err, addr);
+         memory_error (TARGET_XFER_E_IO, addr);
        }
     }
 
index 31301cf4777f4b582c14b09b366bc2ab05963bd5..596da336d85bc21ec5436998feebff8eab1b15ba 100644 (file)
@@ -273,7 +273,7 @@ read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 
   status = target_read_stack (memaddr, myaddr, len);
   if (status != 0)
-    memory_error (status, memaddr);
+    memory_error (TARGET_XFER_E_IO, memaddr);
 }
 
 /* Same as target_read_code, but report an error if can't read.  */
@@ -285,7 +285,7 @@ read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 
   status = target_read_code (memaddr, myaddr, len);
   if (status != 0)
-    memory_error (status, memaddr);
+    memory_error (TARGET_XFER_E_IO, memaddr);
 }
 
 /* Read memory at MEMADDR of length LEN and put the contents in
@@ -392,7 +392,7 @@ write_memory (CORE_ADDR memaddr,
 
   status = target_write_memory (memaddr, myaddr, len);
   if (status != 0)
-    memory_error (status, memaddr);
+    memory_error (TARGET_XFER_E_IO, memaddr);
 }
 
 /* Same as write_memory, but notify 'memory_changed' observers.  */
index 6e3d6c1d0b738a4ec3db85fdf2e301e5e08fd319..c17574ebeea20a176c3280f27722d5b6c8351eef 100644 (file)
@@ -129,10 +129,10 @@ dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
 
 /* Like memory_error with slightly different parameters.  */
 static void
-dis_asm_memory_error (int status, bfd_vma memaddr,
+dis_asm_memory_error (int err, bfd_vma memaddr,
                      struct disassemble_info *info)
 {
-  memory_error (status, memaddr);
+  memory_error (TARGET_XFER_E_IO, memaddr);
 }
 
 /* Like print_address with slightly different parameters.  */
@@ -230,7 +230,7 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
         {
           CORE_ADDR old_pc = pc;
           bfd_byte data;
-          int status;
+          int err;
           const char *spacer = "";
 
           /* Build the opcodes using a temporary stream so we can
@@ -242,9 +242,9 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
           pc += gdbarch_print_insn (gdbarch, pc, di);
           for (;old_pc < pc; old_pc++)
             {
-              status = (*di->read_memory_func) (old_pc, &data, 1, di);
-              if (status != 0)
-                (*di->memory_error_func) (status, old_pc, di);
+              err = (*di->read_memory_func) (old_pc, &data, 1, di);
+              if (err != 0)
+                (*di->memory_error_func) (err, old_pc, di);
               fprintf_filtered (opcode_stream, "%s%02x",
                                 spacer, (unsigned) data);
               spacer = " ";
index 7cea8321a4f1487c1aa8d7d9dacfee44d35ca836..6b5a1bd8f809c2aca1c35bcb41ab048e49447617 100644 (file)
@@ -1429,12 +1429,12 @@ mips_write_pc (struct regcache *regcache, CORE_ADDR pc)
 
 static ULONGEST
 mips_fetch_instruction (struct gdbarch *gdbarch,
-                       enum mips_isa isa, CORE_ADDR addr, int *statusp)
+                       enum mips_isa isa, CORE_ADDR addr, int *errp)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[MIPS_INSN32_SIZE];
   int instlen;
-  int status;
+  int err;
 
   switch (isa)
     {
@@ -1450,13 +1450,13 @@ mips_fetch_instruction (struct gdbarch *gdbarch,
       internal_error (__FILE__, __LINE__, _("invalid ISA"));
       break;
     }
-  status = target_read_memory (addr, buf, instlen);
-  if (statusp != NULL)
-    *statusp = status;
-  if (status)
+  err = target_read_memory (addr, buf, instlen);
+  if (errp != NULL)
+    *errp = err;
+  if (err != 0)
     {
-      if (statusp == NULL)
-       memory_error (status, addr);
+      if (errp == NULL)
+       memory_error (TARGET_XFER_E_IO, addr);
       return 0;
     }
   return extract_unsigned_integer (buf, instlen, byte_order);
@@ -7118,12 +7118,13 @@ mips_breakpoint_from_pc (struct gdbarch *gdbarch,
          static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 };
          static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 };
          ULONGEST insn;
-         int status;
+         int err;
          int size;
 
-         insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status);
-         size = status ? 2
-                       : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4;
+         insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &err);
+         size = (err != 0
+                 ? 2 : (mips_insn_size (ISA_MICROMIPS, insn) == 2
+                        ? 2 : 4));
          *pcptr = unmake_compact_addr (pc);
          *lenptr = size;
          return (size == 2) ? micromips16_big_breakpoint
index d7653c4126ff42b3f299cf4e1af22bcb1642c059..7ad23306c3b8ce470f17e19c924487438769c8fa 100644 (file)
@@ -1380,7 +1380,7 @@ target_xfer_partial (struct target_ops *ops,
 
 /* Read LEN bytes of target memory at address MEMADDR, placing the
    results in GDB's memory at MYADDR.  Returns either 0 for success or
-   TARGET_XFER_E_IO if any error occurs.
+   -1 if any error occurs.
 
    If an error occurs, no guarantee is made about the contents of the data at
    MYADDR.  In particular, the caller should not depend upon partial reads
@@ -1399,7 +1399,7 @@ target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
                   myaddr, memaddr, len) == len)
     return 0;
   else
-    return TARGET_XFER_E_IO;
+    return -1;
 }
 
 /* See target/target.h.  */
@@ -1431,7 +1431,7 @@ target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
                   myaddr, memaddr, len) == len)
     return 0;
   else
-    return TARGET_XFER_E_IO;
+    return -1;
 }
 
 /* Like target_read_memory, but specify explicitly that this is a read from
@@ -1446,7 +1446,7 @@ target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
                   myaddr, memaddr, len) == len)
     return 0;
   else
-    return TARGET_XFER_E_IO;
+    return -1;
 }
 
 /* Like target_read_memory, but specify explicitly that this is a read from
@@ -1461,14 +1461,14 @@ target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
                   myaddr, memaddr, len) == len)
     return 0;
   else
-    return TARGET_XFER_E_IO;
+    return -1;
 }
 
 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
-   Returns either 0 for success or TARGET_XFER_E_IO if any
-   error occurs.  If an error occurs, no guarantee is made about how
-   much data got written.  Callers that can deal with partial writes
-   should call target_write.  */
+   Returns either 0 for success or -1 if any error occurs.  If an
+   error occurs, no guarantee is made about how much data got written.
+   Callers that can deal with partial writes should call
+   target_write.  */
 
 int
 target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
@@ -1479,14 +1479,14 @@ target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
                    myaddr, memaddr, len) == len)
     return 0;
   else
-    return TARGET_XFER_E_IO;
+    return -1;
 }
 
 /* Write LEN bytes from MYADDR to target raw memory at address
-   MEMADDR.  Returns either 0 for success or TARGET_XFER_E_IO
-   if any error occurs.  If an error occurs, no guarantee is made
-   about how much data got written.  Callers that can deal with
-   partial writes should call target_write.  */
+   MEMADDR.  Returns either 0 for success or -1 if any error occurs.
+   If an error occurs, no guarantee is made about how much data got
+   written.  Callers that can deal with partial writes should call
+   target_write.  */
 
 int
 target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
@@ -1497,7 +1497,7 @@ target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
                    myaddr, memaddr, len) == len)
     return 0;
   else
-    return TARGET_XFER_E_IO;
+    return -1;
 }
 
 /* Fetch the target's memory map.  */
index 7e74856c910656c432173c7c4a31b2de188ea173..7f891c988eeda4214ed3281c19fb8fbe66b5f6ab 100644 (file)
@@ -2737,7 +2737,7 @@ val_print_string (struct type *elttype, const char *encoding,
                  const struct value_print_options *options)
 {
   int force_ellipsis = 0;      /* Force ellipsis to be printed if nonzero.  */
-  int errcode;                 /* Errno returned from bad reads.  */
+  int err;                     /* Non-zero if we got a bad read.  */
   int found_nul;               /* Non-zero if we found the nul char.  */
   unsigned int fetchlimit;     /* Maximum number of chars to print.  */
   int bytes_read;
@@ -2758,8 +2758,8 @@ val_print_string (struct type *elttype, const char *encoding,
   fetchlimit = (len == -1 ? options->print_max : min (len,
                                                      options->print_max));
 
-  errcode = read_string (addr, len, width, fetchlimit, byte_order,
-                        &buffer, &bytes_read);
+  err = read_string (addr, len, width, fetchlimit, byte_order,
+                    &buffer, &bytes_read);
   old_chain = make_cleanup (xfree, buffer);
 
   addr += bytes_read;
@@ -2787,7 +2787,7 @@ val_print_string (struct type *elttype, const char *encoding,
          && extract_unsigned_integer (peekbuf, width, byte_order) != 0)
        force_ellipsis = 1;
     }
-  else if ((len >= 0 && errcode != 0) || (len > bytes_read / width))
+  else if ((len >= 0 && err != 0) || (len > bytes_read / width))
     {
       /* Getting an error when we have a requested length, or fetching less
          than the number of characters actually requested, always make us
@@ -2798,17 +2798,17 @@ val_print_string (struct type *elttype, const char *encoding,
   /* If we get an error before fetching anything, don't print a string.
      But if we fetch something and then get an error, print the string
      and then the error message.  */
-  if (errcode == 0 || bytes_read > 0)
+  if (err == 0 || bytes_read > 0)
     {
       LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width,
                       encoding, force_ellipsis, options);
     }
 
-  if (errcode != 0)
+  if (err != 0)
     {
       char *str;
 
-      str = memory_error_message (errcode, gdbarch, addr);
+      str = memory_error_message (TARGET_XFER_E_IO, gdbarch, addr);
       make_cleanup (xfree, str);
 
       fprintf_filtered (stream, "<error: ");
This page took 0.042092 seconds and 4 git commands to generate.