Return std::string from memory_error_message

This changes memory_error_message to return a std::string and fixes up
the callers.  This removes some cleanups.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

	* valprint.c (val_print_string): Update.
	* gdbcore.h (memory_error_message): Return std::string.
	* corefile.c (memory_error_message): Return std::string.
	(memory_error): Update.
	* breakpoint.c (insert_bp_location): Update.
This commit is contained in:
Tom Tromey 2017-08-05 16:23:18 -06:00
parent 0e30d99180
commit 1ccbe9985f
5 changed files with 23 additions and 22 deletions

View file

@ -186,7 +186,7 @@ Use the \"file\" or \"exec-file\" command."));
}
char *
std::string
memory_error_message (enum target_xfer_status err,
struct gdbarch *gdbarch, CORE_ADDR memaddr)
{
@ -195,11 +195,11 @@ memory_error_message (enum target_xfer_status err,
case TARGET_XFER_E_IO:
/* Actually, address between memaddr and memaddr + len was out of
bounds. */
return xstrprintf (_("Cannot access memory at address %s"),
paddress (gdbarch, memaddr));
return string_printf (_("Cannot access memory at address %s"),
paddress (gdbarch, memaddr));
case TARGET_XFER_UNAVAILABLE:
return xstrprintf (_("Memory at address %s unavailable."),
paddress (gdbarch, memaddr));
return string_printf (_("Memory at address %s unavailable."),
paddress (gdbarch, memaddr));
default:
internal_error (__FILE__, __LINE__,
"unhandled target_xfer_status: %s (%s)",
@ -213,12 +213,10 @@ memory_error_message (enum target_xfer_status err,
void
memory_error (enum target_xfer_status err, CORE_ADDR memaddr)
{
char *str;
enum errors exception = GDB_NO_ERROR;
/* Build error string. */
str = memory_error_message (err, target_gdbarch (), memaddr);
make_cleanup (xfree, str);
std::string str = memory_error_message (err, target_gdbarch (), memaddr);
/* Choose the right error to throw. */
switch (err)
@ -232,7 +230,7 @@ memory_error (enum target_xfer_status err, CORE_ADDR memaddr)
}
/* Throw it. */
throw_error (exception, ("%s"), str);
throw_error (exception, ("%s"), str.c_str ());
}
/* Helper function. */