From: Alan Modra <amodra@gmail.com>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org, binutils@sourceware.org
Subject: Re: [PATCH] Fix "gdb --write" with core files
Date: Fri, 13 May 2022 12:27:06 +0930 [thread overview]
Message-ID: <Yn3JAtJicqs4iHoF@squeak.grove.modra.org> (raw)
In-Reply-To: <20220512144915.3270761-1-pedro@palves.net>
On Thu, May 12, 2022 at 03:49:15PM +0100, Pedro Alves wrote:
> That happens because _bfd_elf_set_section_contents does this to seek
> to the section's offset:
>
> pos = hdr->sh_offset + offset;
> if (bfd_seek (abfd, pos, SEEK_SET) != 0
> || bfd_bwrite (location, count, abfd) != count)
> return false;
>
> ... and 'hdr->sh_offset' is zero, so we seek to just OFFSET, which is
> incorrect. The reason 'hdr->sh_offset' is zero is that
> kernel-generated core files normally don't even have a section header
> table (gdb-generated ones do, but that's more an accident than a
> feature), and indeed elf_core_file_p doesn't even try to read sections
> at all:
I'm a little concerned about your patch keying off both_direction. In
particular it seems odd to change bfd behaviour when reading depending
on whether the file was opened "r" or "r+".
Did you try changing
pos = hdr->sh_offset + offset;
to
pos = section->filepos + offset;
in _bfd_elf_set_section_contents? I think that should work for you,
and not break ELF targets.
--
Alan Modra
Australia Development Lab, IBM
next prev parent reply other threads:[~2022-05-13 2:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 14:49 Pedro Alves
2022-05-13 2:57 ` Alan Modra [this message]
2022-05-13 8:04 ` Pedro Alves
2022-05-13 9:48 ` Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yn3JAtJicqs4iHoF@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.org \
--cc=pedro@palves.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).