This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Trivial fix in value_sub


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.

I agree -- I think taking the sizeof an incomplete type should
result in an error, just as it would in c/c++.


> 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?

Heh -- I bet I know.   ;-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]