diff options
Diffstat (limited to 'gdb/p-lang.c')
-rw-r--r-- | gdb/p-lang.c | 197 |
1 files changed, 96 insertions, 101 deletions
diff --git a/gdb/p-lang.c b/gdb/p-lang.c index b8c99c4..1c6aea9 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -202,106 +202,6 @@ pascal_printchar (int c, struct type *type, struct ui_file *stream) fputs_filtered ("'", stream); } -/* Print the character string STRING, printing at most LENGTH characters. - Printing stops early if the number hits print_max; repeat counts - are printed as appropriate. Print ellipses at the end if we - had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */ - -void -pascal_printstr (struct ui_file *stream, struct type *type, - const gdb_byte *string, unsigned int length, - const char *encoding, int force_ellipses, - const struct value_print_options *options) -{ - enum bfd_endian byte_order = type_byte_order (type); - unsigned int i; - unsigned int things_printed = 0; - int in_quotes = 0; - int need_comma = 0; - int width; - - /* Preserve TYPE's original type, just set its LENGTH. */ - check_typedef (type); - width = TYPE_LENGTH (type); - - /* If the string was not truncated due to `set print elements', and - the last byte of it is a null, we don't print that, in traditional C - style. */ - if ((!force_ellipses) && length > 0 - && extract_unsigned_integer (string + (length - 1) * width, width, - byte_order) == 0) - length--; - - if (length == 0) - { - fputs_filtered ("''", stream); - return; - } - - for (i = 0; i < length && things_printed < options->print_max; ++i) - { - /* Position of the character we are examining - to see whether it is repeated. */ - unsigned int rep1; - /* Number of repetitions we have detected so far. */ - unsigned int reps; - unsigned long int current_char; - - QUIT; - - if (need_comma) - { - fputs_filtered (", ", stream); - need_comma = 0; - } - - current_char = extract_unsigned_integer (string + i * width, width, - byte_order); - - rep1 = i + 1; - reps = 1; - while (rep1 < length - && extract_unsigned_integer (string + rep1 * width, width, - byte_order) == current_char) - { - ++rep1; - ++reps; - } - - if (reps > options->repeat_count_threshold) - { - if (in_quotes) - { - fputs_filtered ("', ", stream); - in_quotes = 0; - } - pascal_printchar (current_char, type, stream); - fprintf_filtered (stream, " %p[<repeats %u times>%p]", - metadata_style.style ().ptr (), - reps, nullptr); - i = rep1 - 1; - things_printed += options->repeat_count_threshold; - need_comma = 1; - } - else - { - if ((!in_quotes) && (PRINT_LITERAL_FORM (current_char))) - { - fputs_filtered ("'", stream); - in_quotes = 1; - } - pascal_one_char (current_char, stream, &in_quotes); - ++things_printed; - } - } - - /* Terminate the quotes if necessary. */ - if (in_quotes) - fputs_filtered ("'", stream); - - if (force_ellipses || i < length) - fputs_filtered ("...", stream); -} /* Table mapping opcodes into strings for printing operators @@ -376,7 +276,6 @@ extern const struct language_data pascal_language_data = macro_expansion_no, p_extensions, &exp_descriptor_standard, - pascal_printstr, /* Function to print string constant */ pascal_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ @@ -499,6 +398,102 @@ public: pascal_printchar (ch, chtype, stream); } + /* See language.h. */ + + void printstr (struct ui_file *stream, struct type *elttype, + const gdb_byte *string, unsigned int length, + const char *encoding, int force_ellipses, + const struct value_print_options *options) const override + { + enum bfd_endian byte_order = type_byte_order (elttype); + unsigned int i; + unsigned int things_printed = 0; + int in_quotes = 0; + int need_comma = 0; + int width; + + /* Preserve ELTTYPE's original type, just set its LENGTH. */ + check_typedef (elttype); + width = TYPE_LENGTH (elttype); + + /* If the string was not truncated due to `set print elements', and + the last byte of it is a null, we don't print that, in traditional C + style. */ + if ((!force_ellipses) && length > 0 + && extract_unsigned_integer (string + (length - 1) * width, width, + byte_order) == 0) + length--; + + if (length == 0) + { + fputs_filtered ("''", stream); + return; + } + + for (i = 0; i < length && things_printed < options->print_max; ++i) + { + /* Position of the character we are examining + to see whether it is repeated. */ + unsigned int rep1; + /* Number of repetitions we have detected so far. */ + unsigned int reps; + unsigned long int current_char; + + QUIT; + + if (need_comma) + { + fputs_filtered (", ", stream); + need_comma = 0; + } + + current_char = extract_unsigned_integer (string + i * width, width, + byte_order); + + rep1 = i + 1; + reps = 1; + while (rep1 < length + && extract_unsigned_integer (string + rep1 * width, width, + byte_order) == current_char) + { + ++rep1; + ++reps; + } + + if (reps > options->repeat_count_threshold) + { + if (in_quotes) + { + fputs_filtered ("', ", stream); + in_quotes = 0; + } + pascal_printchar (current_char, elttype, stream); + fprintf_filtered (stream, " %p[<repeats %u times>%p]", + metadata_style.style ().ptr (), + reps, nullptr); + i = rep1 - 1; + things_printed += options->repeat_count_threshold; + need_comma = 1; + } + else + { + if ((!in_quotes) && (PRINT_LITERAL_FORM (current_char))) + { + fputs_filtered ("'", stream); + in_quotes = 1; + } + pascal_one_char (current_char, stream, &in_quotes); + ++things_printed; + } + } + + /* Terminate the quotes if necessary. */ + if (in_quotes) + fputs_filtered ("'", stream); + + if (force_ellipses || i < length) + fputs_filtered ("...", stream); + } }; /* Single instance of the Pascal language class. */ |