aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-10-12 16:48:35 -0600
committerTom Tromey <tom@tromey.com>2017-10-16 16:10:21 -0600
commitb7b030adc405017f01e996a90f85e40730ef8397 (patch)
tree5d6fdf82c43f719834633295cbcde80f75d5663d /gdb/remote.c
parentb80406accc70791a1789e40f24d64161bc41de34 (diff)
downloadgdb-b7b030adc405017f01e996a90f85e40730ef8397.zip
gdb-b7b030adc405017f01e996a90f85e40730ef8397.tar.gz
gdb-b7b030adc405017f01e996a90f85e40730ef8397.tar.bz2
Return unique_xmalloc_ptr from target_read_stralloc
This changes target_read_stralloc to return a unique_xmalloc_ptr, and then fixes all the callers. unique_xmalloc_ptr is used, rather than std::string, because target_read_stralloc gives a special meaning to a NULL return. ChangeLog 2017-10-16 Tom Tromey <tom@tromey.com> * xml-syscall.c (xml_init_syscalls_info): Update. * xml-support.c (xinclude_start_include): Update. (xml_fetch_content_from_file): Return unique_xmalloc_ptr. * xml-support.h (xml_fetch_another): Return unique_xmalloc_ptr. (xml_fetch_content_from_file): Likewise. * osdata.c (get_osdata): Update. * target.h (target_read_stralloc, target_get_osdata): Return unique_xmalloc_ptr. * solib-aix.c (solib_aix_get_library_list): Update. * solib-target.c (solib_target_current_sos): Update. * solib-svr4.c (svr4_current_sos_via_xfer_libraries): Update. * xml-tdesc.c (fetch_available_features_from_target): Update. (target_fetch_description_xml): Update. (file_read_description_xml): Update. * remote.c (remote_get_threads_with_qxfer, remote_memory_map) (remote_traceframe_info, btrace_read_config, remote_read_btrace) (remote_pid_to_exec_file): Update. * target.c (target_read_stralloc): Return unique_xmalloc_ptr. (target_get_osdata): Likewise.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c64
1 files changed, 18 insertions, 46 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 070f82e..9ee4645 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -3203,16 +3203,15 @@ remote_get_threads_with_qxfer (struct target_ops *ops,
#if defined(HAVE_LIBEXPAT)
if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
{
- char *xml = target_read_stralloc (ops, TARGET_OBJECT_THREADS, NULL);
- struct cleanup *back_to = make_cleanup (xfree, xml);
+ gdb::unique_xmalloc_ptr<char> xml
+ = target_read_stralloc (ops, TARGET_OBJECT_THREADS, NULL);
if (xml != NULL && *xml != '\0')
{
gdb_xml_parse_quick (_("threads"), "threads.dtd",
- threads_elements, xml, context);
+ threads_elements, xml.get (), context);
}
- do_cleanups (back_to);
return 1;
}
#endif
@@ -10893,16 +10892,11 @@ static VEC(mem_region_s) *
remote_memory_map (struct target_ops *ops)
{
VEC(mem_region_s) *result = NULL;
- char *text = target_read_stralloc (&current_target,
- TARGET_OBJECT_MEMORY_MAP, NULL);
+ gdb::unique_xmalloc_ptr<char> text
+ = target_read_stralloc (&current_target, TARGET_OBJECT_MEMORY_MAP, NULL);
if (text)
- {
- struct cleanup *back_to = make_cleanup (xfree, text);
-
- result = parse_memory_map (text);
- do_cleanups (back_to);
- }
+ result = parse_memory_map (text.get ());
return result;
}
@@ -13040,18 +13034,11 @@ remote_set_circular_trace_buffer (struct target_ops *self, int val)
static traceframe_info_up
remote_traceframe_info (struct target_ops *self)
{
- char *text;
-
- text = target_read_stralloc (&current_target,
- TARGET_OBJECT_TRACEFRAME_INFO, NULL);
+ gdb::unique_xmalloc_ptr<char> text
+ = target_read_stralloc (&current_target, TARGET_OBJECT_TRACEFRAME_INFO,
+ NULL);
if (text != NULL)
- {
- struct cleanup *back_to = make_cleanup (xfree, text);
- traceframe_info_up info = parse_traceframe_info (text);
-
- do_cleanups (back_to);
- return info;
- }
+ return parse_traceframe_info (text.get ());
return NULL;
}
@@ -13310,18 +13297,10 @@ btrace_sync_conf (const struct btrace_config *conf)
static void
btrace_read_config (struct btrace_config *conf)
{
- char *xml;
-
- xml = target_read_stralloc (&current_target,
- TARGET_OBJECT_BTRACE_CONF, "");
+ gdb::unique_xmalloc_ptr<char> xml
+ = target_read_stralloc (&current_target, TARGET_OBJECT_BTRACE_CONF, "");
if (xml != NULL)
- {
- struct cleanup *cleanup;
-
- cleanup = make_cleanup (xfree, xml);
- parse_xml_btrace_conf (conf, xml);
- do_cleanups (cleanup);
- }
+ parse_xml_btrace_conf (conf, xml.get ());
}
/* Maybe reopen target btrace. */
@@ -13492,9 +13471,7 @@ remote_read_btrace (struct target_ops *self,
enum btrace_read_type type)
{
struct packet_config *packet = &remote_protocol_packets[PACKET_qXfer_btrace];
- struct cleanup *cleanup;
const char *annex;
- char *xml;
if (packet_config_support (packet) != PACKET_ENABLE)
error (_("Target does not support branch tracing."));
@@ -13520,14 +13497,12 @@ remote_read_btrace (struct target_ops *self,
(unsigned int) type);
}
- xml = target_read_stralloc (&current_target,
- TARGET_OBJECT_BTRACE, annex);
+ gdb::unique_xmalloc_ptr<char> xml
+ = target_read_stralloc (&current_target, TARGET_OBJECT_BTRACE, annex);
if (xml == NULL)
return BTRACE_ERR_UNKNOWN;
- cleanup = make_cleanup (xfree, xml);
- parse_xml_btrace (btrace, xml);
- do_cleanups (cleanup);
+ parse_xml_btrace (btrace, xml.get ());
return BTRACE_ERR_NONE;
}
@@ -13561,16 +13536,13 @@ remote_load (struct target_ops *self, const char *name, int from_tty)
static char *
remote_pid_to_exec_file (struct target_ops *self, int pid)
{
- static char *filename = NULL;
+ static gdb::unique_xmalloc_ptr<char> filename;
struct inferior *inf;
char *annex = NULL;
if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE)
return NULL;
- if (filename != NULL)
- xfree (filename);
-
inf = find_inferior_pid (pid);
if (inf == NULL)
internal_error (__FILE__, __LINE__,
@@ -13587,7 +13559,7 @@ remote_pid_to_exec_file (struct target_ops *self, int pid)
filename = target_read_stralloc (&current_target,
TARGET_OBJECT_EXEC_FILE, annex);
- return filename;
+ return filename.get ();
}
/* Implement the to_can_do_single_step target_ops method. */