2007-09-22 Pedro Alves * 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; }