diff options
author | Nick Clifton <nickc@redhat.com> | 2018-11-09 12:48:23 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2018-11-09 12:48:23 +0000 |
commit | 71f5e3f7b624a725ba550a2dd18a413c88ee6497 (patch) | |
tree | 072610aa1e5e93d0bdce4a78867c233f1026c214 /binutils/strings.c | |
parent | 0d0b0a378eb0c6705ff05a52e7468f5df5e47bc4 (diff) | |
download | gdb-71f5e3f7b624a725ba550a2dd18a413c88ee6497.zip gdb-71f5e3f7b624a725ba550a2dd18a413c88ee6497.tar.gz gdb-71f5e3f7b624a725ba550a2dd18a413c88ee6497.tar.bz2 |
Enhance the strings program so that it can display multibyte strings.
* strings.c (print_strings): Check for multibyte encodings.
* binutils-all/strings-1.bin: New file. Test binary for string decoding.
* testsuite/binutils-all/strings.exp: New file. Test the strings program.
* testsuite/config/default.exp (STRINGS): Define if not provided
by the environment.
(STRINGSFLAGS): Likewise.
Diffstat (limited to 'binutils/strings.c')
-rw-r--r-- | binutils/strings.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/binutils/strings.c b/binutils/strings.c index 74545db..eac7292 100644 --- a/binutils/strings.c +++ b/binutils/strings.c @@ -540,9 +540,48 @@ print_strings (const char *filename, FILE *stream, file_ptr address, free (buf); return; } + if (! STRING_ISGRAPHIC (c)) - /* Found a non-graphic. Try again starting with next char. */ - goto tryline; + { + /* Found a non-graphic. Try again starting with next char. */ + if (encoding_bytes > 1) + { + /* In case of multibyte encodings rewind using magic buffer. */ + if (magiccount == 0) + { + /* If no magic buffer exists: use memory of c. */ + switch (encoding) + { + default: + break; + case 'b': + c = c & 0xff; + magiccount += 1; + break; + case 'l': + case 'L': + c = c >> 8; + magiccount += (encoding_bytes -1); + break; + case 'B': + c = (( c & 0xff0000) >> 16) | ( c & 0xff00) + | (( c & 0xff) << 16); + magiccount += 3; + break; + } + magic = (char *) &c; + } + else + { + /* If magic buffer exists: rewind. */ + magic = magic - (encoding_bytes -1); + } + + address = address - (encoding_bytes -1); + } + + goto tryline; + } buf[i] = c; } |