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]

Re: [PATCH] Fix seg fault with --write PR gdb/20948


On 2018-03-08 05:25 PM, Jozef Lawrynowicz wrote:
> GDB segfaults when invoking it with the --write option, then quitting. First
> reported in PR gdb/20948.
> 
> An assertion fails because elf_shstrtab is uninitialized, and 
> elf_shstrtab is
> only initialized if abfd_output_has_begun is FALSE.
> bfd/format.c:bfd_check_format_matches as called from 
> gdb/exec.c:exec_file_attach
> always sets output_has_begun to TRUE if the bfd was opened for update, 
> so the
> attached patch sets output_has_begun back to FALSE in exec_file_attach 
> when we
> return from bfd_check_format_matches.
> 
> This leads to a further assertion failure in
> bfd/elf.c:assign_file_positions_for_non_load_sections:
> 
> BFD_ASSERT (hdr->sh_offset == hdr->bfd_section->filepos);
> 
> filepos for non-load sections has been set already, but sh_offset is 0 as it
> needs to be set by _bfd_elf_assign_file_position_for_section, which is 
> called in
> a further conditional block. So this first conditional has been extended to
> evaluate to FALSE if sh_offset == 0 but filepos != 0.
> 
> The attached patche includes tests which verify that the --write behaviour
> works as expected i.e. that modifications to the loaded executable persist
> once the GDB session is ended.
> 
> For Unix and msp430-elf targets, completed testing for binutils, gas, 
> ld, gdb,
> sim (for msp430) without regressions.
> 
> If the patch is acceptable, I would appreciate if someone could commit 
> it for
> me as I don't have write access.
> 


Hi Jozef,

Thanks for looking into this.

Because of the change in bfd/, this patch should also be sent to the
binutils@sourceware.org mailing list.  The change we'll have to do
in GDB may depend on what is the final solution on the BFD side.

Also, is the problem illustrated in comment #3 of the bug report related?

https://sourceware.org/bugzilla/show_bug.cgi?id=20948#c3

I tried that snippet with your patch applied, and still get a segfault.
I think it would be good to get a fix for the minimal reproducing example
first.

When you post your patch to the binutils mailing list, you can also refer
to the gdb bug (PR20948) and CC the gdb-patches mailing list, so we can
follow the discussion.

Thanks!

Simon

Simon


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