Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro_alves@portugalmail.pt>
To: Pierre Muller <muller@ics.u-strasbg.fr>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC] Stabs parsing regression from GDB 6.6 to GDB 6.6.90
Date: Sat, 22 Sep 2007 19:39:00 -0000	[thread overview]
Message-ID: <46F56F04.6070601@portugalmail.pt> (raw)
In-Reply-To: <46F486B4.6050900@portugalmail.pt>

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

Pedro Alves wrote:

> What about the attached?  Isn't it simpler?
> 
> We get passed the max number of bits the number we're parsing
> can hold in TWOS_COMPLEMENT_BITS.
> 
> Just parse the number as unsigned, if it overflows, it doesn't
> matter, we just account for the bits.
> If it doesn't overflow (host has a big long),
>     and TWOS_COMPLEMENT_BITS < sizeof (long) * HOST_CHAR_BIT
>     and number is signed according to TWOS_COMPLEMENT_BITS - 1
>     bit being set, sign extend the number into a long.
> 
> Just tested that it also fixes the problem.  I'll give it a
> testsuite spin for C/C++ on Cygwin tomorrow, but the testcase
> that suposedly tests this is in ADA, which I don't have a
> setup for...
> 

Just tested the slightly updated patch on Cygwin, and it doesn't
bring about any new problem.

I also stepped through read_huge_number using the attached
read_huge_number.s as a test.  I don't know how to force gcc to
output a range type in octal that triggers
'TWOS_COMPLEMENT_BITS < sizeof (long) * HOST_CHAR_BIT', so I've hacked
the stabs myself:

Replaced:
.stabs  "short int:t(0,8)=@s16;r(0,8);-32768;32767;",128,0,0,0
.stabs  "short unsigned int:t(0,9)=@s16;r(0,9);0;65535;",128,0,0,0

By:
.stabs	"short int:t(0,8)=@s16;r(0,8);0100000;077777;",128,0,0,0
.stabs	"short unsigned int:t(0,9)=@s16;r(0,9);0000000;0177777;",128,0,0,0

'ptype main' triggers the read_range_type call, which calls
read_huge_number twice for the range.

I've confirmed that we read 0100000 as (long)-32768.

Don't know how to convert this to a testcase.
'maint print type short int' doesn't show these ranges,
are they stored anywhere?

Cheers,
Pedro Alves


