aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2018-01-07 09:29:52 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2018-01-07 09:38:16 -0500
commit4d0fdd9b357aff1fea3ef3def55d12464a41bf5b (patch)
tree3d31052e1794ddbe5942daabe65d3fc1d900cf76
parentf979c73fd0be9a8a683f79af40c7b939c2a65d9f (diff)
downloadgdb-4d0fdd9b357aff1fea3ef3def55d12464a41bf5b.zip
gdb-4d0fdd9b357aff1fea3ef3def55d12464a41bf5b.tar.gz
gdb-4d0fdd9b357aff1fea3ef3def55d12464a41bf5b.tar.bz2
Replace VEC(gdb_xml_value_s) with std::vector
This patch replaces VEC(gdb_xml_value_s), which is passed to XML visitors, with an std::vector. In order to be able to remove the cleanup in gdb_xml_parser::start_element, the gdb_xml_parser structure is made to own the value with a gdb::unique_xmalloc_ptr. This patch has been tested on the buildbot. gdb/ChangeLog: * xml-support.h (struct gdb_xml_value): Add constructor. <value>: Change type to unique_xmalloc_ptr. (gdb_xml_value_s): Remove typedef. (DEF_VEC_O (gdb_xml_value_s)): Remove. (gdb_xml_element_start_handler): Change parameter type to std::vector. (xml_find_attribute): Likewise. * xml-support.c (xml_find_attribute): Change parameter type to std::vector and adjust. (gdb_xml_values_cleanup): Remove. (gdb_xml_parser::start_element): Adjust to std::vector. (xinclude_start_include): Change paraeter type to std::vector and adjust. * btrace.c (check_xml_btrace_version): Likewise. (parse_xml_btrace_block): Likewise. (parse_xml_btrace_pt_config_cpu): Likewise. (parse_xml_btrace_pt): Likewise. (parse_xml_btrace_conf_bts): Likewise. (parse_xml_btrace_conf_pt): Likewise. * memory-map.c (memory_map_start_memory): Likewise. (memory_map_start_property): Likewise. * osdata.c (osdata_start_osdata): Likewise. (osdata_start_item): Likewise. (osdata_start_column): Likewise. * remote.c (start_thread): Likewise. * solib-aix.c (library_list_start_library): Likewise. (library_list_start_list): Likewise. * solib-svr4.c (library_list_start_library): Likewise. (svr4_library_list_start_list): Likewise. * solib-target.c (library_list_start_segment): Likewise. (library_list_start_section): Likewise. (library_list_start_library): Likewise. (library_list_start_list): Likewise. * tracepoint.c (traceframe_info_start_memory): Likewise. (traceframe_info_start_tvar): Likewise. * xml-syscall.c (syscall_start_syscall): Likewise. * xml-tdesc.c (tdesc_start_target): Likewise. (tdesc_start_feature): Likewise. (tdesc_start_reg): Likewise. (tdesc_start_union): Likewise. (tdesc_start_struct): Likewise. (tdesc_start_flags): Likewise. (tdesc_start_enum): Likewise. (tdesc_start_field): Likewise. (tdesc_start_enum_value): Likewise. (tdesc_start_vector): Likewise.
-rw-r--r--gdb/ChangeLog49
-rw-r--r--gdb/btrace.c39
-rw-r--r--gdb/memory-map.c14
-rw-r--r--gdb/osdata.c13
-rw-r--r--gdb/remote.c11
-rw-r--r--gdb/solib-aix.c20
-rw-r--r--gdb/solib-svr4.c18
-rw-r--r--gdb/solib-target.c20
-rw-r--r--gdb/tracepoint.c11
-rw-r--r--gdb/xml-support.c42
-rw-r--r--gdb/xml-support.h14
-rw-r--r--gdb/xml-syscall.c23
-rw-r--r--gdb/xml-tdesc.c83
13 files changed, 203 insertions, 154 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ff45306..585ad5e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,54 @@
2018-01-07 Simon Marchi <simon.marchi@polymtl.ca>
+ * xml-support.h (struct gdb_xml_value): Add constructor.
+ <value>: Change type to unique_xmalloc_ptr.
+ (gdb_xml_value_s): Remove typedef.
+ (DEF_VEC_O (gdb_xml_value_s)): Remove.
+ (gdb_xml_element_start_handler): Change parameter type to
+ std::vector.
+ (xml_find_attribute): Likewise.
+ * xml-support.c (xml_find_attribute): Change parameter type to
+ std::vector and adjust.
+ (gdb_xml_values_cleanup): Remove.
+ (gdb_xml_parser::start_element): Adjust to std::vector.
+ (xinclude_start_include): Change paraeter type to std::vector
+ and adjust.
+ * btrace.c (check_xml_btrace_version): Likewise.
+ (parse_xml_btrace_block): Likewise.
+ (parse_xml_btrace_pt_config_cpu): Likewise.
+ (parse_xml_btrace_pt): Likewise.
+ (parse_xml_btrace_conf_bts): Likewise.
+ (parse_xml_btrace_conf_pt): Likewise.
+ * memory-map.c (memory_map_start_memory): Likewise.
+ (memory_map_start_property): Likewise.
+ * osdata.c (osdata_start_osdata): Likewise.
+ (osdata_start_item): Likewise.
+ (osdata_start_column): Likewise.
+ * remote.c (start_thread): Likewise.
+ * solib-aix.c (library_list_start_library): Likewise.
+ (library_list_start_list): Likewise.
+ * solib-svr4.c (library_list_start_library): Likewise.
+ (svr4_library_list_start_list): Likewise.
+ * solib-target.c (library_list_start_segment): Likewise.
+ (library_list_start_section): Likewise.
+ (library_list_start_library): Likewise.
+ (library_list_start_list): Likewise.
+ * tracepoint.c (traceframe_info_start_memory): Likewise.
+ (traceframe_info_start_tvar): Likewise.
+ * xml-syscall.c (syscall_start_syscall): Likewise.
+ * xml-tdesc.c (tdesc_start_target): Likewise.
+ (tdesc_start_feature): Likewise.
+ (tdesc_start_reg): Likewise.
+ (tdesc_start_union): Likewise.
+ (tdesc_start_struct): Likewise.
+ (tdesc_start_flags): Likewise.
+ (tdesc_start_enum): Likewise.
+ (tdesc_start_field): Likewise.
+ (tdesc_start_enum_value): Likewise.
+ (tdesc_start_vector): Likewise.
+
+2018-01-07 Simon Marchi <simon.marchi@polymtl.ca>
+
* extension.h (struct xmethod_worker) <clone>: Remove.
* python/py-xmethods.c (struct python_xmethod_worker) <clone>:
Remove.
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 8823046..ffcf53a 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -2002,10 +2002,11 @@ btrace_free_objfile (struct objfile *objfile)
static void
check_xml_btrace_version (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC (gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
const char *version
- = (const char *) xml_find_attribute (attributes, "version")->value;
+ = (const char *) xml_find_attribute (attributes, "version")->value.get ();
if (strcmp (version, "1.0") != 0)
gdb_xml_error (parser, _("Unsupported btrace version: \"%s\""), version);
@@ -2016,7 +2017,8 @@ check_xml_btrace_version (struct gdb_xml_parser *parser,
static void
parse_xml_btrace_block (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC (gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
struct btrace_block *block;
@@ -2038,8 +2040,8 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
gdb_xml_error (parser, _("Btrace format error."));
}
- begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value;
- end = (ULONGEST *) xml_find_attribute (attributes, "end")->value;
+ begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
+ end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
block->begin = *begin;
@@ -2092,16 +2094,20 @@ static void
parse_xml_btrace_pt_config_cpu (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
void *user_data,
- VEC (gdb_xml_value_s) *attributes)
+ std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
const char *vendor;
ULONGEST *family, *model, *stepping;
- vendor = (const char *) xml_find_attribute (attributes, "vendor")->value;
- family = (ULONGEST *) xml_find_attribute (attributes, "family")->value;
- model = (ULONGEST *) xml_find_attribute (attributes, "model")->value;
- stepping = (ULONGEST *) xml_find_attribute (attributes, "stepping")->value;
+ vendor =
+ (const char *) xml_find_attribute (attributes, "vendor")->value.get ();
+ family
+ = (ULONGEST *) xml_find_attribute (attributes, "family")->value.get ();
+ model
+ = (ULONGEST *) xml_find_attribute (attributes, "model")->value.get ();
+ stepping
+ = (ULONGEST *) xml_find_attribute (attributes, "stepping")->value.get ();
btrace = (struct btrace_data *) user_data;
@@ -2132,7 +2138,8 @@ parse_xml_btrace_pt_raw (struct gdb_xml_parser *parser,
static void
parse_xml_btrace_pt (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC (gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
@@ -2226,7 +2233,8 @@ parse_xml_btrace (struct btrace_data *btrace, const char *buffer)
static void
parse_xml_btrace_conf_bts (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC (gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct btrace_config *conf;
struct gdb_xml_value *size;
@@ -2237,7 +2245,7 @@ parse_xml_btrace_conf_bts (struct gdb_xml_parser *parser,
size = xml_find_attribute (attributes, "size");
if (size != NULL)
- conf->bts.size = (unsigned int) *(ULONGEST *) size->value;
+ conf->bts.size = (unsigned int) *(ULONGEST *) size->value.get ();
}
/* Parse a btrace-conf "pt" xml record. */
@@ -2245,7 +2253,8 @@ parse_xml_btrace_conf_bts (struct gdb_xml_parser *parser,
static void
parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC (gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct btrace_config *conf;
struct gdb_xml_value *size;
@@ -2256,7 +2265,7 @@ parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
size = xml_find_attribute (attributes, "size");
if (size != NULL)
- conf->pt.size = (unsigned int) *(ULONGEST *) size->value;
+ conf->pt.size = (unsigned int) *(ULONGEST *) size->value.get ();
}
static const struct gdb_xml_attribute btrace_conf_pt_attributes[] = {
diff --git a/gdb/memory-map.c b/gdb/memory-map.c
index 55b207e..6a1220e 100644
--- a/gdb/memory-map.c
+++ b/gdb/memory-map.c
@@ -58,18 +58,19 @@ struct memory_map_parsing_data
static void
memory_map_start_memory (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct memory_map_parsing_data *data
= (struct memory_map_parsing_data *) user_data;
ULONGEST *start_p, *length_p, *type_p;
start_p
- = (ULONGEST *) xml_find_attribute (attributes, "start")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "start")->value.get ();
length_p
- = (ULONGEST *) xml_find_attribute (attributes, "length")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "length")->value.get ();
type_p
- = (ULONGEST *) xml_find_attribute (attributes, "type")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "type")->value.get ();
data->memory_map->emplace_back (*start_p, *start_p + *length_p,
(enum mem_access_mode) *type_p);
@@ -97,13 +98,14 @@ memory_map_end_memory (struct gdb_xml_parser *parser,
static void
memory_map_start_property (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct memory_map_parsing_data *data
= (struct memory_map_parsing_data *) user_data;
char *name;
- name = (char *) xml_find_attribute (attributes, "name")->value;
+ name = (char *) xml_find_attribute (attributes, "name")->value.get ();
data->property_name.assign (name);
}
diff --git a/gdb/osdata.c b/gdb/osdata.c
index f390940..5c41cb1 100644
--- a/gdb/osdata.c
+++ b/gdb/osdata.c
@@ -56,14 +56,15 @@ struct osdata_parsing_data
static void
osdata_start_osdata (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct osdata_parsing_data *data = (struct osdata_parsing_data *) user_data;
if (data->osdata != NULL)
gdb_xml_error (parser, _("Seen more than on osdata element"));
- char *type = (char *) xml_find_attribute (attributes, "type")->value;
+ char *type = (char *) xml_find_attribute (attributes, "type")->value.get ();
data->osdata.reset (new struct osdata (std::string (type)));
}
@@ -72,7 +73,8 @@ osdata_start_osdata (struct gdb_xml_parser *parser,
static void
osdata_start_item (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct osdata_parsing_data *data = (struct osdata_parsing_data *) user_data;
data->osdata->items.emplace_back ();
@@ -83,11 +85,12 @@ osdata_start_item (struct gdb_xml_parser *parser,
static void
osdata_start_column (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct osdata_parsing_data *data = (struct osdata_parsing_data *) user_data;
const char *name
- = (const char *) xml_find_attribute (attributes, "name")->value;
+ = (const char *) xml_find_attribute (attributes, "name")->value.get ();
data->property_name.assign (name);
}
diff --git a/gdb/remote.c b/gdb/remote.c
index 9ff6028..81c772a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -3077,13 +3077,14 @@ remote_get_threads_with_ql (struct target_ops *ops,
static void
start_thread (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct threads_listing_context *data
= (struct threads_listing_context *) user_data;
struct gdb_xml_value *attr;
- char *id = (char *) xml_find_attribute (attributes, "id")->value;
+ char *id = (char *) xml_find_attribute (attributes, "id")->value.get ();
ptid_t ptid = read_ptid (id, NULL);
data->items.emplace_back (ptid);
@@ -3091,15 +3092,15 @@ start_thread (struct gdb_xml_parser *parser,
attr = xml_find_attribute (attributes, "core");
if (attr != NULL)
- item.core = *(ULONGEST *) attr->value;
+ item.core = *(ULONGEST *) attr->value.get ();
attr = xml_find_attribute (attributes, "name");
if (attr != NULL)
- item.name = (const char *) attr->value;
+ item.name = (const char *) attr->value.get ();
attr = xml_find_attribute (attributes, "handle");
if (attr != NULL)
- item.thread_handle = hex2bin ((const char *) attr->value);
+ item.thread_handle = hex2bin ((const char *) attr->value.get ());
}
static void
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index 74f0eaa..463f060 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -134,30 +134,30 @@ static void
library_list_start_library (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
void *user_data,
- VEC (gdb_xml_value_s) *attributes)
+ std::vector<gdb_xml_value> &attributes)
{
VEC (lm_info_aix_p) **list = (VEC (lm_info_aix_p) **) user_data;
lm_info_aix *item = new lm_info_aix;
struct gdb_xml_value *attr;
attr = xml_find_attribute (attributes, "name");
- item->filename = xstrdup ((const char *) attr->value);
+ item->filename = xstrdup ((const char *) attr->value.get ());
attr = xml_find_attribute (attributes, "member");
if (attr != NULL)
- item->member_name = xstrdup ((const char *) attr->value);
+ item->member_name = xstrdup ((const char *) attr->value.get ());
attr = xml_find_attribute (attributes, "text_addr");
- item->text_addr = * (ULONGEST *) attr->value;
+ item->text_addr = * (ULONGEST *) attr->value.get ();
attr = xml_find_attribute (attributes, "text_size");
- item->text_size = * (ULONGEST *) attr->value;
+ item->text_size = * (ULONGEST *) attr->value.get ();
attr = xml_find_attribute (attributes, "data_addr");
- item->data_addr = * (ULONGEST *) attr->value;
+ item->data_addr = * (ULONGEST *) attr->value.get ();
attr = xml_find_attribute (attributes, "data_size");
- item->data_size = * (ULONGEST *) attr->value;
+ item->data_size = * (ULONGEST *) attr->value.get ();
VEC_safe_push (lm_info_aix_p, *list, item);
}
@@ -167,9 +167,11 @@ library_list_start_library (struct gdb_xml_parser *parser,
static void
library_list_start_list (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC (gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
- char *version = (char *) xml_find_attribute (attributes, "version")->value;
+ char *version
+ = (char *) xml_find_attribute (attributes, "version")->value.get ();
if (strcmp (version, "1.0") != 0)
gdb_xml_error (parser,
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 4973cc2..c8f5e93 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1144,17 +1144,18 @@ svr4_copy_library_list (struct so_list *src)
static void
library_list_start_library (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct svr4_library_list *list = (struct svr4_library_list *) user_data;
const char *name
- = (const char *) xml_find_attribute (attributes, "name")->value;
+ = (const char *) xml_find_attribute (attributes, "name")->value.get ();
ULONGEST *lmp
- = (ULONGEST *) xml_find_attribute (attributes, "lm")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "lm")->value.get ();
ULONGEST *l_addrp
- = (ULONGEST *) xml_find_attribute (attributes, "l_addr")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "l_addr")->value.get ();
ULONGEST *l_ldp
- = (ULONGEST *) xml_find_attribute (attributes, "l_ld")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "l_ld")->value.get ();
struct so_list *new_elem;
new_elem = XCNEW (struct so_list);
@@ -1177,11 +1178,12 @@ library_list_start_library (struct gdb_xml_parser *parser,
static void
svr4_library_list_start_list (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct svr4_library_list *list = (struct svr4_library_list *) user_data;
const char *version
- = (const char *) xml_find_attribute (attributes, "version")->value;
+ = (const char *) xml_find_attribute (attributes, "version")->value.get ();
struct gdb_xml_value *main_lm = xml_find_attribute (attributes, "main-lm");
if (strcmp (version, "1.0") != 0)
@@ -1190,7 +1192,7 @@ svr4_library_list_start_list (struct gdb_xml_parser *parser,
version);
if (main_lm)
- list->main_lm = *(ULONGEST *) main_lm->value;
+ list->main_lm = *(ULONGEST *) main_lm->value.get ();
}
/* The allowed elements and attributes for an XML library list.
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 70f864e..0968e49 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -79,12 +79,13 @@ solib_target_parse_libraries (const char *library)
static void
library_list_start_segment (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
VEC(lm_info_target_p) **list = (VEC(lm_info_target_p) **) user_data;
lm_info_target *last = VEC_last (lm_info_target_p, *list);
ULONGEST *address_p
- = (ULONGEST *) xml_find_attribute (attributes, "address")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "address")->value.get ();
CORE_ADDR address = (CORE_ADDR) *address_p;
if (!last->section_bases.empty ())
@@ -97,12 +98,13 @@ library_list_start_segment (struct gdb_xml_parser *parser,
static void
library_list_start_section (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
VEC(lm_info_target_p) **list = (VEC(lm_info_target_p) **) user_data;
lm_info_target *last = VEC_last (lm_info_target_p, *list);
ULONGEST *address_p
- = (ULONGEST *) xml_find_attribute (attributes, "address")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "address")->value.get ();
CORE_ADDR address = (CORE_ADDR) *address_p;
if (!last->segment_bases.empty ())
@@ -117,12 +119,13 @@ library_list_start_section (struct gdb_xml_parser *parser,
static void
library_list_start_library (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
VEC(lm_info_target_p) **list = (VEC(lm_info_target_p) **) user_data;
lm_info_target *item = new lm_info_target;
const char *name
- = (const char *) xml_find_attribute (attributes, "name")->value;
+ = (const char *) xml_find_attribute (attributes, "name")->value.get ();
item->name = xstrdup (name);
VEC_safe_push (lm_info_target_p, *list, item);
@@ -146,14 +149,15 @@ library_list_end_library (struct gdb_xml_parser *parser,
static void
library_list_start_list (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct gdb_xml_value *version = xml_find_attribute (attributes, "version");
/* #FIXED attribute may be omitted, Expat returns NULL in such case. */
if (version != NULL)
{
- const char *string = (const char *) version->value;
+ const char *string = (const char *) version->value.get ();
if (strcmp (string, "1.0") != 0)
gdb_xml_error (parser,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index b0f855a..f34f103 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3959,15 +3959,16 @@ parse_traceframe_info (const char *tframe_info)
static void
traceframe_info_start_memory (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct traceframe_info *info = (struct traceframe_info *) user_data;
ULONGEST *start_p, *length_p;
start_p
- = (ULONGEST *) xml_find_attribute (attributes, "start")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "start")->value.get ();
length_p
- = (ULONGEST *) xml_find_attribute (attributes, "length")->value;
+ = (ULONGEST *) xml_find_attribute (attributes, "length")->value.get ();
info->memory.emplace_back (*start_p, *length_p);
}
@@ -3978,11 +3979,11 @@ static void
traceframe_info_start_tvar (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
void *user_data,
- VEC(gdb_xml_value_s) *attributes)
+ std::vector<gdb_xml_value> &attributes)
{
struct traceframe_info *info = (struct traceframe_info *) user_data;
const char *id_attrib
- = (const char *) xml_find_attribute (attributes, "id")->value;
+ = (const char *) xml_find_attribute (attributes, "id")->value.get ();
int id = gdb_xml_parse_ulongest (parser, id_attrib);
info->tvars.push_back (id);
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index dacc5c4..2547882 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -228,32 +228,16 @@ gdb_xml_error (struct gdb_xml_parser *parser, const char *format, ...)
ATTRIBUTES. Returns NULL if not found. */
struct gdb_xml_value *
-xml_find_attribute (VEC(gdb_xml_value_s) *attributes, const char *name)
+xml_find_attribute (std::vector<gdb_xml_value> &attributes,
+ const char *name)
{
- struct gdb_xml_value *value;
- int ix;
-
- for (ix = 0; VEC_iterate (gdb_xml_value_s, attributes, ix, value); ix++)
- if (strcmp (value->name, name) == 0)
- return value;
+ for (gdb_xml_value &value : attributes)
+ if (strcmp (value.name, name) == 0)
+ return &value;
return NULL;
}
-/* Clean up a vector of parsed attribute values. */
-
-static void
-gdb_xml_values_cleanup (void *data)
-{
- VEC(gdb_xml_value_s) **values = (VEC(gdb_xml_value_s) **) data;
- struct gdb_xml_value *value;
- int ix;
-
- for (ix = 0; VEC_iterate (gdb_xml_value_s, *values, ix, value); ix++)
- xfree (value->value);
- VEC_free (gdb_xml_value_s, *values);
-}
-
/* Handle the start of an element. NAME is the element, and ATTRS are
the names and values of this element's attributes. */
@@ -266,9 +250,7 @@ gdb_xml_parser::start_element (const XML_Char *name,
const struct gdb_xml_element *element;
const struct gdb_xml_attribute *attribute;
- VEC(gdb_xml_value_s) *attributes = NULL;
unsigned int seen;
- struct cleanup *back_to;
/* Push an error scope. If we return or throw an exception before
filling this in, it will tell us to ignore children of this
@@ -317,7 +299,7 @@ gdb_xml_parser::start_element (const XML_Char *name,
scope.seen |= seen;
- back_to = make_cleanup (gdb_xml_values_cleanup, &attributes);
+ std::vector<gdb_xml_value> attributes;
for (attribute = element->attributes;
attribute != NULL && attribute->name != NULL;
@@ -326,7 +308,6 @@ gdb_xml_parser::start_element (const XML_Char *name,
const char *val = NULL;
const XML_Char **p;
void *parsed_value;
- struct gdb_xml_value new_value;
for (p = attrs; *p != NULL; p += 2)
if (!strcmp (attribute->name, p[0]))
@@ -361,9 +342,7 @@ gdb_xml_parser::start_element (const XML_Char *name,
else
parsed_value = xstrdup (val);
- new_value.name = attribute->name;
- new_value.value = parsed_value;
- VEC_safe_push (gdb_xml_value_s, attributes, &new_value);
+ attributes.emplace_back (attribute->name, parsed_value);
}
/* Check for unrecognized attributes. */
@@ -395,8 +374,6 @@ gdb_xml_parser::start_element (const XML_Char *name,
scope_level &new_scope = m_scopes.back ();
new_scope.element = element;
new_scope.elements = element->children;
-
- do_cleanups (back_to);
}
/* Wrapper for gdb_xml_start_element, to prevent throwing exceptions
@@ -803,11 +780,12 @@ struct xinclude_parsing_data
static void
xinclude_start_include (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct xinclude_parsing_data *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.get ();
gdb_xml_debug (parser, _("Processing XInclude of \"%s\""), href);
diff --git a/gdb/xml-support.h b/gdb/xml-support.h
index ee5fd52..5947623 100644
--- a/gdb/xml-support.h
+++ b/gdb/xml-support.h
@@ -74,11 +74,13 @@ bool xml_process_xincludes (std::string &result,
struct gdb_xml_value
{
+ gdb_xml_value (const char *name_, void *value_)
+ : name (name_), value (value_)
+ {}
+
const char *name;
- void *value;
+ gdb::unique_xmalloc_ptr<void> value;
};
-typedef struct gdb_xml_value gdb_xml_value_s;
-DEF_VEC_O(gdb_xml_value_s);
/* The type of an attribute handler.
@@ -146,7 +148,7 @@ enum gdb_xml_element_flag
typedef void (gdb_xml_element_start_handler)
(struct gdb_xml_parser *parser, const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes);
+ void *user_data, std::vector<gdb_xml_value> &attributes);
/* A handler called at the end of an element.
@@ -199,8 +201,8 @@ void gdb_xml_error (struct gdb_xml_parser *parser, const char *format, ...)
/* Find the attribute named NAME in the set of parsed attributes
ATTRIBUTES. Returns NULL if not found. */
-struct gdb_xml_value *xml_find_attribute (VEC(gdb_xml_value_s) *attributes,
- const char *name);
+struct gdb_xml_value *xml_find_attribute
+ (std::vector<gdb_xml_value> &attributes, const char *name);
/* Parse an integer attribute into a ULONGEST. */
diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
index a53b76f..0ba6d44 100644
--- a/gdb/xml-syscall.c
+++ b/gdb/xml-syscall.c
@@ -227,29 +227,26 @@ syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
static void
syscall_start_syscall (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data,
+ std::vector<gdb_xml_value> &attributes)
{
struct syscall_parsing_data *data = (struct syscall_parsing_data *) user_data;
- struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes);
- int len, i;
/* syscall info. */
char *name = NULL;
int number = 0;
char *groups = NULL;
- len = VEC_length (gdb_xml_value_s, attributes);
-
- for (i = 0; i < len; i++)
+ for (const gdb_xml_value &attr : attributes)
{
- if (strcmp (attrs[i].name, "name") == 0)
- name = (char *) attrs[i].value;
- else if (strcmp (attrs[i].name, "number") == 0)
- number = * (ULONGEST *) attrs[i].value;
- else if (strcmp (attrs[i].name, "groups") == 0)
- groups = (char *) attrs[i].value;
+ if (strcmp (attr.name, "name") == 0)
+ name = (char *) attr.value.get ();
+ else if (strcmp (attr.name, "number") == 0)
+ number = * (ULONGEST *) attr.value.get ();
+ else if (strcmp (attr.name, "groups") == 0)
+ groups = (char *) attr.value.get ();
else
internal_error (__FILE__, __LINE__,
- _("Unknown attribute name '%s'."), attrs[i].name);
+ _("Unknown attribute name '%s'."), attr.name);
}
gdb_assert (name);
diff --git a/gdb/xml-tdesc.c b/gdb/xml-tdesc.c
index 1228375..9190d5f 100644
--- a/gdb/xml-tdesc.c
+++ b/gdb/xml-tdesc.c
@@ -144,9 +144,10 @@ tdesc_end_compatible (struct gdb_xml_parser *parser,
static void
tdesc_start_target (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
- char *version = (char *) xml_find_attribute (attributes, "version")->value;
+ char *version
+ = (char *) xml_find_attribute (attributes, "version")->value.get ();
if (strcmp (version, "1.0") != 0)
gdb_xml_error (parser,
@@ -159,10 +160,10 @@ tdesc_start_target (struct gdb_xml_parser *parser,
static void
tdesc_start_feature (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
- char *name = (char *) xml_find_attribute (attributes, "name")->value;
+ char *name = (char *) xml_find_attribute (attributes, "name")->value.get ();
data->current_feature = tdesc_create_feature (data->tdesc, name);
}
@@ -173,37 +174,36 @@ tdesc_start_feature (struct gdb_xml_parser *parser,
static void
tdesc_start_reg (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
- struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes);
- int ix = 0, length;
+ int ix = 0;
char *name, *group;
const char *type;
int bitsize, regnum, save_restore;
- length = VEC_length (gdb_xml_value_s, attributes);
+ int length = attributes.size ();
- name = (char *) attrs[ix++].value;
- bitsize = * (ULONGEST *) attrs[ix++].value;
+ name = (char *) attributes[ix++].value.get ();
+ bitsize = * (ULONGEST *) attributes[ix++].value.get ();
- if (ix < length && strcmp (attrs[ix].name, "regnum") == 0)
- regnum = * (ULONGEST *) attrs[ix++].value;
+ if (ix < length && strcmp (attributes[ix].name, "regnum") == 0)
+ regnum = * (ULONGEST *) attributes[ix++].value.get ();
else
regnum = data->next_regnum;
- if (ix < length && strcmp (attrs[ix].name, "type") == 0)
- type = (char *) attrs[ix++].value;
+ if (ix < length && strcmp (attributes[ix].name, "type") == 0)
+ type = (char *) attributes[ix++].value.get ();
else
type = "int";
- if (ix < length && strcmp (attrs[ix].name, "group") == 0)
- group = (char *) attrs[ix++].value;
+ if (ix < length && strcmp (attributes[ix].name, "group") == 0)
+ group = (char *) attributes[ix++].value.get ();
else
group = NULL;
- if (ix < length && strcmp (attrs[ix].name, "save-restore") == 0)
- save_restore = * (ULONGEST *) attrs[ix++].value;
+ if (ix < length && strcmp (attributes[ix].name, "save-restore") == 0)
+ save_restore = * (ULONGEST *) attributes[ix++].value.get ();
else
save_restore = 1;
@@ -225,10 +225,10 @@ tdesc_start_reg (struct gdb_xml_parser *parser,
static void
tdesc_start_union (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
- char *id = (char *) xml_find_attribute (attributes, "id")->value;
+ char *id = (char *) xml_find_attribute (attributes, "id")->value.get ();
data->current_type = tdesc_create_union (data->current_feature, id);
data->current_type_size = 0;
@@ -240,10 +240,10 @@ tdesc_start_union (struct gdb_xml_parser *parser,
static void
tdesc_start_struct (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
- char *id = (char *) xml_find_attribute (attributes, "id")->value;
+ char *id = (char *) xml_find_attribute (attributes, "id")->value.get ();
struct gdb_xml_value *attr;
tdesc_type_with_fields *type_with_fields
@@ -254,7 +254,7 @@ tdesc_start_struct (struct gdb_xml_parser *parser,
attr = xml_find_attribute (attributes, "size");
if (attr != NULL)
{
- ULONGEST size = * (ULONGEST *) attr->value;
+ ULONGEST size = * (ULONGEST *) attr->value.get ();
if (size > MAX_FIELD_SIZE)
{
@@ -270,12 +270,12 @@ tdesc_start_struct (struct gdb_xml_parser *parser,
static void
tdesc_start_flags (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
- char *id = (char *) xml_find_attribute (attributes, "id")->value;
+ char *id = (char *) xml_find_attribute (attributes, "id")->value.get ();
ULONGEST size = * (ULONGEST *)
- xml_find_attribute (attributes, "size")->value;
+ xml_find_attribute (attributes, "size")->value.get ();
if (size > MAX_FIELD_SIZE)
{
@@ -291,12 +291,12 @@ tdesc_start_flags (struct gdb_xml_parser *parser,
static void
tdesc_start_enum (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
- char *id = (char *) xml_find_attribute (attributes, "id")->value;
+ char *id = (char *) xml_find_attribute (attributes, "id")->value.get ();
int size = * (ULONGEST *)
- xml_find_attribute (attributes, "size")->value;
+ xml_find_attribute (attributes, "size")->value.get ();
if (size > MAX_FIELD_SIZE)
{
@@ -315,7 +315,7 @@ tdesc_start_enum (struct gdb_xml_parser *parser,
static void
tdesc_start_field (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
struct gdb_xml_value *attr;
@@ -323,12 +323,12 @@ tdesc_start_field (struct gdb_xml_parser *parser,
char *field_name, *field_type_id;
int start, end;
- field_name = (char *) xml_find_attribute (attributes, "name")->value;
+ field_name = (char *) xml_find_attribute (attributes, "name")->value.get ();
attr = xml_find_attribute (attributes, "type");
if (attr != NULL)
{
- field_type_id = (char *) attr->value;
+ field_type_id = (char *) attr->value.get ();
field_type = tdesc_named_type (data->current_feature, field_type_id);
}
else
@@ -340,7 +340,7 @@ tdesc_start_field (struct gdb_xml_parser *parser,
attr = xml_find_attribute (attributes, "start");
if (attr != NULL)
{
- ULONGEST ul_start = * (ULONGEST *) attr->value;
+ ULONGEST ul_start = * (ULONGEST *) attr->value.get ();
if (ul_start > MAX_FIELD_BITSIZE)
{
@@ -356,7 +356,7 @@ tdesc_start_field (struct gdb_xml_parser *parser,
attr = xml_find_attribute (attributes, "end");
if (attr != NULL)
{
- ULONGEST ul_end = * (ULONGEST *) attr->value;
+ ULONGEST ul_end = * (ULONGEST *) attr->value.get ();
if (ul_end > MAX_FIELD_BITSIZE)
{
@@ -444,7 +444,7 @@ tdesc_start_field (struct gdb_xml_parser *parser,
static void
tdesc_start_enum_value (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
struct gdb_xml_value *attr;
@@ -452,10 +452,10 @@ tdesc_start_enum_value (struct gdb_xml_parser *parser,
ULONGEST ul_value;
int value;
- field_name = (char *) xml_find_attribute (attributes, "name")->value;
+ field_name = (char *) xml_find_attribute (attributes, "name")->value.get ();
attr = xml_find_attribute (attributes, "value");
- ul_value = * (ULONGEST *) attr->value;
+ ul_value = * (ULONGEST *) attr->value.get ();
if (ul_value > INT_MAX)
{
gdb_xml_error (parser,
@@ -473,17 +473,16 @@ tdesc_start_enum_value (struct gdb_xml_parser *parser,
static void
tdesc_start_vector (struct gdb_xml_parser *parser,
const struct gdb_xml_element *element,
- void *user_data, VEC(gdb_xml_value_s) *attributes)
+ void *user_data, std::vector<gdb_xml_value> &attributes)
{
struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
- struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes);
struct tdesc_type *field_type;
char *id, *field_type_id;
ULONGEST count;
- id = (char *) attrs[0].value;
- field_type_id = (char *) attrs[1].value;
- count = * (ULONGEST *) attrs[2].value;
+ id = (char *) attributes[0].value.get ();
+ field_type_id = (char *) attributes[1].value.get ();
+ count = * (ULONGEST *) attributes[2].value.get ();
if (count > MAX_VECTOR_SIZE)
{