[PATCH] Use ELF_SECTION_IN_SEGMENT to map segments
Alan Hayward
Alan.Hayward@arm.com
Mon Jun 4 16:30:00 GMT 2018
Pushed this with changes as suggested.
The BFD patch hasn’t progressed yet (possible extra changes needed
elsewhere). Regardless, this patch can stand on it’s own.
Alan.
> On 23 May 2018, at 11:36, Alan Hayward <Alan.Hayward@arm.com> wrote:
>
>
> Thanks for the review.
>
>> On 22 May 2018, at 14:46, Pedro Alves <palves@redhat.com> wrote:
>>
>> On 05/22/2018 12:00 PM, Alan Hayward wrote:
>>> 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.
>>
>> Sounds reasonable.
>>
>>> --- 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);
>>
>> Drop unnecessary parens.
>>
>> You could defer this call until after the SEC_ALLOC check.
>
> Ok.
>
>>
>>>
>>> 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])
>>
>> That is some odd-looking C/C++ code, for assuming the macro's
>> internals are wrapped in parens. Please write the more usual:
>>
>> if (ELF_SECTION_IN_SEGMENT (this_hdr, segments[j]))
>
> Not quite sure why I didn’t spot that when writing it.
>
>
>>
>> OK with those fixed.
>>
>
> I’ll wait until the BFD patch has been approved before I push, as there
> is a small chance that review will cause me to make further changes. Will
> post again if I do.
>
>
> Alan.
More information about the Gdb-patches
mailing list