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.
This commit is contained in:
Tom Tromey 2017-10-12 16:48:35 -06:00
parent b80406accc
commit b7b030adc4
12 changed files with 102 additions and 168 deletions

View file

@ -1,3 +1,25 @@
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.
2017-10-16 Tom Tromey <tom@tromey.com> 2017-10-16 Tom Tromey <tom@tromey.com>
* remote.c (remote_register_number_and_offset): Use std::vector. * remote.c (remote_register_number_and_offset): Use std::vector.

View file

@ -245,13 +245,11 @@ struct osdata *
get_osdata (const char *type) get_osdata (const char *type)
{ {
struct osdata *osdata = NULL; struct osdata *osdata = NULL;
char *xml = target_get_osdata (type); gdb::unique_xmalloc_ptr<char> xml = target_get_osdata (type);
if (xml) if (xml)
{ {
struct cleanup *old_chain = make_cleanup (xfree, xml); if (xml.get ()[0] == '\0')
if (xml[0] == '\0')
{ {
if (type) if (type)
warning (_("Empty data returned by target. Wrong osdata type?")); warning (_("Empty data returned by target. Wrong osdata type?"));
@ -259,9 +257,7 @@ get_osdata (const char *type)
warning (_("Empty type list returned by target. No type data?")); warning (_("Empty type list returned by target. No type data?"));
} }
else else
osdata = osdata_parse (xml); osdata = osdata_parse (xml.get ());
do_cleanups (old_chain);
} }
if (!osdata) if (!osdata)

View file

@ -3203,16 +3203,15 @@ remote_get_threads_with_qxfer (struct target_ops *ops,
#if defined(HAVE_LIBEXPAT) #if defined(HAVE_LIBEXPAT)
if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE) if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
{ {
char *xml = target_read_stralloc (ops, TARGET_OBJECT_THREADS, NULL); gdb::unique_xmalloc_ptr<char> xml
struct cleanup *back_to = make_cleanup (xfree, xml); = target_read_stralloc (ops, TARGET_OBJECT_THREADS, NULL);
if (xml != NULL && *xml != '\0') if (xml != NULL && *xml != '\0')
{ {
gdb_xml_parse_quick (_("threads"), "threads.dtd", gdb_xml_parse_quick (_("threads"), "threads.dtd",
threads_elements, xml, context); threads_elements, xml.get (), context);
} }
do_cleanups (back_to);
return 1; return 1;
} }
#endif #endif
@ -10893,16 +10892,11 @@ static VEC(mem_region_s) *
remote_memory_map (struct target_ops *ops) remote_memory_map (struct target_ops *ops)
{ {
VEC(mem_region_s) *result = NULL; VEC(mem_region_s) *result = NULL;
char *text = target_read_stralloc (&current_target, gdb::unique_xmalloc_ptr<char> text
TARGET_OBJECT_MEMORY_MAP, NULL); = target_read_stralloc (&current_target, TARGET_OBJECT_MEMORY_MAP, NULL);
if (text) if (text)
{ result = parse_memory_map (text.get ());
struct cleanup *back_to = make_cleanup (xfree, text);
result = parse_memory_map (text);
do_cleanups (back_to);
}
return result; return result;
} }
@ -13040,18 +13034,11 @@ remote_set_circular_trace_buffer (struct target_ops *self, int val)
static traceframe_info_up static traceframe_info_up
remote_traceframe_info (struct target_ops *self) remote_traceframe_info (struct target_ops *self)
{ {
char *text; gdb::unique_xmalloc_ptr<char> text
= target_read_stralloc (&current_target, TARGET_OBJECT_TRACEFRAME_INFO,
text = target_read_stralloc (&current_target, NULL);
TARGET_OBJECT_TRACEFRAME_INFO, NULL);
if (text != NULL) if (text != NULL)
{ return parse_traceframe_info (text.get ());
struct cleanup *back_to = make_cleanup (xfree, text);
traceframe_info_up info = parse_traceframe_info (text);
do_cleanups (back_to);
return info;
}
return NULL; return NULL;
} }
@ -13310,18 +13297,10 @@ btrace_sync_conf (const struct btrace_config *conf)
static void static void
btrace_read_config (struct btrace_config *conf) btrace_read_config (struct btrace_config *conf)
{ {
char *xml; gdb::unique_xmalloc_ptr<char> xml
= target_read_stralloc (&current_target, TARGET_OBJECT_BTRACE_CONF, "");
xml = target_read_stralloc (&current_target,
TARGET_OBJECT_BTRACE_CONF, "");
if (xml != NULL) if (xml != NULL)
{ parse_xml_btrace_conf (conf, xml.get ());
struct cleanup *cleanup;
cleanup = make_cleanup (xfree, xml);
parse_xml_btrace_conf (conf, xml);
do_cleanups (cleanup);
}
} }
/* Maybe reopen target btrace. */ /* Maybe reopen target btrace. */
@ -13492,9 +13471,7 @@ remote_read_btrace (struct target_ops *self,
enum btrace_read_type type) enum btrace_read_type type)
{ {
struct packet_config *packet = &remote_protocol_packets[PACKET_qXfer_btrace]; struct packet_config *packet = &remote_protocol_packets[PACKET_qXfer_btrace];
struct cleanup *cleanup;
const char *annex; const char *annex;
char *xml;
if (packet_config_support (packet) != PACKET_ENABLE) if (packet_config_support (packet) != PACKET_ENABLE)
error (_("Target does not support branch tracing.")); error (_("Target does not support branch tracing."));
@ -13520,14 +13497,12 @@ remote_read_btrace (struct target_ops *self,
(unsigned int) type); (unsigned int) type);
} }
xml = target_read_stralloc (&current_target, gdb::unique_xmalloc_ptr<char> xml
TARGET_OBJECT_BTRACE, annex); = target_read_stralloc (&current_target, TARGET_OBJECT_BTRACE, annex);
if (xml == NULL) if (xml == NULL)
return BTRACE_ERR_UNKNOWN; return BTRACE_ERR_UNKNOWN;
cleanup = make_cleanup (xfree, xml); parse_xml_btrace (btrace, xml.get ());
parse_xml_btrace (btrace, xml);
do_cleanups (cleanup);
return BTRACE_ERR_NONE; return BTRACE_ERR_NONE;
} }
@ -13561,16 +13536,13 @@ remote_load (struct target_ops *self, const char *name, int from_tty)
static char * static char *
remote_pid_to_exec_file (struct target_ops *self, int pid) 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; struct inferior *inf;
char *annex = NULL; char *annex = NULL;
if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE) if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE)
return NULL; return NULL;
if (filename != NULL)
xfree (filename);
inf = find_inferior_pid (pid); inf = find_inferior_pid (pid);
if (inf == NULL) if (inf == NULL)
internal_error (__FILE__, __LINE__, 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, filename = target_read_stralloc (&current_target,
TARGET_OBJECT_EXEC_FILE, annex); TARGET_OBJECT_EXEC_FILE, annex);
return filename; return filename.get ();
} }
/* Implement the to_can_do_single_step target_ops method. */ /* Implement the to_can_do_single_step target_ops method. */

