This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix the x87 FP register printout by “info float”.


Hello,

Please find attached a patch that fixes the x87 FP register printout
when issuing the “info float” command.

Consider the following simple program:

.globl  _start
.text
_start:
      fldt    val
.data
      val: .byte 0x00,0x00,0x45,0x07,0x11,0x19,0x22,0xe9,0xfe,0xbf

With the current gdb revision(7.6.50.20130417-cvs) on my x86-64 target
machine after the moment the fldt command has been executed the
register st(0) looks like this, according to the “info regs” output
(TOP=7):

R7: Valid   0xffffffbffffffffeffffffe922191107450000 -0.910676542908976927

which is clearly wrong (just count its length). The problem is due to
the printf() statement (see patch) printing a promoted integer value
of a char argument "raw[i]", and, since char is signed on my machine,
the erroneous “ffffff” are printed for the first three bytes which
turn out to be "negative". The fix adds the char length modifier that
forces fprintf to treat the value as a char instead of int. After the
fix the value will be printed correctly:

R7: Valid   0xbffee922191107450000 -0.910676542908976927

Another way to fix this would be to replace the type in the definition
of variable "raw" from "char" to "gdb_char" which is currently defined
as "unsigned char", but I couldn't find any signs in the code that
this typedef wouldn't be changed in the future to something else.

2013-04-18  Vladimir Kargov <kargov@gmail.com>
	* i387-tdep.c (i387_print_float_info): Add the "hh" length modifier
	to the format string of fprintf_filtered().

Index: gdb/i387-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i387-tdep.c,v
retrieving revision 1.76
diff -u -p -r1.76 i387-tdep.c
--- gdb/i387-tdep.c     1 Jan 2013 06:32:45 -0000       1.76
+++ gdb/i387-tdep.c     18 Apr 2013 00:23:27 -0000
@@ -302,7 +302,7 @@ i387_print_float_info (struct gdbarch *g

              fputs_filtered ("0x", file);
              for (i = 9; i >= 0; i--)
-               fprintf_filtered (file, "%02x", raw[i]);
+               fprintf_filtered (file, "%02hhx", raw[i]);

              if (tag != -1 && tag != 3)
                print_i387_ext (gdbarch, raw, file);

Best regards,
--
Vladimir


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]