aboutsummaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2015-12-29 23:52:57 -0500
committerMike Frysinger <vapier@gentoo.org>2021-01-07 12:18:59 -0500
commite904f56d02afd68ffd9333435fe8b026f1e14b5f (patch)
tree21af166171abe5a1aa80ed2b2b37b8cbc9b64bcf /sim
parentf478212851a25cd9849ad7f41112d08f91ab308b (diff)
downloadfsf-binutils-gdb-e904f56d02afd68ffd9333435fe8b026f1e14b5f.zip
fsf-binutils-gdb-e904f56d02afd68ffd9333435fe8b026f1e14b5f.tar.gz
fsf-binutils-gdb-e904f56d02afd68ffd9333435fe8b026f1e14b5f.tar.bz2
gdb/sim: add support for exporting memory map
This allows gdb to quickly dump & process the memory map that the sim knows about. This isn't fully accurate, but is largely limited by the gdb memory map format. While the sim supports RWX bits, gdb can only handle RW or RO regions.
Diffstat (limited to 'sim')
-rw-r--r--sim/common/ChangeLog4
-rw-r--r--sim/common/sim-core.c57
2 files changed, 61 insertions, 0 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 0898a6f..05948f2 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,7 @@
+2021-01-07 Mike Frysinger <vapier@gentoo.org>
+
+ * sim-core.c (sim_memory_map): Define.
+
2021-01-04 Mike Frysinger <vapier@gentoo.org>
* acinclude.m4 (ACX_BUGURL): Change http:// to https://.
diff --git a/sim/common/sim-core.c b/sim/common/sim-core.c
index 74369aa..5382306 100644
--- a/sim/common/sim-core.c
+++ b/sim/common/sim-core.c
@@ -453,6 +453,63 @@ sim_core_translate (sim_core_mapping *mapping,
#if EXTERN_SIM_CORE_P
+/* See include/gdb/remote-sim.h. */
+char *
+sim_memory_map (SIM_DESC sd)
+{
+ sim_core *core = STATE_CORE (sd);
+ unsigned map;
+ char *s1, *s2, *entry;
+
+ s1 = xstrdup (
+ "<?xml version='1.0'?>\n"
+ "<!DOCTYPE memory-map PUBLIC '+//IDN gnu.org//DTD GDB Memory Map V1.0//EN'"
+ " 'http://sourceware.org/gdb/gdb-memory-map.dtd'>\n"
+ "<memory-map>\n");
+
+ for (map = 0; map < nr_maps; ++map)
+ {
+ sim_core_mapping *mapping;
+
+ for (mapping = core->common.map[map].first;
+ mapping != NULL;
+ mapping = mapping->next)
+ {
+ /* GDB can only handle a single address space. */
+ if (mapping->level != 0)
+ continue;
+
+ entry = xasprintf ("<memory type='ram' start='%#x' length='%#x'/>\n",
+ mapping->base, mapping->nr_bytes);
+ /* The sim memory map is organized by access, not by addresses.
+ So a RWX memory map will have three independent mappings.
+ GDB's format cannot support overlapping regions, so we have
+ to filter those out.
+
+ Further, GDB can only handle RX ("rom") or RWX ("ram") mappings.
+ We just emit "ram" everywhere to keep it simple. If GDB ever
+ gains support for more stuff, we can expand this.
+
+ Using strstr is kind of hacky, but as long as the map is not huge
+ (we're talking <10K), should be fine. */
+ if (strstr (s1, entry) == NULL)
+ {
+ s2 = concat (s1, entry, NULL);
+ free (s1);
+ s1 = s2;
+ }
+ free (entry);
+ }
+ }
+
+ s2 = concat (s1, "</memory-map>", NULL);
+ free (s1);
+ return s2;
+}
+#endif
+
+
+#if EXTERN_SIM_CORE_P
unsigned
sim_core_read_buffer (SIM_DESC sd,
sim_cpu *cpu,