Remove some TUI asserts
[deliverable/binutils-gdb.git] / gdb / memory-map.c
CommitLineData
fd79ecee
DJ
1/* Routines for handling XML memory maps provided by target.
2
42a4f53d 3 Copyright (C) 2006-2019 Free Software Foundation, Inc.
fd79ecee
DJ
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
fd79ecee
DJ
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fd79ecee
DJ
19
20#include "defs.h"
21#include "memory-map.h"
fd79ecee 22
fd79ecee
DJ
23#if !defined(HAVE_LIBEXPAT)
24
a664f67e 25std::vector<mem_region>
fd79ecee
DJ
26parse_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
a664f67e 37 return std::vector<mem_region> ();
fd79ecee
DJ
38}
39
40#else /* HAVE_LIBEXPAT */
41
42#include "xml-support.h"
fd79ecee 43
e776119f 44/* Internal parsing data passed to all XML callbacks. */
fd79ecee 45struct memory_map_parsing_data
6e17c565 46{
a664f67e
SM
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;
6e17c565
SM
52
53 std::string property_name;
54};
fd79ecee 55
e776119f
DJ
56/* Handle the start of a <memory> element. */
57
fd79ecee 58static void
e776119f
DJ
59memory_map_start_memory (struct gdb_xml_parser *parser,
60 const struct gdb_xml_element *element,
4d0fdd9b
SM
61 void *user_data,
62 std::vector<gdb_xml_value> &attributes)
fd79ecee 63{
19ba03f4
SM
64 struct memory_map_parsing_data *data
65 = (struct memory_map_parsing_data *) user_data;
e776119f
DJ
66 ULONGEST *start_p, *length_p, *type_p;
67
19ba03f4 68 start_p
4d0fdd9b 69 = (ULONGEST *) xml_find_attribute (attributes, "start")->value.get ();
19ba03f4 70 length_p
4d0fdd9b 71 = (ULONGEST *) xml_find_attribute (attributes, "length")->value.get ();
19ba03f4 72 type_p
4d0fdd9b 73 = (ULONGEST *) xml_find_attribute (attributes, "type")->value.get ();
e776119f 74
07431908 75 data->memory_map->emplace_back (*start_p, *start_p + *length_p,
a664f67e 76 (enum mem_access_mode) *type_p);
fd79ecee
DJ
77}
78
e776119f
DJ
79/* Handle the end of a <memory> element. Verify that any necessary
80 children were present. */
fd79ecee
DJ
81
82static void
e776119f
DJ
83memory_map_end_memory (struct gdb_xml_parser *parser,
84 const struct gdb_xml_element *element,
85 void *user_data, const char *body_text)
fd79ecee 86{
19ba03f4
SM
87 struct memory_map_parsing_data *data
88 = (struct memory_map_parsing_data *) user_data;
a664f67e 89 const mem_region &r = data->memory_map->back ();
fd79ecee 90
a664f67e 91 if (r.attrib.mode == MEM_FLASH && r.attrib.blocksize == -1)
e776119f 92 gdb_xml_error (parser, _("Flash block size is not set"));
fd79ecee
DJ
93}
94
e776119f
DJ
95/* Handle the start of a <property> element by saving the name
96 attribute for later. */
fd79ecee
DJ
97
98static void
e776119f
DJ
99memory_map_start_property (struct gdb_xml_parser *parser,
100 const struct gdb_xml_element *element,
4d0fdd9b
SM
101 void *user_data,
102 std::vector<gdb_xml_value> &attributes)
fd79ecee 103{
19ba03f4
SM
104 struct memory_map_parsing_data *data
105 = (struct memory_map_parsing_data *) user_data;
e776119f 106 char *name;
fd79ecee 107
4d0fdd9b 108 name = (char *) xml_find_attribute (attributes, "name")->value.get ();
6e17c565 109 data->property_name.assign (name);
fd79ecee
DJ
110}
111
e776119f 112/* Handle the end of a <property> element and its value. */
fd79ecee 113
fd79ecee 114static void
e776119f
DJ
115memory_map_end_property (struct gdb_xml_parser *parser,
116 const struct gdb_xml_element *element,
117 void *user_data, const char *body_text)
fd79ecee 118{
19ba03f4
SM
119 struct memory_map_parsing_data *data
120 = (struct memory_map_parsing_data *) user_data;
fd79ecee 121
6e17c565 122 if (data->property_name == "blocksize")
fd79ecee 123 {
a664f67e 124 mem_region &r = data->memory_map->back ();
fd79ecee 125
a664f67e 126 r.attrib.blocksize = gdb_xml_parse_ulongest (parser, body_text);
e776119f
DJ
127 }
128 else
6e17c565
SM
129 gdb_xml_debug (parser, _("Unknown property \"%s\""),
130 data->property_name.c_str ());
fd79ecee
DJ
131}
132
e776119f
DJ
133/* The allowed elements and attributes for an XML memory map. */
134
135const struct gdb_xml_attribute property_attributes[] = {
136 { "name", GDB_XML_AF_NONE, NULL, NULL },
137 { NULL, GDB_XML_AF_NONE, NULL, NULL }
138};
139
140const struct gdb_xml_element memory_children[] = {
141 { "property", property_attributes, NULL,
142 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
143 memory_map_start_property, memory_map_end_property },
144 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
145};
146
147const struct gdb_xml_enum memory_type_enum[] = {
148 { "ram", MEM_RW },
149 { "rom", MEM_RO },
150 { "flash", MEM_FLASH },
151 { NULL, 0 }
152};
153
154const struct gdb_xml_attribute memory_attributes[] = {
155 { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
156 { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
157 { "type", GDB_XML_AF_NONE, gdb_xml_parse_attr_enum, &memory_type_enum },
158 { NULL, GDB_XML_AF_NONE, NULL, NULL }
159};
160
161const struct gdb_xml_element memory_map_children[] = {
162 { "memory", memory_attributes, memory_children, GDB_XML_EF_REPEATABLE,
163 memory_map_start_memory, memory_map_end_memory },
164 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
165};
166
167const struct gdb_xml_element memory_map_elements[] = {
168 { "memory-map", NULL, memory_map_children, GDB_XML_EF_NONE,
169 NULL, NULL },
170 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
171};
172
a664f67e 173std::vector<mem_region>
fd79ecee
DJ
174parse_memory_map (const char *memory_map)
175{
a664f67e
SM
176 std::vector<mem_region> ret;
177 memory_map_parsing_data data (&ret);
fd79ecee 178
efc0eabd
PA
179 if (gdb_xml_parse_quick (_("target memory map"), NULL, memory_map_elements,
180 memory_map, &data) == 0)
181 {
182 /* Parsed successfully, keep the result. */
a664f67e 183 return ret;
efc0eabd 184 }
fd79ecee 185
a664f67e 186 return std::vector<mem_region> ();
fd79ecee
DJ
187}
188
189#endif /* HAVE_LIBEXPAT */
This page took 1.406704 seconds and 4 git commands to generate.