This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use ELF_SECTION_IN_SEGMENT to map segments


The macro ELF_SECTION_IN_SEGMENT should be used when calculating if
a section maps to a segment.

The binutils patch "[PATCH] Use offsets instead of addresses in
ELF_SECTION_IN_SEGMENT" makes further improvements to the macro.
When the two patches are combined, this will allow GDB to be used
to debug Arm baremetal binaries produced by the Arm Compiler. See
the binutils patch for further details.

Regardless of Arm debugging, this patch reduces code/logic duplication
in gdb.

This change has been tested using make check x86 on a binutils+gdb
build. It has also been manually tested by using gdb to debug a Arm
Mbed board.

Alan.

2018-05-22  Alan Hayward  <alan.hayward@arm.com>

	* elfread.c (elf_symfile_segments): Use ELF_SECTION_IN_SEGMENT.
---
 gdb/elfread.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gdb/elfread.c b/gdb/elfread.c
index b4b4a1b24c..3cf9b1ec21 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -120,17 +120,13 @@ elf_symfile_segments (bfd *abfd)
   for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
     {
       int j;
-      CORE_ADDR vma;
+      Elf_Internal_Shdr *this_hdr = &(elf_section_data (sect)->this_hdr);
 
       if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0)
 	continue;
 
-      vma = bfd_get_section_vma (abfd, sect);
-
       for (j = 0; j < num_segments; j++)
-	if (segments[j]->p_memsz > 0
-	    && vma >= segments[j]->p_vaddr
-	    && (vma - segments[j]->p_vaddr) < segments[j]->p_memsz)
+	if ELF_SECTION_IN_SEGMENT (this_hdr, segments[j])
 	  {
 	    data->segment_info[i] = j + 1;
 	    break;
-- 
2.15.1 (Apple Git-101)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]