diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7dc6c4146ab..2a7ffde1f76 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2020-07-22 Kevin Buettner + + * corelow.c (gdbcmd.h): Include. + (core_target::info_proc_mappings): New method. + (get_current_core_target): New function. + (maintenance_print_core_file_backed_mappings): New function. + (_initialize_corelow): Add core-file-backed-mappings to + "maint print" commands. + 2020-07-22 Kevin Buettner * linux-tdep.c (dump_note_entry_p): New function. diff --git a/gdb/corelow.c b/gdb/corelow.c index 64a7613f295..2add78349a5 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -47,6 +47,7 @@ #include "build-id.h" #include "gdbsupport/pathstuff.h" #include +#include "gdbcmd.h" #ifndef O_LARGEFILE #define O_LARGEFILE 0 @@ -113,6 +114,9 @@ public: const char *human_name, bool required); + /* See definition. */ + void info_proc_mappings (struct gdbarch *gdbarch); + private: /* per-core data */ /* The core's section table. Note that these target sections are @@ -1029,9 +1033,92 @@ core_target::info_proc (const char *args, enum info_proc_what request) return true; } +/* Get a pointer to the current core target. If not connected to a + core target, return NULL. */ + +static core_target * +get_current_core_target () +{ + target_ops *proc_target = current_inferior ()->process_target (); + return dynamic_cast (proc_target); +} + +/* Display file backed mappings from core file. */ + +void +core_target::info_proc_mappings (struct gdbarch *gdbarch) +{ + if (m_core_file_mappings.sections != m_core_file_mappings.sections_end) + { + printf_filtered (_("Mapped address spaces:\n\n")); + if (gdbarch_addr_bit (gdbarch) == 32) + { + printf_filtered ("\t%10s %10s %10s %10s %s\n", + "Start Addr", + " End Addr", + " Size", " Offset", "objfile"); + } + else + { + printf_filtered (" %18s %18s %10s %10s %s\n", + "Start Addr", + " End Addr", + " Size", " Offset", "objfile"); + } + } + + for (const struct target_section *tsp = m_core_file_mappings.sections; + tsp < m_core_file_mappings.sections_end; + tsp++) + { + ULONGEST start = tsp->addr; + ULONGEST end = tsp->endaddr; + ULONGEST file_ofs = tsp->the_bfd_section->filepos; + const char *filename = bfd_get_filename (tsp->the_bfd_section->owner); + + if (gdbarch_addr_bit (gdbarch) == 32) + printf_filtered ("\t%10s %10s %10s %10s %s\n", + paddress (gdbarch, start), + paddress (gdbarch, end), + hex_string (end - start), + hex_string (file_ofs), + filename); + else + printf_filtered (" %18s %18s %10s %10s %s\n", + paddress (gdbarch, start), + paddress (gdbarch, end), + hex_string (end - start), + hex_string (file_ofs), + filename); + } +} + +/* Implement "maintenance print core-file-backed-mappings" command. + + If mappings are loaded, the results should be similar to the + mappings shown by "info proc mappings". This command is mainly a + debugging tool for GDB developers to make sure that the expected + mappings are present after loading a core file. For Linux, the + output provided by this command will be very similar (if not + identical) to that provided by "info proc mappings". This is not + necessarily the case for other OSes which might provide + more/different information in the "info proc mappings" output. */ + +static void +maintenance_print_core_file_backed_mappings (const char *args, int from_tty) +{ + core_target *targ = get_current_core_target (); + if (targ != nullptr) + targ->info_proc_mappings (targ->core_gdbarch ()); +} + void _initialize_corelow (); void _initialize_corelow () { add_target (core_target_info, core_target_open, filename_completer); + add_cmd ("core-file-backed-mappings", class_maintenance, + maintenance_print_core_file_backed_mappings, + _("Print core file's file-backed mappings"), + &maintenanceprintlist); }