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

Jozef Lawrynowicz jozef.l@mittosystems.com
Thu Mar 8 22:26:00 GMT 2018


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-GDB-segfault-with-write.patch
Type: text/x-patch
Size: 3448 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20180308/2fa15fcd/attachment.bin>


More information about the Gdb-patches mailing list