From: Jim Ingham <jingham@apple.com>
To: Jim Blandy <jimb@redhat.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: Trivial fix in value_sub
Date: Wed, 03 Apr 2002 16:11:00 -0000 [thread overview]
Message-ID: <775EF184-4760-11D6-A9CC-000393540DDC@apple.com> (raw)
In-Reply-To: <np3cyce6o4.fsf@zwingli.cygnus.com>
Jim,
For incomplete types, TYPE_LENGTH does indeed return 0. If it is an
incomplete type, I don't think you should treat the size as 0, since
that is CERTAINLY not what the user expected. If you are going to
handle it specially, then you should return an error in this case,
saying something like "Can't do pointer arithmetic on incomplete types,
try casting it as (void *)."
The way the problem came up is that the Toolbox folks here use lots of
intentionally incomplete structures to mark tokens that are hiding real
structures behind the curtains. But they know the secret handshakes, so
they know where things are around the pointers to fake structs, and use
this kind of pointer arithmetic to poke around. So treating the
addition as void * is what they expect, and an error would probably
mildly tick them off.
OTOH, you can always get around this by casting the pointer, either to
void * or to what it is... I am pretty sure their use is just shorthand.
So... I don't think you should keep the size at 0. This seems like gdb
is just silently ignoring the " - x" part of what they typed, and you
should always be explicit about what you have done. But if you think an
error is more appropriate, I am fine with that...
Jim
On Wednesday, April 3, 2002, at 02:52 PM, Jim Blandy wrote:
>
> (Thanks for making value_add and value_sub consistent!)
>
> If I use an incomplete type in my program --- say, by making a
> definition like this:
>
> struct foo *x;
>
> where there is no definition for `struct foo' in scope --- does GDB
> set TYPE_LENGTH (TYPE_TARGET_TYPE (p)) to zero, where `p' is the type
> of x?
>
> See, that code in value_add (and now in value_sub) is supposed to
> handle void *; as an extension, GCC allows arithmetic on void *
> values, treating sizeof (void) as one. This makes sense for void *
> values, since they're often used as pointers to raw memory.
>
> However, for things like incomplete struct types, treating the size as
> one is completely bogus. That's surely not the behavior the user
> would expect; they may not even realize that the type is incomplete.
>
> If GDB really does set the length of an incomplete struct type to
> zero, then that code should really read something like:
>
> if (sz == 0 && TYPE_CODE (TYPE_TARGET_TYPE (type1)) == TYPE_CODE_VOID)
> sz = 1;
>
> Can you tell me more about the context in which you noticed this
> problem?
>
--
Jim Ingham jingham@apple.com
Developer Tools - gdb
Apple Computer
next prev parent reply other threads:[~2002-04-04 0:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-29 15:27 Jim Ingham
2002-04-03 14:52 ` Jim Blandy
2002-04-03 15:55 ` Michael Snyder
2002-04-03 16:11 ` Jim Ingham [this message]
2002-04-03 19:55 ` Jim Blandy
2002-04-03 20:11 ` Daniel Jacobowitz
2002-04-04 13:46 ` Jim Ingham
2002-04-04 14:24 ` Jim Blandy
2002-04-04 15:07 ` Jim Ingham
2002-04-04 15:15 ` Jim Blandy
2002-04-09 17:12 ` Jim Ingham
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=775EF184-4760-11D6-A9CC-000393540DDC@apple.com \
--to=jingham@apple.com \
--cc=gdb-patches@sources.redhat.com \
--cc=jimb@redhat.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