* [review] Add scalar_storage_order support for floating point
@ 2019-11-27 18:48 Tom Tromey (Code Review)
2019-11-27 22:02 ` Simon Marchi (Code Review)
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Tom Tromey (Code Review) @ 2019-11-27 18:48 UTC (permalink / raw)
To: gdb-patches
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/727
......................................................................
Add scalar_storage_order support for floating point
Testing the scalar_storage_order patch pointed out that it does not
handle floating point properly. This patch fixes this problem.
gdb/ChangeLog
2019-11-27 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (dwarf2_init_float_type)
(dwarf2_init_complex_target_type): Add byte_order parameter.
(read_base_type): Compute byte order earlier.
* gdbtypes.c (init_float_type): Add byte_order parameter.
* gdbtypes.h (init_float_type): Add byte_order parameter.
gdb/testsuite/ChangeLog
2019-11-27 Tom Tromey <tromey@adacore.com>
* gdb.base/endianity.c (struct otherendian) <f>: New field.
(main): Initialize it.
* gdb.base/endianity.exp: Update.
Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
---
M gdb/ChangeLog
M gdb/dwarf2read.c
M gdb/gdbtypes.c
M gdb/gdbtypes.h
M gdb/testsuite/ChangeLog
M gdb/testsuite/gdb.base/endianity.c
M gdb/testsuite/gdb.base/endianity.exp
7 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f1ed42a..66afaea 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2019-11-27 Tom Tromey <tromey@adacore.com>
+ * dwarf2read.c (dwarf2_init_float_type)
+ (dwarf2_init_complex_target_type): Add byte_order parameter.
+ (read_base_type): Compute byte order earlier.
+ * gdbtypes.c (init_float_type): Add byte_order parameter.
+ * gdbtypes.h (init_float_type): Add byte_order parameter.
+
+2019-11-27 Tom Tromey <tromey@adacore.com>
+
* dwarf2read.h (struct dwarf2_per_objfile): Remove unnecessary
backslashes.
* cp-support.c: Remove unnecessary backslashes.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1ca801c..cc815a2 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -17552,7 +17552,7 @@
static struct type *
dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
- const char *name_hint)
+ const char *name_hint, enum bfd_endian byte_order)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const struct floatformat **format;
@@ -17560,7 +17560,7 @@
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format)
- type = init_float_type (objfile, bits, name, format);
+ type = init_float_type (objfile, bits, name, format, byte_order);
else
type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
@@ -17599,7 +17599,8 @@
static struct type *
dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
struct objfile *objfile,
- int bits, const char *name_hint)
+ int bits, const char *name_hint,
+ enum bfd_endian byte_order)
{
gdbarch *gdbarch = get_objfile_arch (objfile);
struct type *tt = nullptr;
@@ -17648,7 +17649,7 @@
tt = nullptr;
const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
- return dwarf2_init_float_type (objfile, bits, name, name_hint);
+ return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
}
/* Find a representation of a given base type and install
@@ -17679,6 +17680,17 @@
endianity = DW_UNSND (attr);
arch = get_objfile_arch (objfile);
+ enum bfd_endian byte_order = gdbarch_byte_order (arch);
+ switch (endianity)
+ {
+ case DW_END_big:
+ byte_order = BFD_ENDIAN_BIG;
+ break;
+ case DW_END_little:
+ byte_order = BFD_ENDIAN_LITTLE;
+ break;
+ }
+
switch (encoding)
{
case DW_ATE_address:
@@ -17690,14 +17702,15 @@
type = init_boolean_type (objfile, bits, 1, name);
break;
case DW_ATE_complex_float:
- type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name);
+ type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
+ byte_order);
type = init_complex_type (objfile, name, type);
break;
case DW_ATE_decimal_float:
type = init_decfloat_type (objfile, bits, name);
break;
case DW_ATE_float:
- type = dwarf2_init_float_type (objfile, bits, name, name);
+ type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
break;
case DW_ATE_signed:
type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
@@ -17755,17 +17768,7 @@
maybe_set_alignment (cu, die, type);
- switch (endianity)
- {
- case DW_END_big:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_LITTLE)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- case DW_END_little:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- }
+ TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
return set_die_type (die, type, cu);
}
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 31c1a7b..ff89009 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2909,10 +2909,15 @@
struct type *
init_float_type (struct objfile *objfile,
int bit, const char *name,
- const struct floatformat **floatformats)
+ const struct floatformat **floatformats,
+ enum bfd_endian byte_order)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
- const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
+ if (byte_order == BFD_ENDIAN_UNKNOWN)
+ {
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ byte_order = gdbarch_byte_order (gdbarch);
+ }
+ const struct floatformat *fmt = floatformats[byte_order];
struct type *t;
bit = verify_floatformat (bit, fmt);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 8fc770c..dc4cb3e 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1804,7 +1804,8 @@
extern struct type *init_boolean_type (struct objfile *, int, int,
const char *);
extern struct type *init_float_type (struct objfile *, int, const char *,
- const struct floatformat **);
+ const struct floatformat **,
+ enum bfd_endian = BFD_ENDIAN_UNKNOWN);
extern struct type *init_decfloat_type (struct objfile *, int, const char *);
extern struct type *init_complex_type (struct objfile *, const char *,
struct type *);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 93e94f8..9931534 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-11-27 Tom Tromey <tromey@adacore.com>
+
+ * gdb.base/endianity.c (struct otherendian) <f>: New field.
+ (main): Initialize it.
+ * gdb.base/endianity.exp: Update.
+
2019-11-27 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.mi/mi-fortran-modules-2.f90: New file.
diff --git a/gdb/testsuite/gdb.base/endianity.c b/gdb/testsuite/gdb.base/endianity.c
index 5ab090d..57378c2 100644
--- a/gdb/testsuite/gdb.base/endianity.c
+++ b/gdb/testsuite/gdb.base/endianity.c
@@ -21,6 +21,8 @@
{
int v;
short w;
+ float f;
+ __complex__ float cplx;
}
#if defined __GNUC__ && (__GNUC__ >= 6)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -39,7 +41,7 @@
int
main (void)
{
- struct otherendian o = {3,2};
+ struct otherendian o = {3, 2, 23.5, 1.25 + 7.25i};
do_nothing (&o); /* START */
}
diff --git a/gdb/testsuite/gdb.base/endianity.exp b/gdb/testsuite/gdb.base/endianity.exp
index 80df012..a6ddea3 100644
--- a/gdb/testsuite/gdb.base/endianity.exp
+++ b/gdb/testsuite/gdb.base/endianity.exp
@@ -25,10 +25,12 @@
return -1
}
-gdb_test "print o" "= {v = 3, w = 2}" "print o before assignment"
+gdb_test "print o" "= {v = 3, w = 2, f = 23.5, cplx = 1.25 \\+ 7.25 \\* I}" \
+ "print o before assignment"
gdb_test "print o.v = 4" "= 4"
gdb_test "print o.w = 3" "= 3"
+gdb_test "print o.f = 1.5" "= 1.5"
# scalar_storage_order requires gcc >= 6
if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
@@ -37,4 +39,5 @@
gdb_test "x/x &o.v" "0x04000000"
gdb_test "x/xh &o.w" "0x0300"
-gdb_test "print o" "= {v = 4, w = 3}" "print o after assignment"
+gdb_test "print o" "= {v = 4, w = 3, f = 1.5, cplx = 1.25 \\+ 7.25 \\* I}" \
+ "print o after assignment"
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
Gerrit-Change-Number: 727
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newchange
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review] Add scalar_storage_order support for floating point
2019-11-27 18:48 [review] Add scalar_storage_order support for floating point Tom Tromey (Code Review)
@ 2019-11-27 22:02 ` Simon Marchi (Code Review)
2019-12-03 21:30 ` Tom Tromey (Code Review)
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi (Code Review) @ 2019-11-27 22:02 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
Simon Marchi has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/727
......................................................................
Patch Set 1:
(4 comments)
| --- gdb/dwarf2read.c
| +++ gdb/dwarf2read.c
| @@ -17681,8 +17682,19 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
| arch = get_objfile_arch (objfile);
| + enum bfd_endian byte_order = gdbarch_byte_order (arch);
| + switch (endianity)
| + {
| + case DW_END_big:
| + byte_order = BFD_ENDIAN_BIG;
| + break;
| + case DW_END_little:
| + byte_order = BFD_ENDIAN_LITTLE;
| + break;
PS1, Line 17691:
Not really related to this patch, since this is pre-exising code, but
what do you think of complaining if `endianity` has another value than
_big or _little?
| + }
| +
| switch (encoding)
| {
| case DW_ATE_address:
| /* Turn DW_ATE_address into a void * pointer. */
| type = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
| type = init_pointer_type (objfile, bits, name, type);
| break;
| --- gdb/gdbtypes.c
| +++ gdb/gdbtypes.c
| @@ -2898,18 +2898,15 @@ init_boolean_type (struct objfile *objfile,
| if (unsigned_p)
| TYPE_UNSIGNED (t) = 1;
|
| return t;
| }
|
| /* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
| BIT is the type size in bits; if BIT equals -1, the size is
| determined by the floatformat. NAME is the type name. Set the
| TYPE_FLOATFORMAT from FLOATFORMATS. */
PS1, Line 2907:
Could you document the new parameter (especially the behavior for
_UNKNOWN)?
|
| struct type *
| init_float_type (struct objfile *objfile,
| int bit, const char *name,
| - const struct floatformat **floatformats)
| -{
| - struct gdbarch *gdbarch = get_objfile_arch (objfile);
| - const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
| + const struct floatformat **floatformats,
| --- gdb/testsuite/gdb.base/endianity.c
| +++ gdb/testsuite/gdb.base/endianity.c
| @@ -15,17 +15,19 @@ /* This testcase is part of GDB, the GNU debugger.
| You should have received a copy of the GNU General Public License
| along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
| /* This tests the handling of dwarf attributes:
| DW_AT_endianity, DW_END_big, and DW_END_little. */
| struct otherendian
| {
| int v;
| short w;
| + float f;
PS1, Line 24:
I wonder if we should test double too, or if it would be superfluous?
| + __complex__ float cplx;
| }
| #if defined __GNUC__ && (__GNUC__ >= 6)
| #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
| __attribute__( ( scalar_storage_order( "big-endian" ) ) )
| #else
| __attribute__( ( scalar_storage_order( "little-endian" ) ) )
| #endif
| #endif
| --- gdb/testsuite/gdb.base/endianity.exp
| +++ gdb/testsuite/gdb.base/endianity.exp
| @@ -25,16 +25,17 @@ if ![runto "endianity.c:$bp_location" ] then {
| return -1
| }
|
| -gdb_test "print o" "= {v = 3, w = 2}" "print o before assignment"
| +gdb_test "print o" "= {v = 3, w = 2, f = 23.5, cplx = 1.25 \\+ 7.25 \\* I}" \
| + "print o before assignment"
|
| gdb_test "print o.v = 4" "= 4"
| gdb_test "print o.w = 3" "= 3"
| +gdb_test "print o.f = 1.5" "= 1.5"
PS1, Line 33:
Just wondering why we don't set cplx, does gdb not offer a way to set
complex?
|
| # scalar_storage_order requires gcc >= 6
| if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
| setup_xfail "*-*-*"
| }
| gdb_test "x/x &o.v" "0x04000000"
| gdb_test "x/xh &o.w" "0x0300"
|
| -gdb_test "print o" "= {v = 4, w = 3}" "print o after assignment"
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
Gerrit-Change-Number: 727
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Comment-Date: Wed, 27 Nov 2019 22:02:04 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review] Add scalar_storage_order support for floating point
2019-11-27 18:48 [review] Add scalar_storage_order support for floating point Tom Tromey (Code Review)
2019-11-27 22:02 ` Simon Marchi (Code Review)
@ 2019-12-03 21:30 ` Tom Tromey (Code Review)
2019-12-04 14:36 ` [review v2] " Tom Tromey (Code Review)
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey (Code Review) @ 2019-12-03 21:30 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Tom Tromey has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/727
......................................................................
Patch Set 1:
(1 comment)
| --- gdb/testsuite/gdb.base/endianity.exp
| +++ gdb/testsuite/gdb.base/endianity.exp
| @@ -25,16 +25,17 @@ if ![runto "endianity.c:$bp_location" ] then {
| return -1
| }
|
| -gdb_test "print o" "= {v = 3, w = 2}" "print o before assignment"
| +gdb_test "print o" "= {v = 3, w = 2, f = 23.5, cplx = 1.25 \\+ 7.25 \\* I}" \
| + "print o before assignment"
|
| gdb_test "print o.v = 4" "= 4"
| gdb_test "print o.w = 3" "= 3"
| +gdb_test "print o.f = 1.5" "= 1.5"
PS1, Line 33:
> Just wondering why we don't set cplx, does gdb not offer a way to set complex?
I don't think there's a way. I went through the GCC node about
complex
types, and basically gdb doesn't implement any of it, and in fact
the way gdb print complex numbers for C is not a way that GCC can
read.
|
| # scalar_storage_order requires gcc >= 6
| if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
| setup_xfail "*-*-*"
| }
| gdb_test "x/x &o.v" "0x04000000"
| gdb_test "x/xh &o.w" "0x0300"
|
| -gdb_test "print o" "= {v = 4, w = 3}" "print o after assignment"
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
Gerrit-Change-Number: 727
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Comment-Date: Tue, 03 Dec 2019 21:30:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-MessageType: comment
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review v2] Add scalar_storage_order support for floating point
2019-11-27 18:48 [review] Add scalar_storage_order support for floating point Tom Tromey (Code Review)
2019-11-27 22:02 ` Simon Marchi (Code Review)
2019-12-03 21:30 ` Tom Tromey (Code Review)
@ 2019-12-04 14:36 ` Tom Tromey (Code Review)
2019-12-04 15:33 ` Simon Marchi (Code Review)
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey (Code Review) @ 2019-12-04 14:36 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/727
......................................................................
Add scalar_storage_order support for floating point
Testing the scalar_storage_order patch pointed out that it does not
handle floating point properly. This patch fixes this problem.
gdb/ChangeLog
2019-12-04 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (dwarf2_init_float_type)
(dwarf2_init_complex_target_type): Add byte_order parameter.
(read_base_type): Compute byte order earlier.
* gdbtypes.c (init_float_type): Add byte_order parameter.
* gdbtypes.h (init_float_type): Add byte_order parameter.
gdb/testsuite/ChangeLog
2019-12-04 Tom Tromey <tromey@adacore.com>
* gdb.base/endianity.c (struct otherendian) <f>: New field.
(main): Initialize it.
* gdb.base/endianity.exp: Update.
Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
---
M gdb/ChangeLog
M gdb/dwarf2read.c
M gdb/gdbtypes.c
M gdb/gdbtypes.h
M gdb/testsuite/ChangeLog
M gdb/testsuite/gdb.base/endianity.c
M gdb/testsuite/gdb.base/endianity.exp
7 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index aacc0c9..681ae48 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-04 Tom Tromey <tromey@adacore.com>
+
+ * dwarf2read.c (dwarf2_init_float_type)
+ (dwarf2_init_complex_target_type): Add byte_order parameter.
+ (read_base_type): Compute byte order earlier.
+ * gdbtypes.c (init_float_type): Add byte_order parameter.
+ * gdbtypes.h (init_float_type): Add byte_order parameter.
+
2019-12-04 Andrew Burgess <andrew.burgess@embecosm.com>
* mi/mi-symbol-cmds.c (mi_symbol_info): Take extra parameter, and
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 327837c..34513ad 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -17624,7 +17624,7 @@
static struct type *
dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
- const char *name_hint)
+ const char *name_hint, enum bfd_endian byte_order)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const struct floatformat **format;
@@ -17632,7 +17632,7 @@
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format)
- type = init_float_type (objfile, bits, name, format);
+ type = init_float_type (objfile, bits, name, format, byte_order);
else
type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
@@ -17671,7 +17671,8 @@
static struct type *
dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
struct objfile *objfile,
- int bits, const char *name_hint)
+ int bits, const char *name_hint,
+ enum bfd_endian byte_order)
{
gdbarch *gdbarch = get_objfile_arch (objfile);
struct type *tt = nullptr;
@@ -17720,7 +17721,7 @@
tt = nullptr;
const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
- return dwarf2_init_float_type (objfile, bits, name, name_hint);
+ return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
}
/* Find a representation of a given base type and install
@@ -17733,7 +17734,6 @@
struct type *type;
struct attribute *attr;
int encoding = 0, bits = 0;
- int endianity = 0;
const char *name;
gdbarch *arch;
@@ -17746,11 +17746,29 @@
name = dwarf2_name (die, cu);
if (!name)
complaint (_("DW_AT_name missing from DW_TAG_base_type"));
- attr = dwarf2_attr (die, DW_AT_endianity, cu);
- if (attr)
- endianity = DW_UNSND (attr);
arch = get_objfile_arch (objfile);
+ enum bfd_endian byte_order = gdbarch_byte_order (arch);
+
+ attr = dwarf2_attr (die, DW_AT_endianity, cu);
+ if (attr)
+ {
+ int endianity = DW_UNSND (attr);
+
+ switch (endianity)
+ {
+ case DW_END_big:
+ byte_order = BFD_ENDIAN_BIG;
+ break;
+ case DW_END_little:
+ byte_order = BFD_ENDIAN_LITTLE;
+ break;
+ default:
+ complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
+ break;
+ }
+ }
+
switch (encoding)
{
case DW_ATE_address:
@@ -17762,14 +17780,15 @@
type = init_boolean_type (objfile, bits, 1, name);
break;
case DW_ATE_complex_float:
- type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name);
+ type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
+ byte_order);
type = init_complex_type (objfile, name, type);
break;
case DW_ATE_decimal_float:
type = init_decfloat_type (objfile, bits, name);
break;
case DW_ATE_float:
- type = dwarf2_init_float_type (objfile, bits, name, name);
+ type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
break;
case DW_ATE_signed:
type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
@@ -17827,17 +17846,7 @@
maybe_set_alignment (cu, die, type);
- switch (endianity)
- {
- case DW_END_big:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_LITTLE)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- case DW_END_little:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- }
+ TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
return set_die_type (die, type, cu);
}
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f10f65d..0609634 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2976,15 +2976,22 @@
/* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
BIT is the type size in bits; if BIT equals -1, the size is
determined by the floatformat. NAME is the type name. Set the
- TYPE_FLOATFORMAT from FLOATFORMATS. */
+ TYPE_FLOATFORMAT from FLOATFORMATS. BYTE_ORDER is the byte order
+ to use. If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
+ order of the objfile's architecture is used. */
struct type *
init_float_type (struct objfile *objfile,
int bit, const char *name,
- const struct floatformat **floatformats)
+ const struct floatformat **floatformats,
+ enum bfd_endian byte_order)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
- const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
+ if (byte_order == BFD_ENDIAN_UNKNOWN)
+ {
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ byte_order = gdbarch_byte_order (gdbarch);
+ }
+ const struct floatformat *fmt = floatformats[byte_order];
struct type *t;
bit = verify_floatformat (bit, fmt);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 963314d..f6879e8 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1821,7 +1821,8 @@
extern struct type *init_boolean_type (struct objfile *, int, int,
const char *);
extern struct type *init_float_type (struct objfile *, int, const char *,
- const struct floatformat **);
+ const struct floatformat **,
+ enum bfd_endian = BFD_ENDIAN_UNKNOWN);
extern struct type *init_decfloat_type (struct objfile *, int, const char *);
extern struct type *init_complex_type (struct objfile *, const char *,
struct type *);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 112049f..1c8aa86 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-04 Tom Tromey <tromey@adacore.com>
+
+ * gdb.base/endianity.c (struct otherendian) <f>: New field.
+ (main): Initialize it.
+ * gdb.base/endianity.exp: Update.
+
2019-12-04 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.mi/mi-sym-info.exp: Add tests for -max-results parameter.
diff --git a/gdb/testsuite/gdb.base/endianity.c b/gdb/testsuite/gdb.base/endianity.c
index 5ab090d..42ee9ae 100644
--- a/gdb/testsuite/gdb.base/endianity.c
+++ b/gdb/testsuite/gdb.base/endianity.c
@@ -21,6 +21,9 @@
{
int v;
short w;
+ float f;
+ __complex__ float cplx;
+ double d;
}
#if defined __GNUC__ && (__GNUC__ >= 6)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -39,7 +42,7 @@
int
main (void)
{
- struct otherendian o = {3,2};
+ struct otherendian o = {3, 2, 23.5, 1.25 + 7.25i, 75};
do_nothing (&o); /* START */
}
diff --git a/gdb/testsuite/gdb.base/endianity.exp b/gdb/testsuite/gdb.base/endianity.exp
index 80df012..4277c1f 100644
--- a/gdb/testsuite/gdb.base/endianity.exp
+++ b/gdb/testsuite/gdb.base/endianity.exp
@@ -25,10 +25,13 @@
return -1
}
-gdb_test "print o" "= {v = 3, w = 2}" "print o before assignment"
+gdb_test "print o" "= {v = 3, w = 2, f = 23.5, cplx = 1.25 \\+ 7.25 \\* I, d = 75}" \
+ "print o before assignment"
gdb_test "print o.v = 4" "= 4"
gdb_test "print o.w = 3" "= 3"
+gdb_test "print o.f = 1.5" "= 1.5"
+gdb_test "print o.d = -23.125" "= -23.125"
# scalar_storage_order requires gcc >= 6
if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
@@ -37,4 +40,5 @@
gdb_test "x/x &o.v" "0x04000000"
gdb_test "x/xh &o.w" "0x0300"
-gdb_test "print o" "= {v = 4, w = 3}" "print o after assignment"
+gdb_test "print o" "= {v = 4, w = 3, f = 1.5, cplx = 1.25 \\+ 7.25 \\* I, d = -23.125}" \
+ "print o after assignment"
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
Gerrit-Change-Number: 727
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-MessageType: newpatchset
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review v2] Add scalar_storage_order support for floating point
2019-11-27 18:48 [review] Add scalar_storage_order support for floating point Tom Tromey (Code Review)
` (2 preceding siblings ...)
2019-12-04 14:36 ` [review v2] " Tom Tromey (Code Review)
@ 2019-12-04 15:33 ` Simon Marchi (Code Review)
2019-12-04 16:41 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-04 16:41 ` Sourceware to Gerrit sync (Code Review)
5 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi (Code Review) @ 2019-12-04 15:33 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
Simon Marchi has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/727
......................................................................
Patch Set 2: Code-Review+2
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
Gerrit-Change-Number: 727
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-Comment-Date: Wed, 04 Dec 2019 15:33:42 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pushed] Add scalar_storage_order support for floating point
2019-11-27 18:48 [review] Add scalar_storage_order support for floating point Tom Tromey (Code Review)
` (3 preceding siblings ...)
2019-12-04 15:33 ` Simon Marchi (Code Review)
@ 2019-12-04 16:41 ` Sourceware to Gerrit sync (Code Review)
2019-12-04 16:41 ` Sourceware to Gerrit sync (Code Review)
5 siblings, 0 replies; 7+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-04 16:41 UTC (permalink / raw)
To: Tom Tromey, gdb-patches; +Cc: Simon Marchi
Sourceware to Gerrit sync has submitted this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/727
......................................................................
Add scalar_storage_order support for floating point
Testing the scalar_storage_order patch pointed out that it does not
handle floating point properly. This patch fixes this problem.
gdb/ChangeLog
2019-12-04 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (dwarf2_init_float_type)
(dwarf2_init_complex_target_type): Add byte_order parameter.
(read_base_type): Compute byte order earlier.
* gdbtypes.c (init_float_type): Add byte_order parameter.
* gdbtypes.h (init_float_type): Add byte_order parameter.
gdb/testsuite/ChangeLog
2019-12-04 Tom Tromey <tromey@adacore.com>
* gdb.base/endianity.c (struct otherendian) <f>: New field.
(main): Initialize it.
* gdb.base/endianity.exp: Update.
Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
---
M gdb/ChangeLog
M gdb/dwarf2read.c
M gdb/gdbtypes.c
M gdb/gdbtypes.h
M gdb/testsuite/ChangeLog
M gdb/testsuite/gdb.base/endianity.c
M gdb/testsuite/gdb.base/endianity.exp
7 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8837a23..ffae608 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2019-12-04 Tom Tromey <tromey@adacore.com>
+ * dwarf2read.c (dwarf2_init_float_type)
+ (dwarf2_init_complex_target_type): Add byte_order parameter.
+ (read_base_type): Compute byte order earlier.
+ * gdbtypes.c (init_float_type): Add byte_order parameter.
+ * gdbtypes.h (init_float_type): Add byte_order parameter.
+
+2019-12-04 Tom Tromey <tromey@adacore.com>
+
* unittests/tui-selftests.c: Conditionally include tui-winsource.h.
2019-12-04 Tom Tromey <tromey@adacore.com>
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index f99061d..40d93c9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -17624,7 +17624,7 @@
static struct type *
dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
- const char *name_hint)
+ const char *name_hint, enum bfd_endian byte_order)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const struct floatformat **format;
@@ -17632,7 +17632,7 @@
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format)
- type = init_float_type (objfile, bits, name, format);
+ type = init_float_type (objfile, bits, name, format, byte_order);
else
type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
@@ -17671,7 +17671,8 @@
static struct type *
dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
struct objfile *objfile,
- int bits, const char *name_hint)
+ int bits, const char *name_hint,
+ enum bfd_endian byte_order)
{
gdbarch *gdbarch = get_objfile_arch (objfile);
struct type *tt = nullptr;
@@ -17720,7 +17721,7 @@
tt = nullptr;
const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
- return dwarf2_init_float_type (objfile, bits, name, name_hint);
+ return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
}
/* Find a representation of a given base type and install
@@ -17733,7 +17734,6 @@
struct type *type;
struct attribute *attr;
int encoding = 0, bits = 0;
- int endianity = 0;
const char *name;
gdbarch *arch;
@@ -17746,11 +17746,29 @@
name = dwarf2_name (die, cu);
if (!name)
complaint (_("DW_AT_name missing from DW_TAG_base_type"));
- attr = dwarf2_attr (die, DW_AT_endianity, cu);
- if (attr)
- endianity = DW_UNSND (attr);
arch = get_objfile_arch (objfile);
+ enum bfd_endian byte_order = gdbarch_byte_order (arch);
+
+ attr = dwarf2_attr (die, DW_AT_endianity, cu);
+ if (attr)
+ {
+ int endianity = DW_UNSND (attr);
+
+ switch (endianity)
+ {
+ case DW_END_big:
+ byte_order = BFD_ENDIAN_BIG;
+ break;
+ case DW_END_little:
+ byte_order = BFD_ENDIAN_LITTLE;
+ break;
+ default:
+ complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
+ break;
+ }
+ }
+
switch (encoding)
{
case DW_ATE_address:
@@ -17762,14 +17780,15 @@
type = init_boolean_type (objfile, bits, 1, name);
break;
case DW_ATE_complex_float:
- type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name);
+ type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
+ byte_order);
type = init_complex_type (objfile, name, type);
break;
case DW_ATE_decimal_float:
type = init_decfloat_type (objfile, bits, name);
break;
case DW_ATE_float:
- type = dwarf2_init_float_type (objfile, bits, name, name);
+ type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
break;
case DW_ATE_signed:
type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
@@ -17827,17 +17846,7 @@
maybe_set_alignment (cu, die, type);
- switch (endianity)
- {
- case DW_END_big:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_LITTLE)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- case DW_END_little:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- }
+ TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
return set_die_type (die, type, cu);
}
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f10f65d..0609634 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2976,15 +2976,22 @@
/* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
BIT is the type size in bits; if BIT equals -1, the size is
determined by the floatformat. NAME is the type name. Set the
- TYPE_FLOATFORMAT from FLOATFORMATS. */
+ TYPE_FLOATFORMAT from FLOATFORMATS. BYTE_ORDER is the byte order
+ to use. If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
+ order of the objfile's architecture is used. */
struct type *
init_float_type (struct objfile *objfile,
int bit, const char *name,
- const struct floatformat **floatformats)
+ const struct floatformat **floatformats,
+ enum bfd_endian byte_order)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
- const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
+ if (byte_order == BFD_ENDIAN_UNKNOWN)
+ {
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ byte_order = gdbarch_byte_order (gdbarch);
+ }
+ const struct floatformat *fmt = floatformats[byte_order];
struct type *t;
bit = verify_floatformat (bit, fmt);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 963314d..f6879e8 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1821,7 +1821,8 @@
extern struct type *init_boolean_type (struct objfile *, int, int,
const char *);
extern struct type *init_float_type (struct objfile *, int, const char *,
- const struct floatformat **);
+ const struct floatformat **,
+ enum bfd_endian = BFD_ENDIAN_UNKNOWN);
extern struct type *init_decfloat_type (struct objfile *, int, const char *);
extern struct type *init_complex_type (struct objfile *, const char *,
struct type *);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 112049f..1c8aa86 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-04 Tom Tromey <tromey@adacore.com>
+
+ * gdb.base/endianity.c (struct otherendian) <f>: New field.
+ (main): Initialize it.
+ * gdb.base/endianity.exp: Update.
+
2019-12-04 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.mi/mi-sym-info.exp: Add tests for -max-results parameter.
diff --git a/gdb/testsuite/gdb.base/endianity.c b/gdb/testsuite/gdb.base/endianity.c
index 5ab090d..42ee9ae 100644
--- a/gdb/testsuite/gdb.base/endianity.c
+++ b/gdb/testsuite/gdb.base/endianity.c
@@ -21,6 +21,9 @@
{
int v;
short w;
+ float f;
+ __complex__ float cplx;
+ double d;
}
#if defined __GNUC__ && (__GNUC__ >= 6)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -39,7 +42,7 @@
int
main (void)
{
- struct otherendian o = {3,2};
+ struct otherendian o = {3, 2, 23.5, 1.25 + 7.25i, 75};
do_nothing (&o); /* START */
}
diff --git a/gdb/testsuite/gdb.base/endianity.exp b/gdb/testsuite/gdb.base/endianity.exp
index 80df012..4277c1f 100644
--- a/gdb/testsuite/gdb.base/endianity.exp
+++ b/gdb/testsuite/gdb.base/endianity.exp
@@ -25,10 +25,13 @@
return -1
}
-gdb_test "print o" "= {v = 3, w = 2}" "print o before assignment"
+gdb_test "print o" "= {v = 3, w = 2, f = 23.5, cplx = 1.25 \\+ 7.25 \\* I, d = 75}" \
+ "print o before assignment"
gdb_test "print o.v = 4" "= 4"
gdb_test "print o.w = 3" "= 3"
+gdb_test "print o.f = 1.5" "= 1.5"
+gdb_test "print o.d = -23.125" "= -23.125"
# scalar_storage_order requires gcc >= 6
if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
@@ -37,4 +40,5 @@
gdb_test "x/x &o.v" "0x04000000"
gdb_test "x/xh &o.w" "0x0300"
-gdb_test "print o" "= {v = 4, w = 3}" "print o after assignment"
+gdb_test "print o" "= {v = 4, w = 3, f = 1.5, cplx = 1.25 \\+ 7.25 \\* I, d = -23.125}" \
+ "print o after assignment"
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
Gerrit-Change-Number: 727
Gerrit-PatchSet: 3
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: merged
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pushed] Add scalar_storage_order support for floating point
2019-11-27 18:48 [review] Add scalar_storage_order support for floating point Tom Tromey (Code Review)
` (4 preceding siblings ...)
2019-12-04 16:41 ` [pushed] " Sourceware to Gerrit sync (Code Review)
@ 2019-12-04 16:41 ` Sourceware to Gerrit sync (Code Review)
5 siblings, 0 replies; 7+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-04 16:41 UTC (permalink / raw)
To: Tom Tromey, Simon Marchi, gdb-patches
The original change was created by Tom Tromey.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/727
......................................................................
Add scalar_storage_order support for floating point
Testing the scalar_storage_order patch pointed out that it does not
handle floating point properly. This patch fixes this problem.
gdb/ChangeLog
2019-12-04 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (dwarf2_init_float_type)
(dwarf2_init_complex_target_type): Add byte_order parameter.
(read_base_type): Compute byte order earlier.
* gdbtypes.c (init_float_type): Add byte_order parameter.
* gdbtypes.h (init_float_type): Add byte_order parameter.
gdb/testsuite/ChangeLog
2019-12-04 Tom Tromey <tromey@adacore.com>
* gdb.base/endianity.c (struct otherendian) <f>: New field.
(main): Initialize it.
* gdb.base/endianity.exp: Update.
Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
---
M gdb/ChangeLog
M gdb/dwarf2read.c
M gdb/gdbtypes.c
M gdb/gdbtypes.h
M gdb/testsuite/ChangeLog
M gdb/testsuite/gdb.base/endianity.c
M gdb/testsuite/gdb.base/endianity.exp
7 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8837a23..ffae608 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2019-12-04 Tom Tromey <tromey@adacore.com>
+ * dwarf2read.c (dwarf2_init_float_type)
+ (dwarf2_init_complex_target_type): Add byte_order parameter.
+ (read_base_type): Compute byte order earlier.
+ * gdbtypes.c (init_float_type): Add byte_order parameter.
+ * gdbtypes.h (init_float_type): Add byte_order parameter.
+
+2019-12-04 Tom Tromey <tromey@adacore.com>
+
* unittests/tui-selftests.c: Conditionally include tui-winsource.h.
2019-12-04 Tom Tromey <tromey@adacore.com>
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index f99061d..40d93c9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -17624,7 +17624,7 @@
static struct type *
dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
- const char *name_hint)
+ const char *name_hint, enum bfd_endian byte_order)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const struct floatformat **format;
@@ -17632,7 +17632,7 @@
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format)
- type = init_float_type (objfile, bits, name, format);
+ type = init_float_type (objfile, bits, name, format, byte_order);
else
type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
@@ -17671,7 +17671,8 @@
static struct type *
dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
struct objfile *objfile,
- int bits, const char *name_hint)
+ int bits, const char *name_hint,
+ enum bfd_endian byte_order)
{
gdbarch *gdbarch = get_objfile_arch (objfile);
struct type *tt = nullptr;
@@ -17720,7 +17721,7 @@
tt = nullptr;
const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
- return dwarf2_init_float_type (objfile, bits, name, name_hint);
+ return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
}
/* Find a representation of a given base type and install
@@ -17733,7 +17734,6 @@
struct type *type;
struct attribute *attr;
int encoding = 0, bits = 0;
- int endianity = 0;
const char *name;
gdbarch *arch;
@@ -17746,11 +17746,29 @@
name = dwarf2_name (die, cu);
if (!name)
complaint (_("DW_AT_name missing from DW_TAG_base_type"));
- attr = dwarf2_attr (die, DW_AT_endianity, cu);
- if (attr)
- endianity = DW_UNSND (attr);
arch = get_objfile_arch (objfile);
+ enum bfd_endian byte_order = gdbarch_byte_order (arch);
+
+ attr = dwarf2_attr (die, DW_AT_endianity, cu);
+ if (attr)
+ {
+ int endianity = DW_UNSND (attr);
+
+ switch (endianity)
+ {
+ case DW_END_big:
+ byte_order = BFD_ENDIAN_BIG;
+ break;
+ case DW_END_little:
+ byte_order = BFD_ENDIAN_LITTLE;
+ break;
+ default:
+ complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
+ break;
+ }
+ }
+
switch (encoding)
{
case DW_ATE_address:
@@ -17762,14 +17780,15 @@
type = init_boolean_type (objfile, bits, 1, name);
break;
case DW_ATE_complex_float:
- type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name);
+ type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
+ byte_order);
type = init_complex_type (objfile, name, type);
break;
case DW_ATE_decimal_float:
type = init_decfloat_type (objfile, bits, name);
break;
case DW_ATE_float:
- type = dwarf2_init_float_type (objfile, bits, name, name);
+ type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
break;
case DW_ATE_signed:
type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
@@ -17827,17 +17846,7 @@
maybe_set_alignment (cu, die, type);
- switch (endianity)
- {
- case DW_END_big:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_LITTLE)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- case DW_END_little:
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
- TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
- break;
- }
+ TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
return set_die_type (die, type, cu);
}
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f10f65d..0609634 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2976,15 +2976,22 @@
/* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
BIT is the type size in bits; if BIT equals -1, the size is
determined by the floatformat. NAME is the type name. Set the
- TYPE_FLOATFORMAT from FLOATFORMATS. */
+ TYPE_FLOATFORMAT from FLOATFORMATS. BYTE_ORDER is the byte order
+ to use. If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
+ order of the objfile's architecture is used. */
struct type *
init_float_type (struct objfile *objfile,
int bit, const char *name,
- const struct floatformat **floatformats)
+ const struct floatformat **floatformats,
+ enum bfd_endian byte_order)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
- const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
+ if (byte_order == BFD_ENDIAN_UNKNOWN)
+ {
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ byte_order = gdbarch_byte_order (gdbarch);
+ }
+ const struct floatformat *fmt = floatformats[byte_order];
struct type *t;
bit = verify_floatformat (bit, fmt);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 963314d..f6879e8 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1821,7 +1821,8 @@
extern struct type *init_boolean_type (struct objfile *, int, int,
const char *);
extern struct type *init_float_type (struct objfile *, int, const char *,
- const struct floatformat **);
+ const struct floatformat **,
+ enum bfd_endian = BFD_ENDIAN_UNKNOWN);
extern struct type *init_decfloat_type (struct objfile *, int, const char *);
extern struct type *init_complex_type (struct objfile *, const char *,
struct type *);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 112049f..1c8aa86 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-04 Tom Tromey <tromey@adacore.com>
+
+ * gdb.base/endianity.c (struct otherendian) <f>: New field.
+ (main): Initialize it.
+ * gdb.base/endianity.exp: Update.
+
2019-12-04 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.mi/mi-sym-info.exp: Add tests for -max-results parameter.
diff --git a/gdb/testsuite/gdb.base/endianity.c b/gdb/testsuite/gdb.base/endianity.c
index 5ab090d..42ee9ae 100644
--- a/gdb/testsuite/gdb.base/endianity.c
+++ b/gdb/testsuite/gdb.base/endianity.c
@@ -21,6 +21,9 @@
{
int v;
short w;
+ float f;
+ __complex__ float cplx;
+ double d;
}
#if defined __GNUC__ && (__GNUC__ >= 6)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -39,7 +42,7 @@
int
main (void)
{
- struct otherendian o = {3,2};
+ struct otherendian o = {3, 2, 23.5, 1.25 + 7.25i, 75};
do_nothing (&o); /* START */
}
diff --git a/gdb/testsuite/gdb.base/endianity.exp b/gdb/testsuite/gdb.base/endianity.exp
index 80df012..4277c1f 100644
--- a/gdb/testsuite/gdb.base/endianity.exp
+++ b/gdb/testsuite/gdb.base/endianity.exp
@@ -25,10 +25,13 @@
return -1
}
-gdb_test "print o" "= {v = 3, w = 2}" "print o before assignment"
+gdb_test "print o" "= {v = 3, w = 2, f = 23.5, cplx = 1.25 \\+ 7.25 \\* I, d = 75}" \
+ "print o before assignment"
gdb_test "print o.v = 4" "= 4"
gdb_test "print o.w = 3" "= 3"
+gdb_test "print o.f = 1.5" "= 1.5"
+gdb_test "print o.d = -23.125" "= -23.125"
# scalar_storage_order requires gcc >= 6
if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
@@ -37,4 +40,5 @@
gdb_test "x/x &o.v" "0x04000000"
gdb_test "x/xh &o.w" "0x0300"
-gdb_test "print o" "= {v = 4, w = 3}" "print o after assignment"
+gdb_test "print o" "= {v = 4, w = 3, f = 1.5, cplx = 1.25 \\+ 7.25 \\* I, d = -23.125}" \
+ "print o after assignment"
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440
Gerrit-Change-Number: 727
Gerrit-PatchSet: 3
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newpatchset
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-12-04 16:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-27 18:48 [review] Add scalar_storage_order support for floating point Tom Tromey (Code Review)
2019-11-27 22:02 ` Simon Marchi (Code Review)
2019-12-03 21:30 ` Tom Tromey (Code Review)
2019-12-04 14:36 ` [review v2] " Tom Tromey (Code Review)
2019-12-04 15:33 ` Simon Marchi (Code Review)
2019-12-04 16:41 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-04 16:41 ` Sourceware to Gerrit sync (Code Review)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).