View file

@ -271,39 +271,34 @@ static VEC (lm_info_aix_p) *
solib_aix_get_library_list (struct inferior *inf, const char *warning_msg) solib_aix_get_library_list (struct inferior *inf, const char *warning_msg)
{ {
struct solib_aix_inferior_data *data; struct solib_aix_inferior_data *data;
char *library_document;
struct cleanup *cleanup;
/* If already computed, return the cached value. */ /* If already computed, return the cached value. */
data = get_solib_aix_inferior_data (inf); data = get_solib_aix_inferior_data (inf);
if (data->library_list != NULL) if (data->library_list != NULL)
return data->library_list; return data->library_list;
library_document = target_read_stralloc (&current_target, gdb::unique_xmalloc_ptr<char> library_document
TARGET_OBJECT_LIBRARIES_AIX, = target_read_stralloc (&current_target, TARGET_OBJECT_LIBRARIES_AIX,
NULL); NULL);
if (library_document == NULL && warning_msg != NULL) if (library_document == NULL && warning_msg != NULL)
{ {
warning (_("%s (failed to read TARGET_OBJECT_LIBRARIES_AIX)"), warning (_("%s (failed to read TARGET_OBJECT_LIBRARIES_AIX)"),
warning_msg); warning_msg);
return NULL; return NULL;
} }
cleanup = make_cleanup (xfree, library_document);
if (solib_aix_debug) if (solib_aix_debug)
fprintf_unfiltered (gdb_stdlog, fprintf_unfiltered (gdb_stdlog,
"DEBUG: TARGET_OBJECT_LIBRARIES_AIX = \n%s\n", "DEBUG: TARGET_OBJECT_LIBRARIES_AIX = \n%s\n",
library_document); library_document.get ());
data->library_list = solib_aix_parse_libraries (library_document); data->library_list = solib_aix_parse_libraries (library_document.get ());
if (data->library_list == NULL && warning_msg != NULL) if (data->library_list == NULL && warning_msg != NULL)
{ {
warning (_("%s (missing XML support?)"), warning_msg); warning (_("%s (missing XML support?)"), warning_msg);
do_cleanups (cleanup);
return NULL; return NULL;
} }
do_cleanups (cleanup);
return data->library_list; return data->library_list;
} }

