Restore readelf's string dump to previous behaviour where newlines were caused line breaks.
PR 25543 * readelf.c (dump_section_as_strings): Display new-line characters as \n and then insert a line break. * testsuite/binutils-all/pr25543.s: New test. * testsuite/binutils-all/pr25543.d: Test driver. * testsuite/binutils-all/readelf.exp: Run the new test.
This commit is contained in:
parent
cb001c0d28
commit
ba3265d04c
5 changed files with 102 additions and 7 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2020-03-02 Nick Clifton <nickc@redhat.com>
|
||||||
|
|
||||||
|
PR 25543
|
||||||
|
* readelf.c (dump_section_as_strings): Display new-line characters
|
||||||
|
as \n and then insert a line break.
|
||||||
|
* testsuite/binutils-all/pr25543.s: New test.
|
||||||
|
* testsuite/binutils-all/pr25543.d: Test driver.
|
||||||
|
* testsuite/binutils-all/readelf.exp: Run the new test.
|
||||||
|
|
||||||
2020-02-27 Nick Clifton <nickc@redhat.com>
|
2020-02-27 Nick Clifton <nickc@redhat.com>
|
||||||
|
|
||||||
PR 25526
|
PR 25526
|
||||||
|
|
|
@ -13732,6 +13732,14 @@ dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
|
||||||
end = start + num_bytes;
|
end = start + num_bytes;
|
||||||
some_strings_shown = FALSE;
|
some_strings_shown = FALSE;
|
||||||
|
|
||||||
|
#ifdef HAVE_MBSTATE_T
|
||||||
|
mbstate_t state;
|
||||||
|
/* Initialise the multibyte conversion state. */
|
||||||
|
memset (& state, 0, sizeof (state));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bfd_boolean continuing = FALSE;
|
||||||
|
|
||||||
while (data < end)
|
while (data < end)
|
||||||
{
|
{
|
||||||
while (!ISPRINT (* data))
|
while (!ISPRINT (* data))
|
||||||
|
@ -13742,6 +13750,13 @@ dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
|
||||||
{
|
{
|
||||||
size_t maxlen = end - data;
|
size_t maxlen = end - data;
|
||||||
|
|
||||||
|
if (continuing)
|
||||||
|
{
|
||||||
|
printf (" ");
|
||||||
|
continuing = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
#ifndef __MSVCRT__
|
#ifndef __MSVCRT__
|
||||||
/* PR 11128: Use two separate invocations in order to work
|
/* PR 11128: Use two separate invocations in order to work
|
||||||
around bugs in the Solaris 8 implementation of printf. */
|
around bugs in the Solaris 8 implementation of printf. */
|
||||||
|
@ -13749,11 +13764,62 @@ dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
|
||||||
#else
|
#else
|
||||||
printf (" [%6Ix] ", (size_t) (data - start));
|
printf (" [%6Ix] ", (size_t) (data - start));
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (maxlen > 0)
|
if (maxlen > 0)
|
||||||
{
|
{
|
||||||
print_symbol ((int) maxlen, (const char *) data);
|
char c;
|
||||||
|
|
||||||
|
while (maxlen)
|
||||||
|
{
|
||||||
|
c = *data++;
|
||||||
|
|
||||||
|
if (c == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* PR 25543: Treat new-lines as string-ending characters. */
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
printf ("\\n\n");
|
||||||
|
if (*data != 0)
|
||||||
|
continuing = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do not print control characters directly as they can affect terminal
|
||||||
|
settings. Such characters usually appear in the names generated
|
||||||
|
by the assembler for local labels. */
|
||||||
|
if (ISCNTRL (c))
|
||||||
|
{
|
||||||
|
printf ("^%c", c + 0x40);
|
||||||
|
}
|
||||||
|
else if (ISPRINT (c))
|
||||||
|
{
|
||||||
|
putchar (c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t n;
|
||||||
|
#ifdef HAVE_MBSTATE_T
|
||||||
|
wchar_t w;
|
||||||
|
#endif
|
||||||
|
/* Let printf do the hard work of displaying multibyte characters. */
|
||||||
|
printf ("%.1s", data - 1);
|
||||||
|
#ifdef HAVE_MBSTATE_T
|
||||||
|
/* Try to find out how many bytes made up the character that was
|
||||||
|
just printed. Advance the symbol pointer past the bytes that
|
||||||
|
were displayed. */
|
||||||
|
n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state);
|
||||||
|
#else
|
||||||
|
n = 1;
|
||||||
|
#endif
|
||||||
|
if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
|
||||||
|
data += (n - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c != '\n')
|
||||||
putchar ('\n');
|
putchar ('\n');
|
||||||
data += strnlen ((const char *) data, maxlen);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
12
binutils/testsuite/binutils-all/pr25543.d
Normal file
12
binutils/testsuite/binutils-all/pr25543.d
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#source: pr25543.s
|
||||||
|
#readelf: -p.data
|
||||||
|
#notarget: rx-*
|
||||||
|
|
||||||
|
String dump of section '.data':
|
||||||
|
\[ 0\] line1 : This is a line without a newline at the end
|
||||||
|
\[ 34\] line2 : This is a line with a newline at the end\\n
|
||||||
|
\[ 66\] line3 : This is a line with a \\n
|
||||||
|
newline in the middle
|
||||||
|
\[ 9b\] line4 : This is a line with a \^Mcontrol character
|
||||||
|
\[ cd\] line6 : The previous line was empty\\n
|
||||||
|
#pass
|
7
binutils/testsuite/binutils-all/pr25543.s
Normal file
7
binutils/testsuite/binutils-all/pr25543.s
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
.data
|
||||||
|
.asciz "line1 : This is a line without a newline at the end"
|
||||||
|
.asciz "line2 : This is a line with a newline at the end\n"
|
||||||
|
.asciz "line3 : This is a line with a \nnewline in the middle"
|
||||||
|
.asciz "line4 : This is a line with a \rcontrol character"
|
||||||
|
.asciz ""
|
||||||
|
.asciz "line6 : The previous line was empty\n"
|
|
@ -349,6 +349,7 @@ readelf_wi_test
|
||||||
readelf_compressed_wa_test
|
readelf_compressed_wa_test
|
||||||
|
|
||||||
readelf_dump_test
|
readelf_dump_test
|
||||||
|
run_dump_test "pr25543"
|
||||||
|
|
||||||
# PR 13482 - Check for off-by-one errors when dumping .note sections.
|
# PR 13482 - Check for off-by-one errors when dumping .note sections.
|
||||||
if {![binutils_assemble $srcdir/$subdir/version.s tmpdir/version.o]} then {
|
if {![binutils_assemble $srcdir/$subdir/version.s tmpdir/version.o]} then {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue