gdb patch for 64-bit enum values on 64-bit hosts (ia64-linux)
Jim Wilson
wilson@cygnus.com
Thu Jun 8 17:53:00 GMT 2000
This fixes two bugs in the handling of 64-bit values on 64-bit LP64 hosts.
We need to use long instead of int in several places, so that we don't
accidentally truncate values to 32-bits when longs are 64-bits.
The specific problems fixed are unsigned 64-bit enum values, and signed 64-bit
enum values.
This testcase is extracted from emacs.
enum gdb_lisp_params
{
gdb_data_seg_bits = 0x8000000000000000UL,
};
main()
{
printf ("0x%lx\n", gdb_data_seg_bits);
}
Without this patch, "print (long) gdb_data_seg_bits" gives 0.
#include <limits.h>
enum foo
{
bar = LONG_MIN
};
main()
{
printf ("0x%lx\n", bar);
}
Without this patch, "print (long) bar" gives 0.
In order for these testcases to work, you also need the gcc patches I checked
in today, as gcc also got it wrong until today.
This was tested on ia64-linux with make check in the gdb directory.
2000-06-08 James E. Wilson <wilson@bletchleypark.cygnus.com>
* dwarf2read.c (struct attribute): Change unsnd and snd field types
to long.
(read_8_bytes): Change return type to long.
(read_unsigned_leb128): Change return type to long. Change type of
local result to long. Cast argument of left shift to long.
(read_signed_leb128): Likewise.
*** orig-devo/gdb/dwarf2read.c Fri Jun 2 14:22:37 2000
--- devo/gdb/dwarf2read.c Thu Jun 8 15:37:41 2000
*************** struct attribute
*** 227,234 ****
{
char *str;
struct dwarf_block *blk;
! unsigned int unsnd;
! int snd;
CORE_ADDR addr;
}
u;
--- 227,234 ----
{
char *str;
struct dwarf_block *blk;
! unsigned long unsnd;
! long int snd;
CORE_ADDR addr;
}
u;
*************** static unsigned int read_2_bytes (bfd *,
*** 591,597 ****
static unsigned int read_4_bytes (bfd *, char *);
! static unsigned int read_8_bytes (bfd *, char *);
static CORE_ADDR read_address (bfd *, char *);
--- 591,597 ----
static unsigned int read_4_bytes (bfd *, char *);
! static unsigned long read_8_bytes (bfd *, char *);
static CORE_ADDR read_address (bfd *, char *);
*************** static char *read_n_bytes (bfd *, char *
*** 599,607 ****
static char *read_string (bfd *, char *, unsigned int *);
! static unsigned int read_unsigned_leb128 (bfd *, char *, unsigned int *);
! static int read_signed_leb128 (bfd *, char *, unsigned int *);
static void set_cu_language (unsigned int);
--- 599,607 ----
static char *read_string (bfd *, char *, unsigned int *);
! static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
! static long read_signed_leb128 (bfd *, char *, unsigned int *);
static void set_cu_language (unsigned int);
*************** read_4_signed_bytes (abfd, buf)
*** 3446,3452 ****
return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
}
! static unsigned int
read_8_bytes (abfd, buf)
bfd *abfd;
char *buf;
--- 3446,3452 ----
return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
}
! static unsigned long
read_8_bytes (abfd, buf)
bfd *abfd;
char *buf;
*************** read_string (abfd, buf, bytes_read_ptr)
*** 3543,3555 ****
#endif
}
! static unsigned int
read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
bfd *abfd;
char *buf;
unsigned int *bytes_read_ptr;
{
! unsigned int result, num_read;
int i, shift;
unsigned char byte;
--- 3543,3556 ----
#endif
}
! static unsigned long
read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
bfd *abfd;
char *buf;
unsigned int *bytes_read_ptr;
{
! unsigned long result;
! unsigned int num_read;
int i, shift;
unsigned char byte;
*************** read_unsigned_leb128 (abfd, buf, bytes_r
*** 3562,3568 ****
byte = bfd_get_8 (abfd, (bfd_byte *) buf);
buf++;
num_read++;
! result |= ((byte & 127) << shift);
if ((byte & 128) == 0)
{
break;
--- 3563,3569 ----
byte = bfd_get_8 (abfd, (bfd_byte *) buf);
buf++;
num_read++;
! result |= ((unsigned long)(byte & 127) << shift);
if ((byte & 128) == 0)
{
break;
*************** read_unsigned_leb128 (abfd, buf, bytes_r
*** 3573,3585 ****
return result;
}
! static int
read_signed_leb128 (abfd, buf, bytes_read_ptr)
bfd *abfd;
char *buf;
unsigned int *bytes_read_ptr;
{
! int result;
int i, shift, size, num_read;
unsigned char byte;
--- 3574,3586 ----
return result;
}
! static long
read_signed_leb128 (abfd, buf, bytes_read_ptr)
bfd *abfd;
char *buf;
unsigned int *bytes_read_ptr;
{
! long result;
int i, shift, size, num_read;
unsigned char byte;
*************** read_signed_leb128 (abfd, buf, bytes_rea
*** 3593,3599 ****
byte = bfd_get_8 (abfd, (bfd_byte *) buf);
buf++;
num_read++;
! result |= ((byte & 127) << shift);
shift += 7;
if ((byte & 128) == 0)
{
--- 3594,3600 ----
byte = bfd_get_8 (abfd, (bfd_byte *) buf);
buf++;
num_read++;
! result |= ((long)(byte & 127) << shift);
shift += 7;
if ((byte & 128) == 0)
{
More information about the Gdb-patches
mailing list