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: [RFC/RFA] print arrays with indexes


> > There is also Jim's suggestion which has some merits. I'm more of
> > an all or nothing kind of guy, so I prefer the approach I've chosen,
> > but I am flexible.
> 
> I've got no strong opinions on this either way.  Thresholds seem
> complicated as a UI.

I feel the same way too.

Here is a revised patch, that implements the language method.
Now, with C, we get:

        (gdb) p array
        $1 = {[0] = 1, [1] = 2, [2] = 3, [3] = 4}

This is also the default for all the other languages, except Ada, where
the debugger will print:

        (gdb) p one_two_three 
        $1 = (1 => 1, 2 => 2, 3 => 3)

2005-09-07  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.
        * 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.
        * ada-lang.c (ada_print_array_index): New function.
        (ada_language_defn): Add value for new field.
        * valprint.h (print_array_indexes_p): Add declaration.
        (maybe_print_array_index): Add declaration.
        (val_print_array_elements): Add new parameter to function profile.
        * valprint.c (print_array_indexes): New static variable.
        (show_print_array_indexes): New function.
        (print_array_indexes_p): New function.
        (maybe_print_array_index): New function.
        (val_print_array_elements): Add new parameter real_index_offset.
        Print the index of each element if required by the user.
        (_initialize_valprint): Add new array-indexes "set/show print" command.
        * c-valprint.c (c_val_print): Update call to val_print_array_elements.
        * p-valprint.c (pascal_val_print): Likewise.
        * ada-valprint.c (ada_get_array_low_bound_and_type): New function,
        mostly extracted from print_optional_low_bound().
        (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.
        (ada_val_print_1): For non-packed arrays, compute the array low
        bound, and pass it to val_print_array_elements().

Tested on x86-linux, no regression. Testcases and documentation to follow
after the review.

Thanks,
-- 
Joel

Attachment: indexes.diff
Description: Text document


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