public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: "Ulrich Weigand" <uweigand@de.ibm.com>
Cc: gdb-patches@sourceware.org, jan.kratochvil@redhat.com,
	sergiodj@redhat.com
Subject: Re: [rfc] Options for "info mappings" etc. (Re: [PATCH] Implement new `info core mappings' command)
Date: Fri, 09 Dec 2011 13:28:00 -0000	[thread overview]
Message-ID: <201112091256.41787.pedro@codesourcery.com> (raw)
In-Reply-To: <201112071755.pB7HtTK3024601@d06av02.portsmouth.uk.ibm.com>

Hi Ulrich,

sorry for my delays.

On Wednesday 07 December 2011 17:55:29, Ulrich Weigand wrote:
> Pedro Alves wrote:
> > On Tuesday 06 December 2011 16:46:04, Ulrich Weigand wrote:
> > > For remote, we could do something along those lines (we cannot directly
> > > use "remote:" because this is only implemented for BFD access -- but
> > > we could use the underlying remote_hostio_pread etc. routines).
> > 
> > Right, I did not mean to imply "remote:" literally.  
> > I kind of see "remote:/proc/PID/maps" as a target path mounted
> > on the host, so "remote:/proc/PID/maps" is a really a host path.
> > The "/proc/PID/maps" path, what the code in question wants to get at, is
> > a target path.  I was trying to say is that the gdbarch hook would always
> > open/read "/proc/PID/maps" from the target, instead of from the host.  On
> > native targets, that ends up falling back to the host filesystem.  For
> > remote targets, that would use the existing hostio mechanism, the same
> > as used by "remote:".  This suggests e.g., a target method to
> > fully open/read/close a target path and return the file's contents (like
> > you say), or, alternatively, wrap the hostio mechanism in a
> > ui-file (through open/read/write/close/... target methods perhaps), and
> > use that.
> 
> I see.  It still seems that the target object mechanism should be a good
> fit for that; but instead of talking about a specific TARGET_OBJECT_PROC,
> we're now talking about a generic TARGET_OBJECT_FILE -- which may have been
> part of the original target object design to start with, see e.g. the 
> comment in target.h:
> 
>   /* Possible future objects: TARGET_OBJECT_FILE, ...  */

Yeah.  Although, I'm not so sure a target object for reading a file
is a good idea.  The problem with it, is that there's no notion of
"open/session handle" in target objects.  That means that for each
partial transfer of a given target object, that can start at any offset,
and extend for any number of bytes, not necessarily the length of the
object (which might not be known upfront), the backend/server xfer method
needs to open/close the destination object.  If the file changes, or
even if deleted/recreated behind the client's back, the transfer
ends up corrupted.  (e.g., the program is running, and the mappings
change while the xfer is taking place; or, the PID program vanishes
and PID is reused.)

We already take this into consideration in some cases.  E.g., 

common/linux-osdata.c:
static LONGEST
linux_xfer_osdata_processes (gdb_byte *readbuf,
			     ULONGEST offset, LONGEST len)
{
  /* We make the process list snapshot when the object starts to be read.  */
  static const char *buf;
  static LONGEST len_avail = -1;
  static struct buffer buffer;

  if (offset == 0)
    {
      ... build snapshot ...
    }
  else
    {
       ... return a piece of the previously built snapshot ...
    }
}

Triggered with "(gdb) info os processes".

We've managed to get away with this so far, because we took the
assumption that GDB always reads the full object, and always
reads it sequencially starting at offset 0.  Another drawback with
this is the need to keep an in-memory snapshot of the object (the
static vars shown above).  We currently keep the snapshot in memory
until a new transfer of the same object starts.

I now notice the new TARGET_OBJECT_PROC implementation was not safe
against this issue.

If we assumed that GDB never transfers more than
one object at the same time (which is true today), we could make
the server discard any previous snapshot whenever it sees an
unrelated packet.  These workarounds don't sound like a good idea to
me for file access.

> > > [ I guess we could implement TARGET_OBJECT_PROC without a new packet type
> > > but implementing TARGET_OBJECT_PROC xfer in remote.c via remote_hostio_pread.
> > > This makes the assumption that the remote side always has a Linux-style /proc,
> > > however.  Not sure whether we should make that assumption ... ]
> > 
> > If the OS does has something else entirely, then the gdbarch method will
> > be aware, because it is the gdbarch method itself that retrieves
> > the data.  It may even use something completely different, not
> > based on filesystems at all.  Otherwise, we're back at making targets
> > fake a file system and proc interface they don't have, where we might
> > as well return some structured data.
> 
> Hmm, OK.  I agree.  So this option would be to:
> 
> - Define a new TARGET_OBJECT_FILE.  The "annex" is simply a full path name
>   of a file on the target system.
> 
> - Implement its xfer method for native targets, probably in inf-ptrace.c
>   (or maybe even as generic default in target.c), via native file I/O.

inf-child.c may be better than inf-ptrace.c.  target.c sounds fine too.
We'd probably want to make the methods be run on the default run target,
if no target is pushed.

> - Implement its xfer method for remote targets in remote.c, using the
>   hostio mechanism (no new packets required).
> 
> - Implement its xfer method for core files via a gdbarch callback allowing
>   the arch to synthesize contents of arbitrary files.
> 
> 
> Note that to fully implement "info proc", we also need to be able to
> read the link path names for files that happen to be symbolic links.
> For TARGET_OBJECT_PROC, I simply defined the target object that way;
> this doesn't really make sense for TARGET_OBJECT_FILE.  So we might
> want to add another target object type TARGET_OBJECT_SYMLINK that
> provides that capability.  Unfortunately, this does mean we need a
> new remote protocol packet, since hostio does not support readlink ...

That's unfortunate, though, it sounds like something generically useful
for other scenarios too.

> Pros of this method would be:
> 
> - New target objects are quite generic and well-defined.
> 
> - "info proc" now can go back to display info about arbitrary processes.
> 
> - No new remote protocol packets for TARGET_OBJECT_FILE.
> 
> 
> Cons of the method:
> 
> - Need new remote protocol packet for TARGET_OBJECT_SYMLINK after all.
> 
> - Synthesizing file contents for core files is a bit more awkward, since
>   you have to recognize particular /proc/PID/... file names.
> 
> 
> The alternative to TARGET_OBJECT_FILE/SYMLINK would be to provide a set
> of target_file_... accessor routines that map to native IO for native
> targets and hostio for remote targets, again with a gdbarch option to
> synthesize file contents from core files.

Right, that's what my "alternatively, wrap the hostio mechanism in a
ui-file (through open/read/write/close/... target methods perhaps), and
use that." comment aluded to.  Since you'd need to keep a reference
to an open handle to a file somewhere, I thought ui-file could be good
for that.  The core target could just use mem_fileopen() to return an
in-memory ui-file with the synthetic /proc/PID/... contents.  I guess
we'd need a new symlink ui-file type too.

> This would require the exact same set of remote protocol extensions
> as the above (i.e. a vFile:readlink or so), and allow the exact same
> set of capabilities; this is purely a question of what GDB-internal
> interface is preferable.

I lean torwards not using target objects for this.

-- 
Pedro Alves

  reply	other threads:[~2011-12-09 12:57 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-26 21:08 [PATCH] Implement new `info core mappings' command Sergio Durigan Junior
2011-10-26 21:25 ` Sergio Durigan Junior
2011-10-27  7:30   ` Eli Zaretskii
2011-10-27 18:09     ` Sergio Durigan Junior
2011-10-29 19:48       ` Eli Zaretskii
2011-10-31  0:34 ` Jan Kratochvil
2011-10-31  7:00   ` Sergio Durigan Junior
2011-10-31  8:13     ` Jan Kratochvil
2011-10-31 12:57       ` Pedro Alves
2011-11-01 11:54         ` [patch] `info proc ' completion [Re: [PATCH] Implement new `info core mappings' command] Jan Kratochvil
2011-11-01 16:23           ` Eli Zaretskii
2011-11-03 14:12             ` [patch] `info proc *' help fix [Re: [patch] `info proc ' completion] Jan Kratochvil
2011-11-03 16:57               ` Eli Zaretskii
2011-11-03 17:07                 ` Jan Kratochvil
2011-11-03 18:08                   ` Eli Zaretskii
2011-11-03 18:25                     ` Jan Kratochvil
2011-11-02 18:30           ` [patch] `info proc ' completion [Re: [PATCH] Implement new `info core mappings' command] Pedro Alves
2011-11-02 18:48             ` [commit] " Jan Kratochvil
2011-11-03 20:01       ` [PATCH] Implement new `info core mappings' command Sergio Durigan Junior
2011-11-04 10:38         ` Eli Zaretskii
2011-11-04 16:27         ` Jan Kratochvil
2011-11-08  1:49           ` Sergio Durigan Junior
2011-11-08 21:47             ` Jan Kratochvil
2011-11-09 20:32             ` Jan Kratochvil
2011-11-16  4:10               ` Sergio Durigan Junior
2011-11-21 16:15                 ` Sergio Durigan Junior
2011-11-23 16:32                   ` [rfc] Options for "info mappings" etc. (Re: [PATCH] Implement new `info core mappings' command) Ulrich Weigand
2011-11-23 23:37                     ` Sergio Durigan Junior
2011-12-01 19:51                       ` Ulrich Weigand
2011-12-05 12:59                     ` Pedro Alves
2011-12-05 15:02                       ` Ulrich Weigand
2011-12-06 16:01                         ` Pedro Alves
2011-12-06 17:19                           ` Ulrich Weigand
2011-12-07 16:29                             ` Pedro Alves
2011-12-07 17:24                               ` Pedro Alves
2011-12-07 20:14                               ` Ulrich Weigand
2011-12-09 13:28                                 ` Pedro Alves [this message]
2011-12-09 14:10                                   ` Pedro Alves
2011-12-20 23:08                                 ` Ulrich Weigand
2011-12-21 22:36                                   ` Jan Kratochvil
2011-12-22 16:15                                     ` Ulrich Weigand
2012-01-05 16:02                                   ` Pedro Alves
2012-01-05 18:03                                     ` Ulrich Weigand
2012-01-05 18:20                                       ` Pedro Alves
2012-01-05 19:54                                         ` Ulrich Weigand
2012-01-06  6:41                                           ` Joel Brobecker
2012-01-06 12:29                                             ` Pedro Alves
2012-01-06 12:27                                           ` Pedro Alves
2012-01-09 15:44                                             ` Ulrich Weigand
2012-01-11 16:38                                               ` Pedro Alves
2012-01-11 18:32                                                 ` Ulrich Weigand
2012-01-05 18:37                                       ` Mark Kettenis
2012-01-05 19:35                                         ` Ulrich Weigand
  -- strict thread matches above, loose matches on Subject: below --
