* [PATCH] Generalize addrmap dumping
@ 2021-08-06 22:26 Tom Tromey
2021-08-10 3:31 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2021-08-06 22:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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.
---
gdb/addrmap.c | 35 ++++++++++++++++++++++++++++++++
gdb/addrmap.h | 6 ++++++
gdb/psymtab.c | 56 +++++----------------------------------------------
3 files changed, 46 insertions(+), 51 deletions(-)
diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index 49e51a388e1..d16e0aeca20 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 {
diff --git a/gdb/addrmap.h b/gdb/addrmap.h
index 4b1a59684b1..5286a9261b0 100644
--- a/gdb/addrmap.h
+++ b/gdb/addrmap.h
@@ -104,4 +104,10 @@ typedef gdb::function_view<int (CORE_ADDR start_addr, void *obj)>
returns 0. */
int addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn);
+/* Dump the addrmap to OUTFILE. If PAYLOAD is non-NULL, only dump any
+ components that map to PAYLOAD. (If PAYLOAD is NULL, the entire
+ map is dumped.) */
+void addrmap_dump (struct addrmap *map, struct ui_file *outfile,
+ void *payload);
+
#endif /* ADDRMAP_H */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 4c5b10012ce..7ffb7437785 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1469,43 +1469,6 @@ psymtab_storage::discard_psymtab (struct partial_symtab *pst)
\f
-/* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
-
-static int
-dump_psymtab_addrmap_1 (struct objfile *objfile,
- struct partial_symtab *psymtab,
- struct ui_file *outfile,
- int *previous_matched,
- CORE_ADDR start_addr,
- void *obj)
-{
- struct gdbarch *gdbarch = objfile->arch ();
- struct partial_symtab *addrmap_psymtab = (struct partial_symtab *) obj;
- const char *psymtab_address_or_end = NULL;
-
- QUIT;
-
- if (psymtab == NULL
- || psymtab == addrmap_psymtab)
- psymtab_address_or_end = host_address_to_string (addrmap_psymtab);
- else if (*previous_matched)
- psymtab_address_or_end = "<ends here>";
-
- if (psymtab == NULL
- || psymtab == addrmap_psymtab
- || *previous_matched)
- {
- fprintf_filtered (outfile, " %s%s %s\n",
- psymtab != NULL ? " " : "",
- paddress (gdbarch, start_addr),
- psymtab_address_or_end);
- }
-
- *previous_matched = psymtab == NULL || psymtab == addrmap_psymtab;
-
- return 0;
-}
-
/* Helper function for maintenance_print_psymbols to print the addrmap
of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
@@ -1519,20 +1482,11 @@ dump_psymtab_addrmap (struct objfile *objfile,
|| psymtab->psymtabs_addrmap_supported)
&& partial_symtabs->psymtabs_addrmap != NULL)
{
- /* Non-zero if the previously printed addrmap entry was for
- PSYMTAB. If so, we want to print the next one as well (since
- the next addrmap entry defines the end of the range). */
- int previous_matched = 0;
-
- auto callback = [&] (CORE_ADDR start_addr, void *obj)
- {
- return dump_psymtab_addrmap_1 (objfile, psymtab, outfile,
- &previous_matched, start_addr, obj);
- };
-
- fprintf_filtered (outfile, "%sddress map:\n",
- psymtab == NULL ? "Entire a" : " A");
- addrmap_foreach (partial_symtabs->psymtabs_addrmap, callback);
+ if (psymtab == nullptr)
+ fprintf_filtered (outfile, _("Entire address map:\n"));
+ else
+ fprintf_filtered (outfile, _("Address map:\n"));
+ addrmap_dump (partial_symtabs->psymtabs_addrmap, outfile, psymtab);
}
}
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Generalize addrmap dumping
2021-08-06 22:26 [PATCH] Generalize addrmap dumping Tom Tromey
@ 2021-08-10 3:31 ` Simon Marchi
2021-08-10 21:22 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2021-08-10 3:31 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2021-08-06 6:26 p.m., Tom Tromey wrote:
> 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.
That looks reasonable to me. I presume that the upcoming series you refer
to will make use of this?
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Generalize addrmap dumping
2021-08-10 3:31 ` Simon Marchi
@ 2021-08-10 21:22 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2021-08-10 21:22 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
>> 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.
Simon> That looks reasonable to me. I presume that the upcoming series you refer
Simon> to will make use of this?
Nope, this was just so I could call addrmap_dump from gdb while
debugging that series.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-10 21:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 22:26 [PATCH] Generalize addrmap dumping Tom Tromey
2021-08-10 3:31 ` Simon Marchi
2021-08-10 21:22 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).