From b315ab2151bc2501de3ab6f0075ecc1646c2ae67 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 27 Jun 2011 08:41:39 +0000 Subject: [PATCH] 2011-06-27 Tristan Gingold * dwarf2read.c (struct dwarf2_section_info): Replace was_mmapped field by map_addr and map_len. (dwarf2_read_section): Adjust for the new bfd_mmap api. (munmap_section_buffer): Likewise. --- gdb/ChangeLog | 7 +++++++ gdb/dwarf2read.c | 29 ++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b10ce0ff91..cd62b1c941 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2011-06-27 Tristan Gingold + + * dwarf2read.c (struct dwarf2_section_info): Replace was_mmapped + field by map_addr and map_len. + (dwarf2_read_section): Adjust for the new bfd_mmap api. + (munmap_section_buffer): Likewise. + 2011-06-24 Tom Tromey * varobj.c (update_dynamic_varobj_children): Make 'name' const. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 399d593221..cfe0514eb8 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -134,7 +134,10 @@ struct dwarf2_section_info asection *asection; gdb_byte *buffer; bfd_size_type size; - int was_mmapped; + /* Not NULL if the section was actually mmapped. */ + void *map_addr; + /* Page aligned size of mmapped area. */ + bfd_size_type map_len; /* True if we have tried to read this section. */ int readin; }; @@ -1562,7 +1565,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) if (info->readin) return; info->buffer = NULL; - info->was_mmapped = 0; + info->map_addr = NULL; info->readin = 1; if (dwarf2_section_empty_p (info)) @@ -1592,17 +1595,14 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) { - off_t pg_offset = sectp->filepos & ~(pagesize - 1); - size_t map_length = info->size + sectp->filepos - pg_offset; - caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, - MAP_PRIVATE, pg_offset); + info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, + MAP_PRIVATE, sectp->filepos, + &info->map_addr, &info->map_len); - if (retbuf != MAP_FAILED) + if ((caddr_t)info->buffer != MAP_FAILED) { - info->was_mmapped = 1; - info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; #if HAVE_POSIX_MADVISE - posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); + posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); #endif return; } @@ -15357,14 +15357,13 @@ show_dwarf2_cmd (char *args, int from_tty) static void munmap_section_buffer (struct dwarf2_section_info *info) { - if (info->was_mmapped) + if (info->map_addr != NULL) { #ifdef HAVE_MMAP - intptr_t begin = (intptr_t) info->buffer; - intptr_t map_begin = begin & ~(pagesize - 1); - size_t map_length = info->size + begin - map_begin; + int res; - gdb_assert (munmap ((void *) map_begin, map_length) == 0); + res = munmap (info->map_addr, info->map_len); + gdb_assert (res == 0); #else /* Without HAVE_MMAP, we should never be here to begin with. */ gdb_assert_not_reached ("no mmap support"); -- 2.34.1