Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: John Gilmore <gnu@toad.com>
To: Aleksandar Ristovski <aristovski@qnx.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>,
	  Raphael Zulliger <zulliger@indel.ch>,
	gdb@sourceware.org
Subject: Re: Ensure correct symbol-file when attaching to a (remote) process
Date: Sat, 22 Dec 2012 00:38:00 -0000	[thread overview]
Message-ID: <201212220138.qBM1caIl012256@new.toad.com> (raw)
In-Reply-To: <50D4D099.3030601@qnx.com>

> Interesting timing. I have just posted 
> http://sourceware.org/ml/gdb-patches/2012-12/msg00776.html addressing 
> this issue.

That's a useful patch.  It's smart to read the headers from the
"symbol_file" bfd (well, in this case the solib bfd used for symbols)
rather than from the "exec_file" bfd.

But doesn't it read the ELF header twice?  In
svr4_validate_hdrs_match, it reads it once in the call to
read_elf_header_from_target, and then reads it again by calling
read_program_headers_from_target which again calls
read_elf_header_from_target.  I suspect that you should pass the
already-read ELF header into each of the read_program_headers
functions.

Also, in read_elf_header_from_bfd, BFD has probably already read the
ELF header, when it first opened the file, and has it lying around.
This code should not be (1) reading it again, nor (2) seeking to file
offset "0" (not even a #define, not even "0L", but an int constant!)
to get it.

Also, it might be simpler in read_program_headers_from_target to just
translate the ELF header into its internal BFD struct form - then all
that manual messing with byte orders and field lengths could be
eliminated.  See how read_program_headers_from_bfd does it.

You could also just call bfd_get_elf_phdrs (and before that,
bfd_get_elf_phdr_upper_bound to size the buffer) which would avoid
spreading details into GDB about these headers and how they are read
and translated into local byte order.  BFD even has a
bfd_elf_bfd_from_remote_memory function for creating a BFD by portably
reading the target's ELF header and phdrs out of memory.

Also, is "validate" the right name for this?  That works for checking
shared libraries, but it's not as obvious what this function should
do when e.g. checking the argument to symbol_file, or immediately
after doing "target attach remote".  If "validation" fails, should
we refuse to read that symbol file, or refuse to attach to the remote
target?  What exactly are we validating?  Perhaps "compare_headers"
or "do_symbols_and_target_match" are better names.

With those things addressed, it's a good start.  Then, shouldn't this
call be implemented for non-shared-library symbol files (like
Mr. Zulliger was hoping for), and for object file formats other than
ELF?

Has this code been tested when the target uses a different byte
order than the host?  Probably not, since it is only currently invoked
for shared library loads, which usually only happen native.  Is
there a test case written for it?

Could it be easily extended to check a build-id when one exists?  Or
would that require different function arguments, or need to happen at
a different time?

Should "target attach" do this kind of validation traffic to and from
the target?  Or should checking this be a separate step initiated by
the user?  The target might be in a relatively sensitive state -- or
the user might not want to wait for this check -- immediately after
attaching.  We could add yet another GDB setting for automatic or
manual validation, defaulting to "check", and requiring those who want
to bypass the check to set that setting.  Is that too much
complication for the gain?

	John


  reply	other threads:[~2012-12-22  0:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-21  6:05 Raphael Zulliger
2012-12-21 16:11 ` Jan Kratochvil
2012-12-21 18:17   ` John Gilmore
2013-01-02 17:57     ` Pedro Alves
2013-01-12 10:59       ` Martin Runge
     [not found]       ` <50EA78FB.3040609@indel.ch>
2013-01-14 18:57         ` Pedro Alves
2013-01-29  3:18       ` Raphael Zulliger
2013-01-29  3:51         ` Raphael Zulliger
2013-02-06 18:47           ` Tom Tromey
2012-12-21 21:12   ` Aleksandar Ristovski
2012-12-22  0:38     ` John Gilmore [this message]
2012-12-22  2:54       ` Aleksandar Ristovski
2012-12-24 20:02         ` Aleksandar Ristovski
2012-12-26  0:47           ` John Gilmore
2012-12-27 20:13             ` Aleksandar Ristovski
2013-01-29  3:18     ` Raphael Zulliger

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=201212220138.qBM1caIl012256@new.toad.com \
    --to=gnu@toad.com \
    --cc=aristovski@qnx.com \
    --cc=gdb@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=zulliger@indel.ch \
    /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