View file

@ -1269,24 +1269,16 @@ static int
svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list, svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list,
const char *annex) const char *annex)
{ {
char *svr4_library_document;
int result;
struct cleanup *back_to;
gdb_assert (annex == NULL || target_augmented_libraries_svr4_read ()); gdb_assert (annex == NULL || target_augmented_libraries_svr4_read ());
/* Fetch the list of shared libraries. */ /* Fetch the list of shared libraries. */
svr4_library_document = target_read_stralloc (&current_target, gdb::unique_xmalloc_ptr<char> svr4_library_document
TARGET_OBJECT_LIBRARIES_SVR4, = target_read_stralloc (&current_target, TARGET_OBJECT_LIBRARIES_SVR4,
annex); annex);
if (svr4_library_document == NULL) if (svr4_library_document == NULL)
return 0; return 0;
back_to = make_cleanup (xfree, svr4_library_document); return svr4_parse_libraries (svr4_library_document.get (), list);
result = svr4_parse_libraries (svr4_library_document, list);
do_cleanups (back_to);
return result;
} }
#else #else

View file

@ -248,27 +248,18 @@ static struct so_list *
solib_target_current_sos (void) solib_target_current_sos (void)
{ {
struct so_list *new_solib, *start = NULL, *last = NULL; struct so_list *new_solib, *start = NULL, *last = NULL;
char *library_document;
struct cleanup *old_chain;
VEC(lm_info_target_p) *library_list; VEC(lm_info_target_p) *library_list;
lm_info_target *info; lm_info_target *info;
int ix; int ix;
/* Fetch the list of shared libraries. */ /* Fetch the list of shared libraries. */
library_document = target_read_stralloc (&current_target, gdb::unique_xmalloc_ptr<char> library_document
TARGET_OBJECT_LIBRARIES, = target_read_stralloc (&current_target, TARGET_OBJECT_LIBRARIES, NULL);
NULL);
if (library_document == NULL) if (library_document == NULL)
return NULL; return NULL;
/* solib_target_parse_libraries may throw, so we use a cleanup. */
old_chain = make_cleanup (xfree, library_document);
/* Parse the list. */ /* Parse the list. */
library_list = solib_target_parse_libraries (library_document); library_list = solib_target_parse_libraries (library_document.get ());
/* library_document string is not needed behind this point. */
do_cleanups (old_chain);
if (library_list == NULL) if (library_list == NULL)
return NULL; return NULL;

View file

@ -1924,13 +1924,9 @@ target_read_alloc (struct target_ops *ops, enum target_object object,
return target_read_alloc_1 (ops, object, annex, buf_p, 0); return target_read_alloc_1 (ops, object, annex, buf_p, 0);
} }
/* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and /* See target.h. */
returned as a string, allocated using xmalloc. If an error occurs
or the transfer is unsupported, NULL is returned. Empty objects
are returned as allocated but empty strings. A warning is issued
if the result contains any embedded NUL bytes. */
char * gdb::unique_xmalloc_ptr<char>
target_read_stralloc (struct target_ops *ops, enum target_object object, target_read_stralloc (struct target_ops *ops, enum target_object object,
const char *annex) const char *annex)
{ {
@ -1945,7 +1941,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object,
return NULL; return NULL;
if (transferred == 0) if (transferred == 0)
return xstrdup (""); return gdb::unique_xmalloc_ptr<char> (xstrdup (""));
bufstr[transferred] = 0; bufstr[transferred] = 0;
@ -1959,7 +1955,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object,
break; break;
} }
return bufstr; return gdb::unique_xmalloc_ptr<char> (bufstr);
} }
/* Memory transfer methods. */ /* Memory transfer methods. */
@ -2654,7 +2650,9 @@ target_supports_multi_process (void)
return (*current_target.to_supports_multi_process) (&current_target); return (*current_target.to_supports_multi_process) (&current_target);
} }
char * /* See target.h. */
gdb::unique_xmalloc_ptr<char>
target_get_osdata (const char *type) target_get_osdata (const char *type)
{ {
struct target_ops *t; struct target_ops *t;

View file

@ -353,14 +353,13 @@ extern LONGEST target_read_alloc (struct target_ops *ops,
const char *annex, gdb_byte **buf_p); const char *annex, gdb_byte **buf_p);
/* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
returned as a string, allocated using xmalloc. If an error occurs returned as a string. If an error occurs or the transfer is
or the transfer is unsupported, NULL is returned. Empty objects unsupported, NULL is returned. Empty objects are returned as
are returned as allocated but empty strings. A warning is issued allocated but empty strings. A warning is issued if the result
if the result contains any embedded NUL bytes. */ contains any embedded NUL bytes. */
extern char *target_read_stralloc (struct target_ops *ops, extern gdb::unique_xmalloc_ptr<char> target_read_stralloc
enum target_object object, (struct target_ops *ops, enum target_object object, const char *annex);
const char *annex);
/* See target_ops->to_xfer_partial. */ /* See target_ops->to_xfer_partial. */
extern target_xfer_partial_ftype target_xfer_partial; extern target_xfer_partial_ftype target_xfer_partial;
@ -2396,12 +2395,12 @@ extern struct target_ops *find_target_beneath (struct target_ops *);
struct target_ops *find_target_at (enum strata stratum); struct target_ops *find_target_at (enum strata stratum);
/* Read OS data object of type TYPE from the target, and return it in /* Read OS data object of type TYPE from the target, and return it in
XML format. The result is NUL-terminated and returned as a string, XML format. The result is NUL-terminated and returned as a string.
allocated using xmalloc. If an error occurs or the transfer is If an error occurs or the transfer is unsupported, NULL is
unsupported, NULL is returned. Empty objects are returned as returned. Empty objects are returned as allocated but empty
allocated but empty strings. */ strings. */
extern char *target_get_osdata (const char *type); extern gdb::unique_xmalloc_ptr<char> target_get_osdata (const char *type);
/* Stuff that should be shared among the various remote targets. */ /* Stuff that should be shared among the various remote targets. */

View file

@ -808,8 +808,6 @@ xinclude_start_include (struct gdb_xml_parser *parser,
struct xinclude_parsing_data *data struct xinclude_parsing_data *data
= (struct xinclude_parsing_data *) user_data; = (struct xinclude_parsing_data *) user_data;
char *href = (char *) xml_find_attribute (attributes, "href")->value; char *href = (char *) xml_find_attribute (attributes, "href")->value;
struct cleanup *back_to;
char *text, *output;
gdb_xml_debug (parser, _("Processing XInclude of \"%s\""), href); gdb_xml_debug (parser, _("Processing XInclude of \"%s\""), href);
@ -817,19 +815,17 @@ xinclude_start_include (struct gdb_xml_parser *parser,
gdb_xml_error (parser, _("Maximum XInclude depth (%d) exceeded"), gdb_xml_error (parser, _("Maximum XInclude depth (%d) exceeded"),
MAX_XINCLUDE_DEPTH); MAX_XINCLUDE_DEPTH);
text = data->fetcher (href, data->fetcher_baton); gdb::unique_xmalloc_ptr<char> text = data->fetcher (href,
data->fetcher_baton);
if (text == NULL) if (text == NULL)
gdb_xml_error (parser, _("Could not load XML document \"%s\""), href); gdb_xml_error (parser, _("Could not load XML document \"%s\""), href);
back_to = make_cleanup (xfree, text);
if (!xml_process_xincludes (data->output, parser->name (), if (!xml_process_xincludes (data->output, parser->name (),
text, data->fetcher, text.get (), data->fetcher,
data->fetcher_baton, data->fetcher_baton,
data->include_depth + 1)) data->include_depth + 1))
gdb_xml_error (parser, _("Parsing \"%s\" failed"), href); gdb_xml_error (parser, _("Parsing \"%s\" failed"), href);
do_cleanups (back_to);
data->skip_depth++; data->skip_depth++;
} }
@ -997,13 +993,11 @@ show_debug_xml (struct ui_file *file, int from_tty,
fprintf_filtered (file, _("XML debugging is %s.\n"), value); fprintf_filtered (file, _("XML debugging is %s.\n"), value);
} }
char * gdb::unique_xmalloc_ptr<char>
xml_fetch_content_from_file (const char *filename, void *baton) xml_fetch_content_from_file (const char *filename, void *baton)
{ {
const char *dirname = (const char *) baton; const char *dirname = (const char *) baton;
gdb_file_up file; gdb_file_up file;
struct cleanup *back_to;
char *text;
size_t len, offset; size_t len, offset;
if (dirname && *dirname) if (dirname && *dirname)
@ -1024,19 +1018,18 @@ xml_fetch_content_from_file (const char *filename, void *baton)
/* Read in the whole file, one chunk at a time. */ /* Read in the whole file, one chunk at a time. */
len = 4096; len = 4096;
offset = 0; offset = 0;
text = (char *) xmalloc (len); gdb::unique_xmalloc_ptr<char> text ((char *) xmalloc (len));
back_to = make_cleanup (free_current_contents, &text);
while (1) while (1)
{ {
size_t bytes_read; size_t bytes_read;
/* Continue reading where the last read left off. Leave at least /* Continue reading where the last read left off. Leave at least
one byte so that we can NUL-terminate the result. */ one byte so that we can NUL-terminate the result. */
bytes_read = fread (text + offset, 1, len - offset - 1, file.get ()); bytes_read = fread (text.get () + offset, 1, len - offset - 1,
file.get ());
if (ferror (file.get ())) if (ferror (file.get ()))
{ {
warning (_("Read error from \"%s\""), filename); warning (_("Read error from \"%s\""), filename);
do_cleanups (back_to);
return NULL; return NULL;
} }
@ -1046,12 +1039,10 @@ xml_fetch_content_from_file (const char *filename, void *baton)
break; break;
len = len * 2; len = len * 2;
text = (char *) xrealloc (text, len); text.reset ((char *) xrealloc (text.get (), len));
} }
discard_cleanups (back_to); text.get ()[offset] = '\0';
text[offset] = '\0';
return text; return text;
} }

