* [RFA] New function type_code_name.
@ 2002-12-11 17:41 Klee Dienes
2002-12-12 9:12 ` Richard Earnshaw
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Klee Dienes @ 2002-12-11 17:41 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 208 bytes --]
This patch moves the type-printing code from recursive_dump_type() into
the new function type_code_name(). It's handy when one wants to use
the type code of a type in debugging or warning/error messages.
[-- Attachment #2: type-code-name.txt --]
[-- Type: text/plain, Size: 5467 bytes --]
2002-12-11 Klee Dienes <kdienes@apple.com>
* gdbtypes.h (type_code_name): Add prototype.
* gdbtypes.c (type_code_name): New function. Returns a
constant string containing the ASCII name of the type code.
(recursive_dump_type): Use type_code_name.
Index: gdbtypes.c
===================================================================
RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/gdbtypes.c,v
retrieving revision 1.25
diff -u -r1.25 gdbtypes.c
--- gdbtypes.c 2002/12/01 04:40:19 1.25
+++ gdbtypes.c 2002/12/12 00:06:45
@@ -3046,6 +3046,64 @@
static struct obstack dont_print_type_obstack;
+const char *type_code_name (int code)
+{
+ switch (code)
+ {
+ case TYPE_CODE_UNDEF:
+ return "TYPE_CODE_UNDEF";
+ case TYPE_CODE_PTR:
+ return "TYPE_CODE_PTR";
+ case TYPE_CODE_ARRAY:
+ return "TYPE_CODE_ARRAY";
+ case TYPE_CODE_STRUCT:
+ return "TYPE_CODE_STRUCT";
+ case TYPE_CODE_UNION:
+ return "TYPE_CODE_UNION";
+ case TYPE_CODE_ENUM:
+ return "TYPE_CODE_ENUM";
+ case TYPE_CODE_FUNC:
+ return "TYPE_CODE_FUNC";
+ case TYPE_CODE_INT:
+ return "TYPE_CODE_INT";
+ case TYPE_CODE_FLT:
+ return "TYPE_CODE_FLT";
+ case TYPE_CODE_VOID:
+ return "TYPE_CODE_VOID";
+ case TYPE_CODE_SET:
+ return "TYPE_CODE_SET";
+ case TYPE_CODE_RANGE:
+ return "TYPE_CODE_RANGE";
+ case TYPE_CODE_STRING:
+ return "TYPE_CODE_STRING";
+ case TYPE_CODE_BITSTRING:
+ return "TYPE_CODE_BITSTRING";
+ case TYPE_CODE_ERROR:
+ return "TYPE_CODE_ERROR";
+ case TYPE_CODE_MEMBER:
+ return "TYPE_CODE_MEMBER";
+ case TYPE_CODE_METHOD:
+ return "TYPE_CODE_METHOD";
+ case TYPE_CODE_REF:
+ return "TYPE_CODE_REF";
+ case TYPE_CODE_CHAR:
+ return "TYPE_CODE_CHAR";
+ case TYPE_CODE_BOOL:
+ return "TYPE_CODE_BOOL";
+ case TYPE_CODE_COMPLEX:
+ return "TYPE_CODE_COMPLEX";
+ case TYPE_CODE_TYPEDEF:
+ return "TYPE_CODE_TYPEDEF";
+ case TYPE_CODE_TEMPLATE:
+ return "TYPE_CODE_TEMPLATE";
+ case TYPE_CODE_TEMPLATE_ARG:
+ return "TYPE_CODE_TEMPLATE_ARG";
+ default:
+ return "UNKNOWN TYPE CODE";
+ }
+}
+
+
void
recursive_dump_type (struct type *type, int spaces)
{
@@ -3088,85 +3146,8 @@
TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
printf_filtered (")\n");
- printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
- switch (TYPE_CODE (type))
- {
- case TYPE_CODE_UNDEF:
- printf_filtered ("(TYPE_CODE_UNDEF)");
- break;
- case TYPE_CODE_PTR:
- printf_filtered ("(TYPE_CODE_PTR)");
- break;
- case TYPE_CODE_ARRAY:
- printf_filtered ("(TYPE_CODE_ARRAY)");
- break;
- case TYPE_CODE_STRUCT:
- printf_filtered ("(TYPE_CODE_STRUCT)");
- break;
- case TYPE_CODE_UNION:
- printf_filtered ("(TYPE_CODE_UNION)");
- break;
- case TYPE_CODE_ENUM:
- printf_filtered ("(TYPE_CODE_ENUM)");
- break;
- case TYPE_CODE_FUNC:
- printf_filtered ("(TYPE_CODE_FUNC)");
- break;
- case TYPE_CODE_INT:
- printf_filtered ("(TYPE_CODE_INT)");
- break;
- case TYPE_CODE_FLT:
- printf_filtered ("(TYPE_CODE_FLT)");
- break;
- case TYPE_CODE_VOID:
- printf_filtered ("(TYPE_CODE_VOID)");
- break;
- case TYPE_CODE_SET:
- printf_filtered ("(TYPE_CODE_SET)");
- break;
- case TYPE_CODE_RANGE:
- printf_filtered ("(TYPE_CODE_RANGE)");
- break;
- case TYPE_CODE_STRING:
- printf_filtered ("(TYPE_CODE_STRING)");
- break;
- case TYPE_CODE_BITSTRING:
- printf_filtered ("(TYPE_CODE_BITSTRING)");
- break;
- case TYPE_CODE_ERROR:
- printf_filtered ("(TYPE_CODE_ERROR)");
- break;
- case TYPE_CODE_MEMBER:
- printf_filtered ("(TYPE_CODE_MEMBER)");
- break;
- case TYPE_CODE_METHOD:
- printf_filtered ("(TYPE_CODE_METHOD)");
- break;
- case TYPE_CODE_REF:
- printf_filtered ("(TYPE_CODE_REF)");
- break;
- case TYPE_CODE_CHAR:
- printf_filtered ("(TYPE_CODE_CHAR)");
- break;
- case TYPE_CODE_BOOL:
- printf_filtered ("(TYPE_CODE_BOOL)");
- break;
- case TYPE_CODE_COMPLEX:
- printf_filtered ("(TYPE_CODE_COMPLEX)");
- break;
- case TYPE_CODE_TYPEDEF:
- printf_filtered ("(TYPE_CODE_TYPEDEF)");
- break;
- case TYPE_CODE_TEMPLATE:
- printf_filtered ("(TYPE_CODE_TEMPLATE)");
- break;
- case TYPE_CODE_TEMPLATE_ARG:
- printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
- break;
- default:
- printf_filtered ("(UNKNOWN TYPE CODE)");
- break;
- }
+ printfi_filtered (spaces, "code 0x%x (%s)", TYPE_CODE (type),
+ type_code_name (TYPE_CODE (type)));
puts_filtered ("\n");
printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
printfi_filtered (spaces, "upper_bound_type 0x%x ",
Index: gdbtypes.h
===================================================================
RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/gdbtypes.h,v
retrieving revision 1.17
diff -u -r1.17 gdbtypes.h
--- gdbtypes.h 2002/12/01 04:40:20 1.17
+++ gdbtypes.h 2002/12/12 00:06:49
@@ -1261,6 +1261,8 @@
extern int rank_one_type (struct type *, struct type *);
+extern const char *type_code_name (int code);
+
extern void recursive_dump_type (struct type *, int);
/* printcmd.c */
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [RFA] New function type_code_name.
2002-12-11 17:41 [RFA] New function type_code_name Klee Dienes
@ 2002-12-12 9:12 ` Richard Earnshaw
2002-12-14 2:32 ` Daniel Jacobowitz
2003-01-03 21:11 ` Elena Zannoni
2 siblings, 0 replies; 5+ messages in thread
From: Richard Earnshaw @ 2002-12-12 9:12 UTC (permalink / raw)
To: Klee Dienes; +Cc: gdb-patches, Richard.Earnshaw
klee@apple.com said:
> This patch moves the type-printing code from recursive_dump_type()
> into the new function type_code_name(). It's handy when one wants to
> use the type code of a type in debugging or warning/error messages.
> * gdbtypes.h (type_code_name): Add prototype.
> * gdbtypes.c (type_code_name): New function. Returns a
> constant string containing the ASCII name of the type code.
> (recursive_dump_type): Use type_code_name.
Hmm, I think this could be much cleaner if we considered moving towards
GCC's model of having a gdbtype.def file which defined the type the
strings together. We could then build up an array of strings that is kept
in sync with the enum definition. Something like
gdbtype.def:
DEF_TYPE (TYPE_CODE_INT, "TYPE_CODE_INT", anything else needed by all
types)
DEF_TYPE (TYPE_CODE_TYPEDEF, "TYPE_CODE_TYPEDEF", ...)
etc
then to use it, do
#define DEF_TYPE(X,Y,Z) X,
enum type_code {
#include "gdbtype.def"
TYPE_CODE_NUM_TYPES
};
#undef DEF_TYPE
#define DEF_TYPE(X,Y,Z) Y,
const char char *const type_code_names[] = {
#include "gdbtype.def"
};
You can then look up the type name simply with
if (type_code_number < TYPE_CODE_NUM_TYPES)
type_name = type_code_names[type_code_number];
else
type_name = "INVALID TYPE";
and adding a new type (should we need to) is trivial.
R.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [RFA] New function type_code_name.
2002-12-11 17:41 [RFA] New function type_code_name Klee Dienes
2002-12-12 9:12 ` Richard Earnshaw
@ 2002-12-14 2:32 ` Daniel Jacobowitz
2003-01-03 21:11 ` Elena Zannoni
2 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2002-12-14 2:32 UTC (permalink / raw)
To: gdb-patches
On Wed, Dec 11, 2002 at 07:21:55PM -0500, Klee Dienes wrote:
> This patch moves the type-printing code from recursive_dump_type() into
> the new function type_code_name(). It's handy when one wants to use
> the type code of a type in debugging or warning/error messages.
>
> 2002-12-11 Klee Dienes <kdienes@apple.com>
>
> * gdbtypes.h (type_code_name): Add prototype.
> * gdbtypes.c (type_code_name): New function. Returns a
> constant string containing the ASCII name of the type code.
> (recursive_dump_type): Use type_code_name.
This is mostly OK. Would you add a comment by the enum for TYPE_CODE_*
mentioning the list in type_code_name ()? Also, the argument to
type_code_name should be an enum type_code, not an int.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] New function type_code_name.
2002-12-11 17:41 [RFA] New function type_code_name Klee Dienes
2002-12-12 9:12 ` Richard Earnshaw
2002-12-14 2:32 ` Daniel Jacobowitz
@ 2003-01-03 21:11 ` Elena Zannoni
2003-01-03 21:35 ` Andrew Cagney
2 siblings, 1 reply; 5+ messages in thread
From: Elena Zannoni @ 2003-01-03 21:11 UTC (permalink / raw)
To: Klee Dienes; +Cc: gdb-patches
Klee Dienes writes:
> This patch moves the type-printing code from recursive_dump_type() into
> the new function type_code_name(). It's handy when one wants to use
> the type code of a type in debugging or warning/error messages.
>
> 2002-12-11 Klee Dienes <kdienes@apple.com>
>
> * gdbtypes.h (type_code_name): Add prototype.
Why is this exported? Could it be made static? Maybe you are coming up
with another patch that uses it in another file? If so, I would prefer
to export the function only then.
thanks
Elena
> * gdbtypes.c (type_code_name): New function. Returns a
> constant string containing the ASCII name of the type code.
> (recursive_dump_type): Use type_code_name.
>
> Index: gdbtypes.c
> ===================================================================
> RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/gdbtypes.c,v
> retrieving revision 1.25
> diff -u -r1.25 gdbtypes.c
> --- gdbtypes.c 2002/12/01 04:40:19 1.25
> +++ gdbtypes.c 2002/12/12 00:06:45
> @@ -3046,6 +3046,64 @@
>
> static struct obstack dont_print_type_obstack;
>
> +const char *type_code_name (int code)
> +{
> + switch (code)
> + {
> + case TYPE_CODE_UNDEF:
> + return "TYPE_CODE_UNDEF";
> + case TYPE_CODE_PTR:
> + return "TYPE_CODE_PTR";
> + case TYPE_CODE_ARRAY:
> + return "TYPE_CODE_ARRAY";
> + case TYPE_CODE_STRUCT:
> + return "TYPE_CODE_STRUCT";
> + case TYPE_CODE_UNION:
> + return "TYPE_CODE_UNION";
> + case TYPE_CODE_ENUM:
> + return "TYPE_CODE_ENUM";
> + case TYPE_CODE_FUNC:
> + return "TYPE_CODE_FUNC";
> + case TYPE_CODE_INT:
> + return "TYPE_CODE_INT";
> + case TYPE_CODE_FLT:
> + return "TYPE_CODE_FLT";
> + case TYPE_CODE_VOID:
> + return "TYPE_CODE_VOID";
> + case TYPE_CODE_SET:
> + return "TYPE_CODE_SET";
> + case TYPE_CODE_RANGE:
> + return "TYPE_CODE_RANGE";
> + case TYPE_CODE_STRING:
> + return "TYPE_CODE_STRING";
> + case TYPE_CODE_BITSTRING:
> + return "TYPE_CODE_BITSTRING";
> + case TYPE_CODE_ERROR:
> + return "TYPE_CODE_ERROR";
> + case TYPE_CODE_MEMBER:
> + return "TYPE_CODE_MEMBER";
> + case TYPE_CODE_METHOD:
> + return "TYPE_CODE_METHOD";
> + case TYPE_CODE_REF:
> + return "TYPE_CODE_REF";
> + case TYPE_CODE_CHAR:
> + return "TYPE_CODE_CHAR";
> + case TYPE_CODE_BOOL:
> + return "TYPE_CODE_BOOL";
> + case TYPE_CODE_COMPLEX:
> + return "TYPE_CODE_COMPLEX";
> + case TYPE_CODE_TYPEDEF:
> + return "TYPE_CODE_TYPEDEF";
> + case TYPE_CODE_TEMPLATE:
> + return "TYPE_CODE_TEMPLATE";
> + case TYPE_CODE_TEMPLATE_ARG:
> + return "TYPE_CODE_TEMPLATE_ARG";
> + default:
> + return "UNKNOWN TYPE CODE";
> + }
> +}
> +
> +
> void
> recursive_dump_type (struct type *type, int spaces)
> {
> @@ -3088,85 +3146,8 @@
> TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
> gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
> printf_filtered (")\n");
> - printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
> - switch (TYPE_CODE (type))
> - {
> - case TYPE_CODE_UNDEF:
> - printf_filtered ("(TYPE_CODE_UNDEF)");
> - break;
> - case TYPE_CODE_PTR:
> - printf_filtered ("(TYPE_CODE_PTR)");
> - break;
> - case TYPE_CODE_ARRAY:
> - printf_filtered ("(TYPE_CODE_ARRAY)");
> - break;
> - case TYPE_CODE_STRUCT:
> - printf_filtered ("(TYPE_CODE_STRUCT)");
> - break;
> - case TYPE_CODE_UNION:
> - printf_filtered ("(TYPE_CODE_UNION)");
> - break;
> - case TYPE_CODE_ENUM:
> - printf_filtered ("(TYPE_CODE_ENUM)");
> - break;
> - case TYPE_CODE_FUNC:
> - printf_filtered ("(TYPE_CODE_FUNC)");
> - break;
> - case TYPE_CODE_INT:
> - printf_filtered ("(TYPE_CODE_INT)");
> - break;
> - case TYPE_CODE_FLT:
> - printf_filtered ("(TYPE_CODE_FLT)");
> - break;
> - case TYPE_CODE_VOID:
> - printf_filtered ("(TYPE_CODE_VOID)");
> - break;
> - case TYPE_CODE_SET:
> - printf_filtered ("(TYPE_CODE_SET)");
> - break;
> - case TYPE_CODE_RANGE:
> - printf_filtered ("(TYPE_CODE_RANGE)");
> - break;
> - case TYPE_CODE_STRING:
> - printf_filtered ("(TYPE_CODE_STRING)");
> - break;
> - case TYPE_CODE_BITSTRING:
> - printf_filtered ("(TYPE_CODE_BITSTRING)");
> - break;
> - case TYPE_CODE_ERROR:
> - printf_filtered ("(TYPE_CODE_ERROR)");
> - break;
> - case TYPE_CODE_MEMBER:
> - printf_filtered ("(TYPE_CODE_MEMBER)");
> - break;
> - case TYPE_CODE_METHOD:
> - printf_filtered ("(TYPE_CODE_METHOD)");
> - break;
> - case TYPE_CODE_REF:
> - printf_filtered ("(TYPE_CODE_REF)");
> - break;
> - case TYPE_CODE_CHAR:
> - printf_filtered ("(TYPE_CODE_CHAR)");
> - break;
> - case TYPE_CODE_BOOL:
> - printf_filtered ("(TYPE_CODE_BOOL)");
> - break;
> - case TYPE_CODE_COMPLEX:
> - printf_filtered ("(TYPE_CODE_COMPLEX)");
> - break;
> - case TYPE_CODE_TYPEDEF:
> - printf_filtered ("(TYPE_CODE_TYPEDEF)");
> - break;
> - case TYPE_CODE_TEMPLATE:
> - printf_filtered ("(TYPE_CODE_TEMPLATE)");
> - break;
> - case TYPE_CODE_TEMPLATE_ARG:
> - printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
> - break;
> - default:
> - printf_filtered ("(UNKNOWN TYPE CODE)");
> - break;
> - }
> + printfi_filtered (spaces, "code 0x%x (%s)", TYPE_CODE (type),
> + type_code_name (TYPE_CODE (type)));
> puts_filtered ("\n");
> printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
> printfi_filtered (spaces, "upper_bound_type 0x%x ",
> Index: gdbtypes.h
> ===================================================================
> RCS file: /cvs/Darwin/src/live/cygnus/src/gdb/gdbtypes.h,v
> retrieving revision 1.17
> diff -u -r1.17 gdbtypes.h
> --- gdbtypes.h 2002/12/01 04:40:20 1.17
> +++ gdbtypes.h 2002/12/12 00:06:49
> @@ -1261,6 +1261,8 @@
>
> extern int rank_one_type (struct type *, struct type *);
>
> +extern const char *type_code_name (int code);
> +
> extern void recursive_dump_type (struct type *, int);
>
> /* printcmd.c */
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-01-03 21:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-11 17:41 [RFA] New function type_code_name Klee Dienes
2002-12-12 9:12 ` Richard Earnshaw
2002-12-14 2:32 ` Daniel Jacobowitz
2003-01-03 21:11 ` Elena Zannoni
2003-01-03 21:35 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox