GDB (xrefs)

/tmp/gdb-8.1/gdb/memory-map.c
Go to the documentation of this file.
1 /* Routines for handling XML memory maps provided by target.
2
3 Copyright (C) 2006-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "memory-map.h"
22
23 #if !defined(HAVE_LIBEXPAT)
24
25 std::vector<mem_region>
26 parse_memory_map (const char *memory_map)
27 {
28 static int have_warned;
29
30 if (!have_warned)
31 {
32 have_warned = 1;
33 warning (_("Can not parse XML memory map; XML support was disabled "
34 "at compile time"));
35 }
36
37 return std::vector<mem_region> ();
38 }
39
40 #else /* HAVE_LIBEXPAT */
41
42 #include "xml-support.h"
43
44 /* Internal parsing data passed to all XML callbacks. */
45 struct memory_map_parsing_data
46 {
47 memory_map_parsing_data (std::vector<mem_region> *memory_map_)
48 : memory_map (memory_map_)
49 {}
50
51 std::vector<mem_region> *memory_map;
52
53 std::string property_name;
54 };
55
56 /* Handle the start of a <memory> element. */
57
58 static void
59 memory_map_start_memory (struct gdb_xml_parser *parser,
60 const struct gdb_xml_element *element,
61 void *user_data, VEC(gdb_xml_value_s) *attributes)
62 {
63 struct memory_map_parsing_data *data
64 = (struct memory_map_parsing_data *) user_data;
65 ULONGEST *start_p, *length_p, *type_p;
66
67 start_p
68 = (ULONGEST *) xml_find_attribute (attributes, "start")->value;
69 length_p
70 = (ULONGEST *) xml_find_attribute (attributes, "length")->value;
71 type_p
72 = (ULONGEST *) xml_find_attribute (attributes, "type")->value;
73
74 data->memory_map->emplace_back (*start_p, *start_p + *length_p,
75 (enum mem_access_mode) *type_p);
76 }
77
78 /* Handle the end of a <memory> element. Verify that any necessary
79 children were present. */
80
81 static void
82 memory_map_end_memory (struct gdb_xml_parser *parser,
83 const struct gdb_xml_element *element,
84 void *user_data, const char *body_text)
85 {
86 struct memory_map_parsing_data *data
87 = (struct memory_map_parsing_data *) user_data;
88 const mem_region &r = data->memory_map->back ();
89
90 if (r.attrib.mode == MEM_FLASH && r.attrib.blocksize == -1)
91 gdb_xml_error (parser, _("Flash block size is not set"));
92 }
93
94 /* Handle the start of a <property> element by saving the name
95 attribute for later. */
96
97 static void
98 memory_map_start_property (struct gdb_xml_parser *parser,
99 const struct gdb_xml_element *element,
100 void *user_data, VEC(gdb_xml_value_s) *attributes)
101 {
102 struct memory_map_parsing_data *data
103 = (struct memory_map_parsing_data *) user_data;
104 char *name;
105
106 name = (char *) xml_find_attribute (attributes, "name")->value;
107 data->property_name.assign (name);
108 }
109
110 /* Handle the end of a <property> element and its value. */
111
112 static void
113 memory_map_end_property (struct gdb_xml_parser *parser,
114 const struct gdb_xml_element *element,
115 void *user_data, const char *body_text)
116 {
117 struct memory_map_parsing_data *data
118 = (struct memory_map_parsing_data *) user_data;
119
120 if (data->property_name == "blocksize")
121 {
122 mem_region &r = data->memory_map->back ();
123
124 r.attrib.blocksize = gdb_xml_parse_ulongest (parser, body_text);
125 }
126 else
127 gdb_xml_debug (parser, _("Unknown property \"%s\""),
128 data->property_name.c_str ());
129 }
130
131 /* The allowed elements and attributes for an XML memory map. */
132
133 const struct gdb_xml_attribute property_attributes[] = {
134 { "name", GDB_XML_AF_NONE, NULL, NULL },
135 { NULL, GDB_XML_AF_NONE, NULL, NULL }
136 };
137
138 const struct gdb_xml_element memory_children[] = {
139 { "property", property_attributes, NULL,
140 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
141 memory_map_start_property, memory_map_end_property },
142 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
143 };
144
145 const struct gdb_xml_enum memory_type_enum[] = {
146 { "ram", MEM_RW },
147 { "rom", MEM_RO },
148 { "flash", MEM_FLASH },
149 { NULL, 0 }
150 };
151
152 const struct gdb_xml_attribute memory_attributes[] = {
153 { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
154 { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
155 { "type", GDB_XML_AF_NONE, gdb_xml_parse_attr_enum, &memory_type_enum },
156 { NULL, GDB_XML_AF_NONE, NULL, NULL }
157 };
158
159 const struct gdb_xml_element memory_map_children[] = {
160 { "memory", memory_attributes, memory_children, GDB_XML_EF_REPEATABLE,
161 memory_map_start_memory, memory_map_end_memory },
162 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
163 };
164
165 const struct gdb_xml_element memory_map_elements[] = {
166 { "memory-map", NULL, memory_map_children, GDB_XML_EF_NONE,
167 NULL, NULL },
168 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
169 };
170
171 std::vector<mem_region>
172 parse_memory_map (const char *memory_map)
173 {
174 std::vector<mem_region> ret;
175 memory_map_parsing_data data (&ret);
176
177 if (gdb_xml_parse_quick (_("target memory map"), NULL, memory_map_elements,
178 memory_map, &data) == 0)
179 {
180 /* Parsed successfully, keep the result. */
181 return ret;
182 }
183
184 return std::vector<mem_region> ();
185 }
186
187 #endif /* HAVE_LIBEXPAT */
string
const char * string
Definition: signals.c:50
MEM_RO
Definition: memattr.h:27
memory_attributes
const struct gdb_xml_attribute memory_attributes[]
Definition: memory-map.c:152
memory_map_start_property
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)
Definition: memory-map.c:98
gdb_xml_value::value
void * value
Definition: xml-support.h:78
memory_type_enum
const struct gdb_xml_enum memory_type_enum[]
Definition: memory-map.c:145
warning
void warning(const char *fmt,...)
Definition: errors.c:26
gdb_xml_parse_attr_enum
gdb_xml_attribute_handler gdb_xml_parse_attr_enum
gdb_xml_parser
Definition: xml-support.c:68
memory_map_parsing_data
Definition: memory-map.c:45
gdb_xml_value
Definition: xml-support.h:75
VEC
#define VEC(T)
Definition: vec.h:414
_
#define _(String)
Definition: gdb_locale.h:35
memory_map_parsing_data::memory_map_parsing_data
memory_map_parsing_data(std::vector< mem_region > *memory_map_)
Definition: memory-map.c:47
defs.h
GDB_XML_AF_NONE
Definition: xml-support.h:106
memory_map_children
const struct gdb_xml_element memory_map_children[]
Definition: memory-map.c:159
memory_map_parsing_data::property_name
std::string property_name
Definition: memory-map.c:53
memory_map_end_property
static void memory_map_end_property(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, const char *body_text)
Definition: memory-map.c:113
name
const char *const name
Definition: aarch64-tdep.c:76
memory_map_parsing_data::memory_map
std::vector< mem_region > * memory_map
Definition: memory-map.c:51
GDB_XML_EF_NONE
Definition: xml-support.h:127
property_attributes
const struct gdb_xml_attribute property_attributes[]
Definition: memory-map.c:133
gdb_xml_parse_quick
int gdb_xml_parse_quick(const char *name, const char *dtd_name, const struct gdb_xml_element *elements, const char *document, void *user_data)
Definition: xml-support.c:647
xml_find_attribute
struct gdb_xml_value * xml_find_attribute(VEC(gdb_xml_value_s) *attributes, const char *name)
Definition: xml-support.c:231
gdb_xml_debug
void gdb_xml_debug(struct gdb_xml_parser *parser, const char *format,...)
Definition: xml-support.c:195
parse_memory_map
std::vector< mem_region > parse_memory_map(const char *memory_map)
Definition: memory-map.c:172
mem_region::attrib
mem_attrib attrib
Definition: memattr.h:125
xml-support.h
GDB_XML_EF_REPEATABLE
Definition: xml-support.h:129
memory_children
const struct gdb_xml_element memory_children[]
Definition: memory-map.c:138
memory_map_elements
const struct gdb_xml_element memory_map_elements[]
Definition: memory-map.c:165
gdb_xml_parse_ulongest
ULONGEST gdb_xml_parse_ulongest(struct gdb_xml_parser *parser, const char *value)
Definition: xml-support.c:684
mem_attrib::blocksize
int blocksize
Definition: memattr.h:80
gdb_xml_element
Definition: xml-support.h:165
gdb_xml_error
void gdb_xml_error(struct gdb_xml_parser *parser, const char *format,...)
Definition: xml-support.c:219
MEM_RW
Definition: memattr.h:26
memory_map_end_memory
static void memory_map_end_memory(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, const char *body_text)
Definition: memory-map.c:82
gdb_xml_parse_attr_ulongest
gdb_xml_attribute_handler gdb_xml_parse_attr_ulongest
mem_access_mode
mem_access_mode
Definition: memattr.h:23
ULONGEST
unsigned long long ULONGEST
Definition: common-types.h:53
memory_map_start_memory
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)
Definition: memory-map.c:59
gdb_xml_attribute
Definition: xml-support.h:114
GDB_XML_EF_OPTIONAL
Definition: xml-support.h:128
gdb_xml_enum
Definition: xml-support.h:214
MEM_FLASH
Definition: memattr.h:31
memory-map.h
mem_region
Definition: memattr.h:83
mem_attrib::mode
enum mem_access_mode mode
Definition: memattr.h:65