This is the mail archive of the gdb-patches@sourceware.org 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: [RFA] print arrays with indexes


> > +  if (TYPE_CODE (index) == TYPE_CODE_RANGE)
> > +    index = TYPE_TARGET_TYPE (index);
> > 
> > which the function used to have. I couldn't understand why this
> > was necessary, and a look at where the type was used showed that
> > this was not necessary, as ada_print_scalar, the only eventual consumer
> > of that type, knew how to handle range types. I would think the same is
> > true of all other languages, right?
> 
> Not sure what you mean by "used to have", to be honest.  I guess this
> code had some prior life in an ACT tree, if you didn't write it?  It
> seems like the sort of check that only Ada would need.

I wasn't clear, sorry. The code in get_array_low_bound() has been
extracted from ada-valprint.c:print_optional_low_bound(). That's where
all the extra code comes from.

> And, this code is still in the patch below.  It's definitely dead code,
> though, so I assume you meant to remove it.

Yes. I removed it in one tree, which I tested with our full Ada
testsuite, and forgot to remove it from the tree I'm using to submit
this change. Good catch. Updated patch attached, with the testsuite
rerun one more time, no regression.

> Should the "return 0;" cases in get_array_low_bound be errors? Or even
> internal errors (probably not)?

I don't think we should use an internal error in this case, since the
erroneous situation can also come from incorrect debugging information.
In this case, it would be misleading to label this as an internal error
when the problem is outside the debugger.

I wouldn't use an error in this case either, as it allows us to emit
a warning instead, and recover in a way that at least allows us to
print the array. Otherwise, it's more complicated to still print the
array.

So I would leave this unchanged. Or perhaps a little comment addition
before the function, along with the description, explaining the above?

> There's already lots of code that uses TYPE_LOW_BOUND (TYPE_INDEX_TYPE
> (array_type)).  If that's not valid, we need to know why not.

The new function does essentially this, except that it adds a bit
of double-checking, probably to avoid falling in a trap laid by
incorrect debugging information.

I'm including the ChangeLog again, as reviewing it, I noticed that
I forgot to include scm-lang.c.

2005-10-02  Joel Brobecker  <brobecker@adacore.com>

        * language.h (language_defn): New field la_print_array_index.
        (LA_PRINT_ARRAY_INDEX): New macro.
        (default_print_array_index): Add declaration.
        * language.c (default_print_array_index): new function.
        (unknown_language): Add value for new field.
        (auto_language): Likewise.
        (local_language): Likewise.
        * ada-lang.c (ada_print_array_index): New function.
        (ada_language_defn): Add value for new field.
        * c-lang.c (c_language_defn): Likewise.
        (cpluc_language_defn): Likewise.
        (asm_language_defn): Likewise.
        (minimal_language_defn): Likewise.
        * f-lang.c (f_language_defn): Likewise.
        * jv-lang.c (java_language_defn): Likewise.
        * m2-lang.c (m2_language_defn): Likewise.
        * objc-lang.c (objc_language_defn): Likewise.
        * p-lang.c (pascal_language_defn): Likewise.
        * scm-lang.c (scm_language_defn): Likewise.
        * valprint.h (print_array_indexes_p): Add declaration.
        (get_array_low_bound): Add declaration.
        (maybe_print_array_index): Add declaration.
        * valprint.c (print_array_indexes): New static variable.
        (show_print_array_indexes): New function.
        (print_array_indexes_p): New function.
        (get_array_low_bound): New function.
        (maybe_print_array_index): New function.
        (val_print_array_elements): Print the index of each element if
        requested by the user.
        (_initialize_valprint): Add new array-indexes "set/show print" command.
        * ada-valprint.c (print_optional_low_bound): Replace extracted code
        by call to ada_get_array_low_bound_and_type(). Stop printing the low
        bound if indexes will be printed for all elements of the array.
        (val_print_packed_array_elements): Print the index of each element
        of the array if necessary.

Re-tested on x86-linux, no regression.

Thanks,
-- 
Joel

Attachment: idx.diff
Description: Text document


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