diff options
author | Pedro Alves <palves@redhat.com> | 2017-04-18 21:39:25 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-04-18 23:50:55 +0100 |
commit | bd8a901f9e34191e0645a5527556d124ba5c345a (patch) | |
tree | ca2c04a1e7ed2387b979584beff7682e8a21c2e1 /gdb/tracefile-tfile.c | |
parent | d35d19584cf56a50b4833ff9c003597e01022f27 (diff) | |
download | gdb-bd8a901f9e34191e0645a5527556d124ba5c345a.zip gdb-bd8a901f9e34191e0645a5527556d124ba5c345a.tar.gz gdb-bd8a901f9e34191e0645a5527556d124ba5c345a.tar.bz2 |
xml-support.c: Use std::string for growing string buffer
This main idea behind this patch is this change to xml-support.c:scope_level
- /* Body text accumulation. This is an owning pointer. */
- struct obstack *body;
+ /* Body text accumulation. */
+ std::string body;
... which allows simplifying other parts of the code.
In target_fetch_description_xml, we want to distinguish between
returning "success + empty std::string" and "no success", and
gdb::optional is a natural fit for that.
gdb/ChangeLog:
2017-04-18 Pedro Alves <palves@redhat.com>
* tracefile-tfile.c (tfile_write_tdesc): Adjust to use
gdb::optional<std::string>.
* xml-support.c: Include <string>.
(scope_level::scope_level(scope_level &&))
(scope_level::~scope_level): Delete.
(scope_level::body): Now a std::string.
(gdb_xml_body_text, gdb_xml_end_element): Adjust.
(xinclude_parsing_data::xinclude_parsing_data): Add 'output'
parameter.
(xinclude_parsing_data::~xinclude_parsing_data): Delete.
(xinclude_parsing_data::output): Now a std::string reference.
(xinclude_start_include): Adjust.
(xml_xinclude_default): Adjust.
(xml_process_xincludes): Add 'output' parameter, and return bool.
* xml-support.h (xml_process_xincludes): Add 'output' parameter,
and return bool.
* xml-tdesc.c: Include <unordered_map> and <string>.
(tdesc_xml_cache): Delete.
(tdesc_xml_cache_s): Delete.
(xml_cache): Now an std::unordered_map.
(tdesc_parse_xml): Adjust to use std::string and unordered_map.
(target_fetch_description_xml): Change return type to
gdb::optional<std::string>, and adjust.
* xml-tdesc.h: Include "common/gdb_optional.h" and <string>.
(target_fetch_description_xml): Change return type to
gdb::optional<std::string>.
Diffstat (limited to 'gdb/tracefile-tfile.c')
-rw-r--r-- | gdb/tracefile-tfile.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 5d63c16..255bbc9 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -275,17 +275,19 @@ tfile_write_tdesc (struct trace_file_writer *self) { struct tfile_trace_file_writer *writer = (struct tfile_trace_file_writer *) self; - char *tdesc = target_fetch_description_xml (¤t_target); - char *ptr = tdesc; - char *next; - if (tdesc == NULL) + gdb::optional<std::string> tdesc + = target_fetch_description_xml (¤t_target); + + if (!tdesc) return; + const char *ptr = tdesc->c_str (); + /* Write tdesc line by line, prefixing each line with "tdesc ". */ while (ptr != NULL) { - next = strchr (ptr, '\n'); + const char *next = strchr (ptr, '\n'); if (next != NULL) { fprintf (writer->fp, "tdesc %.*s\n", (int) (next - ptr), ptr); @@ -299,8 +301,6 @@ tfile_write_tdesc (struct trace_file_writer *self) } ptr = next; } - - xfree (tdesc); } /* This is the implementation of trace_file_write_ops method |