aboutsummaryrefslogtreecommitdiff
path: root/gdb/value.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2019-05-13 13:21:48 -0600
committerTom Tromey <tromey@adacore.com>2019-09-03 10:20:40 -0600
commit4e962e74e45f2b0365e5b21504f33480c468ff00 (patch)
tree7f20b55fbf46c379db243e1bcbf8a84ccd55c028 /gdb/value.c
parentf44b758d3133ef0a7f3131c1e12ed20feb33ee61 (diff)
downloadgdb-4e962e74e45f2b0365e5b21504f33480c468ff00.zip
gdb-4e962e74e45f2b0365e5b21504f33480c468ff00.tar.gz
gdb-4e962e74e45f2b0365e5b21504f33480c468ff00.tar.bz2
Handle biased types
In Ada, the programmer can request that a range type with a non-zero base be stored in the minimal number of bits required for the range. This is done by biasing the values; so, for example, a range of -7..-4 may be stored as two bits with a bias of -7. This patch implements this for gdb. It is done by adding a bias to struct range_bounds and then adjusting a few spots to handle this. The test case is written to use -fgnat-encodings=minimal, but a future compiler patch will change the compiler to emit DW_AT_GNU_bias with -fgnat-encodings=gdb. It seemed good to get the gdb patch in first. Tested on x86-64 Fedora 29; plus a variety of targets using AdaCore's internal test suite. gdb/ChangeLog 2019-09-03 Tom Tromey <tromey@adacore.com> * ada-valprint.c (ada_val_print_num): Don't recurse for range types. (has_negatives): Unbias a range type bound. * dwarf2read.c (read_subrange_type): Handle DW_AT_GNU_bias. * gdbtypes.c (operator==): Handle new field. (create_range_type): Add "bias" parameter. (create_static_range_type, resolve_dynamic_range): Update. * gdbtypes.h (struct range_bounds) <bias>: New member. (create_range_type): Add bias parameter. * printcmd.c (print_scalar_formatted): Unbias range types. * value.c (unpack_long): Unbias range types. (pack_long): Bias range types. gdb/testsuite/ChangeLog 2019-09-03 Tom Tromey <tromey@adacore.com> * gdb.ada/bias.exp: New file. * gdb.ada/bias/bias.adb: New file. * gdb.ada/print_chars.exp: Add regression test. * gdb.ada/print_chars/foo.adb (My_Character): New type. (MC): New variable.
Diffstat (limited to 'gdb/value.c')
-rw-r--r--gdb/value.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/gdb/value.c b/gdb/value.c
index 9103d8f..d58a964 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2751,10 +2751,16 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
case TYPE_CODE_CHAR:
case TYPE_CODE_RANGE:
case TYPE_CODE_MEMBERPTR:
- if (nosign)
- return extract_unsigned_integer (valaddr, len, byte_order);
- else
- return extract_signed_integer (valaddr, len, byte_order);
+ {
+ LONGEST result;
+ if (nosign)
+ result = extract_unsigned_integer (valaddr, len, byte_order);
+ else
+ result = extract_signed_integer (valaddr, len, byte_order);
+ if (code == TYPE_CODE_RANGE)
+ result += TYPE_RANGE_DATA (type)->bias;
+ return result;
+ }
case TYPE_CODE_FLT:
case TYPE_CODE_DECFLOAT:
@@ -3315,12 +3321,14 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
switch (TYPE_CODE (type))
{
+ case TYPE_CODE_RANGE:
+ num -= TYPE_RANGE_DATA (type)->bias;
+ /* Fall through. */
case TYPE_CODE_INT:
case TYPE_CODE_CHAR:
case TYPE_CODE_ENUM:
case TYPE_CODE_FLAGS:
case TYPE_CODE_BOOL:
- case TYPE_CODE_RANGE:
case TYPE_CODE_MEMBERPTR:
store_signed_integer (buf, len, byte_order, num);
break;