This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/2] Suppress printing of empty bitfields when printing flags
- From: Alan Hayward <Alan dot Hayward at arm dot com>
- To: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Cc: nd <nd at arm dot com>, Alan Hayward <Alan dot Hayward at arm dot com>
- Date: Thu, 6 Jun 2019 12:23:24 +0000
- Subject: [PATCH 2/2] Suppress printing of empty bitfields when printing flags
- References: <20190606122240.10406-1-alan.hayward@arm.com>
Consider a variable containing:
flags A=1 and B=0, 2 bit ranges X=3 and Y=0
When printing, empty flags are suppressed, giving:
$1 = [ A X=3 Y=0 ]
For consistency, it makes sense to also suppress any bit ranges which are
also 0. This now gives us:
$2 = [ A X=3 ]
Consider the CPSR register on AArch64 made up of many flags and bitfields.
DIT is a single bit flag, only used on Armv8.4-A, and TCO is a 2 bit field
only used on Armv8.5-A. Printing this in the existing code on Armv8.1-A
gives:
$3 = [C Z TCO=0]
This is confusing for the Armv8.1-A user as TCO does not exist, and would
be better shown as:
$4 = [C Z]
gdb/ChangeLog:
2019-06-06 Alan Hayward <alan.hayward@arm.com>
* valprint.c (val_print_type_code_flags): Suppress printing of
empty bitfields.
---
gdb/valprint.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 4c3d67a9ff..1e05eb0270 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1225,7 +1225,15 @@ val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
fputs_filtered ("[", stream);
for (field = 0; field < nfields; field++)
{
- if (TYPE_FIELD_NAME (type, field)[0] != '\0')
+ unsigned field_len = TYPE_FIELD_BITSIZE (type, field);
+ ULONGEST field_val
+ = val >> (TYPE_FIELD_BITPOS (type, field) - field_len + 1);
+ const char *field_name = TYPE_FIELD_NAME (type, field);
+
+ if (field_len < sizeof (ULONGEST) * TARGET_CHAR_BIT)
+ field_val &= ((ULONGEST) 1 << field_len) - 1;
+
+ if (field_name[0] != '\0' && field_val != 0)
{
struct type *field_type = TYPE_FIELD_TYPE (type, field);
@@ -1234,22 +1242,11 @@ val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
problematic place to notify the user of an internal error
though. Instead just fall through and print the field as an
int. */
- && TYPE_FIELD_BITSIZE (type, field) == 1)
- {
- if (val & ((ULONGEST)1 << TYPE_FIELD_BITPOS (type, field)))
- fprintf_filtered (stream, " %s",
- TYPE_FIELD_NAME (type, field));
- }
+ && field_len == 1)
+ fprintf_filtered (stream, " %s", field_name);
else
{
- unsigned field_len = TYPE_FIELD_BITSIZE (type, field);
- ULONGEST field_val
- = val >> (TYPE_FIELD_BITPOS (type, field) - field_len + 1);
-
- if (field_len < sizeof (ULONGEST) * TARGET_CHAR_BIT)
- field_val &= ((ULONGEST) 1 << field_len) - 1;
- fprintf_filtered (stream, " %s=",
- TYPE_FIELD_NAME (type, field));
+ fprintf_filtered (stream, " %s=", field_name);
if (TYPE_CODE (field_type) == TYPE_CODE_ENUM)
generic_val_print_enum_1 (field_type, field_val, stream);
else
--
2.20.1 (Apple Git-117)