From: Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/7] Use .def file to stringify type codes
Date: Mon, 25 Sep 2023 22:58:10 +0100 [thread overview]
Message-ID: <20230925215810.jhxq35iznktykrzl@octopus> (raw)
In-Reply-To: <20230921-field-bits-v1-1-201285360900@adacore.com>
Hi Tom,
On Thu, Sep 21, 2023 at 12:01:28PM -0600, Tom Tromey via Gdb-patches wrote:
> This changes recursive_dump_type to reuse the type-codes.def file when
> stringifying type codes.
> ---
> gdb/gdbtypes.c | 99 +++++++++++-----------------------------------------------
> 1 file changed, 18 insertions(+), 81 deletions(-)
>
> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index 7011fddd695..18aa8e5c29e 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -5099,6 +5099,23 @@ dump_dynamic_prop (dynamic_prop const& prop)
> }
> }
>
> +/* Return a string that represents a type code. */
> +static const char *
> +type_code_name (type_code code)
> +{
> + switch (code)
> + {
> +#define OP(X) case X: return # X;
> +#include "type-codes.def"
> +#undef OP
> +
> + case TYPE_CODE_UNDEF:
> + return "TYPE_CODE_UNDEF";
> + default:
> + return "UNKNOWN TYPE CODE";
Is this default "just" to make the compiler happy? I don't expect it
should ever executed. If so, I usually prefer the following construct:
static const char *
foo (some_enume e)
{
switch (e)
{
case A:
return "A";
case B:
return "B";
[...]
/* No "default:". */
}
return "unknown";
}
The return after the switch block avoids the "control reaches end of
non-void function" error, but since there is no "default:" the compiler
can warn if some enumerator is not covered by the switch.
That being said, given how type_code is constructed, the
"#include type-codes.def" make it really unlikely that type_code_name
can evolve without having this function evolve as well.
Best,
Lancelot.
> + }
> +}
> +
> void
> recursive_dump_type (struct type *type, int spaces)
> {
> @@ -5136,87 +5153,7 @@ recursive_dump_type (struct type *type, int spaces)
> type->name () ? type->name () : "<NULL>",
> host_address_to_string (type->name ()));
> gdb_printf ("%*scode 0x%x ", spaces, "", type->code ());
> - switch (type->code ())
> - {
> - case TYPE_CODE_UNDEF:
> - gdb_printf ("(TYPE_CODE_UNDEF)");
> - break;
> - case TYPE_CODE_PTR:
> - gdb_printf ("(TYPE_CODE_PTR)");
> - break;
> - case TYPE_CODE_ARRAY:
> - gdb_printf ("(TYPE_CODE_ARRAY)");
> - break;
> - case TYPE_CODE_STRUCT:
> - gdb_printf ("(TYPE_CODE_STRUCT)");
> - break;
> - case TYPE_CODE_UNION:
> - gdb_printf ("(TYPE_CODE_UNION)");
> - break;
> - case TYPE_CODE_ENUM:
> - gdb_printf ("(TYPE_CODE_ENUM)");
> - break;
> - case TYPE_CODE_FLAGS:
> - gdb_printf ("(TYPE_CODE_FLAGS)");
> - break;
> - case TYPE_CODE_FUNC:
> - gdb_printf ("(TYPE_CODE_FUNC)");
> - break;
> - case TYPE_CODE_INT:
> - gdb_printf ("(TYPE_CODE_INT)");
> - break;
> - case TYPE_CODE_FLT:
> - gdb_printf ("(TYPE_CODE_FLT)");
> - break;
> - case TYPE_CODE_VOID:
> - gdb_printf ("(TYPE_CODE_VOID)");
> - break;
> - case TYPE_CODE_SET:
> - gdb_printf ("(TYPE_CODE_SET)");
> - break;
> - case TYPE_CODE_RANGE:
> - gdb_printf ("(TYPE_CODE_RANGE)");
> - break;
> - case TYPE_CODE_STRING:
> - gdb_printf ("(TYPE_CODE_STRING)");
> - break;
> - case TYPE_CODE_ERROR:
> - gdb_printf ("(TYPE_CODE_ERROR)");
> - break;
> - case TYPE_CODE_MEMBERPTR:
> - gdb_printf ("(TYPE_CODE_MEMBERPTR)");
> - break;
> - case TYPE_CODE_METHODPTR:
> - gdb_printf ("(TYPE_CODE_METHODPTR)");
> - break;
> - case TYPE_CODE_METHOD:
> - gdb_printf ("(TYPE_CODE_METHOD)");
> - break;
> - case TYPE_CODE_REF:
> - gdb_printf ("(TYPE_CODE_REF)");
> - break;
> - case TYPE_CODE_CHAR:
> - gdb_printf ("(TYPE_CODE_CHAR)");
> - break;
> - case TYPE_CODE_BOOL:
> - gdb_printf ("(TYPE_CODE_BOOL)");
> - break;
> - case TYPE_CODE_COMPLEX:
> - gdb_printf ("(TYPE_CODE_COMPLEX)");
> - break;
> - case TYPE_CODE_TYPEDEF:
> - gdb_printf ("(TYPE_CODE_TYPEDEF)");
> - break;
> - case TYPE_CODE_NAMESPACE:
> - gdb_printf ("(TYPE_CODE_NAMESPACE)");
> - break;
> - case TYPE_CODE_FIXED_POINT:
> - gdb_printf ("(TYPE_CODE_FIXED_POINT)");
> - break;
> - default:
> - gdb_printf ("(UNKNOWN TYPE CODE)");
> - break;
> - }
> + gdb_printf ("(%s)", type_code_name (type->code ()));
> gdb_puts ("\n");
> gdb_printf ("%*slength %s\n", spaces, "",
> pulongest (type->length ()));
>
> --
> 2.40.1
>
next prev parent reply other threads:[~2023-09-25 21:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-21 18:01 [PATCH 0/7] Remove char-based bitfield macros Tom Tromey via Gdb-patches
2023-09-21 18:01 ` [PATCH 1/7] Use .def file to stringify type codes Tom Tromey via Gdb-patches
2023-09-25 21:58 ` Lancelot SIX via Gdb-patches [this message]
2023-09-26 13:10 ` Tom Tromey via Gdb-patches
2023-09-21 18:01 ` [PATCH 2/7] Print field accessibility inline Tom Tromey via Gdb-patches
2023-09-21 18:01 ` [PATCH 3/7] Remove byte vectors from cplus_struct_type Tom Tromey via Gdb-patches
2023-09-25 22:32 ` Lancelot SIX via Gdb-patches
2023-10-27 14:20 ` Tom Tromey
2023-09-21 18:01 ` [PATCH 4/7] Add field::is_public Tom Tromey via Gdb-patches
2023-09-21 18:01 ` [PATCH 5/7] Remove some QUIT calls from need_access_label_p Tom Tromey via Gdb-patches
2023-09-21 18:01 ` [PATCH 6/7] Remove some type field accessor macros Tom Tromey via Gdb-patches
2023-09-21 18:01 ` [PATCH 7/7] Remove char-based bitfield macros Tom Tromey via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230925215810.jhxq35iznktykrzl@octopus \
--to=gdb-patches@sourceware.org \
--cc=lsix@lancelotsix.com \
--cc=tromey@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox