From 603e861955d66c3ef81e59abee902ad7dc6bec21 Mon Sep 17 00:00:00 2001 From: "Paul N. Hilfinger" Date: Sat, 11 Sep 2004 10:24:53 +0000 Subject: * language.c (local_hex_format_custom): Remove. (local_hex_string): Rename to hex_string, use C format, and move to utils.c (local_hex_string_custom): Rename to hex_string_custom and change interface. Now uses C format. Move to utils.c (local_octal_format_custom): Remove. (local_decimal_format_custom): Remove. (unknown_language_defn): Remove language-specific number formatting entries. (auto_language_defn): Ditto. (local_language_defn): Ditto. * language.h (struct language_format_info): Delete declaration. (struct language_defn): Remove language_format_info fields la_binary_format, la_octal_format, la_decimal_format, la_hex_format. (local_binary_format): Remove macro. (local_binary_format_prefix): Remove macro. (local_binary_format_specifier): Remove macro. (local_binary_format_suffix): Remove macro. (local_octal_format): Remove macro. (local_octal_format_prefix): Remove macro. (local_octal_format_specifier): Remove macro. (local_octal_format_suffix): Remove macro. (local_decimal_format): Remove macro. (local_decimal_format_prefix): Remove macro. (local_decimal_format_specifier): Remove macro. (local_decimal_format_suffix): Remove macro. (local_hex_format): Remove macro. (local_hex_format_prefix): Remove macro. (local_hex_format_specifier): Remove macro. (local_hex_format_suffix): Remove macro. (local_decimal_format_custom): Remove. (local_octal_format_custom): Remove. (local_hex_format_custom): Remove. (local_hex_string): Rename to hex_string and move to defs.h. (local_hex_string_custom): Rename to hex_string_custom, change interface, and move to defs.h. * utils.c: (int_string): New function. (hex_string): New function (from language.c). (hex_string_custom): New function (from language.c). (octal2str): New function. (decimal2str): Add width parameter. (paddr_u): Use new decimal2str interface. (paddr_d): Ditto. * defs.h (hex_string): Declare. (hex_string_custom): Declare. (int_string): Declare. * printcmd.c (print_scalar_formatted): Remove localized binary formatting. * valprint.c (print_longest): Use int_string. (print_floating): Use C hex format. (print_hex_chars): Ditto. (print_binary_chars): Remove language-specific formatting. (print_octal_chars): Use C octal format. (print_decimal_chars): Delocalize format. (print_decimal): Remove. * ada-lang.c (ada_language_defn): Remove language-specific number formatting entries. * p-lang.c (pascal_language_defn): Ditto. * c-lang.c (c_language_defn): Ditto. (cplus_language_defn): Ditto. (asm_language_defn): Ditto. (minimal_language_defn): Ditto. * f-lang.c (f_language_defn): Ditto. * jv-lang.c (java_language_defn): Ditto. * m2-lang.c (m2_language_defn): Ditto. * scm-lang.c (scm_language_defn): Ditto. * objc-lang.c (objc_language_defn): Ditto. * memattr.c (mem_info_command): Use renamed hex_string_custom with new interface. * pa64solib.c (pa64_sharedlibrary_info_command): Ditto. * ui-out.c (ui_out_field_core_addr): Ditto. * breakpoint.c (breakpoint_adjustment_warning): Ditto. * exec.c (print_section_info): Ditto. * i387-tdep.c (print_i387_status_word): Ditto. (print_i387_control_word): Ditto. (i387_print_float_info): Ditto. * maint.c (maint_print_section_info): Ditto. * solib.c (info_sharedlibrary_command): Ditto. * somsolib.c (som_sharedlibrary_info_command): Ditto. * symtab.c (print_msymbol_info): Ditto. * tracepoint.c (tracepoints_info): Ditto. * solib-frv.c (lm_base): Ditto. (frv_current_sos): Ditto. (enable_break2): Ditto. (enable_break): Ditto. * dbxread.c (read_dbx_symtab): Use renamed hex_string. (process_one_symbol): Ditto. * infcmd.c (program_info): Ditto. * mdebugread.c (parse_partial_symbols): Ditto. * symfile.c (add_symbol_file_command): Ditto. * cli/cli-cmds.c (edit_command): Ditto. (list_command): Ditto. * infcall.c (call_function_by_hand): Ditto. * remote-vx.c (vx_run_files_info): Ditto. (vx_wait): Ditto. (vx_attach): Ditto. (vx_detach): Ditto. (vx_kill): Ditto. * aix-thread.c (pdc_symbol_addrs): Ditto. (pdc_read_regs): Ditto. (pdc_write_regs): Ditto. (pdc_read_data): Ditto. (pdc_write_data): Ditto. * d10v-tdep.c (display_trace): Ditto. * rs6000-nat.c (find_toc_address): Ditto. * aix-thread.c: Don't include language.h. * buildsym.c: Ditto. * dbxread.c: Ditto. * mdebugread.c: Ditto. * rs6000-nat.c: Ditto. * buildsym.c (make_blockvector): Use renamed hex_string. --- gdb/language.c | 145 ++++++++++----------------------------------------------- 1 file changed, 25 insertions(+), 120 deletions(-) (limited to 'gdb/language.c') diff --git a/gdb/language.c b/gdb/language.c index dfbfa3a6d26..4c59b285c3c 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -583,124 +583,41 @@ binop_result_type (struct value *v1, struct value *v2) /* This page contains functions that return format strings for printf for printing out numbers in different formats */ -/* Returns the appropriate printf format for hexadecimal - numbers. */ -char * -local_hex_format_custom (char *pre) -{ - static char form[50]; - - strcpy (form, local_hex_format_prefix ()); - strcat (form, "%"); - strcat (form, pre); - strcat (form, local_hex_format_specifier ()); - strcat (form, local_hex_format_suffix ()); - return form; -} +#define MAX_NUM_STRING_LEN 50 -/* Converts a LONGEST to custom hexadecimal and stores it in a static - string. Returns a pointer to this string. */ +/* Converts a LONGEST to a C-format hexadecimal literal and stores it in + a static string. Returns a pointer to this string. */ char * -local_hex_string (LONGEST num) +hex_string (LONGEST num) { - return local_hex_string_custom (num, "l"); + static char result[MAX_NUM_STRING_LEN]; + sprintf (result, "0x%s", phex_nz (num, sizeof (num))); + return result; } -/* Converts a LONGEST number to custom hexadecimal and stores it in a static - string. Returns a pointer to this string. Note that the width parameter - should end with "l", e.g. "08l" as with calls to local_hex_string_custom */ +/* Converts a LONGEST number to a C-format hexadecimal literal and stores + it in a static string. Returns a pointer to this string that is + valid until the next call. The number is padded on the left with + 0s to at least WIDTH characters. */ char * -local_hex_string_custom (LONGEST num, char *width) -{ -#define RESULT_BUF_LEN 50 - static char res2[RESULT_BUF_LEN]; - char format[RESULT_BUF_LEN]; - int field_width; - int num_len; - int num_pad_chars; - char *pad_char; /* string with one character */ - int pad_on_left; - char *parse_ptr; - char temp_nbr_buf[RESULT_BUF_LEN]; - - /* Use phex_nz to print the number into a string, then - build the result string from local_hex_format_prefix, padding and - the hex representation as indicated by "width". */ - strcpy (temp_nbr_buf, phex_nz (num, sizeof (num))); - /* parse width */ - parse_ptr = width; - pad_on_left = 1; - pad_char = " "; - if (*parse_ptr == '-') - { - parse_ptr++; - pad_on_left = 0; - } - if (*parse_ptr == '0') - { - parse_ptr++; - if (pad_on_left) - pad_char = "0"; /* If padding is on the right, it is blank */ - } - field_width = atoi (parse_ptr); - num_len = strlen (temp_nbr_buf); - num_pad_chars = field_width - strlen (temp_nbr_buf); /* possibly negative */ - - if (strlen (local_hex_format_prefix ()) + num_len + num_pad_chars - >= RESULT_BUF_LEN) /* paranoia */ - internal_error (__FILE__, __LINE__, - "local_hex_string_custom: insufficient space to store result"); - - strcpy (res2, local_hex_format_prefix ()); - if (pad_on_left) - { - while (num_pad_chars > 0) - { - strcat (res2, pad_char); - num_pad_chars--; - } - } - strcat (res2, temp_nbr_buf); - if (!pad_on_left) - { - while (num_pad_chars > 0) - { - strcat (res2, pad_char); - num_pad_chars--; - } - } - return res2; - -} /* local_hex_string_custom */ - -/* Returns the appropriate printf format for octal - numbers. */ -char * -local_octal_format_custom (char *pre) +hex_string_custom (LONGEST num, int width) { - static char form[50]; - - strcpy (form, local_octal_format_prefix ()); - strcat (form, "%"); - strcat (form, pre); - strcat (form, local_octal_format_specifier ()); - strcat (form, local_octal_format_suffix ()); - return form; -} + static char result[MAX_NUM_STRING_LEN]; + char *result_end = result + MAX_NUM_STRING_LEN - 1; + const char* hex = phex_nz (num, sizeof (num)); + int hex_len = strlen (hex); -/* Returns the appropriate printf format for decimal numbers. */ -char * -local_decimal_format_custom (char *pre) -{ - static char form[50]; + if (hex_len > width) + width = hex_len; + if (width + 2 >= MAX_NUM_STRING_LEN) + internal_error (__FILE__, __LINE__, + "hex_string_custom: insufficient space to store result"); - strcpy (form, local_decimal_format_prefix ()); - strcat (form, "%"); - strcat (form, pre); - strcat (form, local_decimal_format_specifier ()); - strcat (form, local_decimal_format_suffix ()); - return form; + strcpy (result_end - width - 2, "0x"); + memset (result_end - width, '0', width); + strcpy (result_end - hex_len, hex); + return result_end - width - 2; } #if 0 @@ -1313,10 +1230,6 @@ const struct language_defn unknown_language_defn = basic_lookup_transparent_type,/* lookup_transparent_type */ unk_lang_demangle, /* Language specific symbol demangler */ unk_lang_class_name, /* Language specific class_name_from_physname */ - {"", "", "", ""}, /* Binary format info */ - {"0%lo", "0", "o", ""}, /* Octal format info */ - {"%ld", "", "d", ""}, /* Decimal format info */ - {"0x%lx", "0x", "x", ""}, /* Hex format info */ unk_op_print_tab, /* expression operators for printing */ 1, /* c-style arrays */ 0, /* String lower bound */ @@ -1353,10 +1266,6 @@ const struct language_defn auto_language_defn = basic_lookup_transparent_type,/* lookup_transparent_type */ unk_lang_demangle, /* Language specific symbol demangler */ unk_lang_class_name, /* Language specific class_name_from_physname */ - {"", "", "", ""}, /* Binary format info */ - {"0%lo", "0", "o", ""}, /* Octal format info */ - {"%ld", "", "d", ""}, /* Decimal format info */ - {"0x%lx", "0x", "x", ""}, /* Hex format info */ unk_op_print_tab, /* expression operators for printing */ 1, /* c-style arrays */ 0, /* String lower bound */ @@ -1392,10 +1301,6 @@ const struct language_defn local_language_defn = basic_lookup_transparent_type,/* lookup_transparent_type */ unk_lang_demangle, /* Language specific symbol demangler */ unk_lang_class_name, /* Language specific class_name_from_physname */ - {"", "", "", ""}, /* Binary format info */ - {"0%lo", "0", "o", ""}, /* Octal format info */ - {"%ld", "", "d", ""}, /* Decimal format info */ - {"0x%lx", "0x", "x", ""}, /* Hex format info */ unk_op_print_tab, /* expression operators for printing */ 1, /* c-style arrays */ 0, /* String lower bound */ -- cgit v1.2.1