From: Vladimir Kargov <kargov@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Fix the x87 FP register printout by “info float”.
Date: Thu, 18 Apr 2013 15:40:00 -0000 [thread overview]
Message-ID: <CAHLdKi=qPX-x7Eb0gwqTaOsWp0gK0=3WQFLmc6_HBKGUZ7RzfQ@mail.gmail.com> (raw)
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
next reply other threads:[~2013-04-18 0:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-18 15:40 Vladimir Kargov [this message]
2013-04-19 9:43 ` Pedro Alves
2013-04-19 14:30 ` Vladimir Kargov
2013-04-19 14:33 ` Pedro Alves
2013-04-19 18:23 ` Vladimir Kargov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHLdKi=qPX-x7Eb0gwqTaOsWp0gK0=3WQFLmc6_HBKGUZ7RzfQ@mail.gmail.com' \
--to=kargov@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox