Commit | Line | Data |
---|---|---|
80629b1b | 1 | /* Memory attributes support, for GDB. |
14a5e767 | 2 | |
61baf725 | 3 | Copyright (C) 2001-2017 Free Software Foundation, Inc. |
80629b1b EZ |
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 |
80629b1b EZ |
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/>. */ |
80629b1b | 19 | |
29e57380 C |
20 | #include "defs.h" |
21 | #include "command.h" | |
22 | #include "gdbcmd.h" | |
23 | #include "memattr.h" | |
24 | #include "target.h" | |
68c765e2 | 25 | #include "target-dcache.h" |
29e57380 C |
26 | #include "value.h" |
27 | #include "language.h" | |
c96fc75e | 28 | #include "vec.h" |
fbcb778d | 29 | #include "breakpoint.h" |
197f0a60 | 30 | #include "cli/cli-utils.h" |
a664f67e | 31 | #include <algorithm> |
29e57380 | 32 | |
a664f67e SM |
33 | static std::vector<mem_region> user_mem_region_list, target_mem_region_list; |
34 | static std::vector<mem_region> *mem_region_list = &target_mem_region_list; | |
f4d650ec | 35 | static int mem_number = 0; |
29e57380 | 36 | |
fd79ecee DJ |
37 | /* If this flag is set, the memory region list should be automatically |
38 | updated from the target. If it is clear, the list is user-controlled | |
39 | and should be left alone. */ | |
a664f67e SM |
40 | |
41 | static bool | |
42 | mem_use_target () | |
43 | { | |
44 | return mem_region_list == &target_mem_region_list; | |
45 | } | |
fd79ecee DJ |
46 | |
47 | /* If this flag is set, we have tried to fetch the target memory regions | |
48 | since the last time it was invalidated. If that list is still | |
49 | empty, then the target can't supply memory regions. */ | |
a664f67e | 50 | static bool target_mem_regions_valid; |
fd79ecee | 51 | |
4b5752d0 VP |
52 | /* If this flag is set, gdb will assume that memory ranges not |
53 | specified by the memory map have type MEM_NONE, and will | |
54 | emit errors on all accesses to that memory. */ | |
56cf5405 | 55 | static int inaccessible_by_default = 1; |
4b5752d0 VP |
56 | |
57 | static void | |
58 | show_inaccessible_by_default (struct ui_file *file, int from_tty, | |
59 | struct cmd_list_element *c, | |
60 | const char *value) | |
61 | { | |
62 | if (inaccessible_by_default) | |
3e43a32a MS |
63 | fprintf_filtered (file, _("Unknown memory addresses will " |
64 | "be treated as inaccessible.\n")); | |
4b5752d0 | 65 | else |
3e43a32a MS |
66 | fprintf_filtered (file, _("Unknown memory addresses " |
67 | "will be treated as RAM.\n")); | |
4b5752d0 VP |
68 | } |
69 | ||
fd79ecee DJ |
70 | /* This function should be called before any command which would |
71 | modify the memory region list. It will handle switching from | |
72 | a target-provided list to a local list, if necessary. */ | |
73 | ||
74 | static void | |
75 | require_user_regions (int from_tty) | |
76 | { | |
77 | struct mem_region *m; | |
78 | int ix, length; | |
79 | ||
80 | /* If we're already using a user-provided list, nothing to do. */ | |
a664f67e | 81 | if (!mem_use_target ()) |
fd79ecee DJ |
82 | return; |
83 | ||
84 | /* Switch to a user-provided list (possibly a copy of the current | |
85 | one). */ | |
a664f67e | 86 | mem_region_list = &user_mem_region_list; |
fd79ecee DJ |
87 | |
88 | /* If we don't have a target-provided region list yet, then | |
89 | no need to warn. */ | |
a664f67e | 90 | if (target_mem_region_list.empty ()) |
fd79ecee DJ |
91 | return; |
92 | ||
93 | /* Otherwise, let the user know how to get back. */ | |
94 | if (from_tty) | |
95 | warning (_("Switching to manual control of memory regions; use " | |
96 | "\"mem auto\" to fetch regions from the target again.")); | |
97 | ||
a664f67e SM |
98 | /* And create a new list (copy of the target-supplied regions) for the user |
99 | to modify. */ | |
100 | user_mem_region_list = target_mem_region_list; | |
fd79ecee DJ |
101 | } |
102 | ||
103 | /* This function should be called before any command which would | |
104 | read the memory region list, other than those which call | |
105 | require_user_regions. It will handle fetching the | |
106 | target-provided list, if necessary. */ | |
107 | ||
108 | static void | |
109 | require_target_regions (void) | |
110 | { | |
a664f67e | 111 | if (mem_use_target () && !target_mem_regions_valid) |
fd79ecee | 112 | { |
a664f67e | 113 | target_mem_regions_valid = true; |
fd79ecee | 114 | target_mem_region_list = target_memory_map (); |
fd79ecee DJ |
115 | } |
116 | } | |
117 | ||
a664f67e SM |
118 | /* Create a new user-defined memory region. */ |
119 | ||
c96fc75e | 120 | static void |
a664f67e SM |
121 | create_user_mem_region (CORE_ADDR lo, CORE_ADDR hi, |
122 | const mem_attrib &attrib) | |
29e57380 | 123 | { |
025bb325 | 124 | /* lo == hi is a useless empty region. */ |
2b236d82 | 125 | if (lo >= hi && hi != 0) |
29e57380 | 126 | { |
a3f17187 | 127 | printf_unfiltered (_("invalid memory region: low >= high\n")); |
c96fc75e | 128 | return; |
29e57380 C |
129 | } |
130 | ||
a664f67e | 131 | mem_region newobj (lo, hi, attrib); |
c96fc75e | 132 | |
a664f67e SM |
133 | auto it = std::lower_bound (user_mem_region_list.begin (), |
134 | user_mem_region_list.end (), | |
135 | newobj); | |
136 | int ix = std::distance (user_mem_region_list.begin (), it); | |
c96fc75e DJ |
137 | |
138 | /* Check for an overlapping memory region. We only need to check | |
139 | in the vicinity - at most one before and one after the | |
140 | insertion point. */ | |
a664f67e | 141 | for (int i = ix - 1; i < ix + 1; i++) |
29e57380 | 142 | { |
c96fc75e DJ |
143 | if (i < 0) |
144 | continue; | |
a664f67e | 145 | if (i >= user_mem_region_list.size ()) |
c96fc75e DJ |
146 | continue; |
147 | ||
a664f67e | 148 | mem_region &n = user_mem_region_list[i]; |
c96fc75e | 149 | |
a664f67e SM |
150 | if ((lo >= n.lo && (lo < n.hi || n.hi == 0)) |
151 | || (hi > n.lo && (hi <= n.hi || n.hi == 0)) | |
152 | || (lo <= n.lo && ((hi >= n.hi && n.hi != 0) || hi == 0))) | |
29e57380 | 153 | { |
a3f17187 | 154 | printf_unfiltered (_("overlapping memory region\n")); |
c96fc75e | 155 | return; |
29e57380 C |
156 | } |
157 | } | |
158 | ||
fe978cb0 | 159 | newobj.number = ++mem_number; |
a664f67e | 160 | user_mem_region_list.insert (it, newobj); |
29e57380 C |
161 | } |
162 | ||
a664f67e SM |
163 | /* Look up the memory region corresponding to ADDR. */ |
164 | ||
29e57380 C |
165 | struct mem_region * |
166 | lookup_mem_region (CORE_ADDR addr) | |
167 | { | |
a664f67e | 168 | static struct mem_region region (0, 0); |
29e57380 C |
169 | struct mem_region *m; |
170 | CORE_ADDR lo; | |
171 | CORE_ADDR hi; | |
c96fc75e | 172 | int ix; |
29e57380 | 173 | |
fd79ecee DJ |
174 | require_target_regions (); |
175 | ||
29e57380 C |
176 | /* First we initialize LO and HI so that they describe the entire |
177 | memory space. As we process the memory region chain, they are | |
178 | redefined to describe the minimal region containing ADDR. LO | |
179 | and HI are used in the case where no memory region is defined | |
180 | that contains ADDR. If a memory region is disabled, it is | |
a76d924d DJ |
181 | treated as if it does not exist. The initial values for LO |
182 | and HI represent the bottom and top of memory. */ | |
29e57380 | 183 | |
a76d924d DJ |
184 | lo = 0; |
185 | hi = 0; | |
29e57380 | 186 | |
a664f67e | 187 | /* Either find memory range containing ADDR, or set LO and HI |
4b5752d0 VP |
188 | to the nearest boundaries of an existing memory range. |
189 | ||
190 | If we ever want to support a huge list of memory regions, this | |
c96fc75e DJ |
191 | check should be replaced with a binary search (probably using |
192 | VEC_lower_bound). */ | |
a664f67e | 193 | for (mem_region &m : *mem_region_list) |
29e57380 | 194 | { |
a664f67e | 195 | if (m.enabled_p == 1) |
29e57380 | 196 | { |
3e43a32a MS |
197 | /* If the address is in the memory region, return that |
198 | memory range. */ | |
a664f67e SM |
199 | if (addr >= m.lo && (addr < m.hi || m.hi == 0)) |
200 | return &m; | |
29e57380 | 201 | |
a76d924d DJ |
202 | /* This (correctly) won't match if m->hi == 0, representing |
203 | the top of the address space, because CORE_ADDR is unsigned; | |
204 | no value of LO is less than zero. */ | |
a664f67e SM |
205 | if (addr >= m.hi && lo < m.hi) |
206 | lo = m.hi; | |
29e57380 | 207 | |
a76d924d DJ |
208 | /* This will never set HI to zero; if we're here and ADDR |
209 | is at or below M, and the region starts at zero, then ADDR | |
210 | would have been in the region. */ | |
a664f67e SM |
211 | if (addr <= m.lo && (hi == 0 || hi > m.lo)) |
212 | hi = m.lo; | |
29e57380 C |
213 | } |
214 | } | |
215 | ||
216 | /* Because no region was found, we must cons up one based on what | |
217 | was learned above. */ | |
218 | region.lo = lo; | |
219 | region.hi = hi; | |
4b5752d0 VP |
220 | |
221 | /* When no memory map is defined at all, we always return | |
222 | 'default_mem_attrib', so that we do not make all memory | |
223 | inaccessible for targets that don't provide a memory map. */ | |
a664f67e SM |
224 | if (inaccessible_by_default && !mem_region_list->empty ()) |
225 | region.attrib = mem_attrib::unknown (); | |
4b5752d0 | 226 | else |
a664f67e | 227 | region.attrib = mem_attrib (); |
4b5752d0 | 228 | |
29e57380 C |
229 | return ®ion; |
230 | } | |
fd79ecee DJ |
231 | |
232 | /* Invalidate any memory regions fetched from the target. */ | |
233 | ||
234 | void | |
235 | invalidate_target_mem_regions (void) | |
236 | { | |
fd79ecee DJ |
237 | if (!target_mem_regions_valid) |
238 | return; | |
239 | ||
a664f67e SM |
240 | target_mem_regions_valid = false; |
241 | target_mem_region_list.clear (); | |
fd79ecee DJ |
242 | } |
243 | ||
a664f67e | 244 | /* Clear user-defined memory region list. */ |
fd79ecee DJ |
245 | |
246 | static void | |
a664f67e | 247 | user_mem_clear (void) |
fd79ecee | 248 | { |
a664f67e | 249 | user_mem_region_list.clear (); |
fd79ecee | 250 | } |
29e57380 C |
251 | \f |
252 | ||
253 | static void | |
0b39b52e | 254 | mem_command (const char *args, int from_tty) |
29e57380 C |
255 | { |
256 | CORE_ADDR lo, hi; | |
29e57380 C |
257 | |
258 | if (!args) | |
e2e0b3e5 | 259 | error_no_arg (_("No mem")); |
29e57380 | 260 | |
fd79ecee DJ |
261 | /* For "mem auto", switch back to using a target provided list. */ |
262 | if (strcmp (args, "auto") == 0) | |
263 | { | |
a664f67e | 264 | if (mem_use_target ()) |
fd79ecee DJ |
265 | return; |
266 | ||
a664f67e SM |
267 | user_mem_clear (); |
268 | mem_region_list = &target_mem_region_list; | |
fd79ecee | 269 | |
fd79ecee DJ |
270 | return; |
271 | } | |
272 | ||
273 | require_user_regions (from_tty); | |
274 | ||
0b39b52e TT |
275 | std::string tok = extract_arg (&args); |
276 | if (tok == "") | |
8a3fe4f8 | 277 | error (_("no lo address")); |
0b39b52e | 278 | lo = parse_and_eval_address (tok.c_str ()); |
29e57380 | 279 | |
0b39b52e TT |
280 | tok = extract_arg (&args); |
281 | if (tok == "") | |
8a3fe4f8 | 282 | error (_("no hi address")); |
0b39b52e | 283 | hi = parse_and_eval_address (tok.c_str ()); |
29e57380 | 284 | |
a664f67e | 285 | mem_attrib attrib; |
0b39b52e | 286 | while ((tok = extract_arg (&args)) != "") |
29e57380 | 287 | { |
0b39b52e | 288 | if (tok == "rw") |
29e57380 | 289 | attrib.mode = MEM_RW; |
0b39b52e | 290 | else if (tok == "ro") |
29e57380 | 291 | attrib.mode = MEM_RO; |
0b39b52e | 292 | else if (tok == "wo") |
29e57380 C |
293 | attrib.mode = MEM_WO; |
294 | ||
0b39b52e | 295 | else if (tok == "8") |
29e57380 | 296 | attrib.width = MEM_WIDTH_8; |
0b39b52e | 297 | else if (tok == "16") |
29e57380 C |
298 | { |
299 | if ((lo % 2 != 0) || (hi % 2 != 0)) | |
8a3fe4f8 | 300 | error (_("region bounds not 16 bit aligned")); |
29e57380 C |
301 | attrib.width = MEM_WIDTH_16; |
302 | } | |
0b39b52e | 303 | else if (tok == "32") |
29e57380 C |
304 | { |
305 | if ((lo % 4 != 0) || (hi % 4 != 0)) | |
8a3fe4f8 | 306 | error (_("region bounds not 32 bit aligned")); |
29e57380 C |
307 | attrib.width = MEM_WIDTH_32; |
308 | } | |
0b39b52e | 309 | else if (tok == "64") |
29e57380 C |
310 | { |
311 | if ((lo % 8 != 0) || (hi % 8 != 0)) | |
8a3fe4f8 | 312 | error (_("region bounds not 64 bit aligned")); |
29e57380 C |
313 | attrib.width = MEM_WIDTH_64; |
314 | } | |
315 | ||
316 | #if 0 | |
0b39b52e | 317 | else if (tok == "hwbreak") |
81a9a963 | 318 | attrib.hwbreak = 1; |
0b39b52e | 319 | else if (tok == "swbreak") |
81a9a963 | 320 | attrib.hwbreak = 0; |
29e57380 C |
321 | #endif |
322 | ||
0b39b52e | 323 | else if (tok == "cache") |
81a9a963 | 324 | attrib.cache = 1; |
0b39b52e | 325 | else if (tok == "nocache") |
81a9a963 | 326 | attrib.cache = 0; |
29e57380 C |
327 | |
328 | #if 0 | |
0b39b52e | 329 | else if (tok == "verify") |
81a9a963 | 330 | attrib.verify = 1; |
0b39b52e | 331 | else if (tok == "noverify") |
81a9a963 | 332 | attrib.verify = 0; |
29e57380 C |
333 | #endif |
334 | ||
335 | else | |
0b39b52e | 336 | error (_("unknown attribute: %s"), tok.c_str ()); |
29e57380 C |
337 | } |
338 | ||
a664f67e | 339 | create_user_mem_region (lo, hi, attrib); |
29e57380 C |
340 | } |
341 | \f | |
342 | ||
343 | static void | |
1d12d88f | 344 | info_mem_command (const char *args, int from_tty) |
29e57380 | 345 | { |
a664f67e | 346 | if (mem_use_target ()) |
fd79ecee DJ |
347 | printf_filtered (_("Using memory regions provided by the target.\n")); |
348 | else | |
349 | printf_filtered (_("Using user-defined memory regions.\n")); | |
350 | ||
351 | require_target_regions (); | |
352 | ||
a664f67e | 353 | if (mem_region_list->empty ()) |
29e57380 | 354 | { |
a3f17187 | 355 | printf_unfiltered (_("There are no memory regions defined.\n")); |
29e57380 C |
356 | return; |
357 | } | |
358 | ||
ab35b611 EZ |
359 | printf_filtered ("Num "); |
360 | printf_filtered ("Enb "); | |
361 | printf_filtered ("Low Addr "); | |
f5656ead | 362 | if (gdbarch_addr_bit (target_gdbarch ()) > 32) |
ab35b611 EZ |
363 | printf_filtered (" "); |
364 | printf_filtered ("High Addr "); | |
f5656ead | 365 | if (gdbarch_addr_bit (target_gdbarch ()) > 32) |
ab35b611 EZ |
366 | printf_filtered (" "); |
367 | printf_filtered ("Attrs "); | |
368 | printf_filtered ("\n"); | |
369 | ||
a664f67e | 370 | for (const mem_region &m : *mem_region_list) |
29e57380 | 371 | { |
a121b7c1 | 372 | const char *tmp; |
b8d56208 | 373 | |
ab35b611 | 374 | printf_filtered ("%-3d %-3c\t", |
a664f67e SM |
375 | m.number, |
376 | m.enabled_p ? 'y' : 'n'); | |
f5656ead | 377 | if (gdbarch_addr_bit (target_gdbarch ()) <= 32) |
a664f67e | 378 | tmp = hex_string_custom (m.lo, 8); |
ab35b611 | 379 | else |
a664f67e | 380 | tmp = hex_string_custom (m.lo, 16); |
ab35b611 EZ |
381 | |
382 | printf_filtered ("%s ", tmp); | |
2b236d82 | 383 | |
f5656ead | 384 | if (gdbarch_addr_bit (target_gdbarch ()) <= 32) |
2163ab9d | 385 | { |
a664f67e | 386 | if (m.hi == 0) |
b8d56208 MS |
387 | tmp = "0x100000000"; |
388 | else | |
a664f67e | 389 | tmp = hex_string_custom (m.hi, 8); |
2163ab9d | 390 | } |
ab35b611 | 391 | else |
2163ab9d | 392 | { |
a664f67e | 393 | if (m.hi == 0) |
b8d56208 MS |
394 | tmp = "0x10000000000000000"; |
395 | else | |
a664f67e | 396 | tmp = hex_string_custom (m.hi, 16); |
2163ab9d DH |
397 | } |
398 | ||
ab35b611 | 399 | printf_filtered ("%s ", tmp); |
29e57380 C |
400 | |
401 | /* Print a token for each attribute. | |
402 | ||
403 | * FIXME: Should we output a comma after each token? It may | |
404 | * make it easier for users to read, but we'd lose the ability | |
405 | * to cut-and-paste the list of attributes when defining a new | |
406 | * region. Perhaps that is not important. | |
407 | * | |
408 | * FIXME: If more attributes are added to GDB, the output may | |
409 | * become cluttered and difficult for users to read. At that | |
410 | * time, we may want to consider printing tokens only if they | |
411 | * are different from the default attribute. */ | |
412 | ||
a664f67e | 413 | switch (m.attrib.mode) |
29e57380 C |
414 | { |
415 | case MEM_RW: | |
416 | printf_filtered ("rw "); | |
417 | break; | |
418 | case MEM_RO: | |
419 | printf_filtered ("ro "); | |
420 | break; | |
421 | case MEM_WO: | |
422 | printf_filtered ("wo "); | |
423 | break; | |
fd79ecee | 424 | case MEM_FLASH: |
a664f67e | 425 | printf_filtered ("flash blocksize 0x%x ", m.attrib.blocksize); |
fd79ecee | 426 | break; |
29e57380 C |
427 | } |
428 | ||
a664f67e | 429 | switch (m.attrib.width) |
29e57380 C |
430 | { |
431 | case MEM_WIDTH_8: | |
432 | printf_filtered ("8 "); | |
433 | break; | |
434 | case MEM_WIDTH_16: | |
435 | printf_filtered ("16 "); | |
436 | break; | |
437 | case MEM_WIDTH_32: | |
438 | printf_filtered ("32 "); | |
439 | break; | |
440 | case MEM_WIDTH_64: | |
441 | printf_filtered ("64 "); | |
442 | break; | |
443 | case MEM_WIDTH_UNSPECIFIED: | |
444 | break; | |
445 | } | |
446 | ||
447 | #if 0 | |
448 | if (attrib->hwbreak) | |
449 | printf_filtered ("hwbreak"); | |
450 | else | |
451 | printf_filtered ("swbreak"); | |
452 | #endif | |
453 | ||
a664f67e | 454 | if (m.attrib.cache) |
29e57380 C |
455 | printf_filtered ("cache "); |
456 | else | |
457 | printf_filtered ("nocache "); | |
458 | ||
459 | #if 0 | |
460 | if (attrib->verify) | |
461 | printf_filtered ("verify "); | |
462 | else | |
463 | printf_filtered ("noverify "); | |
464 | #endif | |
465 | ||
466 | printf_filtered ("\n"); | |
467 | ||
468 | gdb_flush (gdb_stdout); | |
469 | } | |
470 | } | |
471 | \f | |
472 | ||
025bb325 | 473 | /* Enable the memory region number NUM. */ |
29e57380 C |
474 | |
475 | static void | |
476 | mem_enable (int num) | |
477 | { | |
a664f67e SM |
478 | for (mem_region &m : *mem_region_list) |
479 | if (m.number == num) | |
29e57380 | 480 | { |
a664f67e | 481 | m.enabled_p = 1; |
29e57380 C |
482 | return; |
483 | } | |
a3f17187 | 484 | printf_unfiltered (_("No memory region number %d.\n"), num); |
29e57380 C |
485 | } |
486 | ||
487 | static void | |
4465d9db | 488 | enable_mem_command (const char *args, int from_tty) |
29e57380 | 489 | { |
fd79ecee DJ |
490 | require_user_regions (from_tty); |
491 | ||
4e5d721f | 492 | target_dcache_invalidate (); |
29e57380 | 493 | |
fbcb778d MS |
494 | if (args == NULL || *args == '\0') |
495 | { /* Enable all mem regions. */ | |
a664f67e SM |
496 | for (mem_region &m : *mem_region_list) |
497 | m.enabled_p = 1; | |
29e57380 C |
498 | } |
499 | else | |
197f0a60 | 500 | { |
bfd28288 PA |
501 | number_or_range_parser parser (args); |
502 | while (!parser.finished ()) | |
197f0a60 | 503 | { |
a664f67e | 504 | int num = parser.get_number (); |
197f0a60 TT |
505 | mem_enable (num); |
506 | } | |
507 | } | |
29e57380 C |
508 | } |
509 | \f | |
510 | ||
025bb325 | 511 | /* Disable the memory region number NUM. */ |
29e57380 C |
512 | |
513 | static void | |
514 | mem_disable (int num) | |
515 | { | |
a664f67e SM |
516 | for (mem_region &m : *mem_region_list) |
517 | if (m.number == num) | |
29e57380 | 518 | { |
a664f67e | 519 | m.enabled_p = 0; |
29e57380 C |
520 | return; |
521 | } | |
a3f17187 | 522 | printf_unfiltered (_("No memory region number %d.\n"), num); |
29e57380 C |
523 | } |
524 | ||
525 | static void | |
4465d9db | 526 | disable_mem_command (const char *args, int from_tty) |
29e57380 | 527 | { |
fd79ecee DJ |
528 | require_user_regions (from_tty); |
529 | ||
4e5d721f | 530 | target_dcache_invalidate (); |
29e57380 | 531 | |
fbcb778d | 532 | if (args == NULL || *args == '\0') |
29e57380 | 533 | { |
bfd28288 PA |
534 | struct mem_region *m; |
535 | int ix; | |
536 | ||
a664f67e SM |
537 | for (mem_region &m : *mem_region_list) |
538 | m.enabled_p = false; | |
29e57380 C |
539 | } |
540 | else | |
197f0a60 | 541 | { |
bfd28288 PA |
542 | number_or_range_parser parser (args); |
543 | while (!parser.finished ()) | |
197f0a60 | 544 | { |
bfd28288 | 545 | int num = parser.get_number (); |
197f0a60 TT |
546 | mem_disable (num); |
547 | } | |
548 | } | |
29e57380 C |
549 | } |
550 | ||
025bb325 | 551 | /* Delete the memory region number NUM. */ |
29e57380 C |
552 | |
553 | static void | |
554 | mem_delete (int num) | |
555 | { | |
6b4398f7 | 556 | struct mem_region *m; |
c96fc75e | 557 | int ix; |
29e57380 | 558 | |
c96fc75e | 559 | if (!mem_region_list) |
29e57380 | 560 | { |
a3f17187 | 561 | printf_unfiltered (_("No memory region number %d.\n"), num); |
29e57380 C |
562 | return; |
563 | } | |
564 | ||
a664f67e SM |
565 | auto it = std::remove_if (mem_region_list->begin (), mem_region_list->end (), |
566 | [num] (const mem_region &m) | |
29e57380 | 567 | { |
a664f67e SM |
568 | return m.number == num; |
569 | }); | |
c96fc75e | 570 | |
a664f67e SM |
571 | if (it != mem_region_list->end ()) |
572 | mem_region_list->erase (it); | |
573 | else | |
574 | printf_unfiltered (_("No memory region number %d.\n"), num); | |
29e57380 C |
575 | } |
576 | ||
577 | static void | |
4465d9db | 578 | delete_mem_command (const char *args, int from_tty) |
29e57380 | 579 | { |
fd79ecee DJ |
580 | require_user_regions (from_tty); |
581 | ||
4e5d721f | 582 | target_dcache_invalidate (); |
29e57380 | 583 | |
fbcb778d | 584 | if (args == NULL || *args == '\0') |
29e57380 | 585 | { |
9e2f0ad4 | 586 | if (query (_("Delete all memory regions? "))) |
a664f67e | 587 | user_mem_clear (); |
29e57380 C |
588 | dont_repeat (); |
589 | return; | |
590 | } | |
591 | ||
bfd28288 PA |
592 | number_or_range_parser parser (args); |
593 | while (!parser.finished ()) | |
29e57380 | 594 | { |
bfd28288 | 595 | int num = parser.get_number (); |
29e57380 | 596 | mem_delete (num); |
29e57380 C |
597 | } |
598 | ||
599 | dont_repeat (); | |
600 | } | |
4b5752d0 VP |
601 | |
602 | static void | |
981a3fb3 | 603 | dummy_cmd (const char *args, int from_tty) |
4b5752d0 VP |
604 | { |
605 | } | |
b9362cc7 | 606 | |
4b5752d0 VP |
607 | static struct cmd_list_element *mem_set_cmdlist; |
608 | static struct cmd_list_element *mem_show_cmdlist; | |
609 | ||
29e57380 | 610 | void |
5ae5f592 | 611 | _initialize_mem (void) |
29e57380 | 612 | { |
1bedd215 | 613 | add_com ("mem", class_vars, mem_command, _("\ |
fd79ecee DJ |
614 | Define attributes for memory region or reset memory region handling to\n\ |
615 | target-based.\n\ | |
616 | Usage: mem auto\n\ | |
cce7e648 PA |
617 | mem <lo addr> <hi addr> [<mode> <width> <cache>],\n\ |
618 | where <mode> may be rw (read/write), ro (read-only) or wo (write-only),\n\ | |
619 | <width> may be 8, 16, 32, or 64, and\n\ | |
1bedd215 | 620 | <cache> may be cache or nocache")); |
29e57380 | 621 | |
ae3b3f34 | 622 | add_cmd ("mem", class_vars, enable_mem_command, _("\ |
1a966eab | 623 | Enable memory region.\n\ |
29e57380 | 624 | Arguments are the code numbers of the memory regions to enable.\n\ |
fbcb778d | 625 | Usage: enable mem <code number>...\n\ |
1a966eab | 626 | Do \"info mem\" to see current list of code numbers."), &enablelist); |
29e57380 | 627 | |
ae3b3f34 | 628 | add_cmd ("mem", class_vars, disable_mem_command, _("\ |
1a966eab | 629 | Disable memory region.\n\ |
29e57380 | 630 | Arguments are the code numbers of the memory regions to disable.\n\ |
fbcb778d | 631 | Usage: disable mem <code number>...\n\ |
1a966eab | 632 | Do \"info mem\" to see current list of code numbers."), &disablelist); |
29e57380 | 633 | |
ae3b3f34 | 634 | add_cmd ("mem", class_vars, delete_mem_command, _("\ |
1a966eab | 635 | Delete memory region.\n\ |
29e57380 | 636 | Arguments are the code numbers of the memory regions to delete.\n\ |
fbcb778d | 637 | Usage: delete mem <code number>...\n\ |
1a966eab | 638 | Do \"info mem\" to see current list of code numbers."), &deletelist); |
29e57380 | 639 | |
ae3b3f34 | 640 | add_info ("mem", info_mem_command, |
1bedd215 | 641 | _("Memory region attributes")); |
4b5752d0 VP |
642 | |
643 | add_prefix_cmd ("mem", class_vars, dummy_cmd, _("\ | |
644 | Memory regions settings"), | |
645 | &mem_set_cmdlist, "set mem ", | |
646 | 0/* allow-unknown */, &setlist); | |
647 | add_prefix_cmd ("mem", class_vars, dummy_cmd, _("\ | |
648 | Memory regions settings"), | |
649 | &mem_show_cmdlist, "show mem ", | |
650 | 0/* allow-unknown */, &showlist); | |
651 | ||
652 | add_setshow_boolean_cmd ("inaccessible-by-default", no_class, | |
653 | &inaccessible_by_default, _("\ | |
654 | Set handling of unknown memory regions."), _("\ | |
655 | Show handling of unknown memory regions."), _("\ | |
656 | If on, and some memory map is defined, debugger will emit errors on\n\ | |
657 | accesses to memory not defined in the memory map. If off, accesses to all\n\ | |
658 | memory addresses will be allowed."), | |
659 | NULL, | |
660 | show_inaccessible_by_default, | |
661 | &mem_set_cmdlist, | |
662 | &mem_show_cmdlist); | |
29e57380 | 663 | } |