[-- Attachment #2: read_huge_number.diff --]
[-- Type: text/x-diff, Size: 2567 bytes --]

2007-09-22  Pedro Alves  <pedro_alves@portugalmail.pt>

	* stabsread.c (read_huge_number): Remove special parsing of octal
	two's complement representation.  If just parsed a negative number
	in octal two's complement representation, sign extend the result
	to a long.

---
 gdb/stabsread.c |   49 ++++++++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 27 deletions(-)

Index: src/gdb/stabsread.c
===================================================================
--- src.orig/gdb/stabsread.c	2007-09-22 17:09:20.000000000 +0100
+++ src/gdb/stabsread.c	2007-09-22 18:19:26.000000000 +0100
@@ -3734,32 +3734,9 @@ read_huge_number (char **pp, int end, in
     {
       if (n <= upper_limit)
         {
-          if (twos_complement_representation)
-            {
-              /* Octal, signed, twos complement representation. In this case,
-                 sn is the signed value, n is the corresponding absolute
-                 value. signed_bit is the position of the sign bit in the
-                 first three bits.  */
-              if (sn == 0)
-                {
-                  sign_bit = (twos_complement_bits % 3 + 2) % 3;
-                  sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
-                }
-              else
-                {
-                  sn *= radix;
-                  sn += c - '0';
-                }
-
-              if (sn < 0)
-                n = -sn;
-            }
-          else
-            {
-              /* unsigned representation */
-              n *= radix;
-              n += c - '0';		/* FIXME this overflows anyway */
-            }
+	  /* unsigned representation */
+	  n *= radix;
+	  n += c - '0';		/* FIXME this overflows anyway */
         }
       else
         overflow = 1;
@@ -3820,7 +3797,25 @@ read_huge_number (char **pp, int end, in
       if (bits)
 	*bits = 0;
       if (twos_complement_representation)
-        return sn;
+	{
+	  if (n & 1L << (twos_complement_bits - 1))
+	    {
+	      /* N is signed.  TWOS_COMPLEMENT_BITS may be less than
+		 what fits in a long.  Since we can't assume a host
+		 with two's complement long, extract the module value
+		 of N, and multiply it with -1.
+
+		 eg: with TWOS_COMPLEMENT_BITS == 16, and sizeof long == 32,
+		 0x00008111 => 0xffff7eef => 0x00007eef => 0xffff8111.  */
+
+	      unsigned long l = (unsigned long) n;
+	      l = ~l + 1;
+	      l &= (1L << twos_complement_bits) - 1;
+	      n = (long) l;
+	      n *= -1;
+	    }
+	  return n;
+	}
       else
         return n * sign;
     }


[-- Attachment #3: read_huge_number.s --]
[-- Type: text/plain, Size: 1475 bytes --]

	.stabs	"read_huge_number.s",100,0,0,Ltext0
	.text
Ltext0:
	.stabs	"gcc2_compiled.",60,0,0,0
	
	.stabs	"short int:t(0,8)=@s16;r(0,8);0100000;077777;",128,0,0,0
	.stabs	"short unsigned int:t(0,9)=@s16;r(0,9);0000000;0177777;",128,0,0,0
	
	.stabs	"int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0
	.stabs	"char:t(0,2)=r(0,2);0;127;",128,0,0,0
	.stabs	"long int:t(0,3)=r(0,3);-2147483648;2147483647;",128,0,0,0
	.stabs	"unsigned int:t(0,4)=r(0,4);0000000000000;0037777777777;",128,0,0,0
	.stabs	"long unsigned int:t(0,5)=r(0,5);0000000000000;0037777777777;",128,0,0,0
	.stabs	"long long int:t(0,6)=@s64;r(0,6);01000000000000000000000;0777777777777777777777;",128,0,0,0
	.stabs	"long long unsigned int:t(0,7)=@s64;r(0,7);0000000000000;01777777777777777777777;",128,0,0,0
	.stabs	"signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,0,0
	.stabs	"unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,0,0
	.stabs	"float:t(0,12)=r(0,1);4;0;",128,0,0,0
	.stabs	"double:t(0,13)=r(0,1);8;0;",128,0,0,0
	.stabs	"long double:t(0,14)=r(0,1);12;0;",128,0,0,0
	.stabs	"complex int:t(0,15)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0
	.stabs	"complex float:t(0,16)=R3;8;0;",128,0,0,0
	.stabs	"complex double:t(0,17)=R3;16;0;",128,0,0,0
	.stabs	"complex long double:t(0,18)=R3;24;0;",128,0,0,0
	.stabs	"void:t(0,19)=(0,19)",128,0,0,0
	.stabs	"__builtin_va_list:t(0,20)=*(0,2)",128,0,0,0
	.stabs	"_Bool:t(0,21)=@s8;-16",128,0,0,0

	.text
	.stabs	"main:F(0,1)",36,0,5,_main
.globl _main
_main:


  parent reply	other threads:[~2007-09-22 19:39 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <000e01c7fb9b$22e600f0$68b202d0$@u-strasbg.fr>
2007-09-21  8:01 ` Pierre Muller
2007-09-22  3:07   ` Pedro Alves
2007-09-22  4:20     ` Joel Brobecker
2007-09-22 10:17       ` Pedro Alves
2007-09-22 19:39     ` Pedro Alves [this message]
2007-09-22 22:58       ` Joel Brobecker
2007-09-22 23:08         ` Daniel Jacobowitz
2007-09-23  1:17           ` Joel Brobecker
2007-09-23 10:17             ` Pedro Alves
2007-09-23 11:39           ` Pedro Alves
2007-09-23 12:42             ` Daniel Jacobowitz
2007-09-23 13:57               ` Pedro Alves
2007-09-24  0:43       ` Pedro Alves
2007-09-24  9:15         ` Pierre Muller
2007-09-24 10:21           ` Pedro Alves
2007-09-24 13:30             ` Pierre Muller
2007-09-25  8:09               ` Pedro Alves
2007-09-25 23:58                 ` Pedro Alves
2007-10-03 12:06                   ` Pierre Muller
2007-10-03 16:43                     ` Jim Blandy
2007-10-03 18:44                     ` Joel Brobecker
2007-10-03 18:51                       ` Daniel Jacobowitz
2007-10-03 19:07                         ` Joel Brobecker
2007-10-03 21:36                         ` Pedro Alves
2007-10-03 21:40                           ` Daniel Jacobowitz
2007-10-05  9:59                             ` Pedro Alves
2007-10-08 23:26                               ` Pedro Alves
2007-10-09  9:10                                 ` Pierre Muller
2007-10-09 11:39                                   ` Pedro Alves
2007-09-23  1:06     ` Joel Brobecker
2007-09-24  6:57     ` Pierre Muller

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=46F56F04.6070601@portugalmail.pt \
    --to=pedro_alves@portugalmail.pt \
    --cc=gdb-patches@sourceware.org \
    --cc=muller@ics.u-strasbg.fr \
    /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