+ dump_p = (filterflags & COREFILTER_MAPPED_SHARED) != 0;
+ }
+
+ /* Even if we decided that we shouldn't dump this mapping, we still
+ have to check whether (a) the user wants us to dump mappings
+ containing an ELF header, and (b) the mapping in question
+ contains an ELF header. If (a) and (b) are true, then we should
+ dump this mapping.
+
+ A mapping contains an ELF header if it is a private mapping, its
+ offset is zero, and its first word is ELFMAG. */
+ if (!dump_p && private_p && offset == 0
+ && (filterflags & COREFILTER_ELF_HEADERS) != 0)
+ {
+ /* Let's check if we have an ELF header. */
+ gdb::unique_xmalloc_ptr<char> header;
+ int errcode;
+
+ /* Useful define specifying the size of the ELF magical
+ header. */
+#ifndef SELFMAG
+#define SELFMAG 4
+#endif
+
+ /* Read the first SELFMAG bytes and check if it is ELFMAG. */
+ if (target_read_string (addr, &header, SELFMAG, &errcode) == SELFMAG
+ && errcode == 0)
+ {
+ const char *h = header.get ();
+
+ /* The EI_MAG* and ELFMAG* constants come from
+ <elf/common.h>. */
+ if (h[EI_MAG0] == ELFMAG0 && h[EI_MAG1] == ELFMAG1
+ && h[EI_MAG2] == ELFMAG2 && h[EI_MAG3] == ELFMAG3)
+ {
+ /* This mapping contains an ELF header, so we
+ should dump it. */
+ dump_p = 1;
+ }
+ }