2012-04-06  3:28 [PATCH 0/4 v2] Implement support for SystemTap probes on userspace Sergio Durigan Junior
2012-04-06  3:32 ` [PATCH 1/4 v2] Refactor internal variable mechanism Sergio Durigan Junior
2012-04-06  3:36 ` [PATCH 2/4 v2] Implement new features needed for handling SystemTap probes Sergio Durigan Junior
2012-04-11 19:06   ` Jan Kratochvil
2012-04-11 22:14     ` Sergio Durigan Junior
2012-04-11 23:33       ` Jan Kratochvil
2012-04-06  3:37 ` [PATCH 4/4 v2] Documentation and testsuite changes Sergio Durigan Junior
2012-04-06  9:27   ` Eli Zaretskii
2012-04-09 21:37     ` Sergio Durigan Junior
2012-04-06  4:11 ` [PATCH 3/4 v2] Use longjmp and exception probes when available Sergio Durigan Junior
2011-04-04  3:09 [PATCH 4/6] Implement support for SystemTap probes Sergio Durigan Junior
2011-04-04 19:06 ` Eli Zaretskii
2011-04-06 20:20 ` Tom Tromey
2011-04-06 20:52   ` Sergio Durigan Junior
2011-04-07  2:41 ` Yao Qi
2011-04-07  3:32   ` Sergio Durigan Junior
2011-04-07 17:04   ` Tom Tromey
2011-04-11  3:21     ` Yao Qi
2011-04-08 12:38   ` Sergio Durigan Junior
2011-04-11  3:52     ` Yao Qi
2011-08-12 15:45     ` Jan Kratochvil
2011-08-12 17:22       ` Frank Ch. Eigler
2011-08-12 21:33         ` Sergio Durigan Junior
2011-04-19 16:42 ` Jan Kratochvil
2012-05-07 19:36   ` Jan Kratochvil
2012-05-07 19:54     ` Sergio Durigan Junior
2012-05-07 19:58       ` Jan Kratochvil
2012-05-07 20:26         ` Sergio Durigan Junior
2012-05-07 20:38           ` Jan Kratochvil
2012-05-08  1:36             ` Sergio Durigan Junior

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=201112091256.41787.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=sergiodj@redhat.com \
    --cc=uweigand@de.ibm.com \
    /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).