Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: gdb-patches@sourceware.org
Subject: [commit] Fix printing of flags from 64-bit registers
Date: Tue, 22 Aug 2006 20:41:00 -0000	[thread overview]
Message-ID: <200608222032.k7MKWgkF006138@elgar.sibelius.xs4all.nl> (raw)

Printing flags from 64-bit registers showed some random set bits.

(gdb) print /x $pstate
$1 = 0x82
(gdb) print $pstate
$2 = [ IE #7 #33 #39 ]

Obviously bit #33 and #39 are not set.  Turns out the code that prints
this invoked undefined behaviour by shifting the constant 1 (typically
a 32-bit integer) over more than 32 bits.

The attached patch fixes this by adding the right cast.

Mark

Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>
	* valprint.c (val_print_type_code_flags): Fix for bitfields larger
	than 32 bits.

Index: valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.60
diff -u -p -r1.60 valprint.c
--- valprint.c 15 May 2006 16:53:38 -0000 1.60
+++ valprint.c 22 Aug 2006 20:28:09 -0000
@@ -341,13 +341,14 @@ void
 val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
 			   struct ui_file *stream)
 {
-  LONGEST val = unpack_long (type, valaddr);
+  ULONGEST val = unpack_long (type, valaddr);
   int bitpos, nfields = TYPE_NFIELDS (type);
 
   fputs_filtered ("[ ", stream);
   for (bitpos = 0; bitpos < nfields; bitpos++)
     {
-      if (TYPE_FIELD_BITPOS (type, bitpos) != -1 && (val & (1 << bitpos)))
+      if (TYPE_FIELD_BITPOS (type, bitpos) != -1 &&
+	  (val & ((ULONGEST)1 << bitpos)))
 	{
 	  if (TYPE_FIELD_NAME (type, bitpos))
 	    fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos));


                 reply	other threads:[~2006-08-22 20:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200608222032.k7MKWgkF006138@elgar.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --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