public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* m68k disassembler bug in error handling support
@ 2006-04-29 17:51 James E Wilson
  0 siblings, 0 replies; only message in thread
From: James E Wilson @ 2006-04-29 17:51 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

I noticed this while talking to Ben Elliston about PR 1298.

In the file opcodes/m68k-dis.c, in the function match_insn_m68k, there
is code to handle an error return from print_insn_m68k.  This prints an
error message and then exits with an error code.  However, we disabled
printing right before the print_insn_m68k call, so no error message will
ever be printed here.  We need to restore the print functions before we
try to print the error message.

This is trivial to demonstrate by modifying print_insn_arg to return -2
unconditionally, and then running the disassembler on some m68k code. 
Unpatched and patched results are attached.

I tested this with a x86_64-x-m68k-elf cross binutils.  There were no
regressions.  I went ahead and checked in the bug fix patch.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

[-- Attachment #2: result.unpatched --]
[-- Type: text/plain, Size: 260 bytes --]

aretha$ cat tmp.s
        movl $d0, $d1
        movl $d0, $d1
aretha$ ./as-new tmp.s
aretha$ ../binutils/objdump -d a.out
 
a.out:     file format elf32-m68k
 
Disassembly of section .text:
 
00000000 <.text>:
   0:   23f9
        ...
   a:   23f9
        ...

[-- Attachment #3: result.patched --]
[-- Type: text/plain, Size: 376 bytes --]

aretha$ cat tmp.s
        movl $d0, $d1
        movl $d0, $d1
aretha$ ./as-new tmp.s
aretha$ ../binutils/objdump -d a.out
 
a.out:     file format elf32-m68k
 
Disassembly of section .text:
 
00000000 <.text>:
   0:   23f9            <internal error in opcode table: movel *l%d>
 
        ...
   a:   23f9            <internal error in opcode table: movel *l%d>
 
        ...

[-- Attachment #4: patch.induce.bug --]
[-- Type: text/x-patch, Size: 488 bytes --]

Index: m68k-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/m68k-dis.c,v
retrieving revision 1.21
diff -p -p -r1.21 m68k-dis.c
*** m68k-dis.c	7 Feb 2006 19:01:10 -0000	1.21
--- m68k-dis.c	29 Apr 2006 02:58:02 -0000
*************** print_insn_arg (const char *d,
*** 584,589 ****
--- 584,591 ----
    bfd_signed_vma disp;
    unsigned int uval;
  
+   return -2;
+ 
    switch (*d)
      {
      case 'c':		/* Cache identifier.  */

[-- Attachment #5: patch.print.error --]
[-- Type: text/plain, Size: 1222 bytes --]

2006-04-28  James E Wilson  <wilson@specifix.com>

	* m68k-dis.c (match_insn_m68k): Restore fprintf_func before printing
	error message.

Index: m68k-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/m68k-dis.c,v
retrieving revision 1.21
diff -p -p -r1.21 m68k-dis.c
*** m68k-dis.c	7 Feb 2006 19:01:10 -0000	1.21
--- m68k-dis.c	29 Apr 2006 02:46:14 -0000
*************** match_insn_m68k (bfd_vma memaddr,
*** 1308,1319 ****
  	}
        else
  	{
  	  info->fprintf_func (info->stream,
  			      /* xgettext:c-format */
  			      _("<internal error in opcode table: %s %s>\n"),
  			      best->name,  best->args);
- 	  info->fprintf_func = save_printer;
- 	  info->print_address_func = save_print_address;
  	  return 2;
  	}
      }
--- 1308,1321 ----
  	}
        else
  	{
+ 	  /* We must restore the print functions before trying to print the
+ 	     error message.  */
+ 	  info->fprintf_func = save_printer;
+ 	  info->print_address_func = save_print_address;
  	  info->fprintf_func (info->stream,
  			      /* xgettext:c-format */
  			      _("<internal error in opcode table: %s %s>\n"),
  			      best->name,  best->args);
  	  return 2;
  	}
      }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-04-29  3:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-29 17:51 m68k disassembler bug in error handling support James E Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).