From: Daniel Jacobowitz <drow@false.org>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: Vladimir Prus <vladimir@codesourcery.com>,
gdb-patches@sources.redhat.com
Subject: Re: [PATCH] zero-terminate result of target_read_alloc
Date: Tue, 18 Jul 2006 13:39:00 -0000 [thread overview]
Message-ID: <20060718133947.GA16064@nevyn.them.org> (raw)
In-Reply-To: <22754.192.87.1.22.1153228499.squirrel@webmail.xs4all.nl>
On Tue, Jul 18, 2006 at 03:14:59PM +0200, Mark Kettenis wrote:
> Sorry, but the whole distinction between strings and binary data is wrong.
> Strings are binary data, including the terminating NUL. Volodya's patch
> addresses things at the wrong level. Whatever we read using
> target_read_partial() should already include the terminating NUL.
Please consider that you are asserting that a design change is obvious
and necessary in code that we've been working with for months. I
disagree with you that it's at the wrong level; please at least listen
to why.
> So whatever reads the XML from the target should make sure things are
> NUL-terminated, and report the total length, including the terminating
> NUL.
>
> I guess you're thinking too much in terms of the remote protocol, where
> you need to make the distinction between text and binary data because
> you have to encode the latter to avoid problems with embedded NUL's. But
> that's really specific to the way our remote protocol works, and therefore
> should be handled completely in the remote target vector code.
In fact it's exactly the opposite. Embedded NULs are not a problem
with the remote protocol. It is perfectly happy to include NUL
characters in the data. The characters which cause a problem are
[*$#]. Text and binary data are not at all distinguished in the remote
protocol interface underlying TARGET_OBJECT_*. Both are escaped in the
same way, which used to be as hex, but is now a binary encoding only
changing those special characters.
The remote protocol doesn't care at all what's in the object. Right
now it doesn't know. Later on, it will know the contents of some
objects (e.g. the XML memory map) and parse them - but not inside
to_xfer_partial, which is strictly a transfer mechanism. That would be
a layering problem. Instead other bits of the file will call
target_read_alloc to fetch objects.
Here's a better way to think about the patch, I think. Consider the
result of target_read_alloc to be the contents of a disk file. It
might be an ELF executable or a text README file. The caller knows
which sort of data it is, and will process it appropriately, but
target_read_alloc is just fread in this model. It doesn't know whether
the contents are text or binary. If they are text, why should they
include a terminating NUL in the disk file?
So with this change, the interface is friendly to consumers which wish
to parse the result as binary data, and also friendly to consumers
which wish to pass it to strcpy or strlen. Yes, I realize my analogy
is a bit flawed in that fread doesn't do this. But how frequently have
you seen fread followed by some code to add a NUL at the end of the
buffer? I checked a handful of source trees I had handy, and the
answer seems to be about 30% of the time; pretty substantial, and these
aren't text-io-heavy applications, e.g. gcc/libcpp.
--
Daniel Jacobowitz
CodeSourcery
next prev parent reply other threads:[~2006-07-18 13:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-18 9:56 Vladimir Prus
2006-07-18 11:25 ` Mark Kettenis
2006-07-18 11:33 ` Vladimir Prus
2006-07-18 12:34 ` Daniel Jacobowitz
2006-07-18 13:15 ` Mark Kettenis
2006-07-18 13:39 ` Daniel Jacobowitz [this message]
2006-07-18 13:51 ` Vladimir Prus
2006-07-18 19:51 ` Jim Blandy
2006-07-24 4:09 ` Daniel Jacobowitz
2006-07-24 21:41 ` Mark Kettenis
2006-07-24 22:00 ` Daniel Jacobowitz
2006-07-26 21:53 ` Mark Kettenis
2006-07-26 22:25 ` Daniel Jacobowitz
2006-07-26 22:36 ` Mark Kettenis
2006-07-27 21:25 ` Daniel Jacobowitz
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=20060718133947.GA16064@nevyn.them.org \
--to=drow@false.org \
--cc=gdb-patches@sources.redhat.com \
--cc=mark.kettenis@xs4all.nl \
--cc=vladimir@codesourcery.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