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]

[commit] Fix printing of flags from 64-bit registers


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));


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