aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog28
-rw-r--r--gdb/breakpoint.c17
-rw-r--r--gdb/c-lang.c8
-rw-r--r--gdb/corefile.c52
-rw-r--r--gdb/gdbcore.h9
-rw-r--r--gdb/target.c31
-rw-r--r--gdb/target.h15
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.python/py-prettyprint.exp2
-rw-r--r--gdb/valprint.c34
10 files changed, 122 insertions, 79 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3dd66c8..21bc3fe 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,31 @@
+2013-10-09 Pedro Alves <palves@redhat.com>
+
+ * breakpoint.c (insert_bp_location): Use memory_error_message to
+ build the memory error string.
+ * c-lang.c: Include "gdbcore.h".
+ (c_get_string): Use memory_error to throw error.
+ (target_xfer_memory_error): Delete.
+ (memory_error_message): New, factored out from
+ target_xfer_memory_error.
+ (memory_error): Change parameter type to target_xfer_error.
+ Rewrite.
+ (read_memory): Use memory_error instead of
+ target_xfer_memory_error.
+ * gdbcore.h: Include "target.h".
+ (memory_error): Change parameter type to target_xfer_error.
+ (memory_error_message): Declare function.
+ * target.c (target_read_memory, target_read_stack)
+ (target_write_memory, target_write_raw_memory): Return
+ TARGET_XFER_E_IO on error. Adjust comments.
+ (get_target_memory): Pass TARGET_XFER_E_IO to memory_error,
+ instead of EIO.
+ * target.h (target_read, target_insert_breakpoint)
+ (target_remove_breakpoint): Adjust comments.
+ * valprint.c (partial_memory_read): Rename parameter, and adjust
+ comment.
+ (val_print_string): Use memory_error_message to build the memory
+ error string.
+
2013-10-09 Jan Kratochvil <jan.kratochvil@redhat.com>
* common/filestuff.c (gdb_fopen_cloexec): Remove initialization of
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d3e9e49..f0da90a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2570,15 +2570,16 @@ insert_bp_location (struct bp_location *bl,
}
else
{
+ char *message = memory_error_message (TARGET_XFER_E_IO,
+ bl->gdbarch, bl->address);
+ struct cleanup *old_chain = make_cleanup (xfree, message);
+
fprintf_unfiltered (tmp_error_stream,
- "Cannot insert breakpoint %d.\n",
- bl->owner->number);
- fprintf_filtered (tmp_error_stream,
- "Error accessing memory address ");
- fputs_filtered (paddress (bl->gdbarch, bl->address),
- tmp_error_stream);
- fprintf_filtered (tmp_error_stream, ": %s.\n",
- safe_strerror (val));
+ "Cannot insert breakpoint %d.\n"
+ "%s\n",
+ bl->owner->number, message);
+
+ do_cleanups (old_chain);
}
}
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 48a1fb0..33bb444 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -35,6 +35,7 @@
#include "gdb_obstack.h"
#include <ctype.h>
#include "exceptions.h"
+#include "gdbcore.h"
extern void _initialize_c_language (void);
@@ -312,12 +313,7 @@ c_get_string (struct value *value, gdb_byte **buffer,
if (err)
{
xfree (*buffer);
- if (err == EIO)
- throw_error (MEMORY_ERROR, "Address %s out of bounds",
- paddress (get_type_arch (type), addr));
- else
- error (_("Error reading string from inferior: %s"),
- safe_strerror (err));
+ memory_error (err, addr);
}
}
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 1b733e2..345df90 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -193,24 +193,20 @@ Use the \"file\" or \"exec-file\" command."));
}
-/* Report a target xfer memory error by throwing a suitable
- exception. */
-
-static void
-target_xfer_memory_error (enum target_xfer_error err, CORE_ADDR memaddr)
+char *
+memory_error_message (enum target_xfer_error err,
+ struct gdbarch *gdbarch, CORE_ADDR memaddr)
{
switch (err)
{
case TARGET_XFER_E_IO:
/* Actually, address between memaddr and memaddr + len was out of
bounds. */
- throw_error (MEMORY_ERROR,
- _("Cannot access memory at address %s"),
- paddress (target_gdbarch (), memaddr));
+ return xstrprintf (_("Cannot access memory at address %s"),
+ paddress (gdbarch, memaddr));
case TARGET_XFER_E_UNAVAILABLE:
- throw_error (NOT_AVAILABLE_ERROR,
- _("Memory at address %s unavailable."),
- paddress (target_gdbarch (), memaddr));
+ return xstrprintf (_("Memory at address %s unavailable."),
+ paddress (gdbarch, memaddr));
default:
internal_error (__FILE__, __LINE__,
"unhandled target_xfer_error: %s (%s)",
@@ -219,18 +215,30 @@ target_xfer_memory_error (enum target_xfer_error err, CORE_ADDR memaddr)
}
}
-/* Report a memory error by throwing a MEMORY_ERROR error. */
+/* Report a memory error by throwing a suitable exception. */
void
-memory_error (int status, CORE_ADDR memaddr)
+memory_error (enum target_xfer_error err, CORE_ADDR memaddr)
{
- if (status == EIO)
- target_xfer_memory_error (TARGET_XFER_E_IO, memaddr);
- else
- throw_error (MEMORY_ERROR,
- _("Error accessing memory address %s: %s."),
- paddress (target_gdbarch (), memaddr),
- safe_strerror (status));
+ char *str;
+
+ /* Build error string. */
+ str = memory_error_message (err, target_gdbarch (), memaddr);
+ make_cleanup (xfree, str);
+
+ /* Choose the right error to throw. */
+ switch (err)
+ {
+ case TARGET_XFER_E_IO:
+ err = MEMORY_ERROR;
+ break;
+ case TARGET_XFER_E_UNAVAILABLE:
+ err = NOT_AVAILABLE_ERROR;
+ break;
+ }
+
+ /* Throw it. */
+ throw_error (err, ("%s"), str);
}
/* Same as target_read_memory, but report an error if can't read. */
@@ -248,9 +256,9 @@ read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
memaddr + xfered, len - xfered);
if (xfer == 0)
- target_xfer_memory_error (TARGET_XFER_E_IO, memaddr + xfered);
+ memory_error (TARGET_XFER_E_IO, memaddr + xfered);
if (xfer < 0)
- target_xfer_memory_error (xfer, memaddr + xfered);
+ memory_error (xfer, memaddr + xfered);
xfered += xfer;
QUIT;
}
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 01ed4df..41bcf1f 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -27,6 +27,7 @@ struct regcache;
#include "bfd.h"
#include "exec.h"
+#include "target.h"
/* Return the name of the executable file as a string.
ERR nonzero means get error if there is none specified;
@@ -40,7 +41,13 @@ extern int have_core_file_p (void);
/* Report a memory error with error(). */
-extern void memory_error (int status, CORE_ADDR memaddr);
+extern void memory_error (enum target_xfer_error status, CORE_ADDR memaddr);
+
+/* The string 'memory_error' would use as exception message. Space
+ for the result is malloc'd, caller must free. */
+
+extern char *memory_error_message (enum target_xfer_error err,
+ struct gdbarch *gdbarch, CORE_ADDR memaddr);
/* Like target_read_memory, but report an error if can't read. */
diff --git a/gdb/target.c b/gdb/target.c
index 559ae0c..7279359 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1787,9 +1787,9 @@ target_xfer_partial (struct target_ops *ops,
return retval;
}
-/* Read LEN bytes of target memory at address MEMADDR, placing the results in
- GDB's memory at MYADDR. Returns either 0 for success or an errno value
- if any error occurs.
+/* Read LEN bytes of target memory at address MEMADDR, placing the
+ results in GDB's memory at MYADDR. Returns either 0 for success or
+ a target_xfer_error value 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
@@ -1808,7 +1808,7 @@ target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Like target_read_memory, but specify explicitly that this is a read from
@@ -1825,13 +1825,14 @@ target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Write LEN bytes from MYADDR to target memory at address MEMADDR.
- Returns either 0 for success or an errno value 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 a target_xfer_error value 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)
@@ -1843,14 +1844,14 @@ target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Write LEN bytes from MYADDR to target raw memory at address
- MEMADDR. Returns either 0 for success or an errno value 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 a target_xfer_error value
+ 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)
@@ -1862,7 +1863,7 @@ target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Fetch the target's memory map. */
@@ -2440,7 +2441,7 @@ get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf,
for this target). */
if (target_read (ops, TARGET_OBJECT_RAW_MEMORY, NULL, buf, addr, len)
!= len)
- memory_error (EIO, addr);
+ memory_error (TARGET_XFER_E_IO, addr);
}
ULONGEST
diff --git a/gdb/target.h b/gdb/target.h
index 7622465..56ca40c 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -239,11 +239,12 @@ DEF_VEC_P(static_tracepoint_marker_p);
starting point. The ANNEX can be used to provide additional
data-specific information to the target.
- Return the number of bytes actually transfered, or -1 if the
- transfer is not supported or otherwise fails. Return of a positive
- value less than LEN indicates that no further transfer is possible.
- Unlike the raw to_xfer_partial interface, callers of these
- functions do not need to retry partial transfers. */
+ Return the number of bytes actually transfered, or a negative error
+ code (an 'enum target_xfer_error' value) if the transfer is not
+ supported or otherwise fails. Return of a positive value less than
+ LEN indicates that no further transfer is possible. Unlike the raw
+ to_xfer_partial interface, callers of these functions do not need
+ to retry partial transfers. */
extern LONGEST target_read (struct target_ops *ops,
enum target_object object,
@@ -1117,13 +1118,13 @@ int target_write_memory_blocks (VEC(memory_write_request_s) *requests,
(*current_target.to_files_info) (&current_target)
/* Insert a breakpoint at address BP_TGT->placed_address in the target
- machine. Result is 0 for success, or an errno value. */
+ machine. Result is 0 for success, non-zero for error. */
extern int target_insert_breakpoint (struct gdbarch *gdbarch,
struct bp_target_info *bp_tgt);
/* Remove a breakpoint at address BP_TGT->placed_address in the target
- machine. Result is 0 for success, or an errno value. */
+ machine. Result is 0 for success, non-zero for error. */
extern int target_remove_breakpoint (struct gdbarch *gdbarch,
struct bp_target_info *bp_tgt);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 7a5f913..7fc1148 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2013-10-09 Pedro Alves <palves@redhat.com>
+ * gdb.python/py-prettyprint.exp (run_lang_tests): Adjust expected
+ output.
+
+2013-10-09 Pedro Alves <palves@redhat.com>
+
* gdb.base/catch-syscall.exp (test_catch_syscall_without_args)
(test_catch_syscall_with_args, test_catch_syscall_with_many_args)
(test_catch_syscall_with_wrong_args)
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
index d124a72..adbe88d 100644
--- a/gdb/testsuite/gdb.python/py-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
@@ -83,7 +83,7 @@ proc run_lang_tests {exefile lang} {
gdb_py_test_silent_cmd "set print elements 200" "" 1
}
- gdb_test "print ns2" ".error reading variable: Address 0x0 out of bounds."
+ gdb_test "print ns2" ".error reading variable: Cannot access memory at address 0x0."
gdb_test "print x" " = \"this is x\""
gdb_test "print cstring" " = \"const string\""
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 61492cc..0ecea0c 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -83,7 +83,7 @@ struct cmd_list_element *showprintrawlist;
/* Prototypes for local functions */
static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
- int len, int *errnoptr);
+ int len, int *errptr);
static void show_print (char *, int);
@@ -1711,15 +1711,15 @@ val_print_array_elements (struct type *type,
/* Read LEN bytes of target memory at address MEMADDR, placing the
results in GDB's memory at MYADDR. Returns a count of the bytes
- actually read, and optionally an errno value in the location
- pointed to by ERRNOPTR if ERRNOPTR is non-null. */
+ actually read, and optionally a target_xfer_error value in the
+ location pointed to by ERRPTR if ERRPTR is non-null. */
/* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this
function be eliminated. */
static int
partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
- int len, int *errnoptr)
+ int len, int *errptr)
{
int nread; /* Number of bytes actually read. */
int errcode; /* Error from last read. */
@@ -1744,9 +1744,9 @@ partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
nread--;
}
}
- if (errnoptr != NULL)
+ if (errptr != NULL)
{
- *errnoptr = errcode;
+ *errptr = errcode;
}
return (nread);
}
@@ -1755,7 +1755,7 @@ partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
each. Fetch at most FETCHLIMIT characters. BUFFER will be set to a newly
allocated buffer containing the string, which the caller is responsible to
free, and BYTES_READ will be set to the number of bytes read. Returns 0 on
- success, or errno on failure.
+ success, or a target_xfer_error on failure.
If LEN > 0, reads exactly LEN characters (including eventual NULs in
the middle or end of the string). If LEN is -1, stops at the first
@@ -2524,18 +2524,14 @@ val_print_string (struct type *elttype, const char *encoding,
if (errcode != 0)
{
- if (errcode == EIO)
- {
- fprintf_filtered (stream, "<Address ");
- fputs_filtered (paddress (gdbarch, addr), stream);
- fprintf_filtered (stream, " out of bounds>");
- }
- else
- {
- fprintf_filtered (stream, "<Error reading address ");
- fputs_filtered (paddress (gdbarch, addr), stream);
- fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
- }
+ char *str;
+
+ str = memory_error_message (errcode, gdbarch, addr);
+ make_cleanup (xfree, str);
+
+ fprintf_filtered (stream, "<error: ");
+ fputs_filtered (str, stream);
+ fprintf_filtered (stream, ">");
}
gdb_flush (stream);