View file

@ -52,7 +52,8 @@ extern const char *xml_builtin[][2];
/* Callback to fetch a new XML file, based on the provided HREF. */ /* Callback to fetch a new XML file, based on the provided HREF. */
typedef char *(*xml_fetch_another) (const char *href, void *baton); typedef gdb::unique_xmalloc_ptr<char> (*xml_fetch_another) (const char *href,
void *baton);
/* Append the expansion of TEXT after processing <xi:include> tags in /* Append the expansion of TEXT after processing <xi:include> tags in
RESULT. FETCHER will be called (with FETCHER_BATON) to retrieve RESULT. FETCHER will be called (with FETCHER_BATON) to retrieve
@ -230,7 +231,7 @@ ULONGEST gdb_xml_parse_ulongest (struct gdb_xml_parser *parser,
/* Open FILENAME, read all its text into memory, close it, and return /* Open FILENAME, read all its text into memory, close it, and return
the text. If something goes wrong, return NULL and warn. */ the text. If something goes wrong, return NULL and warn. */
extern char *xml_fetch_content_from_file (const char *filename, extern gdb::unique_xmalloc_ptr<char> xml_fetch_content_from_file
void *baton); (const char *filename, void *baton);
#endif #endif

View file

@ -362,22 +362,14 @@ syscall_parse_xml (const char *document, xml_fetch_another fetcher,
static struct syscalls_info * static struct syscalls_info *
xml_init_syscalls_info (const char *filename) xml_init_syscalls_info (const char *filename)
{ {
char *full_file; gdb::unique_xmalloc_ptr<char> full_file
struct syscalls_info *syscalls_info; = xml_fetch_content_from_file (filename, gdb_datadir);
struct cleanup *back_to;
full_file = xml_fetch_content_from_file (filename, gdb_datadir);
if (full_file == NULL) if (full_file == NULL)
return NULL; return NULL;
back_to = make_cleanup (xfree, full_file); return syscall_parse_xml (full_file.get (),
xml_fetch_content_from_file,
syscalls_info = syscall_parse_xml (full_file, (void *) ldirname (filename).c_str ());
xml_fetch_content_from_file,
(void *) ldirname (filename).c_str ());
do_cleanups (back_to);
return syscalls_info;
} }
/* Initializes the syscalls_info structure according to the /* Initializes the syscalls_info structure according to the

View file

@ -673,24 +673,16 @@ tdesc_parse_xml (const char *document, xml_fetch_another fetcher,
const struct target_desc * const struct target_desc *
file_read_description_xml (const char *filename) file_read_description_xml (const char *filename)
{ {
struct target_desc *tdesc; gdb::unique_xmalloc_ptr<char> tdesc_str
char *tdesc_str; = xml_fetch_content_from_file (filename, NULL);
struct cleanup *back_to;
tdesc_str = xml_fetch_content_from_file (filename, NULL);
if (tdesc_str == NULL) if (tdesc_str == NULL)
{ {
warning (_("Could not open \"%s\""), filename); warning (_("Could not open \"%s\""), filename);
return NULL; return NULL;
} }
back_to = make_cleanup (xfree, tdesc_str); return tdesc_parse_xml (tdesc_str.get (), xml_fetch_content_from_file,
(void *) ldirname (filename).c_str ());
tdesc = tdesc_parse_xml (tdesc_str, xml_fetch_content_from_file,
(void *) ldirname (filename).c_str ());
do_cleanups (back_to);
return tdesc;
} }
/* Read a string representation of available features from the target, /* Read a string representation of available features from the target,
@ -700,7 +692,7 @@ file_read_description_xml (const char *filename)
is "target.xml". Other calls may be performed for the DTD or is "target.xml". Other calls may be performed for the DTD or
for <xi:include>. */ for <xi:include>. */
static char * static gdb::unique_xmalloc_ptr<char>
fetch_available_features_from_target (const char *name, void *baton_) fetch_available_features_from_target (const char *name, void *baton_)
{ {
struct target_ops *ops = (struct target_ops *) baton_; struct target_ops *ops = (struct target_ops *) baton_;
@ -719,21 +711,14 @@ fetch_available_features_from_target (const char *name, void *baton_)
const struct target_desc * const struct target_desc *
target_read_description_xml (struct target_ops *ops) target_read_description_xml (struct target_ops *ops)
{ {
struct target_desc *tdesc; gdb::unique_xmalloc_ptr<char> tdesc_str
char *tdesc_str; = fetch_available_features_from_target ("target.xml", ops);
struct cleanup *back_to;
tdesc_str = fetch_available_features_from_target ("target.xml", ops);
if (tdesc_str == NULL) if (tdesc_str == NULL)
return NULL; return NULL;
back_to = make_cleanup (xfree, tdesc_str); return tdesc_parse_xml (tdesc_str.get (),
tdesc = tdesc_parse_xml (tdesc_str, fetch_available_features_from_target,
fetch_available_features_from_target, ops);
ops);
do_cleanups (back_to);
return tdesc;
} }
/* Fetches an XML target description using OPS, processing /* Fetches an XML target description using OPS, processing
@ -758,7 +743,7 @@ target_fetch_description_xml (struct target_ops *ops)
struct target_desc *tdesc; struct target_desc *tdesc;
gdb::unique_xmalloc_ptr<char> gdb::unique_xmalloc_ptr<char>
tdesc_str (fetch_available_features_from_target ("target.xml", ops)); tdesc_str = fetch_available_features_from_target ("target.xml", ops);
if (tdesc_str == NULL) if (tdesc_str == NULL)
return {}; return {};