aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2002-12-23 10:37:38 +0000
committerNick Clifton <nickc@redhat.com>2002-12-23 10:37:38 +0000
commit8745eafadc9d43dbd9f9a0d2cc33e12f11ca1cd6 (patch)
tree876e7a2b7361bd6066ece01c96e9225767ad9a48 /binutils
parentf0a847b8c7d6ba5a4d0df552453821f67c939e82 (diff)
downloadgdb-8745eafadc9d43dbd9f9a0d2cc33e12f11ca1cd6.zip
gdb-8745eafadc9d43dbd9f9a0d2cc33e12f11ca1cd6.tar.gz
gdb-8745eafadc9d43dbd9f9a0d2cc33e12f11ca1cd6.tar.bz2
Add support for 'S' encoding to strings - display 8-bit characters.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog11
-rw-r--r--binutils/NEWS2
-rw-r--r--binutils/doc/binutils.texi10
-rw-r--r--binutils/strings.c53
4 files changed, 45 insertions, 31 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 3f165a2..f411fcd 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,14 @@
+2002-12-23 Nick Clifton <nickc@redhat.com>
+
+ * strings.c (isgraphic): Replace definition with STRING_ISGRAPHIC
+ macro. Handle 'S' encoding, accepting 8-bit characters.
+ (main): Parse 'S' encoding.
+ (get_char): Accept 'S' encoding.
+ (print_strings): Use STRING_ISGRAPHIC.
+ (usage): Document support of 'S' encoding.
+ * doc/binutils.texi: Document support of 'S' encoding/
+ * NEWS: Mention new feature.
+
2002-12-20 Alan Modra <amodra@bigpond.net.au>
* README <building ar>: Don't use libibery's needed_list or
diff --git a/binutils/NEWS b/binutils/NEWS
index 1e74e93..e9e4f40 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,7 @@
-*- text -*-
+* Added 'S' encoding to strings to allow the display of 8-bit characters.
+
* Added --prefix-symbols=<text>, --prefix-sections=<text> and
--prefix-alloc-sections=<text> to objcopy.
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 57103f0..26ed7f9 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -1956,11 +1956,11 @@ octal, @samp{x} for hexadecimal, or @samp{d} for decimal.
@item -e @var{encoding}
@itemx --encoding=@var{encoding}
Select the character encoding of the strings that are to be found.
-Possible values for @var{encoding} are: @samp{s} = single-byte
-characters (ASCII, ISO 8859, etc., default), @samp{b} = 16-bit
-Bigendian, @samp{l} = 16-bit Littleendian, @samp{B} = 32-bit Bigendian,
-@samp{L} = 32-bit Littleendian. Useful for finding wide character
-strings.
+Possible values for @var{encoding} are: @samp{s} = single-7-bit-byte
+characters (ASCII, ISO 8859, etc., default), @samp{S} =
+single-8-bit-byte characters, @samp{b} = 16-bit bigendian, @samp{l} =
+16-bit littleendian, @samp{B} = 32-bit bigendian, @samp{L} = 32-bit
+littleendian. Useful for finding wide character strings.
@item --target=@var{bfdname}
@cindex object code format
diff --git a/binutils/strings.c b/binutils/strings.c
index f1222e0..b5e88d0 100644
--- a/binutils/strings.c
+++ b/binutils/strings.c
@@ -39,10 +39,11 @@
-o Like -to. (Some other implementations have -o like -to,
others like -td. We chose one arbitrarily.)
- --encoding={s,b,l,B,L}
- -e {s,b,l,B,L}
- Select character encoding: single-byte, bigendian 16-bit,
- littleendian 16-bit, bigendian 32-bit, littleendian 32-bit
+ --encoding={s,S,b,l,B,L}
+ -e {s,S,b,l,B,L}
+ Select character encoding: 7-bit-character, 8-bit-character,
+ bigendian 16-bit, littleendian 16-bit, bigendian 32-bit,
+ littleendian 32-bit.
--target=BFDNAME
Specify a non-default object file format.
@@ -80,11 +81,14 @@
#endif
#if O_BINARY
#include <io.h>
-#define SET_BINARY(f) do { if (!isatty(f)) setmode(f,O_BINARY); } while (0)
+#define SET_BINARY(f) do { if (!isatty (f)) setmode (f,O_BINARY); } while (0)
#endif
#endif
-#define isgraphic(c) (ISPRINT (c) || (c) == '\t')
+#define STRING_ISGRAPHIC(c) \
+ ( (c) >= 0 \
+ && (c) <= 255 \
+ && ((c) == '\t' || ISPRINT (c) || (encoding == 'S' && (c) > 127)))
#ifndef errno
extern int errno;
@@ -95,10 +99,10 @@ extern int errno;
#ifdef HAVE_FOPEN64
typedef off64_t file_off;
-#define file_open(s,m) fopen64(s,m)
+#define file_open(s,m) fopen64(s, m)
#else
typedef off_t file_off;
-#define file_open(s,m) fopen(s,m)
+#define file_open(s,m) fopen(s, m)
#endif
/* Radix for printing addresses (must be 8, 10 or 16). */
@@ -148,12 +152,11 @@ static bfd_boolean strings_file
static int integer_arg
PARAMS ((char *s));
static void print_strings
- PARAMS ((const char *filename, FILE *stream, file_off address,
- int stop_point, int magiccount, char *magic));
+ PARAMS ((const char *, FILE *, file_off, int, int, char *));
static void usage
- PARAMS ((FILE *stream, int status));
+ PARAMS ((FILE *, int));
static long get_char
- PARAMS ((FILE *stream, file_off *address, int *magiccount, char **magic));
+ PARAMS ((FILE *, file_off *, int *, char **));
int main
PARAMS ((int, char **));
@@ -202,9 +205,7 @@ main (argc, argv)
case 'n':
string_min = integer_arg (optarg);
if (string_min < 1)
- {
- fatal (_("invalid number %s"), optarg);
- }
+ fatal (_("invalid number %s"), optarg);
break;
case 'o':
@@ -267,6 +268,7 @@ main (argc, argv)
switch (encoding)
{
+ case 'S':
case 's':
encoding_bytes = 1;
break;
@@ -330,6 +332,7 @@ strings_a_section (abfd, sect, filearg)
{
bfd_size_type sz = bfd_get_section_size_before_reloc (sect);
PTR mem = xmalloc (sz);
+
if (bfd_get_section_contents (abfd, sect, mem, (file_ptr) 0, sz))
{
got_a_section = TRUE;
@@ -352,10 +355,8 @@ strings_object_file (file)
bfd *abfd = bfd_openr (file, target);
if (abfd == NULL)
- {
- /* Treat the file as a non-object file. */
- return FALSE;
- }
+ /* Treat the file as a non-object file. */
+ return FALSE;
/* This call is mainly for its side effect of reading in the sections.
We follow the traditional behavior of `strings' in that we don't
@@ -460,6 +461,7 @@ get_char (stream, address, magiccount, magic)
switch (encoding)
{
+ case 'S':
case 's':
r = buf[0];
break;
@@ -524,7 +526,7 @@ print_strings (filename, stream, address, stop_point, magiccount, magic)
c = get_char (stream, &address, &magiccount, &magic);
if (c == EOF)
return;
- if (c > 255 || c < 0 || !isgraphic (c))
+ if (! STRING_ISGRAPHIC (c))
/* Found a non-graphic. Try again starting with next char. */
goto tryline;
buf[i] = c;
@@ -592,7 +594,7 @@ print_strings (filename, stream, address, stop_point, magiccount, magic)
c = get_char (stream, &address, &magiccount, &magic);
if (c == EOF)
break;
- if (c > 255 || c < 0 || !isgraphic (c))
+ if (! STRING_ISGRAPHIC (c))
break;
putchar (c);
}
@@ -642,9 +644,8 @@ integer_arg (s)
p--;
if (*p)
- {
- fatal (_("invalid integer argument %s"), s);
- }
+ fatal (_("invalid integer argument %s"), s);
+
return value;
}
@@ -663,8 +664,8 @@ usage (stream, status)
-t --radix={o,x,d} Print the location of the string in base 8, 10 or 16\n\
-o An alias for --radix=o\n\
-T --target=<BFDNAME> Specify the binary file format\n\
- -e --encoding={s,b,l,B,L} Select character size and endianness:\n\
- s = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
+ -e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\
+ s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
-h --help Display this information\n\
-v --version Print the program's version number\n"));
list_supported_targets (program_name, stream);