Fix PR gdb/20948: --write option to GDB causes segmentation fault
authorJozef Lawrynowicz <jozef.l@mittosystems.com>
Tue, 11 Sep 2018 21:56:36 +0000 (22:56 +0100)
committerTom Tromey <tom@tromey.com>
Mon, 24 Sep 2018 12:20:17 +0000 (06:20 -0600)
commitdb72737006fc383cb8838bf7f3dc8e641e60c38f
tree1c81ecc66318cd2e3e8cb8da3ae04e9855b5c945
parentb5a9bfbebec0a42d3c5b4fe3b7a62bd31cecc440
Fix PR gdb/20948: --write option to GDB causes segmentation fault

When opening a BFD for update, as gdb --write does, modifications to
anything but the contents of sections is restricted.

Do not try to write back any ELF headers in this case.

bfd/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

PR gdb/20948
* elf.c (_bfd_elf_write_object_contents): Return from function
early if abfd->direction == both_direction.

gdb/testsuite/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

PR gdb/20948
* gdb.base/write_mem.exp: New test.
* gdb.base/write_mem.c: Likewise.
bfd/ChangeLog
bfd/elf.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/write_mem.c [new file with mode: 0644]
gdb/testsuite/gdb.base/write_mem.exp [new file with mode: 0644]