From 1b6b755e91408011fa74f0a245369c1979586f9e Mon Sep 17 00:00:00 2001 From: Luis Machado Date: Wed, 14 Apr 2021 11:20:18 -0300 Subject: Print bfloat16 DWARF types correctly Even if the DWARF information contains a bfloat16 base type (__bf16), a variable of such type will still be printed using the IEEE half float format, which is wrong. This patch teaches GDB how to pick the bfloat16 format for __bf16 types in DWARF (based on the base type name) and uses IEEE half float for all the other 16-bit float formats. Tested on aarch64-linux/x86_64-linux. OK? gdb/ChangeLog: 2021-04-16 Luis Machado * arch-utils.c (default_floatformat_for_type): Handle bfloat16. gdb/testsuite: 2021-04-16 Luis Machado * gdb.dwarf2/dw2-bfloat16.exp: New file. --- gdb/arch-utils.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gdb/arch-utils.c') diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 0017e70..e1d5afd 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -279,7 +279,13 @@ default_floatformat_for_type (struct gdbarch *gdbarch, { const struct floatformat **format = NULL; - if (len == gdbarch_half_bit (gdbarch)) + /* Check if this is a bfloat16 type. It has the same size as the + IEEE half float type, so we use the base type name to tell them + apart. */ + if (name != nullptr && strcmp (name, "__bf16") == 0 + && len == gdbarch_bfloat16_bit (gdbarch)) + format = gdbarch_bfloat16_format (gdbarch); + else if (len == gdbarch_half_bit (gdbarch)) format = gdbarch_half_format (gdbarch); else if (len == gdbarch_float_bit (gdbarch)) format = gdbarch_float_format (gdbarch); -- cgit v1.1