--- p-valprint.c 2005-06-13 21:05:45.000000000 +0200 +++ p-valprint.c.patched 2006-08-01 10:24:12.000000000 +0200 @@ -42,6 +42,31 @@ +/* Calculate the bit index of a set element. A set is handled as an array + of 32 bit integer elements by most Pascal compilers, and in each element + individual bits (selected using "1 << (bitnr % 32)") are set/unset. This + means that on little endian sets, set element X corresponds to bit + number X of the array as a whole. On big endian systems set element X + however corresponds to bit number (X - X % 32) + (31 - X % 32) == + X - 2 * (X % 32) + 31 + + ELEMENT is the ordinal of the set element + + IS_BITSTRING notes that this is a bitstring and not a set, and therefore + the index should not be changed for big endian systems either. + +*/ + +static int +pascal_calculate_set_bit_index(int element, int is_bitstring) +{ + if (!is_bitstring && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) + return element - 2 * (element % 32) + 31; + else + return element; +} + + /* Print data of type TYPE located at VALADDR (within GDB), which came from the inferior at address ADDRESS, onto stdio stream STREAM according to FORMAT (a letter or 0 for natural format). The data at VALADDR is in @@ -476,7 +501,7 @@ for (i = low_bound; i <= high_bound; i++) { - int element = value_bit_index (type, valaddr + embedded_offset, i); + int element = value_bit_index (type, valaddr + embedded_offset, pascal_calculate_set_bit_index(i,is_bitstring)); if (element < 0) { i = element; @@ -491,12 +516,12 @@ print_type_scalar (range, i, stream); need_comma = 1; - if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i)) + if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, pascal_calculate_set_bit_index(++i,is_bitstring))) { int j = i; fputs_filtered ("..", stream); while (i + 1 <= high_bound - && value_bit_index (type, valaddr + embedded_offset, ++i)) + && value_bit_index (type, valaddr + embedded_offset, pascal_calculate_set_bit_index(++i,is_bitstring))) j = i; print_type_scalar (range, j, stream); }