diff options
author | Tom Tromey <tom@tromey.com> | 2021-08-06 13:52:23 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-08-10 15:24:42 -0600 |
commit | 192786c72a36388dcf99e21b0335eca0977f3435 (patch) | |
tree | c64e73b3e1af207bbbf89b57a4a8a74168884906 /gdb/addrmap.c | |
parent | 69eadcc9eacf8d4a99ecfcb29c9fbb4eb398b9d8 (diff) | |
download | gdb-192786c72a36388dcf99e21b0335eca0977f3435.zip gdb-192786c72a36388dcf99e21b0335eca0977f3435.tar.gz gdb-192786c72a36388dcf99e21b0335eca0977f3435.tar.bz2 |
Generalize addrmap dumping
While debugging another patch series, I wanted to dump an addrmap. I
came up with this patch, which generalizes the addrmap-dumping code
from psymtab.c and moves it to addrmap.c. psymtab.c is changed to use
the new code.
Diffstat (limited to 'gdb/addrmap.c')
-rw-r--r-- | gdb/addrmap.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gdb/addrmap.c b/gdb/addrmap.c index 49e51a3..d16e0ae 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -590,6 +590,41 @@ addrmap_create_mutable (struct obstack *obstack) return (struct addrmap *) map; } +/* See addrmap.h. */ + +void +addrmap_dump (struct addrmap *map, struct ui_file *outfile, void *payload) +{ + /* True if the previously printed addrmap entry was for PAYLOAD. + If so, we want to print the next one as well (since the next + addrmap entry defines the end of the range). */ + bool previous_matched = false; + + auto callback = [&] (CORE_ADDR start_addr, void *obj) + { + QUIT; + + bool matches = payload == nullptr || payload == obj; + const char *addr_str = nullptr; + if (matches) + addr_str = host_address_to_string (obj); + else if (previous_matched) + addr_str = "<ends here>"; + + if (matches || previous_matched) + fprintf_filtered (outfile, " %s%s %s\n", + payload != nullptr ? " " : "", + core_addr_to_string (start_addr), + addr_str); + + previous_matched = matches; + + return 0; + }; + + addrmap_foreach (map, callback); +} + #if GDB_SELF_TEST namespace selftests { |