aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-09-16 14:19:31 +0200
committerSimon Marchi <simon.marchi@ericsson.com>2017-09-16 14:19:31 +0200
commit5e1875543df7413d3cbc3831390445e347064b75 (patch)
tree215e09584279387448ae183671588f0bac07a1f6
parentc3d7b541fa920e6ecb0f06ffe1e0e3f070fa295d (diff)
downloadgdb-5e1875543df7413d3cbc3831390445e347064b75.zip
gdb-5e1875543df7413d3cbc3831390445e347064b75.tar.gz
gdb-5e1875543df7413d3cbc3831390445e347064b75.tar.bz2
Make xml_escape_text return an std::string
This is a simple replacement, it allows removing some manual free'ing in the callers. gdb/ChangeLog: * common/buffer.c (buffer_xml_printf): Adjust. * common/xml-utils.c (xml_escape_text): Change return type to std::string, update code accordingly. * common/xml-utils.h (xml_escape_text): Change return type to std::string. * rs6000-aix-tdep.c (rs6000_aix_shared_library_to_xml): Adjust. * windows-tdep.c (windows_xfer_shared_library): Adjust. * unittests/xml-utils-selftests.c (test_xml_escape_text): Adjust. gdb/gdbserver/ChangeLog: * linux-low.c (linux_qxfer_libraries_svr4): Adjust to change of return type of xml_escape_text. * server.c (emit_dll_description): Likewise.
-rw-r--r--gdb/ChangeLog12
-rw-r--r--gdb/common/buffer.c6
-rw-r--r--gdb/common/xml-utils.c49
-rw-r--r--gdb/common/xml-utils.h2
-rw-r--r--gdb/gdbserver/ChangeLog6
-rw-r--r--gdb/gdbserver/linux-low.c6
-rw-r--r--gdb/gdbserver/server.c6
-rw-r--r--gdb/rs6000-aix-tdep.c10
-rw-r--r--gdb/unittests/xml-utils-selftests.c6
-rw-r--r--gdb/windows-tdep.c6
10 files changed, 43 insertions, 66 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 21c3694..7d2fb49 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@
2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
+ * common/buffer.c (buffer_xml_printf): Adjust.
+ * common/xml-utils.c (xml_escape_text): Change return type to
+ std::string, update code accordingly.
+ * common/xml-utils.h (xml_escape_text): Change return type to
+ std::string.
+ * rs6000-aix-tdep.c (rs6000_aix_shared_library_to_xml): Adjust.
+ * windows-tdep.c (windows_xfer_shared_library): Adjust.
+ * unittests/xml-utils-selftests.c (test_xml_escape_text):
+ Adjust.
+
+2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
+
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add new source file.
(SUBDIR_UNITTESTS_OBS): Add new object file.
* unittests/xml-utils-selftests.c: New file.
diff --git a/gdb/common/buffer.c b/gdb/common/buffer.c
index c5eb169..70d91e6 100644
--- a/gdb/common/buffer.c
+++ b/gdb/common/buffer.c
@@ -88,7 +88,6 @@ buffer_xml_printf (struct buffer *buffer, const char *format, ...)
if (percent)
{
char buf[32];
- char *p;
char *str = buf;
const char *f_old = f;
@@ -163,9 +162,8 @@ buffer_xml_printf (struct buffer *buffer, const char *format, ...)
if (str)
{
buffer_grow (buffer, prev, f_old - prev - 1);
- p = xml_escape_text (str);
- buffer_grow_str (buffer, p);
- xfree (p);
+ std::string p = xml_escape_text (str);
+ buffer_grow_str (buffer, p.c_str ());
prev = f + 1;
}
percent = 0;
diff --git a/gdb/common/xml-utils.c b/gdb/common/xml-utils.c
index b5fe442..c6dd2fb 100644
--- a/gdb/common/xml-utils.c
+++ b/gdb/common/xml-utils.c
@@ -20,64 +20,37 @@
#include "common-defs.h"
#include "xml-utils.h"
-/* Return a malloc allocated string with special characters from TEXT
- replaced by entity references. */
+/* Return a string with special characters from TEXT replaced by entity
+ references. */
-char *
+std::string
xml_escape_text (const char *text)
{
- char *result;
- int i, special;
-
- /* Compute the length of the result. */
- for (i = 0, special = 0; text[i] != '\0'; i++)
- switch (text[i])
- {
- case '\'':
- case '\"':
- special += 5;
- break;
- case '&':
- special += 4;
- break;
- case '<':
- case '>':
- special += 3;
- break;
- default:
- break;
- }
+ std::string result;
/* Expand the result. */
- result = (char *) xmalloc (i + special + 1);
- for (i = 0, special = 0; text[i] != '\0'; i++)
+ for (int i = 0; text[i] != '\0'; i++)
switch (text[i])
{
case '\'':
- strcpy (result + i + special, "&apos;");
- special += 5;
+ result += "&apos;";
break;
case '\"':
- strcpy (result + i + special, "&quot;");
- special += 5;
+ result += "&quot;";
break;
case '&':
- strcpy (result + i + special, "&amp;");
- special += 4;
+ result += "&amp;";
break;
case '<':
- strcpy (result + i + special, "&lt;");
- special += 3;
+ result += "&lt;";
break;
case '>':
- strcpy (result + i + special, "&gt;");
- special += 3;
+ result += "&gt;";
break;
default:
- result[i + special] = text[i];
+ result += text[i];
break;
}
- result[i + special] = '\0';
return result;
}
diff --git a/gdb/common/xml-utils.h b/gdb/common/xml-utils.h
index d138bab..f69f5f5 100644
--- a/gdb/common/xml-utils.h
+++ b/gdb/common/xml-utils.h
@@ -23,6 +23,6 @@
/* Return a malloc allocated string with special characters from TEXT
replaced by entity references. */
-extern char *xml_escape_text (const char *text);
+extern std::string xml_escape_text (const char *text);
#endif
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 61b2e06..49a76c9 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,11 @@
2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
+ * linux-low.c (linux_qxfer_libraries_svr4): Adjust to change of
+ return type of xml_escape_text.
+ * server.c (emit_dll_description): Likewise.
+
+2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
+
* server.c (captured_main): Accept argument for --selftest.
Update run_tests call.
* linux-x86-tdesc-selftest.c (initialize_low_tdesc): Add names
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 1d96ec2..1bc8f38 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -7288,7 +7288,6 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
{
/* 6x the size for xml_escape_text below. */
size_t len = 6 * strlen ((char *) libname);
- char *name;
if (!header_done)
{
@@ -7307,12 +7306,11 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
p = document + document_len;
}
- name = xml_escape_text ((char *) libname);
+ std::string name = xml_escape_text ((char *) libname);
p += sprintf (p, "<library name=\"%s\" lm=\"0x%lx\" "
"l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>",
- name, (unsigned long) lm_addr,
+ name.c_str (), (unsigned long) lm_addr,
(unsigned long) l_addr, (unsigned long) l_ld);
- free (name);
}
}
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 99dedb2..92943e2 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -1532,13 +1532,11 @@ emit_dll_description (struct inferior_list_entry *inf, void *arg)
struct dll_info *dll = (struct dll_info *) inf;
char **p_ptr = (char **) arg;
char *p = *p_ptr;
- char *name;
strcpy (p, " <library name=\"");
p = p + strlen (p);
- name = xml_escape_text (dll->name);
- strcpy (p, name);
- free (name);
+ std::string name = xml_escape_text (dll->name);
+ strcpy (p, name.c_str ());
p = p + strlen (p);
strcpy (p, "\"><segment address=\"");
p = p + strlen (p);
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index f4f3eb7..fc37d6c 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -908,20 +908,16 @@ static void
rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
struct obstack *obstack)
{
- char *p;
-
obstack_grow_str (obstack, "<library name=\"");
- p = xml_escape_text (ldi->filename);
- obstack_grow_str (obstack, p);
- xfree (p);
+ std::string p = xml_escape_text (ldi->filename);
+ obstack_grow_str (obstack, p.c_str ());
obstack_grow_str (obstack, "\"");
if (ldi->member_name[0] != '\0')
{
obstack_grow_str (obstack, " member=\"");
p = xml_escape_text (ldi->member_name);
- obstack_grow_str (obstack, p);
- xfree (p);
+ obstack_grow_str (obstack, p.c_str ());
obstack_grow_str (obstack, "\"");
}
diff --git a/gdb/unittests/xml-utils-selftests.c b/gdb/unittests/xml-utils-selftests.c
index 21b506a..e4ab483 100644
--- a/gdb/unittests/xml-utils-selftests.c
+++ b/gdb/unittests/xml-utils-selftests.c
@@ -28,11 +28,9 @@ static void test_xml_escape_text ()
{
const char *input = "<this isn't=\"xml\"> &";
const char *expected_output = "&lt;this isn&apos;t=&quot;xml&quot;&gt; &amp;";
- char *actual_output = xml_escape_text (input);
+ std::string actual_output = xml_escape_text (input);
- SELF_CHECK (strcmp (actual_output, expected_output) == 0);
-
- xfree (actual_output);
+ SELF_CHECK (actual_output == expected_output);
}
}
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 886c4ec..197d779 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -371,13 +371,11 @@ void
windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
struct gdbarch *gdbarch, struct obstack *obstack)
{
- char *p;
CORE_ADDR text_offset;
obstack_grow_str (obstack, "<library name=\"");
- p = xml_escape_text (so_name);
- obstack_grow_str (obstack, p);
- xfree (p);
+ std::string p = xml_escape_text (so_name);
+ obstack_grow_str (obstack, p.c_str ());
obstack_grow_str (obstack, "\"><segment address=\"");
gdb_bfd_ref_ptr dll (gdb_bfd_open (so_name, gnutarget, -1));
/* The following calls are OK even if dll is NULL.