diff options
author | Fred Fish <fnf@specifix.com> | 1992-11-23 19:57:29 +0000 |
---|---|---|
committer | Fred Fish <fnf@specifix.com> | 1992-11-23 19:57:29 +0000 |
commit | 5707ea9fad0ff4b51cc2c913af218c0a0b8278e9 (patch) | |
tree | 56bbdf02b7bfe05c993493734ff173af6175a466 | |
parent | f53f0a036d1a9597223ee95a47ecf7a2a019f497 (diff) | |
download | gdb-5707ea9fad0ff4b51cc2c913af218c0a0b8278e9.zip gdb-5707ea9fad0ff4b51cc2c913af218c0a0b8278e9.tar.gz gdb-5707ea9fad0ff4b51cc2c913af218c0a0b8278e9.tar.bz2 |
* language.h (PRINT_LITERAL_FORM): New macro that takes character
and decides if it should be printed in literal form or some other
form, based on it's ASCII value and setting of sevenbit_strings.
* {c-exp.y, m2-exp.y} (emit_char): Use new PRINT_LITERAL_FORM
macro, change indentation style.
**** start-sanitize-chill ****
* ch-exp.y (chill_printchar): Use new PRINT_LITERAL_FORM macro.
* ch-exp.y (chill_printstr): First cut at real function instead
of error stub.
**** end-sanitize-chill ****
-rw-r--r-- | gdb/ChangeLog | 13 | ||||
-rw-r--r-- | gdb/c-exp.y | 75 | ||||
-rw-r--r-- | gdb/ch-exp.y | 110 | ||||
-rw-r--r-- | gdb/language.h | 9 | ||||
-rw-r--r-- | gdb/m2-exp.y | 75 |
5 files changed, 202 insertions, 80 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e84d9b4..bd0852a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +Mon Nov 23 11:14:15 1992 Fred Fish (fnf@cygnus.com) + + * language.h (PRINT_LITERAL_FORM): New macro that takes character + and decides if it should be printed in literal form or some other + form, based on it's ASCII value and setting of sevenbit_strings. + * {c-exp.y, m2-exp.y} (emit_char): Use new PRINT_LITERAL_FORM + macro, change indentation style. + **** start-sanitize-chill **** + * ch-exp.y (chill_printchar): Use new PRINT_LITERAL_FORM macro. + * ch-exp.y (chill_printstr): First cut at real function instead + of error stub. + **** end-sanitize-chill **** + Sun Nov 22 16:21:41 1992 david d `zoo' zuhn (zoo at cirdan.cygnus.com) * nindy-share/stop.h: fixed bogus comment-end in copyright message diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 2ba3c8c..397931e 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1484,43 +1484,44 @@ emit_char (c, stream, quoter) c &= 0xFF; /* Avoid sign bit follies */ - if ( c < 0x20 || /* Low control chars */ - (c >= 0x7F && c < 0xA0) || /* DEL, High controls */ - (sevenbit_strings && c >= 0x80)) { /* high order bit set */ - switch (c) - { - case '\n': - fputs_filtered ("\\n", stream); - break; - case '\b': - fputs_filtered ("\\b", stream); - break; - case '\t': - fputs_filtered ("\\t", stream); - break; - case '\f': - fputs_filtered ("\\f", stream); - break; - case '\r': - fputs_filtered ("\\r", stream); - break; - case '\033': - fputs_filtered ("\\e", stream); - break; - case '\007': - fputs_filtered ("\\a", stream); - break; - default: - fprintf_filtered (stream, "\\%.3o", (unsigned int) c); - break; - } - } else { - if (c == '\\' || c == quoter) - { - fputs_filtered ("\\", stream); - } - fprintf_filtered (stream, "%c", c); - } + if (PRINT_LITERAL_FORM (c)) + { + if (c == '\\' || c == quoter) + { + fputs_filtered ("\\", stream); + } + fprintf_filtered (stream, "%c", c); + } + else + { + switch (c) + { + case '\n': + fputs_filtered ("\\n", stream); + break; + case '\b': + fputs_filtered ("\\b", stream); + break; + case '\t': + fputs_filtered ("\\t", stream); + break; + case '\f': + fputs_filtered ("\\f", stream); + break; + case '\r': + fputs_filtered ("\\r", stream); + break; + case '\033': + fputs_filtered ("\\e", stream); + break; + case '\007': + fputs_filtered ("\\a", stream); + break; + default: + fprintf_filtered (stream, "\\%.3o", (unsigned int) c); + break; + } + } } static void diff --git a/gdb/ch-exp.y b/gdb/ch-exp.y index 1875ea6..d9c985b 100644 --- a/gdb/ch-exp.y +++ b/gdb/ch-exp.y @@ -1221,15 +1221,13 @@ chill_printchar (c, stream) { c &= 0xFF; /* Avoid sign bit follies */ - if ( c < 0x20 || /* Low control chars */ - (c >= 0x7F && c < 0xA0) || /* DEL, High controls */ - (sevenbit_strings && c >= 0x80)) /* high order bit set */ + if (PRINT_LITERAL_FORM (c)) { - fprintf_filtered (stream, "C'%.2x'", (unsigned int) c); + fprintf_filtered (stream, "'%c'", c); } else { - fprintf_filtered (stream, "'%c'", c); + fprintf_filtered (stream, "C'%.2x'", (unsigned int) c); } } @@ -1237,6 +1235,11 @@ chill_printchar (c, stream) 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. + Note that gdb maintains the length of strings without counting the + terminating null byte, while chill strings are typically written with + an explicit null byte. So we always assume an implied null byte + until gdb is able to maintain non-null terminated strings as well + as null terminated strings (FIXME). */ static void @@ -1246,7 +1249,102 @@ chill_printstr (stream, string, length, force_ellipses) unsigned int length; int force_ellipses; { - error ("internal error - unimplemented function chill_printstr called."); + register unsigned int i; + unsigned int things_printed = 0; + int in_literal_form = 0; + int in_control_form = 0; + int need_slashslash = 0; + unsigned int c; + extern int repeat_count_threshold; + extern int print_max; + + if (length == 0) + { + chill_printchar ('\0', stream); + return; + } + + for (i = 0; i < length && things_printed < 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; + + QUIT; + + if (need_slashslash) + { + fputs_filtered ("//", stream); + need_slashslash = 0; + } + + rep1 = i + 1; + reps = 1; + while (rep1 < length && string[rep1] == string[i]) + { + ++rep1; + ++reps; + } + + c = string[i]; + if (reps > repeat_count_threshold) + { + if (in_control_form || in_literal_form) + { + fputs_filtered ("'//", stream); + in_control_form = in_literal_form = 0; + } + chill_printchar (c, stream); + fprintf_filtered (stream, "<repeats %u times>", reps); + i = rep1 - 1; + things_printed += repeat_count_threshold; + need_slashslash = 1; + } + else + { + if (PRINT_LITERAL_FORM (c)) + { + if (!in_literal_form) + { + if (in_control_form) + { + fputs_filtered ("'//", stream); + in_control_form = 0; + } + fputs_filtered ("'", stream); + in_literal_form = 1; + } + fprintf_filtered (stream, "%c", c); + } + else + { + if (!in_control_form) + { + if (in_literal_form) + { + fputs_filtered ("'//", stream); + in_literal_form = 0; + } + fputs_filtered ("c'", stream); + in_control_form = 1; + } + fprintf_filtered (stream, "%.2x", c); + } + ++things_printed; + } + } + + /* Terminate the quotes if necessary. */ + if (in_literal_form || in_control_form) + { + fputs_filtered ("'", stream); + } + if (force_ellipses || (i < length)) + { + fputs_filtered ("...", stream); + } } diff --git a/gdb/language.h b/gdb/language.h index 0e240f5..862323a 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -222,6 +222,15 @@ set_language PARAMS ((enum language)); #define local_printstr(stream, string, length, force_ellipses) \ (current_language->la_printstr(stream, string, length, force_ellipses)) +/* Test a character to decide whether it can be printed in literal form + or needs to be printed in another representation. For example, + in C the literal form of the character with octal value 141 is 'a' + and the "other representation" is '\141'. The "other representation" + is program language dependent. */ + +#define PRINT_LITERAL_FORM(c) \ + ((c)>=0x20 && ((c)<0x7F || (c)>=0xA0) && (!sevenbit_strings || (c)<0x80)) + /* Return a format string for printf that will print a number in one of the local (language-specific) formats. Result is static and is overwritten by the next call. Takes printf options like "08" or "l" diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index 85488cf..6edc059 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -1192,43 +1192,44 @@ emit_char (c, stream, quoter) c &= 0xFF; /* Avoid sign bit follies */ - if ( c < 0x20 || /* Low control chars */ - (c >= 0x7F && c < 0xA0) || /* DEL, High controls */ - (sevenbit_strings && c >= 0x80)) { /* high order bit set */ - switch (c) - { - case '\n': - fputs_filtered ("\\n", stream); - break; - case '\b': - fputs_filtered ("\\b", stream); - break; - case '\t': - fputs_filtered ("\\t", stream); - break; - case '\f': - fputs_filtered ("\\f", stream); - break; - case '\r': - fputs_filtered ("\\r", stream); - break; - case '\033': - fputs_filtered ("\\e", stream); - break; - case '\007': - fputs_filtered ("\\a", stream); - break; - default: - fprintf_filtered (stream, "\\%.3o", (unsigned int) c); - break; - } - } else { - if (c == '\\' || c == quoter) - { - fputs_filtered ("\\", stream); - } - fprintf_filtered (stream, "%c", c); - } + if (PRINT_LITERAL_FORM (c)) + { + if (c == '\\' || c == quoter) + { + fputs_filtered ("\\", stream); + } + fprintf_filtered (stream, "%c", c); + } + else + { + switch (c) + { + case '\n': + fputs_filtered ("\\n", stream); + break; + case '\b': + fputs_filtered ("\\b", stream); + break; + case '\t': + fputs_filtered ("\\t", stream); + break; + case '\f': + fputs_filtered ("\\f", stream); + break; + case '\r': + fputs_filtered ("\\r", stream); + break; + case '\033': + fputs_filtered ("\\e", stream); + break; + case '\007': + fputs_filtered ("\\a", stream); + break; + default: + fprintf_filtered (stream, "\\%.3o", (unsigned int) c); + break; + } + } } /* FIXME: This is a copy of the same function from c-exp.y. It should |