From 79a45b7d67b37d45cdb44d3ee2761a768474dd73 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 28 Oct 2008 17:19:58 +0000 Subject: [PATCH] gdb * varobj.c (value_get_print_value): Include valprint.h. (value_get_print_value): Use get_formatted_print_options. * value.h (struct value_print_options): Declare. (value_print, val_print, common_val_print, val_print_string): Update. * value.c: Include valprint.h. (show_values): Use get_user_print_options. (show_convenience): Likewise. * valprint.h (prettyprint_arrays, prettyprint_structs): Don't declare. (struct value_print_options): New type. (vtblprint, unionprint, addressprint, objectprint, print_max, inspect_it, repeat_count_threshold, output_format, stop_print_at_null): Don't declare. (user_print_options, get_user_print_options, get_raw_print_options, get_formatted_print_options): Declare. (print_array_indexes_p): Don't declare. (maybe_print_array_index, val_print_array_elements): Update. * valprint.c (print_max): Remove. (user_print_options): New global. (get_user_print_options, get_raw_print_options, get_formatted_print_options): New functions. (print_array_indexes, repeat_count_threshold, stop_print_at_null, prettyprint_structs, prettyprint_arrays, unionprint, addressprint): Remove. (val_print): Remove format, deref_ref, pretty arguments; add options. Update. (common_val_print): Likewise. (print_array_indexes_p): Remove. (maybe_print_array_index): Remove format, pretty arguments; add options. Update. (val_print_array_elements): Remove format, deref_ref, pretty arguments; add options. Update. (val_print_string): Add options argument. Update. (_initialize_valprint): Use user_print_options. (output_format): Remove. (set_output_radix_1): Use user_print_options. * typeprint.c: Include valprint.h. (objectprint): Don't declare. (whatis_exp): Use get_user_print_options. * tui/tui-regs.c: Include valprint.h. (tui_register_format): Use get_formatted_print_options. * tracepoint.c: Include valprint.h. (addressprint): Don't declare. (trace_mention): Use get_user_print_options. (tracepoints_info): Likewise. * stack.c (print_frame_args): Use get_raw_print_options. (print_frame_info): Use get_user_print_options. (print_frame): Likewise. * sh64-tdep.c: Include valprint.h (sh64_do_register): Use get_formatted_print_options. * scm-valprint.c (scm_inferior_print): Remove format, deref_ref, pretty arguments; add options. (scm_scmlist_print): Likewise. Update. (scm_scmval_print): Likewise. (scm_val_print): Likewise. (scm_value_print): Remove format, pretty arguments; add options. Update. * scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print): Update. * scm-lang.c (scm_printstr): Add options argument. * python/python-value.c: Include valprint.h. (valpy_str): Use get_user_print_options. * printcmd.c: Include valprint.h. (addressprint): Don't declare. (inspect_it): Remove. (print_formatted): Remove format option; add options. Update. (print_scalar_formatted): Likewise. (print_address_demangle): Use get_user_print_options. (do_examine): Use get_formatted_print_options. (print_command_1): Likewise. (output_command): Use get_formatted_print_options. (do_one_display): Likewise. (print_variable_value): Use get_user_print_options. * p-valprint.c (pascal_val_print): Remove format, deref_ref, pretty arguments; add options. Update. (pascal_value_print): Remove format, pretty arguments; add options. Update. (vtblprint, objectprint): Don't declare. (pascal_static_field_print): Remove. (pascal_object_print_value_fields): Remove format, pretty arguments; add options. Update. (pascal_object_print_static_field): Likewise. (_initialize_pascal_valprint): Use user_print_options. Update. * p-lang.h (pascal_val_print, pascal_value_print, pascal_printstr, pascal_object_print_value_fields): Update. (vtblprint, static_field_print): Don't declare. * p-lang.c (pascal_printstr): Add options argument. Update. * objc-lang.c (objc_printstr): Add options argument. Update. * mt-tdep.c: Include valprint.h. (mt_registers_info): Use get_raw_print_options. * mips-tdep.c: Include valprint.h. (mips_print_fp_register): Use get_formatted_print_options. (mips_print_register): Likewise. * mi/mi-main.c: Include valprint.h. (get_register): Use get_user_print_options. (mi_cmd_data_evaluate_expression): Likewise. (mi_cmd_data_read_memory): Use get_formatted_print_options. * mi/mi-cmd-stack.c: Include valprint.h. (list_args_or_locals): Use get_raw_print_options. * m2-valprint.c (print_function_pointer_address): Add addressprint argument. (m2_print_long_set): Remove format, pretty arguments. (m2_print_unbounded_array): Remove format, deref_ref, pretty arguments; add options. Update. (print_unpacked_pointer): Remove format argument; add options. Now static. Update. (print_variable_at_address): Remove format, deref_ref, pretty arguments; add options. Update. (m2_print_array_contents): Likewise. (m2_val_print): Likewise. * m2-lang.h (m2_val_print): Update. * m2-lang.c (m2_printstr): Add options argument. Update. * language.h (struct value_print_options): Declare. (struct language_defn) : Add options argument. : Remove format, deref_ref, pretty argument; add options. : Remove format, pretty arguments; add options. : Likewise. (LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING, LA_PRINT_ARRAY_INDEX): Update. (default_print_array_index): Update. * language.c (default_print_array_index): Remove format, pretty arguments; add options. Update. (unk_lang_printstr): Add options argument. (unk_lang_val_print): Remove format, deref_ref, pretty arguments; add options. (unk_lang_value_print): Remove format, pretty arguments; add options. * jv-valprint.c (java_value_print): Remove format, pretty arguments; add options. Update. (java_print_value_fields): Likewise. (java_val_print): Remove format, deref_ref, pretty arguments; add options. Update. * jv-lang.h (java_val_print, java_value_print): Declare. * infcmd.c: Include valprint.h. (print_return_value): Use get_raw_print_options. (default_print_registers_info): Use get_user_print_options, get_formatted_print_options. (registers_info): Use get_formatted_print_options. * gdbtypes.h (struct value_print_options): Declare. (print_scalar_formatted): Update. * f-valprint.c (f77_print_array_1): Remove format, deref_ref, pretty arguments; add options. Update. (f77_print_array): Likewise. (f_val_print): Likewise. * f-lang.h (f_val_print): Update. * f-lang.c (f_printstr): Add options argument. Update. (c_value_print): Update declaration. * expprint.c: Include valprint.h. (print_subexp_standard): Use get_raw_print_options, get_user_print_options. * eval.c: Include valprint.h. (objectprint): Don't declare. (evaluate_subexp_standard): Use get_user_print_options. * cp-valprint.c (vtblprint, objectprint, static_field_print): Remove. (cp_print_value_fields): Remove format, pretty arguments; add options. Update. (cp_print_value): Likewise. (cp_print_static_field): Likewise. (_initialize_cp_valprint): Use user_print_options. Update. * c-valprint.c (print_function_pointer_address): Add addressprint argument. (c_val_print): Remove format, deref_ref, pretty arguments; add options. Update. (c_value_print): Add options argument. Update. * c-lang.h (c_val_print, c_value_print, c_printstr): Update. (vtblprint, static_field_print): Don't declare. (cp_print_value_fields): Update. * c-lang.c (c_printstr): Add options argument. Update. * breakpoint.c: Include valprint.h. (addressprint): Don't declare. (watchpoint_value_print): Use get_user_print_options. (print_one_breakpoint_location): Likewise. (breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention, print_exception_catchpoint): Likewise. * auxv.c (fprint_target_auxv): Don't declare addressprint. Use get_user_print_options. * ada-valprint.c (struct ada_val_print_args): Remove format, deref_ref, and pretty; add options. (print_optional_low_bound): Add options argument. (val_print_packed_array_elements): Remove format and pretty arguments; add options. Update. (printstr): Add options argument. Update. (ada_printstr): Likewise. (ada_val_print): Remove format, deref_ref, pretty arguments; add options argument. Update. (ada_val_print_stub): Update. (ada_val_print_array): Remove format, deref_ref, pretty arguments; add options. Update. (ada_val_print_1): Likewise. (print_variant_part): Likewise. (ada_value_print): Remove format, pretty arguments; add options. Update. (print_record): Likewise. (print_field_values): Likewise. * ada-lang.h (ada_val_print, ada_value_print, ada_printstr): Update. * ada-lang.c (ada_print_array_index): Add options argument; remove format and pretty arguments. (print_one_exception): Use get_user_print_options. gdb/testsuite * gdb.base/exprs.exp (test_expr): Add enum formatting tests. --- gdb/ChangeLog | 205 +++++++++++++++++++++++++++++ gdb/ada-lang.c | 9 +- gdb/ada-lang.h | 11 +- gdb/ada-valprint.c | 218 ++++++++++++++++--------------- gdb/auxv.c | 13 +- gdb/breakpoint.c | 49 +++++-- gdb/c-lang.c | 15 ++- gdb/c-lang.h | 17 +-- gdb/c-valprint.c | 167 ++++++++++++----------- gdb/cp-valprint.c | 78 +++++------ gdb/eval.c | 11 +- gdb/expprint.c | 67 +++++++--- gdb/f-lang.c | 19 +-- gdb/f-lang.h | 4 +- gdb/f-valprint.c | 103 ++++++++------- gdb/gdbtypes.h | 6 +- gdb/infcmd.c | 26 +++- gdb/jv-lang.h | 8 +- gdb/jv-valprint.c | 99 +++++++------- gdb/language.c | 18 +-- gdb/language.h | 35 ++--- gdb/m2-lang.c | 15 ++- gdb/m2-lang.h | 4 +- gdb/m2-valprint.c | 174 ++++++++++++------------ gdb/mi/mi-cmd-stack.c | 23 +++- gdb/mi/mi-main.c | 17 ++- gdb/mips-tdep.c | 16 ++- gdb/mt-tdep.c | 6 +- gdb/objc-lang.c | 15 ++- gdb/p-lang.c | 15 ++- gdb/p-lang.h | 19 ++- gdb/p-valprint.c | 203 ++++++++++++++-------------- gdb/printcmd.c | 104 ++++++++------- gdb/python/python-value.c | 9 +- gdb/scm-lang.c | 3 +- gdb/scm-lang.h | 10 +- gdb/scm-valprint.c | 71 +++++----- gdb/sh64-tdep.c | 12 +- gdb/stack.c | 19 ++- gdb/testsuite/ChangeLog | 4 + gdb/testsuite/gdb.base/exprs.exp | 7 + gdb/tracepoint.c | 16 ++- gdb/tui/tui-regs.c | 5 +- gdb/typeprint.c | 9 +- gdb/valprint.c | 197 +++++++++++++++------------- gdb/valprint.h | 103 +++++++++++---- gdb/value.c | 9 +- gdb/value.h | 18 +-- gdb/varobj.c | 7 +- 49 files changed, 1376 insertions(+), 912 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 973772142a5..b2fa68ff767 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,208 @@ +2008-10-28 Tom Tromey + + * varobj.c (value_get_print_value): Include valprint.h. + (value_get_print_value): Use get_formatted_print_options. + * value.h (struct value_print_options): Declare. + (value_print, val_print, common_val_print, val_print_string): + Update. + * value.c: Include valprint.h. + (show_values): Use get_user_print_options. + (show_convenience): Likewise. + * valprint.h (prettyprint_arrays, prettyprint_structs): Don't + declare. + (struct value_print_options): New type. + (vtblprint, unionprint, addressprint, objectprint, print_max, + inspect_it, repeat_count_threshold, output_format, + stop_print_at_null): Don't declare. + (user_print_options, get_user_print_options, + get_raw_print_options, get_formatted_print_options): Declare. + (print_array_indexes_p): Don't declare. + (maybe_print_array_index, val_print_array_elements): Update. + * valprint.c (print_max): Remove. + (user_print_options): New global. + (get_user_print_options, get_raw_print_options, + get_formatted_print_options): New functions. + (print_array_indexes, repeat_count_threshold, stop_print_at_null, + prettyprint_structs, prettyprint_arrays, unionprint, + addressprint): Remove. + (val_print): Remove format, deref_ref, pretty arguments; add + options. Update. + (common_val_print): Likewise. + (print_array_indexes_p): Remove. + (maybe_print_array_index): Remove format, pretty arguments; add + options. Update. + (val_print_array_elements): Remove format, deref_ref, pretty + arguments; add options. Update. + (val_print_string): Add options argument. Update. + (_initialize_valprint): Use user_print_options. + (output_format): Remove. + (set_output_radix_1): Use user_print_options. + * typeprint.c: Include valprint.h. + (objectprint): Don't declare. + (whatis_exp): Use get_user_print_options. + * tui/tui-regs.c: Include valprint.h. + (tui_register_format): Use get_formatted_print_options. + * tracepoint.c: Include valprint.h. + (addressprint): Don't declare. + (trace_mention): Use get_user_print_options. + (tracepoints_info): Likewise. + * stack.c (print_frame_args): Use get_raw_print_options. + (print_frame_info): Use get_user_print_options. + (print_frame): Likewise. + * sh64-tdep.c: Include valprint.h + (sh64_do_register): Use get_formatted_print_options. + * scm-valprint.c (scm_inferior_print): Remove format, deref_ref, + pretty arguments; add options. + (scm_scmlist_print): Likewise. Update. + (scm_scmval_print): Likewise. + (scm_val_print): Likewise. + (scm_value_print): Remove format, pretty arguments; add options. + Update. + * scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print): + Update. + * scm-lang.c (scm_printstr): Add options argument. + * python/python-value.c: Include valprint.h. + (valpy_str): Use get_user_print_options. + * printcmd.c: Include valprint.h. + (addressprint): Don't declare. + (inspect_it): Remove. + (print_formatted): Remove format option; add options. Update. + (print_scalar_formatted): Likewise. + (print_address_demangle): Use get_user_print_options. + (do_examine): Use get_formatted_print_options. + (print_command_1): Likewise. + (output_command): Use get_formatted_print_options. + (do_one_display): Likewise. + (print_variable_value): Use get_user_print_options. + * p-valprint.c (pascal_val_print): Remove format, deref_ref, + pretty arguments; add options. Update. + (pascal_value_print): Remove format, pretty arguments; add + options. Update. + (vtblprint, objectprint): Don't declare. + (pascal_static_field_print): Remove. + (pascal_object_print_value_fields): Remove format, pretty + arguments; add options. Update. + (pascal_object_print_static_field): Likewise. + (_initialize_pascal_valprint): Use user_print_options. Update. + * p-lang.h (pascal_val_print, pascal_value_print, + pascal_printstr, pascal_object_print_value_fields): Update. + (vtblprint, static_field_print): Don't declare. + * p-lang.c (pascal_printstr): Add options argument. Update. + * objc-lang.c (objc_printstr): Add options argument. Update. + * mt-tdep.c: Include valprint.h. + (mt_registers_info): Use get_raw_print_options. + * mips-tdep.c: Include valprint.h. + (mips_print_fp_register): Use get_formatted_print_options. + (mips_print_register): Likewise. + * mi/mi-main.c: Include valprint.h. + (get_register): Use get_user_print_options. + (mi_cmd_data_evaluate_expression): Likewise. + (mi_cmd_data_read_memory): Use get_formatted_print_options. + * mi/mi-cmd-stack.c: Include valprint.h. + (list_args_or_locals): Use get_raw_print_options. + * m2-valprint.c (print_function_pointer_address): Add addressprint + argument. + (m2_print_long_set): Remove format, pretty arguments. + (m2_print_unbounded_array): Remove format, deref_ref, pretty + arguments; add options. Update. + (print_unpacked_pointer): Remove format argument; add options. + Now static. Update. + (print_variable_at_address): Remove format, deref_ref, pretty + arguments; add options. Update. + (m2_print_array_contents): Likewise. + (m2_val_print): Likewise. + * m2-lang.h (m2_val_print): Update. + * m2-lang.c (m2_printstr): Add options argument. Update. + * language.h (struct value_print_options): Declare. + (struct language_defn) : Add options argument. + : Remove format, deref_ref, pretty argument; add + options. + : Remove format, pretty arguments; add options. + : Likewise. + (LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING, + LA_PRINT_ARRAY_INDEX): Update. + (default_print_array_index): Update. + * language.c (default_print_array_index): Remove format, pretty + arguments; add options. Update. + (unk_lang_printstr): Add options argument. + (unk_lang_val_print): Remove format, deref_ref, pretty arguments; + add options. + (unk_lang_value_print): Remove format, pretty arguments; add + options. + * jv-valprint.c (java_value_print): Remove format, pretty + arguments; add options. Update. + (java_print_value_fields): Likewise. + (java_val_print): Remove format, deref_ref, pretty arguments; add + options. Update. + * jv-lang.h (java_val_print, java_value_print): Declare. + * infcmd.c: Include valprint.h. + (print_return_value): Use get_raw_print_options. + (default_print_registers_info): Use get_user_print_options, + get_formatted_print_options. + (registers_info): Use get_formatted_print_options. + * gdbtypes.h (struct value_print_options): Declare. + (print_scalar_formatted): Update. + * f-valprint.c (f77_print_array_1): Remove format, deref_ref, + pretty arguments; add options. Update. + (f77_print_array): Likewise. + (f_val_print): Likewise. + * f-lang.h (f_val_print): Update. + * f-lang.c (f_printstr): Add options argument. Update. + (c_value_print): Update declaration. + * expprint.c: Include valprint.h. + (print_subexp_standard): Use get_raw_print_options, + get_user_print_options. + * eval.c: Include valprint.h. + (objectprint): Don't declare. + (evaluate_subexp_standard): Use get_user_print_options. + * cp-valprint.c (vtblprint, objectprint, static_field_print): + Remove. + (cp_print_value_fields): Remove format, pretty arguments; add + options. Update. + (cp_print_value): Likewise. + (cp_print_static_field): Likewise. + (_initialize_cp_valprint): Use user_print_options. Update. + * c-valprint.c (print_function_pointer_address): Add addressprint + argument. + (c_val_print): Remove format, deref_ref, pretty arguments; add + options. Update. + (c_value_print): Add options argument. Update. + * c-lang.h (c_val_print, c_value_print, c_printstr): Update. + (vtblprint, static_field_print): Don't declare. + (cp_print_value_fields): Update. + * c-lang.c (c_printstr): Add options argument. Update. + * breakpoint.c: Include valprint.h. + (addressprint): Don't declare. + (watchpoint_value_print): Use get_user_print_options. + (print_one_breakpoint_location): Likewise. + (breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention, + print_exception_catchpoint): Likewise. + * auxv.c (fprint_target_auxv): Don't declare addressprint. Use + get_user_print_options. + * ada-valprint.c (struct ada_val_print_args): Remove format, + deref_ref, and pretty; add options. + (print_optional_low_bound): Add options argument. + (val_print_packed_array_elements): Remove format and pretty + arguments; add options. Update. + (printstr): Add options argument. Update. + (ada_printstr): Likewise. + (ada_val_print): Remove format, deref_ref, pretty arguments; add + options argument. Update. + (ada_val_print_stub): Update. + (ada_val_print_array): Remove format, deref_ref, pretty arguments; + add options. Update. + (ada_val_print_1): Likewise. + (print_variant_part): Likewise. + (ada_value_print): Remove format, pretty arguments; add options. + Update. + (print_record): Likewise. + (print_field_values): Likewise. + * ada-lang.h (ada_val_print, ada_value_print, ada_printstr): + Update. + * ada-lang.c (ada_print_array_index): Add options argument; remove + format and pretty arguments. + (print_one_exception): Use get_user_print_options. + 2008-10-28 Tom Tromey * cli/cli-script.c (do_fclose_cleanup): Remove. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index cce7da9f0a8..9fdd944197f 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -353,9 +353,9 @@ ada_get_gdb_completer_word_break_characters (void) static void ada_print_array_index (struct value *index_value, struct ui_file *stream, - int format, enum val_prettyprint pretty) + const struct value_print_options *options) { - LA_VALUE_PRINT (index_value, stream, format, pretty); + LA_VALUE_PRINT (index_value, stream, options); fprintf_filtered (stream, " => "); } @@ -10100,7 +10100,10 @@ static void print_one_exception (enum exception_catchpoint_kind ex, struct breakpoint *b, CORE_ADDR *last_addr) { - if (addressprint) + struct value_print_options opts; + + get_user_print_options (&opts); + if (opts.addressprint) { annotate_field (4); ui_out_field_core_addr (uiout, "addr", b->loc->address); diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index ce6be4bc875..562a8673f0e 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -249,11 +249,11 @@ extern void ada_print_type (struct type *, char *, struct ui_file *, int, int); extern int ada_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); -extern int ada_value_print (struct value *, struct ui_file *, int, - enum val_prettyprint); +extern int ada_value_print (struct value *, struct ui_file *, + const struct value_print_options *); /* Defined in ada-lang.c */ @@ -266,7 +266,8 @@ extern void ada_emit_char (int, struct ui_file *, int, int); extern void ada_printchar (int, struct ui_file *); extern void ada_printstr (struct ui_file *, const gdb_byte *, - unsigned int, int, int); + unsigned int, int, int, + const struct value_print_options *); struct value *ada_convert_actual (struct value *actual, struct type *formal_type0, diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index e2f7740e289..cc8352fdfe8 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -43,18 +43,17 @@ struct ada_val_print_args int embedded_offset; CORE_ADDR address; struct ui_file *stream; - int format; - int deref_ref; int recurse; - enum val_prettyprint pretty; + const struct value_print_options *options; }; static void print_record (struct type *, const gdb_byte *, struct ui_file *, - int, int, enum val_prettyprint); + int, const struct value_print_options *); static int print_field_values (struct type *, const gdb_byte *, - struct ui_file *, int, int, - enum val_prettyprint, int, struct type *, + struct ui_file *, int, + const struct value_print_options *, + int, struct type *, const gdb_byte *); static void adjust_type_signedness (struct type *); @@ -62,8 +61,8 @@ static void adjust_type_signedness (struct type *); static int ada_val_print_stub (void *args0); static int ada_val_print_1 (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); /* Make TYPE unsigned if its range of values includes no negatives. */ @@ -81,13 +80,14 @@ adjust_type_signedness (struct type *type) otherwise 0. */ static int -print_optional_low_bound (struct ui_file *stream, struct type *type) +print_optional_low_bound (struct ui_file *stream, struct type *type, + const struct value_print_options *options) { struct type *index_type; long low_bound; long high_bound; - if (print_array_indexes_p ()) + if (options->print_array_indexes) return 0; if (!get_array_bounds (type, &low_bound, &high_bound)) @@ -137,16 +137,15 @@ print_optional_low_bound (struct ui_file *stream, struct type *type) /* Version of val_print_array_elements for GNAT-style packed arrays. Prints elements of packed array of type TYPE at bit offset - BITOFFSET from VALADDR on STREAM. Formats according to FORMAT and + BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and separates with commas. RECURSE is the recursion (nesting) level. - If PRETTY, uses "prettier" format. TYPE must have been decoded (as - by ada_coerce_to_simple_array). */ + TYPE must have been decoded (as by ada_coerce_to_simple_array). */ static void val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, int bitoffset, struct ui_file *stream, - int format, int recurse, - enum val_prettyprint pretty) + int recurse, + const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; @@ -172,14 +171,14 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, i = 0; annotate_array_section_begin (i, elttype); - while (i < len && things_printed < print_max) + while (i < len && things_printed < options->print_max) { struct value *v0, *v1; int i0; if (i != 0) { - if (prettyprint_arrays) + if (options->prettyprint_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -190,7 +189,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, } } wrap_here (n_spaces (2 + 2 * recurse)); - maybe_print_array_index (index_type, i + low, stream, format, pretty); + maybe_print_array_index (index_type, i + low, stream, options); i0 = i; v0 = ada_value_primitive_packed_val (NULL, valaddr, @@ -210,10 +209,12 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, break; } - if (i - i0 > repeat_count_threshold) + if (i - i0 > options->repeat_count_threshold) { - val_print (elttype, value_contents (v0), 0, 0, stream, format, - 0, recurse + 1, pretty, current_language); + struct value_print_options opts = *options; + opts.deref_ref = 0; + val_print (elttype, value_contents (v0), 0, 0, stream, + recurse + 1, &opts, current_language); annotate_elt_rep (i - i0); fprintf_filtered (stream, _(" "), i - i0); annotate_elt_rep_end (); @@ -222,11 +223,13 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, else { int j; + struct value_print_options opts = *options; + opts.deref_ref = 0; for (j = i0; j < i; j += 1) { if (j > i0) { - if (prettyprint_arrays) + if (options->prettyprint_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -237,10 +240,10 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, } wrap_here (n_spaces (2 + 2 * recurse)); maybe_print_array_index (index_type, j + low, - stream, format, pretty); + stream, options); } - val_print (elttype, value_contents (v0), 0, 0, stream, format, - 0, recurse + 1, pretty, current_language); + val_print (elttype, value_contents (v0), 0, 0, stream, + recurse + 1, &opts, current_language); annotate_elt (); } } @@ -452,7 +455,8 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) static void printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int force_ellipses, int type_len) + unsigned int length, int force_ellipses, int type_len, + const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; @@ -465,7 +469,7 @@ printstr (struct ui_file *stream, const gdb_byte *string, return; } - for (i = 0; i < length && things_printed < print_max; i += 1) + for (i = 0; i < length && things_printed < options->print_max; i += 1) { /* Position of the character we are examining to see whether it is repeated. */ @@ -491,11 +495,11 @@ printstr (struct ui_file *stream, const gdb_byte *string, reps += 1; } - if (reps > repeat_count_threshold) + if (reps > options->repeat_count_threshold) { if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\", ", stream); else fputs_filtered ("\", ", stream); @@ -507,14 +511,14 @@ printstr (struct ui_file *stream, const gdb_byte *string, fputs_filtered ("'", stream); fprintf_filtered (stream, _(" "), reps); i = rep1 - 1; - things_printed += repeat_count_threshold; + things_printed += options->repeat_count_threshold; need_comma = 1; } else { if (!in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); @@ -529,7 +533,7 @@ printstr (struct ui_file *stream, const gdb_byte *string, /* Terminate the quotes if necessary. */ if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); @@ -541,36 +545,28 @@ printstr (struct ui_file *stream, const gdb_byte *string, void ada_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { - printstr (stream, string, length, force_ellipses, width); + printstr (stream, string, length, force_ellipses, width, options); } /* Print data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto stdio stream STREAM according to - FORMAT (a letter as for the printf % codes or 0 for natural format). - The data at VALADDR is in target byte order. + OPTIONS. The data at VALADDR is in target byte order. If the data is printed as a string, returns the number of string characters printed. - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - RECURSE indicates the amount of indentation to supply before - continuation lines; this amount is roughly twice the value of RECURSE. - - When PRETTY is non-zero, prints record fields on separate lines. - (For some reason, the current version of gdb instead uses a global - variable---prettyprint_arrays--- to causes a similar effect on - arrays.) */ + continuation lines; this amount is roughly twice the value of RECURSE. */ int ada_val_print (struct type *type, const gdb_byte *valaddr0, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, int deref_ref, - int recurse, enum val_prettyprint pretty) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { struct ada_val_print_args args; args.type = type; @@ -578,10 +574,8 @@ ada_val_print (struct type *type, const gdb_byte *valaddr0, args.embedded_offset = embedded_offset; args.address = address; args.stream = stream; - args.format = format; - args.deref_ref = deref_ref; args.recurse = recurse; - args.pretty = pretty; + args.options = options; return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL); } @@ -594,8 +588,7 @@ ada_val_print_stub (void *args0) struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0; return ada_val_print_1 (argsp->type, argsp->valaddr0, argsp->embedded_offset, argsp->address, - argsp->stream, argsp->format, argsp->deref_ref, - argsp->recurse, argsp->pretty); + argsp->stream, argsp->recurse, argsp->options); } /* Assuming TYPE is a simple array, print the value of this array located @@ -605,8 +598,8 @@ ada_val_print_stub (void *args0) static int ada_val_print_array (struct type *type, const gdb_byte *valaddr, - CORE_ADDR address, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) + CORE_ADDR address, struct ui_file *stream, int recurse, + const struct value_print_options *options) { struct type *elttype = TYPE_TARGET_TYPE (type); unsigned int eltlen; @@ -623,40 +616,40 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr, len = TYPE_LENGTH (type) / eltlen; /* For an array of chars, print with string syntax. */ - if (ada_is_string_type (type) && (format == 0 || format == 's')) + if (ada_is_string_type (type) + && (options->format == 0 || options->format == 's')) { - if (prettyprint_arrays) + if (options->prettyprint_arrays) print_spaces_filtered (2 + 2 * recurse, stream); /* If requested, look for the first null char and only print elements up to it. */ - if (stop_print_at_null) + if (options->stop_print_at_null) { int temp_len; /* Look for a NULL char. */ for (temp_len = 0; (temp_len < len - && temp_len < print_max + && temp_len < options->print_max && char_at (valaddr, temp_len, eltlen) != 0); temp_len += 1); len = temp_len; } - printstr (stream, valaddr, len, 0, eltlen); + printstr (stream, valaddr, len, 0, eltlen, options); result = len; } else { fprintf_filtered (stream, "("); - print_optional_low_bound (stream, type); + print_optional_low_bound (stream, type, options); if (TYPE_FIELD_BITSIZE (type, 0) > 0) val_print_packed_array_elements (type, valaddr, 0, stream, - format, recurse, pretty); + recurse, options); else val_print_array_elements (type, valaddr, address, stream, - format, deref_ref, recurse, - pretty, 0); + recurse, options, 0); fprintf_filtered (stream, ")"); } @@ -669,8 +662,8 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr, static int ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { unsigned int len; int i; @@ -695,8 +688,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, } else retn = ada_val_print_1 (value_type (val), value_contents (val), 0, - VALUE_ADDRESS (val), stream, format, - deref_ref, recurse, pretty); + VALUE_ADDRESS (val), stream, recurse, options); value_free_to_mark (mark); return retn; } @@ -709,12 +701,12 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, { default: return c_val_print (type, valaddr0, embedded_offset, address, stream, - format, deref_ref, recurse, pretty); + recurse, options); case TYPE_CODE_PTR: { int ret = c_val_print (type, valaddr0, embedded_offset, address, - stream, format, deref_ref, recurse, pretty); + stream, recurse, options); if (ada_is_tag_type (type)) { struct value *val = @@ -778,20 +770,22 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, value_from_contents_and_address (type, valaddr, 0)); return ada_val_print_1 (target_type, value_contents (v), 0, 0, - stream, format, 0, recurse + 1, pretty); + stream, recurse + 1, options); } else return ada_val_print_1 (TYPE_TARGET_TYPE (type), valaddr0, embedded_offset, - address, stream, format, deref_ref, - recurse, pretty); + address, stream, recurse, options); } else { - format = format ? format : output_format; + int format = (options->format ? options->format + : options->output_format); if (format) { - print_scalar_formatted (valaddr, type, format, 0, stream); + struct value_print_options opts = *options; + opts.format = format; + print_scalar_formatted (valaddr, type, &opts, 0, stream); } else if (ada_is_system_address_type (type) && TYPE_OBJFILE (type) != NULL) @@ -830,9 +824,9 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, } case TYPE_CODE_ENUM: - if (format) + if (options->format) { - print_scalar_formatted (valaddr, type, format, 0, stream); + print_scalar_formatted (valaddr, type, options, 0, stream); break; } len = TYPE_NFIELDS (type); @@ -860,16 +854,16 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, break; case TYPE_CODE_FLAGS: - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); + if (options->format) + print_scalar_formatted (valaddr, type, options, 0, stream); else val_print_type_code_flags (type, valaddr, stream); break; case TYPE_CODE_FLT: - if (format) + if (options->format) return c_val_print (type, valaddr0, embedded_offset, address, stream, - format, deref_ref, recurse, pretty); + recurse, options); else ada_print_floating (valaddr0 + embedded_offset, type, stream); break; @@ -883,13 +877,13 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, } else { - print_record (type, valaddr, stream, format, recurse, pretty); + print_record (type, valaddr, stream, recurse, options); return 0; } case TYPE_CODE_ARRAY: - return ada_val_print_array (type, valaddr, address, stream, format, - deref_ref, recurse, pretty); + return ada_val_print_array (type, valaddr, address, stream, + recurse, options); case TYPE_CODE_REF: /* For references, the debugger is expected to print the value as @@ -910,8 +904,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, deref_val_int)); val_print (value_type (deref_val), value_contents (deref_val), 0, - VALUE_ADDRESS (deref_val), stream, format, - deref_ref, recurse + 1, pretty, current_language); + VALUE_ADDRESS (deref_val), stream, recurse + 1, + options, current_language); } else fputs_filtered ("(null)", stream); @@ -927,8 +921,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, static int print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr, - struct ui_file *stream, int format, int recurse, - enum val_prettyprint pretty, int comma_needed, + struct ui_file *stream, int recurse, + const struct value_print_options *options, int comma_needed, struct type *outer_type, const gdb_byte *outer_valaddr) { struct type *var_type = TYPE_FIELD_TYPE (type, field_num); @@ -941,13 +935,13 @@ print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr, (TYPE_FIELD_TYPE (var_type, which), valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT, - stream, format, recurse, pretty, + stream, recurse, options, comma_needed, outer_type, outer_valaddr); } int -ada_value_print (struct value *val0, struct ui_file *stream, int format, - enum val_prettyprint pretty) +ada_value_print (struct value *val0, struct ui_file *stream, + const struct value_print_options *options) { const gdb_byte *valaddr = value_contents (val0); CORE_ADDR address = VALUE_ADDRESS (val0) + value_offset (val0); @@ -955,6 +949,7 @@ ada_value_print (struct value *val0, struct ui_file *stream, int format, ada_to_fixed_type (value_type (val0), valaddr, address, NULL, 1); struct value *val = value_from_contents_and_address (type, valaddr, address); + struct value_print_options opts; /* If it is a pointer, indicate what it points to. */ if (TYPE_CODE (type) == TYPE_CODE_PTR) @@ -984,21 +979,23 @@ ada_value_print (struct value *val0, struct ui_file *stream, int format, return 0; } + opts = *options; + opts.deref_ref = 1; return (val_print (type, value_contents (val), 0, address, - stream, format, 1, 0, pretty, current_language)); + stream, 0, &opts, current_language)); } static void print_record (struct type *type, const gdb_byte *valaddr, - struct ui_file *stream, int format, int recurse, - enum val_prettyprint pretty) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { type = ada_check_typedef (type); fprintf_filtered (stream, "("); - if (print_field_values (type, valaddr, stream, format, recurse, pretty, - 0, type, valaddr) != 0 && pretty) + if (print_field_values (type, valaddr, stream, recurse, options, + 0, type, valaddr) != 0 && options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); @@ -1009,7 +1006,7 @@ print_record (struct type *type, const gdb_byte *valaddr, /* Print out fields of value at VALADDR having structure type TYPE. - TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the + TYPE, VALADDR, STREAM, RECURSE, and OPTIONS have the same meanings as in ada_print_value and ada_val_print. OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record @@ -1023,8 +1020,9 @@ print_record (struct type *type, const gdb_byte *valaddr, static int print_field_values (struct type *type, const gdb_byte *valaddr, - struct ui_file *stream, int format, int recurse, - enum val_prettyprint pretty, int comma_needed, + struct ui_file *stream, int recurse, + const struct value_print_options *options, + int comma_needed, struct type *outer_type, const gdb_byte *outer_valaddr) { int i, len; @@ -1042,7 +1040,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, print_field_values (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, - stream, format, recurse, pretty, + stream, recurse, options, comma_needed, type, valaddr); continue; } @@ -1050,7 +1048,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, { comma_needed = print_variant_part (type, i, valaddr, - stream, format, recurse, pretty, comma_needed, + stream, recurse, options, comma_needed, outer_type, outer_valaddr); continue; } @@ -1059,7 +1057,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, fprintf_filtered (stream, ", "); comma_needed = 1; - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -1068,7 +1066,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, { wrap_here (n_spaces (2 + 2 * recurse)); } - if (inspect_it) + if (options->inspect_it) { if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) fputs_filtered ("\"( ptr \"", stream); @@ -1107,6 +1105,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, { int bit_pos = TYPE_FIELD_BITPOS (type, i); int bit_size = TYPE_FIELD_BITSIZE (type, i); + struct value_print_options opts; adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); v = ada_value_primitive_packed_val (NULL, valaddr, @@ -1114,15 +1113,20 @@ print_field_values (struct type *type, const gdb_byte *valaddr, bit_pos % HOST_CHAR_BIT, bit_size, TYPE_FIELD_TYPE (type, i)); + opts = *options; + opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0, - stream, format, 0, recurse + 1, pretty, - current_language); + stream, recurse + 1, &opts, current_language); } } else - ada_val_print (TYPE_FIELD_TYPE (type, i), - valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, - 0, 0, stream, format, 0, recurse + 1, pretty); + { + struct value_print_options opts = *options; + opts.deref_ref = 0; + ada_val_print (TYPE_FIELD_TYPE (type, i), + valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, + 0, 0, stream, recurse + 1, &opts); + } annotate_field_end (); } diff --git a/gdb/auxv.c b/gdb/auxv.c index afc7fdd46d3..121a7497311 100644 --- a/gdb/auxv.c +++ b/gdb/auxv.c @@ -172,7 +172,6 @@ fprint_target_auxv (struct ui_file *file, struct target_ops *ops) while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0) { - extern int addressprint; const char *name = "???"; const char *description = ""; enum { dec, hex, str } flavor = hex; @@ -240,10 +239,14 @@ fprint_target_auxv (struct ui_file *file, struct target_ops *ops) fprintf_filtered (file, "0x%s\n", paddr_nz (val)); break; case str: - if (addressprint) - fprintf_filtered (file, "0x%s", paddr_nz (val)); - val_print_string (val, -1, 1, file); - fprintf_filtered (file, "\n"); + { + struct value_print_options opts; + get_user_print_options (&opts); + if (opts.addressprint) + fprintf_filtered (file, "0x%s", paddr_nz (val)); + val_print_string (val, -1, 1, file, &opts); + fprintf_filtered (file, "\n"); + } break; } ++ents; diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 180f6c9dee9..01b2990e144 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -56,6 +56,7 @@ #include "ada-lang.h" #include "top.h" #include "wrapper.h" +#include "valprint.h" #include "mi/mi-common.h" @@ -283,8 +284,6 @@ breakpoints_always_inserted_mode (void) void _initialize_breakpoint (void); -extern int addressprint; /* Print machine addresses? */ - /* Are we executing breakpoint commands? */ static int executing_breakpoint_commands; @@ -2259,7 +2258,11 @@ watchpoint_value_print (struct value *val, struct ui_file *stream) if (val == NULL) fprintf_unfiltered (stream, _("")); else - value_print (val, stream, 0, Val_pretty_default); + { + struct value_print_options opts; + get_user_print_options (&opts); + value_print (val, stream, &opts); + } } /* This is the normal print function for a bpstat. In the future, @@ -3577,6 +3580,9 @@ print_one_breakpoint_location (struct breakpoint *b, int header_of_multiple = 0; int part_of_multiple = (loc != NULL); + struct value_print_options opts; + + get_user_print_options (&opts); gdb_assert (!loc || loc_number != 0); /* See comment in print_one_breakpoint concerning @@ -3640,7 +3646,7 @@ print_one_breakpoint_location (struct breakpoint *b, /* 5 and 6 */ strcpy (wrap_indent, " "); - if (addressprint) + if (opts.addressprint) { if (gdbarch_addr_bit (current_gdbarch) <= 32) strcat (wrap_indent, " "); @@ -3672,7 +3678,7 @@ print_one_breakpoint_location (struct breakpoint *b, /* Field 4, the address, is omitted (which makes the columns not line up too nicely with the headers, but the effect is relatively readable). */ - if (addressprint) + if (opts.addressprint) ui_out_field_skip (uiout, "addr"); annotate_field (5); print_expression (b->exp, stb->stream); @@ -3684,7 +3690,7 @@ print_one_breakpoint_location (struct breakpoint *b, /* Field 4, the address, is omitted (which makes the columns not line up too nicely with the headers, but the effect is relatively readable). */ - if (addressprint) + if (opts.addressprint) ui_out_field_skip (uiout, "addr"); annotate_field (5); if (b->dll_pathname == NULL) @@ -3704,7 +3710,7 @@ print_one_breakpoint_location (struct breakpoint *b, /* Field 4, the address, is omitted (which makes the columns not line up too nicely with the headers, but the effect is relatively readable). */ - if (addressprint) + if (opts.addressprint) ui_out_field_skip (uiout, "addr"); annotate_field (5); if (b->exec_pathname != NULL) @@ -3727,7 +3733,7 @@ print_one_breakpoint_location (struct breakpoint *b, case bp_shlib_event: case bp_thread_event: case bp_overlay_event: - if (addressprint) + if (opts.addressprint) { annotate_field (4); if (header_of_multiple) @@ -3933,7 +3939,10 @@ breakpoint_1 (int bnum, int allflag) CORE_ADDR last_addr = (CORE_ADDR) -1; int nr_printable_breakpoints; struct cleanup *bkpttbl_chain; + struct value_print_options opts; + get_user_print_options (&opts); + /* Compute the number of rows in the table. */ nr_printable_breakpoints = 0; ALL_BREAKPOINTS (b) @@ -3944,7 +3953,7 @@ breakpoint_1 (int bnum, int allflag) nr_printable_breakpoints++; } - if (addressprint) + if (opts.addressprint) bkpttbl_chain = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, "BreakpointTable"); @@ -3967,7 +3976,7 @@ breakpoint_1 (int bnum, int allflag) if (nr_printable_breakpoints > 0) annotate_field (3); ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ - if (addressprint) + if (opts.addressprint) { if (nr_printable_breakpoints > 0) annotate_field (4); @@ -4760,10 +4769,14 @@ print_it_catch_fork (struct breakpoint *b) static void print_one_catch_fork (struct breakpoint *b, CORE_ADDR *last_addr) { + struct value_print_options opts; + + get_user_print_options (&opts); + /* Field 4, the address, is omitted (which makes the columns not line up too nicely with the headers, but the effect is relatively readable). */ - if (addressprint) + if (opts.addressprint) ui_out_field_skip (uiout, "addr"); annotate_field (5); ui_out_text (uiout, "fork"); @@ -4838,10 +4851,13 @@ print_it_catch_vfork (struct breakpoint *b) static void print_one_catch_vfork (struct breakpoint *b, CORE_ADDR *last_addr) { + struct value_print_options opts; + + get_user_print_options (&opts); /* Field 4, the address, is omitted (which makes the columns not line up too nicely with the headers, but the effect is relatively readable). */ - if (addressprint) + if (opts.addressprint) ui_out_field_skip (uiout, "addr"); annotate_field (5); ui_out_text (uiout, "vfork"); @@ -5072,6 +5088,9 @@ mention (struct breakpoint *b) int say_where = 0; struct cleanup *old_chain, *ui_out_chain; struct ui_stream *stb; + struct value_print_options opts; + + get_user_print_options (&opts); stb = ui_out_stream_new (uiout); old_chain = make_cleanup_ui_out_stream_delete (stb); @@ -5184,7 +5203,7 @@ mention (struct breakpoint *b) } else { - if (addressprint || b->source_file == NULL) + if (opts.addressprint || b->source_file == NULL) { printf_filtered (" at "); fputs_filtered (paddress (b->loc->address), gdb_stdout); @@ -6746,7 +6765,9 @@ print_exception_catchpoint (struct breakpoint *b) static void print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr) { - if (addressprint) + struct value_print_options opts; + get_user_print_options (&opts); + if (opts.addressprint) { annotate_field (4); if (b->loc == NULL || b->loc->shlib_disabled) diff --git a/gdb/c-lang.c b/gdb/c-lang.c index a978b17ebc4..067e42985af 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -86,7 +86,8 @@ c_printchar (int c, struct ui_file *stream) void c_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; @@ -108,7 +109,7 @@ c_printstr (struct ui_file *stream, const gdb_byte *string, return; } - for (i = 0; i < length && things_printed < print_max; ++i) + for (i = 0; i < length && things_printed < options->print_max; ++i) { /* Position of the character we are examining to see whether it is repeated. */ @@ -137,11 +138,11 @@ c_printstr (struct ui_file *stream, const gdb_byte *string, ++reps; } - if (reps > repeat_count_threshold) + if (reps > options->repeat_count_threshold) { if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\", ", stream); else fputs_filtered ("\", ", stream); @@ -150,14 +151,14 @@ c_printstr (struct ui_file *stream, const gdb_byte *string, LA_PRINT_CHAR (current_char, stream); fprintf_filtered (stream, _(" "), reps); i = rep1 - 1; - things_printed += repeat_count_threshold; + things_printed += options->repeat_count_threshold; need_comma = 1; } else { if (!in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); @@ -171,7 +172,7 @@ c_printstr (struct ui_file *stream, const gdb_byte *string, /* Terminate the quotes if necessary. */ if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); diff --git a/gdb/c-lang.h b/gdb/c-lang.h index fe1939accc3..cc9abde19d5 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -40,11 +40,11 @@ extern void c_print_type (struct type *, char *, struct ui_file *, int, extern void c_print_typedef (struct type *, struct symbol *, struct ui_file *); extern int c_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); -extern int c_value_print (struct value *, struct ui_file *, int, - enum val_prettyprint); +extern int c_value_print (struct value *, struct ui_file *, + const struct value_print_options *); /* These are in c-lang.c: */ @@ -52,7 +52,8 @@ extern void c_printchar (int, struct ui_file *); extern void c_printstr (struct ui_file * stream, const gdb_byte *string, unsigned int length, int width, - int force_ellipses); + int force_ellipses, + const struct value_print_options *options); extern void scan_macro_expansion (char *expansion); extern int scanning_macro_expansion (void); @@ -70,17 +71,13 @@ extern void c_type_print_base (struct type *, struct ui_file *, int, int); /* These are in cp-valprint.c */ -extern int vtblprint; /* Controls printing of vtbl's */ - -extern int static_field_print; - extern void cp_print_class_member (const gdb_byte *, struct type *, struct ui_file *, char *); extern void cp_print_value_fields (struct type *, struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, - int, enum val_prettyprint, + const struct value_print_options *, struct type **, int); extern int cp_is_vtbl_ptr_type (struct type *); diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 1dff6cbcf14..b639e8bb577 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -36,7 +36,8 @@ stream STREAM. */ static void -print_function_pointer_address (CORE_ADDR address, struct ui_file *stream) +print_function_pointer_address (CORE_ADDR address, struct ui_file *stream, + int addressprint) { CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch, address, @@ -102,21 +103,15 @@ textual_element_type (struct type *type, char format) /* Print data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto stdio stream STREAM according to - FORMAT (a letter or 0 for natural format). The data at VALADDR is in - target byte order. + OPTIONS. The data at VALADDR is in target byte order. If the data are a string pointer, returns the number of string characters - printed. - - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - - The PRETTY parameter controls prettyprinting. */ + printed. */ int c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, - CORE_ADDR address, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) + CORE_ADDR address, struct ui_file *stream, int recurse, + const struct value_print_options *options) { unsigned int i = 0; /* Number of characters printed */ unsigned len; @@ -134,29 +129,29 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, { eltlen = TYPE_LENGTH (elttype); len = TYPE_LENGTH (type) / eltlen; - if (prettyprint_arrays) + if (options->prettyprint_arrays) { print_spaces_filtered (2 + 2 * recurse, stream); } /* Print arrays of textual chars with a string syntax. */ - if (textual_element_type (elttype, format)) + if (textual_element_type (elttype, options->format)) { /* If requested, look for the first null char and only print elements up to it. */ - if (stop_print_at_null) + if (options->stop_print_at_null) { unsigned int temp_len; /* Look for a NULL char. */ for (temp_len = 0; (valaddr + embedded_offset)[temp_len] - && temp_len < len && temp_len < print_max; + && temp_len < len && temp_len < options->print_max; temp_len++); len = temp_len; } - LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0); + LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0, options); i = len; } else @@ -174,7 +169,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, i = 0; } val_print_array_elements (type, valaddr + embedded_offset, address, stream, - format, deref_ref, recurse, pretty, i); + recurse, options, i); fprintf_filtered (stream, "}"); } break; @@ -184,9 +179,10 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, goto print_unpacked_pointer; case TYPE_CODE_MEMBERPTR: - if (format) + if (options->format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); break; } cp_print_class_member (valaddr + embedded_offset, type, stream, "&"); @@ -197,19 +193,20 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_PTR: - if (format && format != 's') + if (options->format && options->format != 's') { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); break; } - if (vtblprint && cp_is_vtbl_ptr_type (type)) + if (options->vtblprint && cp_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if we ARE using -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ CORE_ADDR addr = extract_typed_address (valaddr + embedded_offset, type); - print_function_pointer_address (addr, stream); + print_function_pointer_address (addr, stream, options->addressprint); break; } elttype = check_typedef (TYPE_TARGET_TYPE (type)); @@ -220,21 +217,24 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) { /* Try to print what function it points to. */ - print_function_pointer_address (addr, stream); + print_function_pointer_address (addr, stream, + options->addressprint); /* Return value is irrelevant except for string pointers. */ return (0); } - if (addressprint) + if (options->addressprint) fputs_filtered (paddress (addr), stream); /* For a pointer to a textual type, also print the string pointed to, unless pointer is null. */ /* FIXME: need to handle wchar_t here... */ - if (textual_element_type (elttype, format) && addr != 0) + if (textual_element_type (elttype, options->format) + && addr != 0) { - i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); + i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream, + options); } else if (cp_is_vtbl_member (type)) { @@ -250,7 +250,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); fputs_filtered (">", stream); } - if (vt_address && vtblprint) + if (vt_address && options->vtblprint) { struct value *vt_val; struct symbol *wsym = (struct symbol *) NULL; @@ -271,10 +271,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, wtype = TYPE_TARGET_TYPE (type); } vt_val = value_at (wtype, vt_address); - common_val_print (vt_val, stream, format, - deref_ref, recurse + 1, pretty, + common_val_print (vt_val, stream, recurse + 1, options, current_language); - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -291,17 +290,17 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_REF: elttype = check_typedef (TYPE_TARGET_TYPE (type)); - if (addressprint) + if (options->addressprint) { CORE_ADDR addr = extract_typed_address (valaddr + embedded_offset, type); fprintf_filtered (stream, "@"); fputs_filtered (paddress (addr), stream); - if (deref_ref) + if (options->deref_ref) fputs_filtered (": ", stream); } /* De-reference the reference. */ - if (deref_ref) + if (options->deref_ref) { if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) { @@ -309,8 +308,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr + embedded_offset)); - common_val_print (deref_val, stream, format, deref_ref, - recurse, pretty, current_language); + common_val_print (deref_val, stream, recurse, options, + current_language); } else fputs_filtered ("???", stream); @@ -318,7 +317,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_UNION: - if (recurse && !unionprint) + if (recurse && !options->unionprint) { fprintf_filtered (stream, "{...}"); break; @@ -326,7 +325,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, /* Fall through. */ case TYPE_CODE_STRUCT: /*FIXME: Abstract this away */ - if (vtblprint && cp_is_vtbl_ptr_type (type)) + if (options->vtblprint && cp_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if NOT using @@ -337,17 +336,18 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type); - print_function_pointer_address (addr, stream); + print_function_pointer_address (addr, stream, options->addressprint); } else - cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format, - recurse, pretty, NULL, 0); + cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, + recurse, options, NULL, 0); break; case TYPE_CODE_ENUM: - if (format) + if (options->format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); break; } len = TYPE_NFIELDS (type); @@ -371,17 +371,19 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_FLAGS: - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + if (options->format) + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); else val_print_type_code_flags (type, valaddr + embedded_offset, stream); break; case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: - if (format) + if (options->format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); break; } /* FIXME, we should consider, at least for ANSI C language, eliminating @@ -394,9 +396,14 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_BOOL: - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); + } else { val = unpack_long (type, valaddr + embedded_offset); @@ -420,10 +427,13 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, /* FALLTHROUGH */ case TYPE_CODE_INT: - format = format ? format : output_format; - if (format) + if (options->format || options->output_format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); } else { @@ -432,7 +442,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, Since we don't know whether the value is really intended to be used as an integer or a character, print the character equivalent as well. */ - if (textual_element_type (type, format)) + if (textual_element_type (type, options->format)) { fputs_filtered (" ", stream); LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset), @@ -442,10 +452,13 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_CHAR: - format = format ? format : output_format; - if (format) + if (options->format || options->output_format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); } else { @@ -460,9 +473,10 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_FLT: - if (format) + if (options->format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); } else { @@ -471,8 +485,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_DECFLOAT: - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + if (options->format) + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); else print_decimal_floating (valaddr + embedded_offset, type, stream); break; @@ -493,19 +508,19 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_COMPLEX: - if (format) + if (options->format) print_scalar_formatted (valaddr + embedded_offset, TYPE_TARGET_TYPE (type), - format, 0, stream); + options, 0, stream); else print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type), stream); fprintf_filtered (stream, " + "); - if (format) + if (options->format) print_scalar_formatted (valaddr + embedded_offset + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), TYPE_TARGET_TYPE (type), - format, 0, stream); + options, 0, stream); else print_floating (valaddr + embedded_offset + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), @@ -522,11 +537,14 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, } int -c_value_print (struct value *val, struct ui_file *stream, int format, - enum val_prettyprint pretty) +c_value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options) { struct type *type, *real_type; int full, top, using_enc; + struct value_print_options opts = *options; + + opts.deref_ref = 1; /* If it is a pointer, indicate what it points to. @@ -551,7 +569,8 @@ c_value_print (struct value *val, struct ui_file *stream, int format, { /* Print nothing */ } - else if (objectprint && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS)) + else if (options->objectprint + && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS)) { if (TYPE_CODE(type) == TYPE_CODE_REF) @@ -602,7 +621,7 @@ c_value_print (struct value *val, struct ui_file *stream, int format, if (!value_initialized (val)) fprintf_filtered (stream, " [uninitialized] "); - if (objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS)) + if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS)) { /* Attempt to determine real type of object */ real_type = value_rtti_type (val, &full, &top, &using_enc); @@ -616,8 +635,8 @@ c_value_print (struct value *val, struct ui_file *stream, int format, /* Print out object: enclosing type is same as real_type if full */ return val_print (value_enclosing_type (val), value_contents_all (val), 0, - VALUE_ADDRESS (val), stream, format, 1, 0, - pretty, current_language); + VALUE_ADDRESS (val), stream, 0, + &opts, current_language); /* Note: When we look up RTTI entries, we don't get any information on const or volatile attributes */ } @@ -628,8 +647,8 @@ c_value_print (struct value *val, struct ui_file *stream, int format, TYPE_NAME (value_enclosing_type (val))); return val_print (value_enclosing_type (val), value_contents_all (val), 0, - VALUE_ADDRESS (val), stream, format, 1, 0, - pretty, current_language); + VALUE_ADDRESS (val), stream, 0, + &opts, current_language); } /* Otherwise, we end up at the return outside this "if" */ } @@ -637,5 +656,5 @@ c_value_print (struct value *val, struct ui_file *stream, int format, return val_print (type, value_contents_all (val), value_embedded_offset (val), VALUE_ADDRESS (val) + value_offset (val), - stream, format, 1, 0, pretty, current_language); + stream, 0, &opts, current_language); } diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 61559af5808..2968953be93 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -38,7 +38,6 @@ #include "language.h" /* Controls printing of vtbl's */ -int vtblprint; static void show_vtblprint (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -50,7 +49,6 @@ Printing of C++ virtual function tables is %s.\n"), /* Controls looking up an object's derived type using what we find in its vtables. */ -int objectprint; static void show_objectprint (struct ui_file *file, int from_tty, struct cmd_list_element *c, @@ -61,7 +59,6 @@ Printing of object's derived type based on vtable info is %s.\n"), value); } -int static_field_print; /* Controls printing of static fields. */ static void show_static_field_print (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -77,12 +74,12 @@ static struct obstack dont_print_statmem_obstack; extern void _initialize_cp_valprint (void); static void cp_print_static_field (struct type *, struct value *, - struct ui_file *, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); static void cp_print_value (struct type *, struct type *, const gdb_byte *, - int, CORE_ADDR, struct ui_file *, int, int, - enum val_prettyprint, struct type **); + int, CORE_ADDR, struct ui_file *, int, + const struct value_print_options *, struct type **); /* GCC versions after 2.4.5 use this. */ @@ -139,7 +136,7 @@ cp_is_vtbl_member (struct type *type) /* Mutually recursive subroutines of cp_print_value and c_val_print to print out a structure's fields: cp_print_value_fields and cp_print_value. - TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the + TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the same meanings as in cp_print_value and c_val_print. 2nd argument REAL_TYPE is used to carry over the type of the derived @@ -151,9 +148,9 @@ cp_is_vtbl_member (struct type *type) void cp_print_value_fields (struct type *type, struct type *real_type, const gdb_byte *valaddr, int offset, CORE_ADDR address, - struct ui_file *stream, int format, int recurse, - enum val_prettyprint pretty, - struct type **dont_print_vb,int dont_print_statmem) + struct ui_file *stream, int recurse, + const struct value_print_options *options, + struct type **dont_print_vb, int dont_print_statmem) { int i, len, n_baseclasses; char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack); @@ -170,7 +167,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, if (n_baseclasses > 0) cp_print_value (type, real_type, valaddr, offset, address, stream, - format, recurse + 1, pretty, dont_print_vb); + recurse + 1, options, dont_print_vb); /* Second, print out data fields */ @@ -192,7 +189,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, for (i = n_baseclasses; i < len; i++) { /* If requested, skip printing of static fields. */ - if (!static_field_print + if (!options->static_field_print && field_is_static (&TYPE_FIELD (type, i))) continue; @@ -200,7 +197,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, fprintf_filtered (stream, ", "); else if (n_baseclasses > 0) { - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -211,7 +208,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, } fields_seen = 1; - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -220,7 +217,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, { wrap_here (n_spaces (2 + 2 * recurse)); } - if (inspect_it) + if (options->inspect_it) { if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) fputs_filtered ("\"( ptr \"", stream); @@ -266,11 +263,13 @@ cp_print_value_fields (struct type *type, struct type *real_type, } else { + struct value_print_options opts = *options; + opts.deref_ref = 0; v = value_from_longest (TYPE_FIELD_TYPE (type, i), unpack_field_as_long (type, valaddr + offset, i)); - common_val_print (v, stream, format, 0, recurse + 1, pretty, + common_val_print (v, stream, recurse + 1, &opts, current_language); } } @@ -287,15 +286,16 @@ cp_print_value_fields (struct type *type, struct type *real_type, fputs_filtered ("", stream); else cp_print_static_field (TYPE_FIELD_TYPE (type, i), v, - stream, format, recurse + 1, - pretty); + stream, recurse + 1, options); } else { + struct value_print_options opts = *options; + opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, address + TYPE_FIELD_BITPOS (type, i) / 8, - stream, format, 0, recurse + 1, pretty, + stream, recurse + 1, &opts, current_language); } } @@ -310,7 +310,7 @@ cp_print_value_fields (struct type *type, struct type *real_type, dont_print_statmem_obstack = tmp_obstack; } - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); @@ -326,8 +326,9 @@ cp_print_value_fields (struct type *type, struct type *real_type, static void cp_print_value (struct type *type, struct type *real_type, const gdb_byte *valaddr, int offset, CORE_ADDR address, - struct ui_file *stream, int format, int recurse, - enum val_prettyprint pretty, struct type **dont_print_vb) + struct ui_file *stream, int recurse, + const struct value_print_options *options, + struct type **dont_print_vb) { struct type **last_dont_print = (struct type **) obstack_next_free (&dont_print_vb_obstack); @@ -402,7 +403,7 @@ cp_print_value (struct type *type, struct type *real_type, base_valaddr = valaddr; /* now do the printing */ - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); @@ -419,8 +420,7 @@ cp_print_value (struct type *type, struct type *real_type, else cp_print_value_fields (baseclass, thistype, base_valaddr, thisoffset + boffset, address + boffset, - stream, format, - recurse, pretty, + stream, recurse, options, ((struct type **) obstack_base (&dont_print_vb_obstack)), 0); @@ -447,17 +447,17 @@ cp_print_value (struct type *type, struct type *real_type, static member classes in an obstack and refuse to print them more than once. - VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY + VAL contains the value to print, TYPE, STREAM, RECURSE, and OPTIONS have the same meanings as in c_val_print. */ static void cp_print_static_field (struct type *type, struct value *val, struct ui_file *stream, - int format, int recurse, - enum val_prettyprint pretty) + const struct value_print_options *options) { + struct value_print_options opts; if (TYPE_CODE (type) == TYPE_CODE_STRUCT) { CORE_ADDR *first_dont_print; @@ -485,12 +485,15 @@ cp_print_static_field (struct type *type, CHECK_TYPEDEF (type); cp_print_value_fields (type, type, value_contents_all (val), value_embedded_offset (val), VALUE_ADDRESS (val), - stream, format, recurse, pretty, NULL, 1); + stream, recurse, options, NULL, 1); return; } + + opts = *options; + opts.deref_ref = 0; val_print (type, value_contents_all (val), value_embedded_offset (val), VALUE_ADDRESS (val), - stream, format, 0, recurse, pretty, current_language); + stream, recurse, &opts, current_language); } @@ -589,32 +592,29 @@ void _initialize_cp_valprint (void) { add_setshow_boolean_cmd ("static-members", class_support, - &static_field_print, _("\ + &user_print_options.static_field_print, _("\ Set printing of C++ static members."), _("\ Show printing of C++ static members."), NULL, NULL, show_static_field_print, &setprintlist, &showprintlist); - /* Turn on printing of static fields. */ - static_field_print = 1; - add_setshow_boolean_cmd ("vtbl", class_support, &vtblprint, _("\ + add_setshow_boolean_cmd ("vtbl", class_support, + &user_print_options.vtblprint, _("\ Set printing of C++ virtual function tables."), _("\ Show printing of C++ virtual function tables."), NULL, NULL, show_vtblprint, &setprintlist, &showprintlist); - add_setshow_boolean_cmd ("object", class_support, &objectprint, _("\ + add_setshow_boolean_cmd ("object", class_support, + &user_print_options.objectprint, _("\ Set printing of object's derived type based on vtable info."), _("\ Show printing of object's derived type based on vtable info."), NULL, NULL, show_objectprint, &setprintlist, &showprintlist); - /* Give people the defaults which they are used to. */ - objectprint = 0; - vtblprint = 0; obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *)); obstack_specify_allocation (&dont_print_statmem_obstack, 32 * sizeof (CORE_ADDR), sizeof (CORE_ADDR), diff --git a/gdb/eval.c b/gdb/eval.c index cf3e8765d38..4394aa19bd4 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -39,16 +39,13 @@ #include "exceptions.h" #include "regcache.h" #include "user-regs.h" +#include "valprint.h" #include "gdb_assert.h" /* This is defined in valops.c */ extern int overload_resolution; -/* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue - on with successful lookup for member/method of the rtti type. */ -extern int objectprint; - /* Prototypes for local functions. */ static struct value *evaluate_subexp_for_sizeof (struct expression *, int *); @@ -1628,8 +1625,10 @@ evaluate_subexp_standard (struct type *expect_type, struct type *type = value_type (arg1); struct type *real_type; int full, top, using_enc; - - if (objectprint && TYPE_TARGET_TYPE(type) && + struct value_print_options opts; + + get_user_print_options (&opts); + if (opts.objectprint && TYPE_TARGET_TYPE(type) && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS)) { real_type = value_rtti_target_type (arg1, &full, &top, &using_enc); diff --git a/gdb/expprint.c b/gdb/expprint.c index 079f2a9509e..756a02eb876 100644 --- a/gdb/expprint.c +++ b/gdb/expprint.c @@ -31,6 +31,7 @@ #include "block.h" #include "objfiles.h" #include "gdb_assert.h" +#include "valprint.h" #ifdef HAVE_CTYPE_H #include @@ -92,17 +93,25 @@ print_subexp_standard (struct expression *exp, int *pos, return; case OP_LONG: - (*pos) += 3; - value_print (value_from_longest (exp->elts[pc + 1].type, - exp->elts[pc + 2].longconst), - stream, 0, Val_no_prettyprint); + { + struct value_print_options opts; + get_raw_print_options (&opts); + (*pos) += 3; + value_print (value_from_longest (exp->elts[pc + 1].type, + exp->elts[pc + 2].longconst), + stream, &opts); + } return; case OP_DOUBLE: - (*pos) += 3; - value_print (value_from_double (exp->elts[pc + 1].type, - exp->elts[pc + 2].doubleconst), - stream, 0, Val_no_prettyprint); + { + struct value_print_options opts; + get_raw_print_options (&opts); + (*pos) += 3; + value_print (value_from_double (exp->elts[pc + 1].type, + exp->elts[pc + 2].doubleconst), + stream, &opts); + } return; case OP_VAR_VALUE: @@ -169,12 +178,17 @@ print_subexp_standard (struct expression *exp, int *pos, return; case OP_STRING: - nargs = longest_to_int (exp->elts[pc + 1].longconst); - (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); - /* LA_PRINT_STRING will print using the current repeat count threshold. - If necessary, we can temporarily set it to zero, or pass it as an - additional parameter to LA_PRINT_STRING. -fnf */ - LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 1, 0); + { + struct value_print_options opts; + nargs = longest_to_int (exp->elts[pc + 1].longconst); + (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); + /* LA_PRINT_STRING will print using the current repeat count threshold. + If necessary, we can temporarily set it to zero, or pass it as an + additional parameter to LA_PRINT_STRING. -fnf */ + get_user_print_options (&opts); + LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 1, 0, + &opts); + } return; case OP_BITSTRING: @@ -185,11 +199,16 @@ print_subexp_standard (struct expression *exp, int *pos, return; case OP_OBJC_NSSTRING: /* Objective-C Foundation Class NSString constant. */ - nargs = longest_to_int (exp->elts[pc + 1].longconst); - (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); - fputs_filtered ("@\"", stream); - LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 1, 0); - fputs_filtered ("\"", stream); + { + struct value_print_options opts; + nargs = longest_to_int (exp->elts[pc + 1].longconst); + (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); + fputs_filtered ("@\"", stream); + get_user_print_options (&opts); + LA_PRINT_STRING (stream, &exp->elts[pc + 2].string, nargs, 1, 0, + &opts); + fputs_filtered ("\"", stream); + } return; case OP_OBJC_MSGCALL: @@ -270,7 +289,10 @@ print_subexp_standard (struct expression *exp, int *pos, } if (tem > 0) { - LA_PRINT_STRING (stream, tempstr, nargs - 1, 1, 0); + struct value_print_options opts; + get_user_print_options (&opts); + LA_PRINT_STRING (stream, tempstr, nargs - 1, 1, 0, + &opts); (*pos) = pc; } else @@ -394,6 +416,8 @@ print_subexp_standard (struct expression *exp, int *pos, if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC && exp->elts[pc + 3].opcode == OP_LONG) { + struct value_print_options opts; + /* We have a minimal symbol fn, probably. It's encoded as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address). Swallow the OP_LONG (including both its opcodes); ignore @@ -401,7 +425,8 @@ print_subexp_standard (struct expression *exp, int *pos, (*pos) += 4; val = value_at_lazy (exp->elts[pc + 1].type, (CORE_ADDR) exp->elts[pc + 5].longconst); - value_print (val, stream, 0, Val_no_prettyprint); + get_raw_print_options (&opts); + value_print (val, stream, &opts); } else { diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 736d6c60b0a..4d4d4d70a54 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -142,7 +142,8 @@ f_printchar (int c, struct ui_file *stream) static void f_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; @@ -155,7 +156,7 @@ f_printstr (struct ui_file *stream, const gdb_byte *string, return; } - for (i = 0; i < length && things_printed < print_max; ++i) + for (i = 0; i < length && things_printed < options->print_max; ++i) { /* Position of the character we are examining to see whether it is repeated. */ @@ -179,11 +180,11 @@ f_printstr (struct ui_file *stream, const gdb_byte *string, ++reps; } - if (reps > repeat_count_threshold) + if (reps > options->repeat_count_threshold) { if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\', ", stream); else fputs_filtered ("', ", stream); @@ -192,14 +193,14 @@ f_printstr (struct ui_file *stream, const gdb_byte *string, f_printchar (string[i], stream); fprintf_filtered (stream, " ", reps); i = rep1 - 1; - things_printed += repeat_count_threshold; + things_printed += options->repeat_count_threshold; need_comma = 1; } else { if (!in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\'", stream); else fputs_filtered ("'", stream); @@ -213,7 +214,7 @@ f_printstr (struct ui_file *stream, const gdb_byte *string, /* Terminate the quotes if necessary. */ if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\'", stream); else fputs_filtered ("'", stream); @@ -305,8 +306,8 @@ f_language_arch_info (struct gdbarch *gdbarch, /* This is declared in c-lang.h but it is silly to import that file for what is already just a hack. */ -extern int c_value_print (struct value *, struct ui_file *, int, - enum val_prettyprint); +extern int c_value_print (struct value *, struct ui_file *, + const struct value_print_options *); const struct language_defn f_language_defn = { diff --git a/gdb/f-lang.h b/gdb/f-lang.h index 252d25dbdb5..3b3487e6f7e 100644 --- a/gdb/f-lang.h +++ b/gdb/f-lang.h @@ -29,8 +29,8 @@ extern void f_print_type (struct type *, char *, struct ui_file *, int, int); extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); /* Language-specific data structures */ diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 672e95c4a81..f893b4991c4 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -164,42 +164,42 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream) static void f77_print_array_1 (int nss, int ndimensions, struct type *type, const gdb_byte *valaddr, CORE_ADDR address, - struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty, + struct ui_file *stream, int recurse, + const struct value_print_options *options, int *elts) { int i; if (nss != ndimensions) { - for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < print_max); i++) + for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++) { fprintf_filtered (stream, "( "); f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type), valaddr + i * F77_DIM_OFFSET (nss), address + i * F77_DIM_OFFSET (nss), - stream, format, deref_ref, recurse, pretty, elts); + stream, recurse, options, elts); fprintf_filtered (stream, ") "); } - if (*elts >= print_max && i < F77_DIM_SIZE (nss)) + if (*elts >= options->print_max && i < F77_DIM_SIZE (nss)) fprintf_filtered (stream, "..."); } else { - for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < print_max; + for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max; i++, (*elts)++) { val_print (TYPE_TARGET_TYPE (type), valaddr + i * F77_DIM_OFFSET (ndimensions), 0, address + i * F77_DIM_OFFSET (ndimensions), - stream, format, deref_ref, recurse, pretty, - current_language); + stream, recurse, options, current_language); if (i != (F77_DIM_SIZE (nss) - 1)) fprintf_filtered (stream, ", "); - if ((*elts == print_max - 1) && (i != (F77_DIM_SIZE (nss) - 1))) + if ((*elts == options->print_max - 1) + && (i != (F77_DIM_SIZE (nss) - 1))) fprintf_filtered (stream, "..."); } } @@ -211,8 +211,7 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type, static void f77_print_array (struct type *type, const gdb_byte *valaddr, CORE_ADDR address, struct ui_file *stream, - int format, int deref_ref, int recurse, - enum val_prettyprint pretty) + int recurse, const struct value_print_options *options) { int ndimensions; int elts = 0; @@ -229,28 +228,22 @@ f77_print_array (struct type *type, const gdb_byte *valaddr, f77_create_arrayprint_offset_tbl (type, stream); - f77_print_array_1 (1, ndimensions, type, valaddr, address, stream, format, - deref_ref, recurse, pretty, &elts); + f77_print_array_1 (1, ndimensions, type, valaddr, address, stream, + recurse, options, &elts); } /* Print data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto stdio stream STREAM according to - FORMAT (a letter or 0 for natural format). The data at VALADDR is in - target byte order. + OPTIONS. The data at VALADDR is in target byte order. If the data are a string pointer, returns the number of string characters - printed. - - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - - The PRETTY parameter controls prettyprinting. */ + printed. */ int f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, - CORE_ADDR address, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) + CORE_ADDR address, struct ui_file *stream, int recurse, + const struct value_print_options *options) { unsigned int i = 0; /* Number of characters printed */ struct type *elttype; @@ -263,20 +256,19 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, { case TYPE_CODE_STRING: f77_get_dynamic_length_of_aggregate (type); - LA_PRINT_STRING (stream, valaddr, TYPE_LENGTH (type), 1, 0); + LA_PRINT_STRING (stream, valaddr, TYPE_LENGTH (type), 1, 0, options); break; case TYPE_CODE_ARRAY: fprintf_filtered (stream, "("); - f77_print_array (type, valaddr, address, stream, format, - deref_ref, recurse, pretty); + f77_print_array (type, valaddr, address, stream, recurse, options); fprintf_filtered (stream, ")"); break; case TYPE_CODE_PTR: - if (format && format != 's') + if (options->format && options->format != 's') { - print_scalar_formatted (valaddr, type, format, 0, stream); + print_scalar_formatted (valaddr, type, options, 0, stream); break; } else @@ -292,16 +284,17 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, return 0; } - if (addressprint && format != 's') + if (options->addressprint && options->format != 's') fputs_filtered (paddress (addr), stream); /* For a pointer to char or unsigned char, also print the string pointed to, unless pointer is null. */ if (TYPE_LENGTH (elttype) == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT - && (format == 0 || format == 's') + && (options->format == 0 || options->format == 's') && addr != 0) - i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); + i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream, + options); /* Return number of characters printed, including the terminating '\0' if we reached the end. val_print_string takes care including @@ -312,17 +305,17 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_REF: elttype = check_typedef (TYPE_TARGET_TYPE (type)); - if (addressprint) + if (options->addressprint) { CORE_ADDR addr = extract_typed_address (valaddr + embedded_offset, type); fprintf_filtered (stream, "@"); fputs_filtered (paddress (addr), stream); - if (deref_ref) + if (options->deref_ref) fputs_filtered (": ", stream); } /* De-reference the reference. */ - if (deref_ref) + if (options->deref_ref) { if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) { @@ -330,8 +323,8 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr + embedded_offset)); - common_val_print (deref_val, stream, format, deref_ref, recurse, - pretty, current_language); + common_val_print (deref_val, stream, recurse, + options, current_language); } else fputs_filtered ("???", stream); @@ -339,9 +332,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_FUNC: - if (format) + if (options->format) { - print_scalar_formatted (valaddr, type, format, 0, stream); + print_scalar_formatted (valaddr, type, options, 0, stream); break; } /* FIXME, we should consider, at least for ANSI C language, eliminating @@ -354,9 +347,13 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_INT: - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr, type, &opts, 0, stream); + } else { val_print_type_code_int (type, valaddr, stream); @@ -374,15 +371,15 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_FLAGS: - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); + if (options->format) + print_scalar_formatted (valaddr, type, options, 0, stream); else val_print_type_code_flags (type, valaddr, stream); break; case TYPE_CODE_FLT: - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); + if (options->format) + print_scalar_formatted (valaddr, type, options, 0, stream); else print_floating (valaddr, type, stream); break; @@ -401,9 +398,13 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_BOOL: - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr, type, &opts, 0, stream); + } else { val = extract_unsigned_integer (valaddr, TYPE_LENGTH (type)); @@ -417,8 +418,7 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, { /* Bash the type code temporarily. */ TYPE_CODE (type) = TYPE_CODE_INT; - f_val_print (type, valaddr, 0, address, stream, format, - deref_ref, recurse, pretty); + f_val_print (type, valaddr, 0, address, stream, recurse, options); /* Restore the type code so later uses work as intended. */ TYPE_CODE (type) = TYPE_CODE_BOOL; } @@ -450,8 +450,7 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, { int offset = TYPE_FIELD_BITPOS (type, index) / 8; f_val_print (TYPE_FIELD_TYPE (type, index), valaddr + offset, - embedded_offset, address, stream, - format, deref_ref, recurse, pretty); + embedded_offset, address, stream, recurse, options); if (index != TYPE_NFIELDS (type) - 1) fputs_filtered (", ", stream); } diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 2a41c5b90a6..333eb3180e8 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -28,6 +28,7 @@ /* Forward declarations for prototypes. */ struct field; struct block; +struct value_print_options; /* Some macros for char-based bitfields. */ @@ -1246,8 +1247,9 @@ extern int field_is_static (struct field *); /* printcmd.c */ -extern void print_scalar_formatted (const void *, struct type *, int, int, - struct ui_file *); +extern void print_scalar_formatted (const void *, struct type *, + const struct value_print_options *, + int, struct ui_file *); extern int can_dereference (struct type *); diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 28ce813869b..8060af5ed14 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -51,6 +51,7 @@ #include "exceptions.h" #include "cli/cli-decode.h" #include "gdbthread.h" +#include "valprint.h" /* Functions exported for general use, in inferior.h: */ @@ -1291,6 +1292,8 @@ print_return_value (struct type *func_type, struct type *value_type) if (value) { + struct value_print_options opts; + /* Print it. */ stb = ui_out_stream_new (uiout); old_chain = make_cleanup_ui_out_stream_delete (stb); @@ -1298,7 +1301,8 @@ print_return_value (struct type *func_type, struct type *value_type) ui_out_field_fmt (uiout, "gdb-result-var", "$%d", record_latest_value (value)); ui_out_text (uiout, " = "); - value_print (value, stb->stream, 0, Val_no_prettyprint); + get_raw_print_options (&opts); + value_print (value, stb->stream, &opts); ui_out_field_stream (uiout, "return-value", stb); ui_out_text (uiout, "\n"); do_cleanups (old_chain); @@ -1812,9 +1816,12 @@ default_print_registers_info (struct gdbarch *gdbarch, || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT) { int j; + struct value_print_options opts; + get_user_print_options (&opts); + opts.deref_ref = 1; val_print (register_type (gdbarch, i), buffer, 0, 0, - file, 0, 1, 0, Val_pretty_default, current_language); + file, 0, &opts, current_language); fprintf_filtered (file, "\t(raw 0x"); for (j = 0; j < register_size (gdbarch, i); j++) @@ -1830,16 +1837,23 @@ default_print_registers_info (struct gdbarch *gdbarch, } else { + struct value_print_options opts; + /* Print the register in hex. */ + get_formatted_print_options (&opts, 'x'); + opts.deref_ref = 1; val_print (register_type (gdbarch, i), buffer, 0, 0, - file, 'x', 1, 0, Val_pretty_default, current_language); + file, 0, &opts, + current_language); /* If not a vector register, print it also according to its natural format. */ if (TYPE_VECTOR (register_type (gdbarch, i)) == 0) { + get_user_print_options (&opts); + opts.deref_ref = 1; fprintf_filtered (file, "\t"); val_print (register_type (gdbarch, i), buffer, 0, 0, - file, 0, 1, 0, Val_pretty_default, current_language); + file, 0, &opts, current_language); } } @@ -1905,12 +1919,14 @@ registers_info (char *addr_exp, int fpregs) if (regnum >= gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch)) { + struct value_print_options opts; struct value *val = value_of_user_reg (regnum, frame); printf_filtered ("%s: ", start); + get_formatted_print_options (&opts, 'x'); print_scalar_formatted (value_contents (val), check_typedef (value_type (val)), - 'x', 0, gdb_stdout); + &opts, 0, gdb_stdout); printf_filtered ("\n"); } else diff --git a/gdb/jv-lang.h b/gdb/jv-lang.h index 51bada293f4..04ba38394d3 100644 --- a/gdb/jv-lang.h +++ b/gdb/jv-lang.h @@ -41,11 +41,11 @@ extern struct type *java_double_type; extern struct type *java_void_type; extern int java_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); -extern int java_value_print (struct value *, struct ui_file *, int, - enum val_prettyprint); +extern int java_value_print (struct value *, struct ui_file *, + const struct value_print_options *); extern struct value *java_class_from_object (struct value *); diff --git a/gdb/jv-valprint.c b/gdb/jv-valprint.c index 9e36aa4893a..0714e07837c 100644 --- a/gdb/jv-valprint.c +++ b/gdb/jv-valprint.c @@ -35,13 +35,14 @@ /* Local functions */ int -java_value_print (struct value *val, struct ui_file *stream, int format, - enum val_prettyprint pretty) +java_value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options) { struct type *type; CORE_ADDR address; int i; char *name; + struct value_print_options opts; type = value_type (val); address = VALUE_ADDRESS (val) + value_offset (val); @@ -89,7 +90,7 @@ java_value_print (struct value *val, struct ui_file *stream, int format, address += JAVA_OBJECT_SIZE + 4; /* Skip object header and length. */ - while (i < length && things_printed < print_max) + while (i < length && things_printed < options->print_max) { gdb_byte *buf; @@ -145,7 +146,7 @@ java_value_print (struct value *val, struct ui_file *stream, int format, VALUE_ADDRESS (v) = address + JAVA_OBJECT_SIZE + 4; VALUE_ADDRESS (next_v) = VALUE_ADDRESS (v); - while (i < length && things_printed < print_max) + while (i < length && things_printed < options->print_max) { fputs_filtered (", ", stream); wrap_here (n_spaces (2)); @@ -180,8 +181,9 @@ java_value_print (struct value *val, struct ui_file *stream, int format, else fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1); - common_val_print (v, stream, format, 2, 1, pretty, - current_language); + opts = *options; + opts.deref_ref = 1; + common_val_print (v, stream, 1, &opts, current_language); things_printed++; i += reps; @@ -203,7 +205,7 @@ java_value_print (struct value *val, struct ui_file *stream, int format, && TYPE_TAG_NAME (TYPE_TARGET_TYPE (type)) && strcmp (TYPE_TAG_NAME (TYPE_TARGET_TYPE (type)), "java.lang.String") == 0 - && (format == 0 || format == 's') + && (options->format == 0 || options->format == 's') && address != 0 && value_as_address (val) != 0) { @@ -228,16 +230,17 @@ java_value_print (struct value *val, struct ui_file *stream, int format, value_free_to_mark (mark); /* Release unnecessary values */ - val_print_string (data + boffset, count, 2, stream); + val_print_string (data + boffset, count, 2, stream, options); return 0; } - return common_val_print (val, stream, format, 1, 0, pretty, - current_language); + opts = *options; + opts.deref_ref = 1; + return common_val_print (val, stream, 0, &opts, current_language); } -/* TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the +/* TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the same meanings as in cp_print_value and c_val_print. DONT_PRINT is an array of baseclass types that we @@ -246,7 +249,8 @@ java_value_print (struct value *val, struct ui_file *stream, int format, static void java_print_value_fields (struct type *type, const gdb_byte *valaddr, CORE_ADDR address, struct ui_file *stream, - int format, int recurse, enum val_prettyprint pretty) + int recurse, + const struct value_print_options *options) { int i, len, n_baseclasses; @@ -275,7 +279,7 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, boffset = 0; - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * (recurse + 1), stream); @@ -289,7 +293,7 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, base_valaddr = valaddr; java_print_value_fields (baseclass, base_valaddr, address + boffset, - stream, format, recurse + 1, pretty); + stream, recurse + 1, options); fputs_filtered (", ", stream); } @@ -307,7 +311,7 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, if (field_is_static (&TYPE_FIELD (type, i))) { char *name = TYPE_FIELD_NAME (type, i); - if (!static_field_print) + if (!options->static_field_print) continue; if (name != NULL && strcmp (name, "class") == 0) continue; @@ -316,7 +320,7 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, fprintf_filtered (stream, ", "); else if (n_baseclasses > 0) { - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -327,7 +331,7 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, } fields_seen = 1; - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -336,7 +340,7 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, { wrap_here (n_spaces (2 + 2 * recurse)); } - if (inspect_it) + if (options->inspect_it) { if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) fputs_filtered ("\"( ptr \"", stream); @@ -380,11 +384,15 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, } else { + struct value_print_options opts; + v = value_from_longest (TYPE_FIELD_TYPE (type, i), unpack_field_as_long (type, valaddr, i)); - common_val_print (v, stream, format, 0, recurse + 1, - pretty, current_language); + opts = *options; + opts.deref_ref = 0; + common_val_print (v, stream, recurse + 1, + &opts, current_language); } } else @@ -400,28 +408,33 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, fputs_filtered ("", stream); else { + struct value_print_options opts; struct type *t = check_typedef (value_type (v)); if (TYPE_CODE (t) == TYPE_CODE_STRUCT) v = value_addr (v); - common_val_print (v, stream, format, 0, recurse + 1, - pretty, current_language); + opts = *options; + opts.deref_ref = 0; + common_val_print (v, stream, recurse + 1, + &opts, current_language); } } else if (TYPE_FIELD_TYPE (type, i) == NULL) fputs_filtered ("", stream); else { + struct value_print_options opts = *options; + opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / 8, 0, address + TYPE_FIELD_BITPOS (type, i) / 8, - stream, format, 0, recurse + 1, pretty, + stream, recurse + 1, &opts, current_language); } } annotate_field_end (); } - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); @@ -432,22 +445,16 @@ java_print_value_fields (struct type *type, const gdb_byte *valaddr, /* Print data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto stdio stream STREAM according to - FORMAT (a letter or 0 for natural format). The data at VALADDR is in - target byte order. + OPTIONS. The data at VALADDR is in target byte order. If the data are a string pointer, returns the number of string characters - printed. - - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - - The PRETTY parameter controls prettyprinting. */ + printed. */ int java_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, int deref_ref, - int recurse, enum val_prettyprint pretty) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { unsigned int i = 0; /* Number of characters printed */ struct type *target_type; @@ -457,13 +464,13 @@ java_val_print (struct type *type, const gdb_byte *valaddr, switch (TYPE_CODE (type)) { case TYPE_CODE_PTR: - if (format && format != 's') + if (options->format && options->format != 's') { - print_scalar_formatted (valaddr, type, format, 0, stream); + print_scalar_formatted (valaddr, type, options, 0, stream); break; } #if 0 - if (vtblprint && cp_is_vtbl_ptr_type (type)) + if (options->vtblprint && cp_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if we ARE using @@ -490,7 +497,7 @@ java_val_print (struct type *type, const gdb_byte *valaddr, return (0); } - if (addressprint && format != 's') + if (options->addressprint && options->format != 's') { fputs_filtered ("@", stream); print_longest (stream, 'x', 0, (ULONGEST) addr); @@ -502,9 +509,13 @@ java_val_print (struct type *type, const gdb_byte *valaddr, case TYPE_CODE_INT: /* Can't just call c_val_print because that prints bytes as C chars. */ - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr, type, &opts, 0, stream); + } else if (TYPE_CODE (type) == TYPE_CODE_CHAR || (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 2 @@ -515,13 +526,13 @@ java_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_STRUCT: - java_print_value_fields (type, valaddr, address, stream, format, - recurse, pretty); + java_print_value_fields (type, valaddr, address, stream, recurse, + options); break; default: return c_val_print (type, valaddr, embedded_offset, address, stream, - format, deref_ref, recurse, pretty); + recurse, options); } return 0; diff --git a/gdb/language.c b/gdb/language.c index 121fc55c6e1..46e238d8b66 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -72,7 +72,8 @@ static void unk_lang_printchar (int c, struct ui_file *stream); static void unk_lang_print_type (struct type *, char *, struct ui_file *, int, int); -static int unk_lang_value_print (struct value *, struct ui_file *, int, enum val_prettyprint); +static int unk_lang_value_print (struct value *, struct ui_file *, + const struct value_print_options *); static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); @@ -1035,10 +1036,10 @@ default_word_break_characters (void) void default_print_array_index (struct value *index_value, struct ui_file *stream, - int format, enum val_prettyprint pretty) + const struct value_print_options *options) { fprintf_filtered (stream, "["); - LA_VALUE_PRINT (index_value, stream, format, pretty); + LA_VALUE_PRINT (index_value, stream, options); fprintf_filtered (stream, "] = "); } @@ -1070,7 +1071,8 @@ unk_lang_printchar (int c, struct ui_file *stream) static void unk_lang_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { error (_("internal error - unimplemented function unk_lang_printstr called.")); } @@ -1085,15 +1087,15 @@ unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream, static int unk_lang_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { error (_("internal error - unimplemented function unk_lang_val_print called.")); } static int -unk_lang_value_print (struct value *val, struct ui_file *stream, int format, - enum val_prettyprint pretty) +unk_lang_value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options) { error (_("internal error - unimplemented function unk_lang_value_print called.")); } diff --git a/gdb/language.h b/gdb/language.h index cc10ff27422..c92c57c536b 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -30,6 +30,7 @@ struct objfile; struct frame_info; struct expression; struct ui_file; +struct value_print_options; #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ @@ -189,7 +190,8 @@ struct language_defn void (*la_printstr) (struct ui_file * stream, const gdb_byte *string, unsigned int length, int width, - int force_ellipses); + int force_ellipses, + const struct value_print_options *); void (*la_emitchar) (int ch, struct ui_file * stream, int quoter); @@ -208,13 +210,13 @@ struct language_defn /* Print a value using syntax appropriate for this language. */ int (*la_val_print) (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); /* Print a top-level value using syntax appropriate for this language. */ int (*la_value_print) (struct value *, struct ui_file *, - int, enum val_prettyprint); + const struct value_print_options *); /* PC is possibly an unknown languages trampoline. If that PC falls in a trampoline belonging to this language, @@ -274,8 +276,7 @@ struct language_defn /* Print the index of an element of an array. */ void (*la_print_array_index) (struct value *index_value, struct ui_file *stream, - int format, - enum val_prettyprint pretty); + const struct value_print_options *options); /* Return non-zero if TYPE should be passed (and returned) by reference at the language level. */ @@ -366,21 +367,22 @@ extern enum language set_language (enum language); #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \ (current_language->la_print_typedef(type,new_symbol,stream)) -#define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \ - (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \ - recurse,pretty)) -#define LA_VALUE_PRINT(val,stream,fmt,pretty) \ - (current_language->la_value_print(val,stream,fmt,pretty)) +#define LA_VAL_PRINT(type,valaddr,offset,addr,stream,recurse,options) \ + (current_language->la_val_print(type,valaddr,offset,addr,stream, \ + recurse,options)) +#define LA_VALUE_PRINT(val,stream,options) \ + (current_language->la_value_print(val,stream,options)) #define LA_PRINT_CHAR(ch, stream) \ (current_language->la_printchar(ch, stream)) -#define LA_PRINT_STRING(stream, string, length, width, force_ellipses) \ - (current_language->la_printstr(stream, string, length, width, force_ellipses)) +#define LA_PRINT_STRING(stream, string, length, width, force_ellipses,options) \ + (current_language->la_printstr(stream, string, length, width, \ + force_ellipses,options)) #define LA_EMIT_CHAR(ch, stream, quoter) \ (current_language->la_emitchar(ch, stream, quoter)) -#define LA_PRINT_ARRAY_INDEX(index_value, stream, format, pretty) \ - (current_language->la_print_array_index(index_value, stream, format, pretty)) +#define LA_PRINT_ARRAY_INDEX(index_value, stream, optins) \ + (current_language->la_print_array_index(index_value, stream, options)) /* Test a character to decide whether it can be printed in literal form or needs to be printed in another representation. For example, @@ -472,8 +474,7 @@ extern char *default_word_break_characters (void); /* Print the index of an array element using the C99 syntax. */ extern void default_print_array_index (struct value *index_value, struct ui_file *stream, - int format, - enum val_prettyprint pretty); + const struct value_print_options *options); /* Return non-zero if TYPE should be passed (and returned) by reference at the language level. */ diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index ea59403a24a..e09b64b82ec 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -104,7 +104,8 @@ m2_printchar (int c, struct ui_file *stream) static void m2_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; @@ -117,7 +118,7 @@ m2_printstr (struct ui_file *stream, const gdb_byte *string, return; } - for (i = 0; i < length && things_printed < print_max; ++i) + for (i = 0; i < length && things_printed < options->print_max; ++i) { /* Position of the character we are examining to see whether it is repeated. */ @@ -141,11 +142,11 @@ m2_printstr (struct ui_file *stream, const gdb_byte *string, ++reps; } - if (reps > repeat_count_threshold) + if (reps > options->repeat_count_threshold) { if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\", ", stream); else fputs_filtered ("\", ", stream); @@ -154,14 +155,14 @@ m2_printstr (struct ui_file *stream, const gdb_byte *string, m2_printchar (string[i], stream); fprintf_filtered (stream, " ", reps); i = rep1 - 1; - things_printed += repeat_count_threshold; + things_printed += options->repeat_count_threshold; need_comma = 1; } else { if (!in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); @@ -175,7 +176,7 @@ m2_printstr (struct ui_file *stream, const gdb_byte *string, /* Terminate the quotes if necessary. */ if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index 8ce458c3d49..f99e31a116f 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -33,8 +33,8 @@ extern int m2_is_long_set (struct type *type); extern int m2_is_unbounded_array (struct type *type); extern int m2_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); extern int get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high); diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c index 82ff30e0b76..d48108f2c8a 100644 --- a/gdb/m2-valprint.c +++ b/gdb/m2-valprint.c @@ -30,22 +30,24 @@ #include "m2-lang.h" #include "target.h" -int print_unpacked_pointer (struct type *type, - CORE_ADDR address, CORE_ADDR addr, - int format, struct ui_file *stream); +static int print_unpacked_pointer (struct type *type, + CORE_ADDR address, CORE_ADDR addr, + const struct value_print_options *options, + struct ui_file *stream); static void m2_print_array_contents (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, - enum val_prettyprint pretty, - int deref_ref, int recurse, int len); + struct ui_file *stream, int recurse, + const struct value_print_options *options, + int len); /* Print function pointer with inferior address ADDRESS onto stdio stream STREAM. */ static void -print_function_pointer_address (CORE_ADDR address, struct ui_file *stream) +print_function_pointer_address (CORE_ADDR address, struct ui_file *stream, + int addressprint) { CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch, address, @@ -88,8 +90,7 @@ get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high) static void m2_print_long_set (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, - enum val_prettyprint pretty) + struct ui_file *stream) { int empty_set = 1; int element_seen = 0; @@ -184,9 +185,8 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr, static void m2_print_unbounded_array (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, - int deref_ref, enum val_prettyprint pretty, - int recurse) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { struct type *content_type; CORE_ADDR addr; @@ -207,26 +207,27 @@ m2_print_unbounded_array (struct type *type, const gdb_byte *valaddr, fprintf_filtered (stream, "{"); m2_print_array_contents (value_type (val), value_contents(val), value_embedded_offset (val), addr, stream, - format, deref_ref, pretty, recurse, len); + recurse, options, len); fprintf_filtered (stream, ", HIGH = %d}", (int) len); } -int +static int print_unpacked_pointer (struct type *type, CORE_ADDR address, CORE_ADDR addr, - int format, struct ui_file *stream) + const struct value_print_options *options, + struct ui_file *stream) { struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) { /* Try to print what function it points to. */ - print_function_pointer_address (addr, stream); + print_function_pointer_address (addr, stream, options->addressprint); /* Return value is irrelevant except for string pointers. */ return 0; } - if (addressprint && format != 's') + if (options->addressprint && options->format != 's') fputs_filtered (paddress (address), stream); /* For a pointer to char or unsigned char, also print the string @@ -234,9 +235,9 @@ print_unpacked_pointer (struct type *type, if (TYPE_LENGTH (elttype) == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT - && (format == 0 || format == 's') + && (options->format == 0 || options->format == 's') && addr != 0) - return val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); + return val_print_string (addr, -1, TYPE_LENGTH (elttype), stream, options); return 0; } @@ -244,9 +245,9 @@ print_unpacked_pointer (struct type *type, static void print_variable_at_address (struct type *type, const gdb_byte *valaddr, - struct ui_file *stream, int format, - int deref_ref, int recurse, - enum val_prettyprint pretty) + struct ui_file *stream, + int recurse, + const struct value_print_options *options) { CORE_ADDR addr = unpack_pointer (type, valaddr); struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); @@ -259,8 +260,7 @@ print_variable_at_address (struct type *type, { struct value *deref_val = value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr)); - common_val_print (deref_val, stream, format, deref_ref, - recurse, pretty, current_language); + common_val_print (deref_val, stream, recurse, options, current_language); } else fputs_filtered ("???", stream); @@ -276,9 +276,9 @@ print_variable_at_address (struct type *type, static void m2_print_array_contents (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, - enum val_prettyprint pretty, - int deref_ref, int recurse, int len) + struct ui_file *stream, int recurse, + const struct value_print_options *options, + int len) { int eltlen; CHECK_TYPEDEF (type); @@ -286,21 +286,20 @@ m2_print_array_contents (struct type *type, const gdb_byte *valaddr, if (TYPE_LENGTH (type) > 0) { eltlen = TYPE_LENGTH (type); - if (prettyprint_arrays) + if (options->prettyprint_arrays) print_spaces_filtered (2 + 2 * recurse, stream); /* For an array of chars, print with string syntax. */ if (eltlen == 1 && ((TYPE_CODE (type) == TYPE_CODE_INT) || ((current_language->la_language == language_m2) && (TYPE_CODE (type) == TYPE_CODE_CHAR))) - && (format == 0 || format == 's')) - val_print_string (address, len+1, eltlen, stream); + && (options->format == 0 || options->format == 's')) + val_print_string (address, len+1, eltlen, stream, options); else { fprintf_filtered (stream, "{"); val_print_array_elements (type, valaddr + embedded_offset, - address, stream, format, - deref_ref, recurse, pretty, 0); + address, stream, recurse, options, 0); fprintf_filtered (stream, "}"); } } @@ -309,21 +308,15 @@ m2_print_array_contents (struct type *type, const gdb_byte *valaddr, /* Print data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto stdio stream STREAM according to - FORMAT (a letter or 0 for natural format). The data at VALADDR is in - target byte order. + OPTIONS. The data at VALADDR is in target byte order. If the data are a string pointer, returns the number of string characters - printed. - - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - - The PRETTY parameter controls prettyprinting. */ + printed. */ int m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, - CORE_ADDR address, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) + CORE_ADDR address, struct ui_file *stream, int recurse, + const struct value_print_options *options) { unsigned int i = 0; /* Number of characters printed */ unsigned len; @@ -343,74 +336,73 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, elttype = check_typedef (TYPE_TARGET_TYPE (type)); eltlen = TYPE_LENGTH (elttype); len = TYPE_LENGTH (type) / eltlen; - if (prettyprint_arrays) + if (options->prettyprint_arrays) print_spaces_filtered (2 + 2 * recurse, stream); /* For an array of chars, print with string syntax. */ if (eltlen == 1 && ((TYPE_CODE (elttype) == TYPE_CODE_INT) || ((current_language->la_language == language_m2) && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) - && (format == 0 || format == 's')) + && (options->format == 0 || options->format == 's')) { /* If requested, look for the first null char and only print elements up to it. */ - if (stop_print_at_null) + if (options->stop_print_at_null) { unsigned int temp_len; /* Look for a NULL char. */ for (temp_len = 0; (valaddr + embedded_offset)[temp_len] - && temp_len < len && temp_len < print_max; + && temp_len < len && temp_len < options->print_max; temp_len++); len = temp_len; } - LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0); + LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0, + options); i = len; } else { fprintf_filtered (stream, "{"); val_print_array_elements (type, valaddr + embedded_offset, - address, stream, format, deref_ref, - recurse, pretty, 0); + address, stream, recurse, options, 0); fprintf_filtered (stream, "}"); } break; } /* Array of unspecified length: treat like pointer to first elt. */ - print_unpacked_pointer (type, address, address, format, stream); + print_unpacked_pointer (type, address, address, options, stream); break; case TYPE_CODE_PTR: if (TYPE_CONST (type)) print_variable_at_address (type, valaddr + embedded_offset, - stream, format, deref_ref, recurse, - pretty); - else if (format && format != 's') - print_scalar_formatted (valaddr + embedded_offset, type, format, - 0, stream); + stream, recurse, options); + else if (options->format && options->format != 's') + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); else { addr = unpack_pointer (type, valaddr + embedded_offset); - print_unpacked_pointer (type, addr, address, format, stream); + print_unpacked_pointer (type, addr, address, options, stream); } break; case TYPE_CODE_REF: elttype = check_typedef (TYPE_TARGET_TYPE (type)); - if (addressprint) + if (options->addressprint) { CORE_ADDR addr = extract_typed_address (valaddr + embedded_offset, type); fprintf_filtered (stream, "@"); fputs_filtered (paddress (addr), stream); - if (deref_ref) + if (options->deref_ref) fputs_filtered (": ", stream); } /* De-reference the reference. */ - if (deref_ref) + if (options->deref_ref) { if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) { @@ -418,8 +410,8 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr + embedded_offset)); - common_val_print (deref_val, stream, format, deref_ref, - recurse, pretty, current_language); + common_val_print (deref_val, stream, recurse, options, + current_language); } else fputs_filtered ("???", stream); @@ -427,7 +419,7 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_UNION: - if (recurse && !unionprint) + if (recurse && !options->unionprint) { fprintf_filtered (stream, "{...}"); break; @@ -436,22 +428,20 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_STRUCT: if (m2_is_long_set (type)) m2_print_long_set (type, valaddr, embedded_offset, address, - stream, format, pretty); + stream); else if (m2_is_unbounded_array (type)) m2_print_unbounded_array (type, valaddr, embedded_offset, - address, stream, format, deref_ref, - pretty, recurse); + address, stream, recurse, options); else cp_print_value_fields (type, type, valaddr, embedded_offset, - address, stream, format, - recurse, pretty, NULL, 0); + address, stream, recurse, options, NULL, 0); break; case TYPE_CODE_ENUM: - if (format) + if (options->format) { print_scalar_formatted (valaddr + embedded_offset, type, - format, 0, stream); + options, 0, stream); break; } len = TYPE_NFIELDS (type); @@ -475,10 +465,10 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_FUNC: - if (format) + if (options->format) { print_scalar_formatted (valaddr + embedded_offset, type, - format, 0, stream); + options, 0, stream); break; } /* FIXME, we should consider, at least for ANSI C language, eliminating @@ -491,10 +481,14 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_BOOL: - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, - format, 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); + } else { val = unpack_long (type, valaddr + embedded_offset); @@ -511,7 +505,7 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type))) { m2_val_print (TYPE_TARGET_TYPE (type), valaddr, embedded_offset, - address, stream, format, deref_ref, recurse, pretty); + address, stream, recurse, options); break; } /* FIXME: create_range_type does not set the unsigned bit in a @@ -524,19 +518,27 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, /* FALLTHROUGH */ case TYPE_CODE_INT: - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, format, - 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); + } else val_print_type_code_int (type, valaddr + embedded_offset, stream); break; case TYPE_CODE_CHAR: - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, - format, 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); + } else { val = unpack_long (type, valaddr + embedded_offset); @@ -550,9 +552,9 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, break; case TYPE_CODE_FLT: - if (format) + if (options->format) print_scalar_formatted (valaddr + embedded_offset, type, - format, 0, stream); + options, 0, stream); else print_floating (valaddr + embedded_offset, type, stream); break; diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index baf9b6dbd68..33cc8909557 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -30,6 +30,7 @@ #include "dictionary.h" #include "gdb_string.h" #include "language.h" +#include "valprint.h" static void list_args_or_locals (int locals, int values, struct frame_info *fi); @@ -280,21 +281,29 @@ list_args_or_locals (int locals, int values, struct frame_info *fi) && TYPE_CODE (type) != TYPE_CODE_STRUCT && TYPE_CODE (type) != TYPE_CODE_UNION) { + struct value_print_options opts; val = read_var_value (sym2, fi); + get_raw_print_options (&opts); + opts.deref_ref = 1; common_val_print - (val, stb->stream, 0, 1, 0, Val_no_prettyprint, + (val, stb->stream, 0, &opts, language_def (SYMBOL_LANGUAGE (sym2))); ui_out_field_stream (uiout, "value", stb); } do_cleanups (cleanup_tuple); break; case PRINT_ALL_VALUES: - val = read_var_value (sym2, fi); - common_val_print - (val, stb->stream, 0, 1, 0, Val_no_prettyprint, - language_def (SYMBOL_LANGUAGE (sym2))); - ui_out_field_stream (uiout, "value", stb); - do_cleanups (cleanup_tuple); + { + struct value_print_options opts; + val = read_var_value (sym2, fi); + get_raw_print_options (&opts); + opts.deref_ref = 1; + common_val_print + (val, stb->stream, 0, &opts, + language_def (SYMBOL_LANGUAGE (sym2))); + ui_out_field_stream (uiout, "value", stb); + do_cleanups (cleanup_tuple); + } break; } } diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 7780207f95c..a9fbcad2edb 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -45,6 +45,7 @@ #include "frame.h" #include "mi-main.h" #include "language.h" +#include "valprint.h" #include #include @@ -499,9 +500,11 @@ get_register (int regnum, int format) } else { + struct value_print_options opts; + get_user_print_options (&opts); + opts.deref_ref = 1; val_print (register_type (current_gdbarch, regnum), buffer, 0, 0, - stb->stream, format, 1, 0, Val_pretty_default, - current_language); + stb->stream, 0, &opts, current_language); ui_out_field_stream (uiout, "value", stb); ui_out_stream_delete (stb); } @@ -570,6 +573,7 @@ mi_cmd_data_evaluate_expression (char *command, char **argv, int argc) struct cleanup *old_chain = NULL; struct value *val; struct ui_stream *stb = NULL; + struct value_print_options opts; stb = ui_out_stream_new (uiout); @@ -586,9 +590,11 @@ mi_cmd_data_evaluate_expression (char *command, char **argv, int argc) val = evaluate_expression (expr); /* Print the result of the expression evaluation. */ + get_user_print_options (&opts); + opts.deref_ref = 0; val_print (value_type (val), value_contents (val), value_embedded_offset (val), VALUE_ADDRESS (val), - stb->stream, 0, 0, 0, 0, current_language); + stb->stream, 0, &opts, current_language); ui_out_field_stream (uiout, "value", stb); ui_out_stream_delete (stb); @@ -743,10 +749,13 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc) int col_byte; struct cleanup *cleanup_tuple; struct cleanup *cleanup_list_data; + struct value_print_options opts; + cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); ui_out_field_core_addr (uiout, "addr", addr + row_byte); /* ui_out_field_core_addr_symbolic (uiout, "saddr", addr + row_byte); */ cleanup_list_data = make_cleanup_ui_out_list_begin_end (uiout, "data"); + get_formatted_print_options (&opts, word_format); for (col = 0, col_byte = row_byte; col < nr_cols; col++, col_byte += word_size) @@ -758,7 +767,7 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc) else { ui_file_rewind (stream->stream); - print_scalar_formatted (mbuf + col_byte, word_type, word_format, + print_scalar_formatted (mbuf + col_byte, word_type, &opts, word_asize, stream->stream); ui_out_field_stream (uiout, NULL, stream); } diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index 1babccec235..07742668dfd 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -57,6 +57,7 @@ #include "target-descriptions.h" #include "dwarf2-frame.h" #include "user-regs.h" +#include "valprint.h" static const struct objfile_data *mips_pdr_data; @@ -4378,12 +4379,15 @@ mips_print_fp_register (struct ui_file *file, struct frame_info *frame, if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame)) { + struct value_print_options opts; + /* 4-byte registers: Print hex and floating. Also print even numbered registers as doubles. */ mips_read_fp_register_single (frame, regnum, raw_buffer); flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); - print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', + get_formatted_print_options (&opts, 'x'); + print_scalar_formatted (raw_buffer, builtin_type_uint32, &opts, 'w', file); fprintf_filtered (file, " flt: "); @@ -4407,6 +4411,8 @@ mips_print_fp_register (struct ui_file *file, struct frame_info *frame, } else { + struct value_print_options opts; + /* Eight byte registers: print each one as hex, float and double. */ mips_read_fp_register_single (frame, regnum, raw_buffer); flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); @@ -4414,8 +4420,8 @@ mips_print_fp_register (struct ui_file *file, struct frame_info *frame, mips_read_fp_register_double (frame, regnum, raw_buffer); doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2); - - print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', + get_formatted_print_options (&opts, 'x'); + print_scalar_formatted (raw_buffer, builtin_type_uint64, &opts, 'g', file); fprintf_filtered (file, " flt: "); @@ -4439,6 +4445,7 @@ mips_print_register (struct ui_file *file, struct frame_info *frame, struct gdbarch *gdbarch = get_frame_arch (frame); gdb_byte raw_buffer[MAX_REGISTER_SIZE]; int offset; + struct value_print_options opts; if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT) { @@ -4471,8 +4478,9 @@ mips_print_register (struct ui_file *file, struct frame_info *frame, else offset = 0; + get_formatted_print_options (&opts, 'x'); print_scalar_formatted (raw_buffer + offset, - register_type (gdbarch, regnum), 'x', 0, + register_type (gdbarch, regnum), &opts, 0, file); } diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c index da4afe347ce..db42e90c229 100644 --- a/gdb/mt-tdep.c +++ b/gdb/mt-tdep.c @@ -37,6 +37,7 @@ #include "infcall.h" #include "gdb_assert.h" #include "language.h" +#include "valprint.h" enum mt_arch_constants { @@ -675,6 +676,7 @@ mt_registers_info (struct gdbarch *gdbarch, { /* Special output handling for the 'coprocessor' register. */ gdb_byte *buf; + struct value_print_options opts; buf = alloca (register_size (gdbarch, MT_COPRO_REGNUM)); frame_register_read (frame, MT_COPRO_REGNUM, buf); @@ -685,8 +687,10 @@ mt_registers_info (struct gdbarch *gdbarch, print_spaces_filtered (15 - strlen (gdbarch_register_name (gdbarch, regnum)), file); + get_raw_print_options (&opts); + opts.deref_ref = 1; val_print (register_type (gdbarch, regnum), buf, - 0, 0, file, 0, 1, 0, Val_no_prettyprint, + 0, 0, file, 0, &opts, current_language); fputs_filtered ("\n", file); } diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 7d287a0df76..3a952f5ce11 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -341,7 +341,8 @@ objc_printchar (int c, struct ui_file *stream) static void objc_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; @@ -360,7 +361,7 @@ objc_printstr (struct ui_file *stream, const gdb_byte *string, return; } - for (i = 0; i < length && things_printed < print_max; ++i) + for (i = 0; i < length && things_printed < options->print_max; ++i) { /* Position of the character we are examining to see whether it is repeated. */ @@ -384,11 +385,11 @@ objc_printstr (struct ui_file *stream, const gdb_byte *string, ++reps; } - if (reps > repeat_count_threshold) + if (reps > options->repeat_count_threshold) { if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\", ", stream); else fputs_filtered ("\", ", stream); @@ -397,14 +398,14 @@ objc_printstr (struct ui_file *stream, const gdb_byte *string, objc_printchar (string[i], stream); fprintf_filtered (stream, " ", reps); i = rep1 - 1; - things_printed += repeat_count_threshold; + things_printed += options->repeat_count_threshold; need_comma = 1; } else { if (!in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); @@ -418,7 +419,7 @@ objc_printstr (struct ui_file *stream, const gdb_byte *string, /* Terminate the quotes if necessary. */ if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 7ecdd8d08f0..cd4285d2a06 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -207,7 +207,8 @@ pascal_printchar (int c, struct ui_file *stream) void pascal_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { unsigned int i; unsigned int things_printed = 0; @@ -226,7 +227,7 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, return; } - for (i = 0; i < length && things_printed < print_max; ++i) + for (i = 0; i < length && things_printed < options->print_max; ++i) { /* Position of the character we are examining to see whether it is repeated. */ @@ -250,11 +251,11 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, ++reps; } - if (reps > repeat_count_threshold) + if (reps > options->repeat_count_threshold) { if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\', ", stream); else fputs_filtered ("', ", stream); @@ -263,7 +264,7 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, pascal_printchar (string[i], stream); fprintf_filtered (stream, " ", reps); i = rep1 - 1; - things_printed += repeat_count_threshold; + things_printed += options->repeat_count_threshold; need_comma = 1; } else @@ -271,7 +272,7 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, int c = string[i]; if ((!in_quotes) && (PRINT_LITERAL_FORM (c))) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\'", stream); else fputs_filtered ("'", stream); @@ -285,7 +286,7 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, /* Terminate the quotes if necessary. */ if (in_quotes) { - if (inspect_it) + if (options->inspect_it) fputs_filtered ("\\'", stream); else fputs_filtered ("'", stream); diff --git a/gdb/p-lang.h b/gdb/p-lang.h index a4f878f8b95..4ebfbc1f826 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -35,10 +35,11 @@ extern void pascal_print_typedef (struct type *, struct symbol *, struct ui_file *); extern int pascal_val_print (struct type *, const gdb_byte *, int, - CORE_ADDR, struct ui_file *, int, int, - int, enum val_prettyprint); + CORE_ADDR, struct ui_file *, int, + const struct value_print_options *); -extern int pascal_value_print (struct value *, struct ui_file *, int, enum val_prettyprint); +extern int pascal_value_print (struct value *, struct ui_file *, + const struct value_print_options *); extern void pascal_type_print_method_args (char *, char *, struct ui_file *); @@ -51,7 +52,8 @@ extern int extern void pascal_printchar (int, struct ui_file *); extern void pascal_printstr (struct ui_file *, const gdb_byte *, - unsigned int, int, int); + unsigned int, int, int, + const struct value_print_options *); extern struct type **const (pascal_builtin_types[]); @@ -63,15 +65,10 @@ extern void extern void pascal_type_print_varspec_prefix (struct type *, struct ui_file *, int, int); -/* These are in cp-valprint.c */ - -extern int vtblprint; /* Controls printing of vtbl's */ - -extern int static_field_print; - extern void pascal_object_print_value_fields (struct type *, const gdb_byte *, CORE_ADDR, struct ui_file *, - int, int, enum val_prettyprint, + int, + const struct value_print_options *, struct type **, int); extern int pascal_object_is_vtbl_ptr_type (struct type *); diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index bc4fbe106f2..65ab8a10188 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -44,23 +44,17 @@ /* Print data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto stdio stream STREAM according to - FORMAT (a letter or 0 for natural format). The data at VALADDR is in - target byte order. + OPTIONS. The data at VALADDR is in target byte order. If the data are a string pointer, returns the number of string characters - printed. - - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - - The PRETTY parameter controls prettyprinting. */ + printed. */ int pascal_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, int deref_ref, - int recurse, enum val_prettyprint pretty) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { unsigned int i = 0; /* Number of characters printed */ unsigned len; @@ -80,7 +74,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, elttype = check_typedef (TYPE_TARGET_TYPE (type)); eltlen = TYPE_LENGTH (elttype); len = TYPE_LENGTH (type) / eltlen; - if (prettyprint_arrays) + if (options->prettyprint_arrays) { print_spaces_filtered (2 + 2 * recurse, stream); } @@ -89,23 +83,24 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, && ((TYPE_CODE (elttype) == TYPE_CODE_INT) || ((current_language->la_language == language_pascal) && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) - && (format == 0 || format == 's')) + && (options->format == 0 || options->format == 's')) { /* If requested, look for the first null char and only print elements up to it. */ - if (stop_print_at_null) + if (options->stop_print_at_null) { unsigned int temp_len; /* Look for a NULL char. */ for (temp_len = 0; (valaddr + embedded_offset)[temp_len] - && temp_len < len && temp_len < print_max; + && temp_len < len && temp_len < options->print_max; temp_len++); len = temp_len; } - LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0); + LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0, + options); i = len; } else @@ -123,7 +118,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, i = 0; } val_print_array_elements (type, valaddr + embedded_offset, address, stream, - format, deref_ref, recurse, pretty, i); + recurse, options, i); fprintf_filtered (stream, "}"); } break; @@ -133,12 +128,13 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, goto print_unpacked_pointer; case TYPE_CODE_PTR: - if (format && format != 's') + if (options->format && options->format != 's') { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); break; } - if (vtblprint && pascal_object_is_vtbl_ptr_type (type)) + if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if we ARE using @@ -162,7 +158,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, return (0); } - if (addressprint && format != 's') + if (options->addressprint && options->format != 's') { fputs_filtered (paddress (addr), stream); } @@ -172,11 +168,11 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, if (TYPE_LENGTH (elttype) == 1 && (TYPE_CODE (elttype) == TYPE_CODE_INT || TYPE_CODE(elttype) == TYPE_CODE_CHAR) - && (format == 0 || format == 's') + && (options->format == 0 || options->format == 's') && addr != 0) { /* no wide string yet */ - i = val_print_string (addr, -1, 1, stream); + i = val_print_string (addr, -1, 1, stream, options); } /* also for pointers to pascal strings */ /* Note: this is Free Pascal specific: @@ -193,7 +189,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, read_memory (addr + length_pos, buffer, length_size); string_length = extract_unsigned_integer (buffer, length_size); xfree (buffer); - i = val_print_string (addr + string_pos, string_length, char_size, stream); + i = val_print_string (addr + string_pos, string_length, char_size, stream, options); } else if (pascal_object_is_vtbl_member (type)) { @@ -209,7 +205,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); fputs_filtered (">", stream); } - if (vt_address && vtblprint) + if (vt_address && options->vtblprint) { struct value *vt_val; struct symbol *wsym = (struct symbol *) NULL; @@ -230,9 +226,9 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, wtype = TYPE_TARGET_TYPE (type); } vt_val = value_at (wtype, vt_address); - common_val_print (vt_val, stream, format, deref_ref, - recurse + 1, pretty, current_language); - if (pretty) + common_val_print (vt_val, stream, recurse + 1, options, + current_language); + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -249,18 +245,18 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, case TYPE_CODE_REF: elttype = check_typedef (TYPE_TARGET_TYPE (type)); - if (addressprint) + if (options->addressprint) { fprintf_filtered (stream, "@"); /* Extract the address, assume that it is unsigned. */ fputs_filtered (paddress ( extract_unsigned_integer (valaddr + embedded_offset, gdbarch_ptr_bit (current_gdbarch) / HOST_CHAR_BIT)), stream); - if (deref_ref) + if (options->deref_ref) fputs_filtered (": ", stream); } /* De-reference the reference. */ - if (deref_ref) + if (options->deref_ref) { if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) { @@ -268,8 +264,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr + embedded_offset)); - common_val_print (deref_val, stream, format, deref_ref, - recurse + 1, pretty, current_language); + common_val_print (deref_val, stream, recurse + 1, options, + current_language); } else fputs_filtered ("???", stream); @@ -277,14 +273,14 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_UNION: - if (recurse && !unionprint) + if (recurse && !options->unionprint) { fprintf_filtered (stream, "{...}"); break; } /* Fall through. */ case TYPE_CODE_STRUCT: - if (vtblprint && pascal_object_is_vtbl_ptr_type (type)) + if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if NOT using @@ -301,18 +297,19 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, &string_pos, &char_size, NULL)) { len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size); - LA_PRINT_STRING (stream, valaddr + embedded_offset + string_pos, len, char_size, 0); + LA_PRINT_STRING (stream, valaddr + embedded_offset + string_pos, len, char_size, 0, options); } else - pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream, format, - recurse, pretty, NULL, 0); + pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream, + recurse, options, NULL, 0); } break; case TYPE_CODE_ENUM: - if (format) + if (options->format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); break; } len = TYPE_NFIELDS (type); @@ -336,16 +333,18 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_FLAGS: - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + if (options->format) + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); else val_print_type_code_flags (type, valaddr + embedded_offset, stream); break; case TYPE_CODE_FUNC: - if (format) + if (options->format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); break; } /* FIXME, we should consider, at least for ANSI C language, eliminating @@ -358,9 +357,14 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_BOOL: - format = format ? format : output_format; - if (format) - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); + } else { val = unpack_long (type, valaddr + embedded_offset); @@ -387,10 +391,13 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, /* FALLTHROUGH */ case TYPE_CODE_INT: - format = format ? format : output_format; - if (format) + if (options->format || options->output_format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); } else { @@ -399,10 +406,13 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_CHAR: - format = format ? format : output_format; - if (format) + if (options->format || options->output_format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + print_scalar_formatted (valaddr + embedded_offset, type, + &opts, 0, stream); } else { @@ -417,9 +427,10 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_FLT: - if (format) + if (options->format) { - print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + print_scalar_formatted (valaddr + embedded_offset, type, + options, 0, stream); } else { @@ -517,8 +528,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, } int -pascal_value_print (struct value *val, struct ui_file *stream, int format, - enum val_prettyprint pretty) +pascal_value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options) { struct type *type = value_type (val); @@ -547,19 +558,10 @@ pascal_value_print (struct value *val, struct ui_file *stream, int format, fprintf_filtered (stream, ") "); } } - return common_val_print (val, stream, format, 1, 0, pretty, - current_language); + return common_val_print (val, stream, 0, options, current_language); } -/****************************************************************************** - Inserted from cp-valprint -******************************************************************************/ - -extern int vtblprint; /* Controls printing of vtbl's */ -extern int objectprint; /* Controls looking up an object's derived type - using what we find in its vtables. */ -static int pascal_static_field_print; /* Controls printing of static fields. */ static void show_pascal_static_field_print (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -572,12 +574,12 @@ static struct obstack dont_print_vb_obstack; static struct obstack dont_print_statmem_obstack; static void pascal_object_print_static_field (struct value *, - struct ui_file *, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); static void pascal_object_print_value (struct type *, const gdb_byte *, - CORE_ADDR, struct ui_file *, - int, int, enum val_prettyprint, + CORE_ADDR, struct ui_file *, int, + const struct value_print_options *, struct type **); /* It was changed to this after 2.4.5. */ @@ -624,7 +626,7 @@ pascal_object_is_vtbl_member (struct type *type) c_val_print to print out a structure's fields: pascal_object_print_value_fields and pascal_object_print_value. - TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the + TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the same meanings as in pascal_object_print_value and c_val_print. DONT_PRINT is an array of baseclass types that we @@ -633,8 +635,8 @@ pascal_object_is_vtbl_member (struct type *type) void pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, CORE_ADDR address, struct ui_file *stream, - int format, int recurse, - enum val_prettyprint pretty, + int recurse, + const struct value_print_options *options, struct type **dont_print_vb, int dont_print_statmem) { @@ -651,7 +653,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, duplicates of virtual baseclasses. */ if (n_baseclasses > 0) pascal_object_print_value (type, valaddr, address, stream, - format, recurse + 1, pretty, dont_print_vb); + recurse + 1, options, dont_print_vb); if (!len && n_baseclasses == 1) fprintf_filtered (stream, ""); @@ -671,14 +673,14 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, for (i = n_baseclasses; i < len; i++) { /* If requested, skip printing of static fields. */ - if (!pascal_static_field_print + if (!options->pascal_static_field_print && field_is_static (&TYPE_FIELD (type, i))) continue; if (fields_seen) fprintf_filtered (stream, ", "); else if (n_baseclasses > 0) { - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -689,7 +691,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, } fields_seen = 1; - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -698,7 +700,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, { wrap_here (n_spaces (2 + 2 * recurse)); } - if (inspect_it) + if (options->inspect_it) { if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) fputs_filtered ("\"( ptr \"", stream); @@ -742,11 +744,13 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, } else { + struct value_print_options opts = *options; v = value_from_longest (TYPE_FIELD_TYPE (type, i), unpack_field_as_long (type, valaddr, i)); - common_val_print (v, stream, format, 0, recurse + 1, - pretty, current_language); + opts.deref_ref = 0; + common_val_print (v, stream, recurse + 1, &opts, + current_language); } } else @@ -765,11 +769,13 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, if (v == NULL) fputs_filtered ("", stream); else - pascal_object_print_static_field (v, stream, format, - recurse + 1, pretty); + pascal_object_print_static_field (v, stream, recurse + 1, + options); } else { + struct value_print_options opts = *options; + opts.deref_ref = 0; /* val_print (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / 8, address + TYPE_FIELD_BITPOS (type, i) / 8, 0, @@ -777,7 +783,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, val_print (TYPE_FIELD_TYPE (type, i), valaddr, TYPE_FIELD_BITPOS (type, i) / 8, address + TYPE_FIELD_BITPOS (type, i) / 8, - stream, format, 0, recurse + 1, pretty, + stream, recurse + 1, &opts, current_language); } } @@ -792,7 +798,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, dont_print_statmem_obstack = tmp_obstack; } - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); @@ -807,8 +813,8 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, static void pascal_object_print_value (struct type *type, const gdb_byte *valaddr, CORE_ADDR address, struct ui_file *stream, - int format, int recurse, - enum val_prettyprint pretty, + int recurse, + const struct value_print_options *options, struct type **dont_print_vb) { struct type **last_dont_print @@ -849,7 +855,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr, boffset = baseclass_offset (type, i, valaddr, address); - if (pretty) + if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); @@ -881,7 +887,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr, fprintf_filtered (stream, ""); else pascal_object_print_value_fields (baseclass, base_valaddr, address + boffset, - stream, format, recurse, pretty, + stream, recurse, options, (struct type **) obstack_base (&dont_print_vb_obstack), 0); fputs_filtered (", ", stream); @@ -907,15 +913,17 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr, static member classes in an obstack and refuse to print them more than once. - VAL contains the value to print, STREAM, RECURSE, and PRETTY + VAL contains the value to print, STREAM, RECURSE, and OPTIONS have the same meanings as in c_val_print. */ static void pascal_object_print_static_field (struct value *val, - struct ui_file *stream, int format, - int recurse, enum val_prettyprint pretty) + struct ui_file *stream, + int recurse, + const struct value_print_options *options) { struct type *type = value_type (val); + struct value_print_options opts; if (TYPE_CODE (type) == TYPE_CODE_STRUCT) { @@ -942,11 +950,13 @@ pascal_object_print_static_field (struct value *val, CHECK_TYPEDEF (type); pascal_object_print_value_fields (type, value_contents (val), VALUE_ADDRESS (val), - stream, format, recurse, pretty, NULL, 1); + stream, recurse, options, NULL, 1); return; } - common_val_print (val, stream, format, 0, recurse, pretty, - current_language); + + opts = *options; + opts.deref_ref = 0; + common_val_print (val, stream, recurse, &opts, current_language); } extern initialize_file_ftype _initialize_pascal_valprint; /* -Wmissing-prototypes */ @@ -955,13 +965,10 @@ void _initialize_pascal_valprint (void) { add_setshow_boolean_cmd ("pascal_static-members", class_support, - &pascal_static_field_print, _("\ + &user_print_options.pascal_static_field_print, _("\ Set printing of pascal static members."), _("\ Show printing of pascal static members."), NULL, NULL, show_pascal_static_field_print, &setprintlist, &showprintlist); - /* Turn on printing of static fields. */ - pascal_static_field_print = 1; - } diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 021e191c63d..355552db5e0 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -42,6 +42,7 @@ #include "block.h" #include "disasm.h" #include "dfp.h" +#include "valprint.h" #ifdef TUI #include "tui/tui.h" /* For tui_active et.al. */ @@ -55,7 +56,6 @@ #endif extern int asm_demangle; /* Whether to demangle syms in asm printouts */ -extern int addressprint; /* Whether to print hex addresses in HLL " */ struct format_data { @@ -120,13 +120,6 @@ Printing of source filename and line number with is %s.\n"), int current_display_number; -/* Flag to low-level print routines that this value is being printed - in an epoch window. We'd like to pass this as a parameter, but - every routine would need to take it. Perhaps we can encapsulate - this in the I/O stream once we have GNU stdio. */ - -int inspect_it = 0; - struct display { /* Chain link to next auto-display item. */ @@ -254,15 +247,15 @@ decode_format (char **string_ptr, int oformat, int osize) return val; } -/* Print value VAL on stream according to FORMAT, a letter or 0. +/* Print value VAL on stream according to OPTIONS. Do not end with a newline. - 0 means print VAL according to its own type. SIZE is the letter for the size of datum being printed. This is used to pad hex numbers so they line up. SIZE is 0 for print / output and set for examine. */ static void -print_formatted (struct value *val, int format, int size, +print_formatted (struct value *val, int size, + const struct value_print_options *options, struct ui_file *stream) { struct type *type = check_typedef (value_type (val)); @@ -273,12 +266,13 @@ print_formatted (struct value *val, int format, int size, if (size) { - switch (format) + switch (options->format) { case 's': /* FIXME: Need to handle wchar_t's here... */ next_address = VALUE_ADDRESS (val) - + val_print_string (VALUE_ADDRESS (val), -1, 1, stream); + + val_print_string (VALUE_ADDRESS (val), -1, 1, stream, + options); return; case 'i': @@ -291,22 +285,19 @@ print_formatted (struct value *val, int format, int size, } } - if (format == 0 || format == 's' + if (options->format == 0 || options->format == 's' || TYPE_CODE (type) == TYPE_CODE_REF || TYPE_CODE (type) == TYPE_CODE_ARRAY || TYPE_CODE (type) == TYPE_CODE_STRING || TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_UNION || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) - /* If format is 0, use the 'natural' format for that type of - value. If the type is non-scalar, we have to use language - rules to print it as a series of scalars. */ - value_print (val, stream, format, Val_pretty_default); + value_print (val, stream, options); else /* User specified format, so don't look to the the type to tell us what to do. */ print_scalar_formatted (value_contents (val), type, - format, size, stream); + options, size, stream); } /* Return builtin floating point type of same length as TYPE. @@ -328,15 +319,16 @@ float_type_from_length (struct gdbarch *gdbarch, struct type *type) } /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, - according to letters FORMAT and SIZE on STREAM. - FORMAT may not be zero. Formats s and i are not supported at this level. + according to OPTIONS and SIZE on STREAM. + Formats s and i are not supported at this level. This is how the elements of an array or structure are printed with a format. */ void print_scalar_formatted (const void *valaddr, struct type *type, - int format, int size, struct ui_file *stream) + const struct value_print_options *options, + int size, struct ui_file *stream) { LONGEST val_long = 0; unsigned int len = TYPE_LENGTH (type); @@ -345,9 +337,12 @@ print_scalar_formatted (const void *valaddr, struct type *type, /* If we get here with a string format, try again without it. Go all the way back to the language printers, which may call us again. */ - if (format == 's') + if (options->format == 's') { - val_print (type, valaddr, 0, 0, stream, 0, 0, 0, Val_pretty_default, + struct value_print_options opts = *options; + opts.format = 0; + opts.deref_ref = 0; + val_print (type, valaddr, 0, 0, stream, 0, &opts, current_language); return; } @@ -356,7 +351,7 @@ print_scalar_formatted (const void *valaddr, struct type *type, (TYPE_CODE (type) == TYPE_CODE_INT || TYPE_CODE (type) == TYPE_CODE_ENUM)) { - switch (format) + switch (options->format) { case 'o': print_octal_chars (stream, valaddr, len, byte_order); @@ -379,7 +374,7 @@ print_scalar_formatted (const void *valaddr, struct type *type, }; } - if (format != 'f') + if (options->format != 'f') val_long = unpack_long (type, valaddr); /* If the value is a pointer, and pointers and addresses are not the @@ -391,13 +386,13 @@ print_scalar_formatted (const void *valaddr, struct type *type, /* If we are printing it as unsigned, truncate it in case it is actually a negative signed value (e.g. "print/u (short)-1" should print 65535 (if shorts are 16 bits) instead of 4294967295). */ - if (format != 'd') + if (options->format != 'd') { if (len < sizeof (LONGEST)) val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1; } - switch (format) + switch (options->format) { case 'x': if (!size) @@ -442,13 +437,17 @@ print_scalar_formatted (const void *valaddr, struct type *type, break; case 'c': - if (TYPE_UNSIGNED (type)) - value_print (value_from_longest (builtin_type_true_unsigned_char, - val_long), - stream, 0, Val_pretty_default); - else - value_print (value_from_longest (builtin_type_true_char, val_long), - stream, 0, Val_pretty_default); + { + struct value_print_options opts = *options; + opts.format = 0; + if (TYPE_UNSIGNED (type)) + value_print (value_from_longest (builtin_type_true_unsigned_char, + val_long), + stream, &opts); + else + value_print (value_from_longest (builtin_type_true_char, val_long), + stream, &opts); + } break; case 'f': @@ -508,7 +507,7 @@ print_scalar_formatted (const void *valaddr, struct type *type, break; default: - error (_("Undefined output format \"%c\"."), format); + error (_("Undefined output format \"%c\"."), options->format); } } @@ -707,11 +706,13 @@ void print_address_demangle (CORE_ADDR addr, struct ui_file *stream, int do_demangle) { + struct value_print_options opts; + get_user_print_options (&opts); if (addr == 0) { fprintf_filtered (stream, "0"); } - else if (addressprint) + else if (opts.addressprint) { fputs_filtered (paddress (addr), stream); print_address_symbolic (addr, stream, do_demangle, " "); @@ -745,6 +746,7 @@ do_examine (struct format_data fmt, CORE_ADDR addr) struct type *val_type = NULL; int i; int maxelts; + struct value_print_options opts; format = fmt.format; size = fmt.size; @@ -775,6 +777,8 @@ do_examine (struct format_data fmt, CORE_ADDR addr) if (format == 's' || format == 'i') maxelts = 1; + get_formatted_print_options (&opts, format); + /* Print as many objects as specified in COUNT, at most maxelts per line, with the address of the next one at the start of each line. */ @@ -809,7 +813,7 @@ do_examine (struct format_data fmt, CORE_ADDR addr) if (last_examine_value) release_value (last_examine_value); - print_formatted (last_examine_value, format, size, gdb_stdout); + print_formatted (last_examine_value, size, &opts, gdb_stdout); /* Display any branch delay slots following the final insn. */ if (format == 'i' && count == 1) @@ -847,10 +851,6 @@ print_command_1 (char *exp, int inspect, int voidprint) struct format_data fmt; int cleanup = 0; - /* Pass inspect flag to the rest of the print routines in a global - (sigh). */ - inspect_it = inspect; - if (exp && *exp == '/') { exp++; @@ -879,6 +879,7 @@ print_command_1 (char *exp, int inspect, int voidprint) if (voidprint || (val && value_type (val) && TYPE_CODE (value_type (val)) != TYPE_CODE_VOID)) { + struct value_print_options opts; int histindex = record_latest_value (val); if (histindex >= 0) @@ -895,7 +896,10 @@ print_command_1 (char *exp, int inspect, int voidprint) if (histindex >= 0) annotate_value_history_value (); - print_formatted (val, format, fmt.size, gdb_stdout); + get_formatted_print_options (&opts, format); + opts.inspect_it = inspect; + + print_formatted (val, fmt.size, &opts, gdb_stdout); printf_filtered ("\n"); if (histindex >= 0) @@ -909,7 +913,6 @@ print_command_1 (char *exp, int inspect, int voidprint) if (cleanup) do_cleanups (old_chain); - inspect_it = 0; /* Reset print routines to normal. */ } static void @@ -942,6 +945,7 @@ output_command (char *exp, int from_tty) char format = 0; struct value *val; struct format_data fmt; + struct value_print_options opts; fmt.size = 0; @@ -960,7 +964,8 @@ output_command (char *exp, int from_tty) annotate_value_begin (value_type (val)); - print_formatted (val, format, fmt.size, gdb_stdout); + get_formatted_print_options (&opts, format); + print_formatted (val, fmt.size, &opts, gdb_stdout); annotate_value_end (); @@ -1507,6 +1512,8 @@ do_one_display (struct display *d) } else { + struct value_print_options opts; + annotate_display_format (); if (d->format.format) @@ -1521,8 +1528,9 @@ do_one_display (struct display *d) annotate_display_expression (); + get_formatted_print_options (&opts, d->format.format); print_formatted (evaluate_expression (d->exp), - d->format.format, d->format.size, gdb_stdout); + d->format.size, &opts, gdb_stdout); printf_filtered ("\n"); } @@ -1677,8 +1685,10 @@ print_variable_value (struct symbol *var, struct frame_info *frame, struct ui_file *stream) { struct value *val = read_var_value (var, frame); + struct value_print_options opts; - value_print (val, stream, 0, Val_pretty_default); + get_user_print_options (&opts); + value_print (val, stream, &opts); } static void diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c index d95727371be..8bf4ec892ff 100644 --- a/gdb/python/python-value.c +++ b/gdb/python/python-value.c @@ -23,6 +23,7 @@ #include "exceptions.h" #include "language.h" #include "dfp.h" +#include "valprint.h" /* List of all values which are currently exposed to Python. It is maintained so that when an objfile is discarded, preserve_values @@ -189,15 +190,19 @@ valpy_str (PyObject *self) struct ui_file *stb; struct cleanup *old_chain; PyObject *result; + struct value_print_options opts; volatile struct gdb_exception except; + get_user_print_options (&opts); + opts.deref_ref = 0; + stb = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (stb); TRY_CATCH (except, RETURN_MASK_ALL) { - common_val_print (((value_object *) self)->value, stb, 0, 0, 0, - Val_pretty_default, current_language); + common_val_print (((value_object *) self)->value, stb, 0, + &opts, current_language); s = ui_file_xstrdup (stb, &dummy); } GDB_PY_HANDLE_EXCEPTION (except); diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c index 42d25023874..0b25590f8af 100644 --- a/gdb/scm-lang.c +++ b/gdb/scm-lang.c @@ -50,7 +50,8 @@ scm_printchar (int c, struct ui_file *stream) static void scm_printstr (struct ui_file *stream, const gdb_byte *string, - unsigned int length, int width, int force_ellipses) + unsigned int length, int width, int force_ellipses, + const struct value_print_options *options) { fprintf_filtered (stream, "\"%s\"", string); } diff --git a/gdb/scm-lang.h b/gdb/scm-lang.h index 654095cd61a..369905b5119 100644 --- a/gdb/scm-lang.h +++ b/gdb/scm-lang.h @@ -46,16 +46,16 @@ struct value; extern int scm_value_print (struct value *, struct ui_file *, - int, enum val_prettyprint); + const struct value_print_options *); extern int scm_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); + struct ui_file *, int, + const struct value_print_options *); extern LONGEST scm_get_field (LONGEST, int); -extern void scm_scmval_print (LONGEST, struct ui_file *, int, int, int, - enum val_prettyprint); +extern void scm_scmval_print (LONGEST, struct ui_file *, int, + const struct value_print_options *); extern int is_scmvalue_type (struct type *); diff --git a/gdb/scm-valprint.c b/gdb/scm-valprint.c index feb43dd80e4..006f28063a8 100644 --- a/gdb/scm-valprint.c +++ b/gdb/scm-valprint.c @@ -33,18 +33,18 @@ #include "objfiles.h" static void scm_ipruk (char *, LONGEST, struct ui_file *); -static void scm_scmlist_print (LONGEST, struct ui_file *, int, int, - int, enum val_prettyprint); -static int scm_inferior_print (LONGEST, struct ui_file *, int, int, - int, enum val_prettyprint); +static void scm_scmlist_print (LONGEST, struct ui_file *, int, + const struct value_print_options *); +static int scm_inferior_print (LONGEST, struct ui_file *, int, + const struct value_print_options *); /* Prints the SCM value VALUE by invoking the inferior, if appropraite. Returns >= 0 on success; return -1 if the inferior cannot/should not print VALUE. */ static int -scm_inferior_print (LONGEST value, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) +scm_inferior_print (LONGEST value, struct ui_file *stream, + int recurse, const struct value_print_options *options) { struct objfile *objf; struct gdbarch *gdbarch; @@ -129,17 +129,16 @@ static char *scm_isymnames[] = }; static void -scm_scmlist_print (LONGEST svalue, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) +scm_scmlist_print (LONGEST svalue, struct ui_file *stream, int recurse, + const struct value_print_options *options) { - unsigned int more = print_max; + unsigned int more = options->print_max; if (recurse > 6) { fputs_filtered ("...", stream); return; } - scm_scmval_print (SCM_CAR (svalue), stream, format, - deref_ref, recurse + 1, pretty); + scm_scmval_print (SCM_CAR (svalue), stream, recurse + 1, options); svalue = SCM_CDR (svalue); for (; SCM_NIMP (svalue); svalue = SCM_CDR (svalue)) { @@ -151,14 +150,12 @@ scm_scmlist_print (LONGEST svalue, struct ui_file *stream, int format, fputs_filtered ("...", stream); return; } - scm_scmval_print (SCM_CAR (svalue), stream, format, - deref_ref, recurse + 1, pretty); + scm_scmval_print (SCM_CAR (svalue), stream, recurse + 1, options); } if (SCM_NNULLP (svalue)) { fputs_filtered (" . ", stream); - scm_scmval_print (svalue, stream, format, - deref_ref, recurse + 1, pretty); + scm_scmval_print (svalue, stream, recurse + 1, options); } } @@ -174,15 +171,17 @@ scm_ipruk (char *hdr, LONGEST ptr, struct ui_file *stream) } void -scm_scmval_print (LONGEST svalue, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty) +scm_scmval_print (LONGEST svalue, struct ui_file *stream, + int recurse, const struct value_print_options *options) { taloop: switch (7 & (int) svalue) { case 2: case 6: - print_longest (stream, format ? format : 'd', 1, svalue >> 2); + print_longest (stream, + options->format ? options->format : 'd', + 1, svalue >> 2); break; case 4: if (SCM_ICHRP (svalue)) @@ -243,14 +242,12 @@ taloop: case scm_tcs_cons_imcar: case scm_tcs_cons_nimcar: fputs_filtered ("(", stream); - scm_scmlist_print (svalue, stream, format, - deref_ref, recurse + 1, pretty); + scm_scmlist_print (svalue, stream, recurse + 1, options); fputs_filtered (")", stream); break; case scm_tcs_closures: fputs_filtered ("#", stream); break; case scm_tc7_string: @@ -261,9 +258,9 @@ taloop: int done = 0; int buf_size; gdb_byte buffer[64]; - int truncate = print_max && len > (int) print_max; + int truncate = options->print_max && len > (int) options->print_max; if (truncate) - len = print_max; + len = options->print_max; fputs_filtered ("\"", stream); for (; done < len; done += buf_size) { @@ -305,8 +302,8 @@ taloop: { if (i > 0) fputs_filtered (" ", stream); - scm_scmval_print (scm_get_field (elements, i), stream, format, - deref_ref, recurse + 1, pretty); + scm_scmval_print (scm_get_field (elements, i), stream, + recurse + 1, options); } fputs_filtered (")", stream); } @@ -401,21 +398,19 @@ taloop: int scm_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, int deref_ref, - int recurse, enum val_prettyprint pretty) + struct ui_file *stream, int recurse, + const struct value_print_options *options) { if (is_scmvalue_type (type)) { LONGEST svalue = extract_signed_integer (valaddr, TYPE_LENGTH (type)); - if (scm_inferior_print (svalue, stream, format, - deref_ref, recurse, pretty) >= 0) + if (scm_inferior_print (svalue, stream, recurse, options) >= 0) { } else { - scm_scmval_print (svalue, stream, format, - deref_ref, recurse, pretty); + scm_scmval_print (svalue, stream, recurse, options); } gdb_flush (stream); @@ -423,15 +418,15 @@ scm_val_print (struct type *type, const gdb_byte *valaddr, } else { - return c_val_print (type, valaddr, 0, address, stream, format, - deref_ref, recurse, pretty); + return c_val_print (type, valaddr, 0, address, stream, recurse, options); } } int -scm_value_print (struct value *val, struct ui_file *stream, int format, - enum val_prettyprint pretty) +scm_value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options) { - return (common_val_print (val, stream, format, 1, 0, pretty, - current_language)); + struct value_print_options opts = *options; + opts.deref_ref = 1; + return (common_val_print (val, stream, 0, &opts, current_language)); } diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c index 474d49ad838..988e8cbd120 100644 --- a/gdb/sh64-tdep.c +++ b/gdb/sh64-tdep.c @@ -40,6 +40,7 @@ #include "arch-utils.h" #include "regcache.h" #include "osabi.h" +#include "valprint.h" #include "elf-bfd.h" @@ -2092,6 +2093,7 @@ sh64_do_register (struct gdbarch *gdbarch, struct ui_file *file, struct frame_info *frame, int regnum) { unsigned char raw_buffer[MAX_REGISTER_SIZE]; + struct value_print_options opts; fputs_filtered (gdbarch_register_name (gdbarch, regnum), file); print_spaces_filtered (15 - strlen (gdbarch_register_name @@ -2100,12 +2102,16 @@ sh64_do_register (struct gdbarch *gdbarch, struct ui_file *file, /* Get the data in raw format. */ if (!frame_register_read (frame, regnum, raw_buffer)) fprintf_filtered (file, "*value not available*\n"); - + + get_formatted_print_options (&opts, 'x'); + opts.deref_ref = 1; val_print (register_type (gdbarch, regnum), raw_buffer, 0, 0, - file, 'x', 1, 0, Val_pretty_default, current_language); + file, 0, &opts, current_language); fprintf_filtered (file, "\t"); + get_formatted_print_options (&opts, 0); + opts.deref_ref = 1; val_print (register_type (gdbarch, regnum), raw_buffer, 0, 0, - file, 0, 1, 0, Val_pretty_default, current_language); + file, 0, &opts, current_language); fprintf_filtered (file, "\n"); } diff --git a/gdb/stack.c b/gdb/stack.c index 2c3c0bbe376..3c1019b22c1 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -368,6 +368,7 @@ print_frame_args (struct symbol *func, struct frame_info *frame, if (val) { const struct language_defn *language; + struct value_print_options opts; /* Use the appropriate language to display our symbol, unless the user forced the language to a specific @@ -377,8 +378,10 @@ print_frame_args (struct symbol *func, struct frame_info *frame, else language = current_language; - common_val_print (val, stb->stream, 0, 0, 2, - Val_no_prettyprint, language); + get_raw_print_options (&opts); + opts.deref_ref = 0; + common_val_print (val, stb->stream, 2, + &opts, language); ui_out_field_stream (uiout, "value", stb); } else @@ -547,6 +550,8 @@ print_frame_info (struct frame_info *frame, int print_level, sal.line + 1, 0); else { + struct value_print_options opts; + get_user_print_options (&opts); /* We used to do this earlier, but that is clearly wrong. This function is used by many different parts of gdb, including normal_stop in infrun.c, @@ -555,7 +560,7 @@ print_frame_info (struct frame_info *frame, int print_level, line. Only the command line really wants this behavior. Other UIs probably would like the ability to decide for themselves if it is desired. */ - if (addressprint && mid_statement) + if (opts.addressprint && mid_statement) { ui_out_field_core_addr (uiout, "addr", get_frame_pc (frame)); ui_out_text (uiout, "\t"); @@ -584,6 +589,7 @@ print_frame (struct frame_info *frame, int print_level, enum language funlang = language_unknown; struct ui_stream *stb; struct cleanup *old_chain, *list_chain; + struct value_print_options opts; stb = ui_out_stream_new (uiout); old_chain = make_cleanup_ui_out_stream_delete (stb); @@ -665,7 +671,8 @@ print_frame (struct frame_info *frame, int print_level, ui_out_field_fmt_int (uiout, 2, ui_left, "level", frame_relative_level (frame)); } - if (addressprint) + get_user_print_options (&opts); + if (opts.addressprint) if (get_frame_pc (frame) != sal.pc || !sal.symtab || print_what == LOC_AND_ADDRESS) { @@ -1405,10 +1412,12 @@ print_block_frame_labels (struct block *b, int *have_default, if (SYMBOL_CLASS (sym) == LOC_LABEL) { struct symtab_and_line sal; + struct value_print_options opts; sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); values_printed = 1; fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); - if (addressprint) + get_user_print_options (&opts); + if (opts.addressprint) { fprintf_filtered (stream, " "); fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (sym)), stream); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 22a03e805b8..5a8336c240d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-10-28 Tom Tromey + + * gdb.base/exprs.exp (test_expr): Add enum formatting tests. + 2008-10-24 Pedro Alves * gdb.python/python-value.exp (test_value_in_inferior): Don't use diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp index 484b5a4a8f5..f12a23447c3 100644 --- a/gdb/testsuite/gdb.base/exprs.exp +++ b/gdb/testsuite/gdb.base/exprs.exp @@ -252,3 +252,10 @@ gdb_test "print (void*) (~((long long)(unsigned long) -1) - 1)" \ # String concatentation. test_expr "print \"x\" \"y\"" "\\$\[0-9\]* = \"xy\"" test_expr "print \"x\" \"y\" \"z\"" "\\$\[0-9\]* = \"xyz\"" + +# Enum formatting tests. +test_expr "print red" "\\$\[0-9\]* = red" +gdb_test "set output-radix 8" "" +test_expr "print red" "\\$\[0-9\]* = red" +test_expr "print/d red" "\\$\[0-9\]* = 0" +gdb_test "set output-radix 10" "" diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 2d2c3bdffb4..5c8c205bb0e 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -38,6 +38,7 @@ #include "dictionary.h" #include "observer.h" #include "user-regs.h" +#include "valprint.h" #include "ax.h" #include "ax-gdb.h" @@ -67,7 +68,6 @@ extern void (*deprecated_readline_begin_hook) (char *, ...); extern char *(*deprecated_readline_hook) (char *); extern void (*deprecated_readline_end_hook) (void); -extern int addressprint; /* Print machine addresses? */ /* GDB commands implemented in other modules: */ @@ -434,9 +434,11 @@ trace_command (char *arg, int from_tty) static void trace_mention (struct tracepoint *tp) { + struct value_print_options opts; printf_filtered ("Tracepoint %d", tp->number); - if (addressprint || (tp->source_file == NULL)) + get_user_print_options (&opts); + if (opts.addressprint || (tp->source_file == NULL)) { printf_filtered (" at "); printf_filtered ("%s", paddress (tp->address)); @@ -467,12 +469,12 @@ tracepoints_info (char *tpnum_exp, int from_tty) ALL_TRACEPOINTS (t) if (tpnum == -1 || tpnum == t->number) { - extern int addressprint; /* Print machine addresses? */ - + struct value_print_options opts; + get_user_print_options (&opts); if (!found_a_tracepoint++) { printf_filtered ("Num Enb "); - if (addressprint) + if (opts.addressprint) { if (gdbarch_addr_bit (current_gdbarch) <= 32) printf_filtered ("Address "); @@ -482,7 +484,7 @@ tracepoints_info (char *tpnum_exp, int from_tty) printf_filtered ("PassC StepC What\n"); } strcpy (wrap_indent, " "); - if (addressprint) + if (opts.addressprint) { if (gdbarch_addr_bit (current_gdbarch) <= 32) strcat (wrap_indent, " "); @@ -492,7 +494,7 @@ tracepoints_info (char *tpnum_exp, int from_tty) printf_filtered ("%-3d %-3s ", t->number, t->enabled_p ? "y" : "n"); - if (addressprint) + if (opts.addressprint) { char *tmp; diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 39580e675db..b2428ef09eb 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -37,6 +37,7 @@ #include "tui/tui-wingeneral.h" #include "tui/tui-file.h" #include "reggroups.h" +#include "valprint.h" #include "gdb_curses.h" @@ -689,11 +690,13 @@ tui_register_format (struct gdbarch *gdbarch, { gdb_byte buf[MAX_REGISTER_SIZE]; int len; + struct value_print_options opts; len = register_size (current_gdbarch, regnum); fprintf_filtered (stream, "%-14s ", name); get_frame_register (frame, regnum, buf); - print_scalar_formatted (buf, type, 'f', len, stream); + get_formatted_print_options (&opts, 'f'); + print_scalar_formatted (buf, type, &opts, len, stream); } else { diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 44f1a77e12b..edf87cd2cd5 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -33,12 +33,9 @@ #include "cp-abi.h" #include "typeprint.h" #include "gdb_string.h" +#include "valprint.h" #include -/* For real-type printing in whatis_exp() */ -extern int objectprint; /* Controls looking up an object's derived type - using what we find in its vtables. */ - extern void _initialize_typeprint (void); static void ptype_command (char *, int); @@ -95,6 +92,7 @@ whatis_exp (char *exp, int show) int full = 0; int top = -1; int using_enc = 0; + struct value_print_options opts; if (exp) { @@ -107,7 +105,8 @@ whatis_exp (char *exp, int show) type = value_type (val); - if (objectprint) + get_user_print_options (&opts); + if (opts.objectprint) { if (((TYPE_CODE (type) == TYPE_CODE_PTR) || (TYPE_CODE (type) == TYPE_CODE_REF)) diff --git a/gdb/valprint.c b/gdb/valprint.c index 99c376f47b9..5086a700972 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -60,13 +60,55 @@ static void set_output_radix_1 (int, unsigned); void _initialize_valprint (void); -/* Maximum number of chars to print for a string pointer value or vector - contents, or UINT_MAX for no limit. Note that "set print elements 0" - stores UINT_MAX in print_max, which displays in a show command as - "unlimited". */ - -unsigned int print_max; #define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */ + +struct value_print_options user_print_options = +{ + Val_pretty_default, /* pretty */ + 0, /* prettyprint_arrays */ + 0, /* prettyprint_structs */ + 0, /* vtblprint */ + 1, /* unionprint */ + 1, /* addressprint */ + 0, /* objectprint */ + PRINT_MAX_DEFAULT, /* print_max */ + 10, /* repeat_count_threshold */ + 0, /* output_format */ + 0, /* format */ + 0, /* stop_print_at_null */ + 0, /* inspect_it */ + 0, /* print_array_indexes */ + 0, /* deref_ref */ + 1, /* static_field_print */ + 1 /* pascal_static_field_print */ +}; + +/* Initialize *OPTS to be a copy of the user print options. */ +void +get_user_print_options (struct value_print_options *opts) +{ + *opts = user_print_options; +} + +/* Initialize *OPTS to be a copy of the user print options, but with + pretty-printing disabled. */ +void +get_raw_print_options (struct value_print_options *opts) +{ + *opts = user_print_options; + opts->pretty = Val_no_prettyprint; +} + +/* Initialize *OPTS to be a copy of the user print options, but using + FORMAT as the formatting option. */ +void +get_formatted_print_options (struct value_print_options *opts, + char format) +{ + *opts = user_print_options; + opts->format = format; +} + static void show_print_max (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -98,12 +140,10 @@ show_output_radix (struct ui_file *file, int from_tty, Default output radix for printing of values is %s.\n"), value); } -int output_format = 0; /* By default we print arrays without printing the index of each element in the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */ -static int print_array_indexes = 0; static void show_print_array_indexes (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -115,7 +155,6 @@ show_print_array_indexes (struct ui_file *file, int from_tty, element in an array. Referenced by the low level language dependent print routines. */ -unsigned int repeat_count_threshold = 10; static void show_repeat_count_threshold (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -126,7 +165,6 @@ show_repeat_count_threshold (struct ui_file *file, int from_tty, /* If nonzero, stops printing of char arrays at first null. */ -int stop_print_at_null; static void show_stop_print_at_null (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -138,7 +176,6 @@ Printing of char arrays to stop at first null char is %s.\n"), /* Controls pretty printing of structures. */ -int prettyprint_structs; static void show_prettyprint_structs (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -148,7 +185,6 @@ show_prettyprint_structs (struct ui_file *file, int from_tty, /* Controls pretty printing of arrays. */ -int prettyprint_arrays; static void show_prettyprint_arrays (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -159,7 +195,6 @@ show_prettyprint_arrays (struct ui_file *file, int from_tty, /* If nonzero, causes unions inside structures or other unions to be printed. */ -int unionprint; /* Controls printing of nested unions. */ static void show_unionprint (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -171,7 +206,6 @@ Printing of unions interior to structures is %s.\n"), /* If nonzero, causes machine addresses to be printed in certain contexts. */ -int addressprint; /* Controls printing of machine addresses */ static void show_addressprint (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -182,13 +216,7 @@ show_addressprint (struct ui_file *file, int from_tty, /* Print using the given LANGUAGE the data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto - stdio stream STREAM according to FORMAT (a letter, or 0 for natural - format using TYPE). - - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - - The PRETTY parameter controls prettyprinting. + stdio stream STREAM according to OPTIONS. If the data are a string pointer, returns the number of string characters printed. @@ -203,17 +231,18 @@ show_addressprint (struct ui_file *file, int from_tty, int val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, - CORE_ADDR address, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty, + CORE_ADDR address, struct ui_file *stream, int recurse, + const struct value_print_options *options, const struct language_defn *language) { volatile struct gdb_exception except; - volatile enum val_prettyprint real_pretty = pretty; int ret = 0; - + struct value_print_options local_opts = *options; struct type *real_type = check_typedef (type); - if (pretty == Val_pretty_default) - real_pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint; + + if (local_opts.pretty == Val_pretty_default) + local_opts.pretty = (local_opts.prettyprint_structs + ? Val_prettyprint : Val_no_prettyprint); QUIT; @@ -231,8 +260,7 @@ val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, TRY_CATCH (except, RETURN_MASK_ERROR) { ret = language->la_val_print (type, valaddr, embedded_offset, address, - stream, format, deref_ref, recurse, - real_pretty); + stream, recurse, &local_opts); } if (except.reason < 0) fprintf_filtered (stream, _("")); @@ -263,12 +291,7 @@ value_check_printable (struct value *val, struct ui_file *stream) } /* Print using the given LANGUAGE the value VAL onto stream STREAM according - to FORMAT (a letter, or 0 for natural format using TYPE). - - If DEREF_REF is nonzero, then dereference references, otherwise just print - them like pointers. - - The PRETTY parameter controls prettyprinting. + to OPTIONS. If the data are a string pointer, returns the number of string characters printed. @@ -277,8 +300,8 @@ value_check_printable (struct value *val, struct ui_file *stream) GDB's value mechanism. */ int -common_val_print (struct value *val, struct ui_file *stream, int format, - int deref_ref, int recurse, enum val_prettyprint pretty, +common_val_print (struct value *val, struct ui_file *stream, int recurse, + const struct value_print_options *options, const struct language_defn *language) { if (!value_check_printable (val, stream)) @@ -286,23 +309,22 @@ common_val_print (struct value *val, struct ui_file *stream, int format, return val_print (value_type (val), value_contents_all (val), value_embedded_offset (val), VALUE_ADDRESS (val), - stream, format, deref_ref, recurse, pretty, - language); + stream, recurse, options, language); } -/* Print the value VAL in C-ish syntax on stream STREAM. - FORMAT is a format-letter, or 0 for print in natural format of data type. +/* Print the value VAL in C-ish syntax on stream STREAM according to + OPTIONS. If the object printed is a string pointer, returns the number of string bytes printed. */ int -value_print (struct value *val, struct ui_file *stream, int format, - enum val_prettyprint pretty) +value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options) { if (!value_check_printable (val, stream)) return 0; - return LA_VALUE_PRINT (val, stream, format, pretty); + return LA_VALUE_PRINT (val, stream, options); } /* Called by various _val_print routines to print @@ -928,15 +950,6 @@ print_char_chars (struct ui_file *stream, const gdb_byte *valaddr, } } -/* Return non-zero if the debugger should print the index of each element - when printing array values. */ - -int -print_array_indexes_p (void) -{ - return print_array_indexes; -} - /* Assuming TYPE is a simple, non-empty array type, compute its upper and lower bound. Save the low bound into LOW_BOUND if not NULL. Save the high bound into HIGH_BOUND if not NULL. @@ -992,23 +1005,23 @@ get_array_bounds (struct type *type, long *low_bound, long *high_bound) return 1; } -/* Print on STREAM using the given FORMAT the index for the element +/* Print on STREAM using the given OPTIONS the index for the element at INDEX of an array whose index type is INDEX_TYPE. */ void maybe_print_array_index (struct type *index_type, LONGEST index, - struct ui_file *stream, int format, - enum val_prettyprint pretty) + struct ui_file *stream, + const struct value_print_options *options) { struct value *index_value; - if (!print_array_indexes) + if (!options->print_array_indexes) return; index_value = value_from_longest (index_type, index); - LA_PRINT_ARRAY_INDEX (index_value, stream, format, pretty); -} + LA_PRINT_ARRAY_INDEX (index_value, stream, options); +} /* Called by various _val_print routines to print elements of an array in the form ", , , ...". @@ -1022,8 +1035,8 @@ maybe_print_array_index (struct type *index_type, LONGEST index, void val_print_array_elements (struct type *type, const gdb_byte *valaddr, CORE_ADDR address, struct ui_file *stream, - int format, int deref_ref, - int recurse, enum val_prettyprint pretty, + int recurse, + const struct value_print_options *options, unsigned int i) { unsigned int things_printed = 0; @@ -1070,11 +1083,11 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr, annotate_array_section_begin (i, elttype); - for (; i < len && things_printed < print_max; i++) + for (; i < len && things_printed < options->print_max; i++) { if (i != 0) { - if (prettyprint_arrays) + if (options->prettyprint_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); @@ -1086,7 +1099,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr, } wrap_here (n_spaces (2 + 2 * recurse)); maybe_print_array_index (index_type, i + low_bound_index, - stream, format, pretty); + stream, options); rep1 = i + 1; reps = 1; @@ -1097,21 +1110,21 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr, ++rep1; } - if (reps > repeat_count_threshold) + if (reps > options->repeat_count_threshold) { - val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format, - deref_ref, recurse + 1, pretty, current_language); + val_print (elttype, valaddr + i * eltlen, 0, 0, stream, + recurse + 1, options, current_language); annotate_elt_rep (reps); fprintf_filtered (stream, " ", reps); annotate_elt_rep_end (); i = rep1 - 1; - things_printed += repeat_count_threshold; + things_printed += options->repeat_count_threshold; } else { - val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format, - deref_ref, recurse + 1, pretty, current_language); + val_print (elttype, valaddr + i * eltlen, 0, 0, stream, + recurse + 1, options, current_language); annotate_elt (); things_printed++; } @@ -1173,7 +1186,8 @@ partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int *errnoptr /* FIXME: Use target_read_string. */ int -val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream) +val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream, + const struct value_print_options *options) { int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */ int errcode; /* Errno returned from bad reads. */ @@ -1194,7 +1208,7 @@ val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream) because finding the null byte (or available memory) is what actually limits the fetch. */ - fetchlimit = (len == -1 ? print_max : min (len, print_max)); + fetchlimit = (len == -1 ? options->print_max : min (len, options->print_max)); /* Now decide how large of chunks to try to read in one operation. This is also pretty simple. If LEN >= zero, then we want fetchlimit chars, @@ -1317,11 +1331,11 @@ val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream) and then the error message. */ if (errcode == 0 || bufptr > buffer) { - if (addressprint) + if (options->addressprint) { fputs_filtered (" ", stream); } - LA_PRINT_STRING (stream, buffer, (bufptr - buffer) / width, width, force_ellipsis); + LA_PRINT_STRING (stream, buffer, (bufptr - buffer) / width, width, force_ellipsis, options); } if (errcode != 0) @@ -1394,13 +1408,13 @@ set_output_radix_1 (int from_tty, unsigned radix) switch (radix) { case 16: - output_format = 'x'; /* hex */ + user_print_options.output_format = 'x'; /* hex */ break; case 10: - output_format = 0; /* decimal */ + user_print_options.output_format = 0; /* decimal */ break; case 8: - output_format = 'o'; /* octal */ + user_print_options.output_format = 'o'; /* octal */ break; default: /* FIXME: cagney/2002-03-17: This needs to revert the bad radix @@ -1494,7 +1508,8 @@ _initialize_valprint (void) add_alias_cmd ("p", "print", no_class, 1, &showlist); add_alias_cmd ("pr", "print", no_class, 1, &showlist); - add_setshow_uinteger_cmd ("elements", no_class, &print_max, _("\ + add_setshow_uinteger_cmd ("elements", no_class, + &user_print_options.print_max, _("\ Set limit on string chars or array elements to print."), _("\ Show limit on string chars or array elements to print."), _("\ \"set print elements 0\" causes there to be no limit."), @@ -1502,7 +1517,8 @@ Show limit on string chars or array elements to print."), _("\ show_print_max, &setprintlist, &showprintlist); - add_setshow_boolean_cmd ("null-stop", no_class, &stop_print_at_null, _("\ + add_setshow_boolean_cmd ("null-stop", no_class, + &user_print_options.stop_print_at_null, _("\ Set printing of char arrays to stop at first null char."), _("\ Show printing of char arrays to stop at first null char."), NULL, NULL, @@ -1510,7 +1526,7 @@ Show printing of char arrays to stop at first null char."), NULL, &setprintlist, &showprintlist); add_setshow_uinteger_cmd ("repeats", no_class, - &repeat_count_threshold, _("\ + &user_print_options.repeat_count_threshold, _("\ Set threshold for repeated print elements."), _("\ Show threshold for repeated print elements."), _("\ \"set print repeats 0\" causes all elements to be individually printed."), @@ -1518,28 +1534,32 @@ Show threshold for repeated print elements."), _("\ show_repeat_count_threshold, &setprintlist, &showprintlist); - add_setshow_boolean_cmd ("pretty", class_support, &prettyprint_structs, _("\ + add_setshow_boolean_cmd ("pretty", class_support, + &user_print_options.prettyprint_structs, _("\ Set prettyprinting of structures."), _("\ Show prettyprinting of structures."), NULL, NULL, show_prettyprint_structs, &setprintlist, &showprintlist); - add_setshow_boolean_cmd ("union", class_support, &unionprint, _("\ + add_setshow_boolean_cmd ("union", class_support, + &user_print_options.unionprint, _("\ Set printing of unions interior to structures."), _("\ Show printing of unions interior to structures."), NULL, NULL, show_unionprint, &setprintlist, &showprintlist); - add_setshow_boolean_cmd ("array", class_support, &prettyprint_arrays, _("\ + add_setshow_boolean_cmd ("array", class_support, + &user_print_options.prettyprint_arrays, _("\ Set prettyprinting of arrays."), _("\ Show prettyprinting of arrays."), NULL, NULL, show_prettyprint_arrays, &setprintlist, &showprintlist); - add_setshow_boolean_cmd ("address", class_support, &addressprint, _("\ + add_setshow_boolean_cmd ("address", class_support, + &user_print_options.addressprint, _("\ Set printing of addresses."), _("\ Show printing of addresses."), NULL, NULL, @@ -1578,15 +1598,8 @@ Use 'show input-radix' or 'show output-radix' to independently show each."), &showlist); add_setshow_boolean_cmd ("array-indexes", class_support, - &print_array_indexes, _("\ + &user_print_options.print_array_indexes, _("\ Set printing of array indexes."), _("\ Show printing of array indexes"), NULL, NULL, show_print_array_indexes, &setprintlist, &showprintlist); - - /* Give people the defaults which they are used to. */ - prettyprint_structs = 0; - prettyprint_arrays = 0; - unionprint = 1; - addressprint = 1; - print_max = PRINT_MAX_DEFAULT; } diff --git a/gdb/valprint.h b/gdb/valprint.h index 3b20516e000..47a2c4fd2b7 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -21,45 +21,98 @@ #ifndef VALPRINT_H #define VALPRINT_H -extern int prettyprint_arrays; /* Controls pretty printing of arrays. */ -extern int prettyprint_structs; /* Controls pretty printing of structures */ -extern int prettyprint_arrays; /* Controls pretty printing of arrays. */ +/* This is used to pass formatting options to various value-printing + functions. */ +struct value_print_options +{ + /* Pretty-printing control. */ + enum val_prettyprint pretty; -extern int vtblprint; /* Controls printing of vtbl's */ -extern int unionprint; /* Controls printing of nested unions. */ -extern int addressprint; /* Controls pretty printing of addresses. */ -extern int objectprint; /* Controls looking up an object's derived type - using what we find in its vtables. */ + /* Controls pretty printing of arrays. */ + int prettyprint_arrays; -extern unsigned int print_max; /* Max # of chars for strings/vectors */ + /* Controls pretty printing of structures. */ + int prettyprint_structs; -/* Flag to low-level print routines that this value is being printed - in an epoch window. We'd like to pass this as a parameter, but - every routine would need to take it. Perhaps we can encapsulate - this in the I/O stream once we have GNU stdio. */ -extern int inspect_it; + /* Controls printing of virtual tables. */ + int vtblprint; -/* Print repeat counts if there are more than this many repetitions of an - element in an array. Referenced by the low level language dependent - print routines. */ -extern unsigned int repeat_count_threshold; + /* Controls printing of nested unions. */ + int unionprint; -extern int output_format; + /* Controls printing of addresses. */ + int addressprint; -extern int stop_print_at_null; /* Stop printing at null char? */ + /* Controls looking up an object's derived type using what we find + in its vtables. */ + int objectprint; + + /* Maximum number of chars to print for a string pointer value or vector + contents, or UINT_MAX for no limit. Note that "set print elements 0" + stores UINT_MAX in print_max, which displays in a show command as + "unlimited". */ + unsigned int print_max; + + /* Print repeat counts if there are more than this many repetitions + of an element in an array. */ + unsigned int repeat_count_threshold; + + /* The global output format letter. */ + int output_format; + + /* The current format letter. This is set locally for a given call, + e.g. when the user passes a format to "print". */ + int format; + + /* Stop printing at null character? */ + int stop_print_at_null; + + /* True if this value is being printed in an epoch window. */ + int inspect_it; + + /* True if we should print the index of each element when printing + an array. */ + int print_array_indexes; + + /* If nonzero, then dereference references, otherwise just print + them like pointers. */ + int deref_ref; + + /* If nonzero, print static fields. */ + int static_field_print; + + /* If nonzero, print static fields for Pascal. FIXME: C++ and Java + share one flag, why not Pascal too? */ + int pascal_static_field_print; +}; + +/* The global print options set by the user. In general this should + not be directly accessed, except by set/show commands. Ordinary + code should call get_user_print_options instead. */ +extern struct value_print_options user_print_options; + +/* Initialize *OPTS to be a copy of the user print options. */ +extern void get_user_print_options (struct value_print_options *opts); + +/* Initialize *OPTS to be a copy of the user print options, but with + pretty-printing disabled. */ +extern void get_raw_print_options (struct value_print_options *opts); + +/* Initialize *OPTS to be a copy of the user print options, but using + FORMAT as the formatting option. */ +extern void get_formatted_print_options (struct value_print_options *opts, + char format); -extern int print_array_indexes_p (void); - extern int get_array_bounds (struct type *type, long *low_bound, long *high_bound); extern void maybe_print_array_index (struct type *index_type, LONGEST index, - struct ui_file *stream, int format, - enum val_prettyprint pretty); + struct ui_file *stream, + const struct value_print_options *options); extern void val_print_array_elements (struct type *, const gdb_byte *, CORE_ADDR, struct ui_file *, int, - int, int, enum val_prettyprint, + const struct value_print_options *, unsigned int); extern void val_print_type_code_int (struct type *, const gdb_byte *, diff --git a/gdb/value.c b/gdb/value.c index 0b530f00e67..1fa376d6555 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -36,6 +36,7 @@ #include "block.h" #include "dfp.h" #include "objfiles.h" +#include "valprint.h" #include "python/python.h" @@ -708,9 +709,11 @@ show_values (char *num_exp, int from_tty) for (i = num; i < num + 10 && i <= value_history_count; i++) { + struct value_print_options opts; val = access_value_history (i); printf_filtered (("$%d = "), i); - value_print (val, gdb_stdout, 0, Val_pretty_default); + get_user_print_options (&opts); + value_print (val, gdb_stdout, &opts); printf_filtered (("\n")); } @@ -969,7 +972,9 @@ show_convenience (char *ignore, int from_tty) { struct internalvar *var; int varseen = 0; + struct value_print_options opts; + get_user_print_options (&opts); for (var = internalvars; var; var = var->next) { if (!varseen) @@ -978,7 +983,7 @@ show_convenience (char *ignore, int from_tty) } printf_filtered (("$%s = "), var->name); value_print (value_of_internalvar (var), gdb_stdout, - 0, Val_pretty_default); + &opts); printf_filtered (("\n")); } if (!varseen) diff --git a/gdb/value.h b/gdb/value.h index f53d333bb73..65fea99a99e 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -32,6 +32,7 @@ struct symbol; struct type; struct ui_file; struct language_defn; +struct value_print_options; /* The structure which defines the type of a value. It should never be possible for a program lval value to survive over a call to the @@ -526,8 +527,8 @@ extern void print_floating (const gdb_byte *valaddr, struct type *type, extern void print_decimal_floating (const gdb_byte *valaddr, struct type *type, struct ui_file *stream); -extern int value_print (struct value *val, struct ui_file *stream, int format, - enum val_prettyprint pretty); +extern int value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options); extern void value_print_array_elements (struct value *val, struct ui_file *stream, int format, @@ -537,19 +538,18 @@ extern struct value *value_release_to_mark (struct value *mark); extern int val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, - struct ui_file *stream, int format, - int deref_ref, int recurse, - enum val_prettyprint pretty, + struct ui_file *stream, int recurse, + const struct value_print_options *options, const struct language_defn *language); extern int common_val_print (struct value *val, - struct ui_file *stream, int format, - int deref_ref, int recurse, - enum val_prettyprint pretty, + struct ui_file *stream, int recurse, + const struct value_print_options *options, const struct language_defn *language); extern int val_print_string (CORE_ADDR addr, int len, int width, - struct ui_file *stream); + struct ui_file *stream, + const struct value_print_options *options); extern void print_variable_value (struct symbol *var, struct frame_info *frame, diff --git a/gdb/varobj.c b/gdb/varobj.c index 15cbd451bdc..ab369a2925e 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -25,6 +25,7 @@ #include "wrapper.h" #include "gdbcmd.h" #include "block.h" +#include "valprint.h" #include "gdb_assert.h" #include "gdb_string.h" @@ -1791,6 +1792,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format) struct ui_file *stb; struct cleanup *old_chain; char *thevalue; + struct value_print_options opts; if (value == NULL) return NULL; @@ -1798,8 +1800,9 @@ value_get_print_value (struct value *value, enum varobj_display_formats format) stb = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (stb); - common_val_print (value, stb, format_code[(int) format], 1, 0, 0, - current_language); + get_formatted_print_options (&opts, format_code[(int) format]); + opts.deref_ref = 0; + common_val_print (value, stb, 0, &opts, current_language); thevalue = ui_file_xstrdup (stb, &dummy); do_cleanups (old_chain); -- 2.30.2