From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id E658A3857BBB for ; Fri, 14 Oct 2022 16:40:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E658A3857BBB Received: by mail-io1-xd32.google.com with SMTP id o65so4319478iof.4 for ; Fri, 14 Oct 2022 09:40:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j6xY9Hy1FaT2THARDLwASZkqZAS7PeXSg3aco3OtOh0=; b=KVQ2E6TRBG8Qh5YovISQ4NWqWTr82vFTyMrOerfF38xs/MvhSP25/s+aovaIWBdkCC cqRj8e1tKvBoRGfZCUN0MK4NkhiX/TkPYxTyHswzWwo5AmZRD/6JZVrisblucXPba5Ag xa4KmWvnNQdzTPogmU2RTDSmoUN5aVE2uIAVGvO4F6uKHSQQR+C36UNZbSWgE63KI56T eQs+O2W5tCOfDFOSF+n9DDCqLuw+lOyM8GViqGT+6xhe42/kUd4Ico4mvgBU1ACos19x CbgR4zblCyt6TbRo7+6dFrWgfGey0KxULb6xuQVPL4ah9NwOPJcgNWRK9pYzZl5H+e/L lWeg== X-Gm-Message-State: ACrzQf2OtpRkZo1/kzKO4w2fH9MRPwIW9pj0FUviI4zIRLnFF8EMmMt8 R+ojG+RKdVxeYj+Aj5gvQiNMSb/1kyZbww== X-Google-Smtp-Source: AMsMyM6xwu1q1JmZ/jm7GPTGeqy3Oy9Mx8wpeCapTQRS2A+KTQDas23yVTaPA1YwA2IGuxaGwLHn+A== X-Received: by 2002:a6b:7d4d:0:b0:6bc:5e30:eff1 with SMTP id d13-20020a6b7d4d000000b006bc5e30eff1mr2673161ioq.208.1665765600005; Fri, 14 Oct 2022 09:40:00 -0700 (PDT) Received: from localhost.localdomain (71-211-160-49.hlrn.qwest.net. [71.211.160.49]) by smtp.gmail.com with ESMTPSA id j11-20020a056e02014b00b002f956529892sm1010103ilr.2.2022.10.14.09.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 09:39:59 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add missing TYPE_CODE_* constants to Python Date: Fri, 14 Oct 2022 10:39:50 -0600 Message-Id: <20221014163950.920834-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Oct 2022 16:40:20 -0000 A user noticed that TYPE_CODE_FIXED_POINT was not exported by the gdb Python layer. This patch fixes the bug, and prevents future occurences of this type of bug. --- gdb/doc/guile.texi | 13 +++++ gdb/doc/python.texi | 13 +++++ gdb/gdbtypes.h | 114 +------------------------------------ gdb/guile/scm-type.c | 35 ++---------- gdb/python/py-type.c | 37 +++--------- gdb/type-codes.def | 131 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 173 insertions(+), 170 deletions(-) create mode 100644 gdb/type-codes.def diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi index ba916009f74..0375005ba09 100644 --- a/gdb/doc/guile.texi +++ b/gdb/doc/guile.texi @@ -1308,6 +1308,19 @@ A decimal floating point type. @item TYPE_CODE_INTERNAL_FUNCTION A function internal to @value{GDBN}. This is the type used to represent convenience functions (@pxref{Convenience Funs}). + +@vindex TYPE_CODE_XMETHOD +@item gdb.TYPE_CODE_XMETHOD +A method internal to @value{GDBN}. This is the type used to represent +xmethods (@pxref{Writing an Xmethod}). + +@vindex TYPE_CODE_FIXED_POINT +@item gdb.TYPE_CODE_FIXED_POINT +A fixed-point number. + +@vindex TYPE_CODE_NAMESPACE +@item gdb.TYPE_CODE_NAMESPACE +A Fortran namelist. @end vtable Further support for types is provided in the @code{(gdb types)} diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 2692211f388..4f32d35b55e 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -1642,6 +1642,19 @@ A decimal floating point type. @item gdb.TYPE_CODE_INTERNAL_FUNCTION A function internal to @value{GDBN}. This is the type used to represent convenience functions. + +@vindex TYPE_CODE_XMETHOD +@item gdb.TYPE_CODE_XMETHOD +A method internal to @value{GDBN}. This is the type used to represent +xmethods (@pxref{Writing an Xmethod}). + +@vindex TYPE_CODE_FIXED_POINT +@item gdb.TYPE_CODE_FIXED_POINT +A fixed-point number. + +@vindex TYPE_CODE_NAMESPACE +@item gdb.TYPE_CODE_NAMESPACE +A Fortran namelist. @end vtable Further support for types is provided in the @code{gdb.types} diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 19700a7153e..e9b7e37346e 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -97,120 +97,12 @@ sect_offset_str (sect_offset offset) enum type_code { - TYPE_CODE_BITSTRING = -1, /**< Deprecated */ TYPE_CODE_UNDEF = 0, /**< Not used; catches errors */ - TYPE_CODE_PTR, /**< Pointer type */ - /* * Array type with lower & upper bounds. +#define OP(X) X, +#include "type-codes.def" +#undef OP - Regardless of the language, GDB represents multidimensional - array types the way C does: as arrays of arrays. So an - instance of a GDB array type T can always be seen as a series - of instances of T->target_type () laid out sequentially in - memory. - - Row-major languages like C lay out multi-dimensional arrays so - that incrementing the rightmost index in a subscripting - expression results in the smallest change in the address of the - element referred to. Column-major languages like Fortran lay - them out so that incrementing the leftmost index results in the - smallest change. - - This means that, in column-major languages, working our way - from type to target type corresponds to working through indices - from right to left, not left to right. */ - TYPE_CODE_ARRAY, - - TYPE_CODE_STRUCT, /**< C struct or Pascal record */ - TYPE_CODE_UNION, /**< C union or Pascal variant part */ - TYPE_CODE_ENUM, /**< Enumeration type */ - TYPE_CODE_FLAGS, /**< Bit flags type */ - TYPE_CODE_FUNC, /**< Function type */ - TYPE_CODE_INT, /**< Integer type */ - - /* * Floating type. This is *NOT* a complex type. */ - TYPE_CODE_FLT, - - /* * Void type. The length field specifies the length (probably - always one) which is used in pointer arithmetic involving - pointers to this type, but actually dereferencing such a - pointer is invalid; a void type has no length and no actual - representation in memory or registers. A pointer to a void - type is a generic pointer. */ - TYPE_CODE_VOID, - - TYPE_CODE_SET, /**< Pascal sets */ - TYPE_CODE_RANGE, /**< Range (integers within spec'd bounds). */ - - /* * A string type which is like an array of character but prints - differently. It does not contain a length field as Pascal - strings (for many Pascals, anyway) do; if we want to deal with - such strings, we should use a new type code. */ - TYPE_CODE_STRING, - - /* * Unknown type. The length field is valid if we were able to - deduce that much about the type, or 0 if we don't even know - that. */ - TYPE_CODE_ERROR, - - /* C++ */ - TYPE_CODE_METHOD, /**< Method type */ - - /* * Pointer-to-member-function type. This describes how to access a - particular member function of a class (possibly a virtual - member function). The representation may vary between different - C++ ABIs. */ - TYPE_CODE_METHODPTR, - - /* * Pointer-to-member type. This is the offset within a class to - some particular data member. The only currently supported - representation uses an unbiased offset, with -1 representing - NULL; this is used by the Itanium C++ ABI (used by GCC on all - platforms). */ - TYPE_CODE_MEMBERPTR, - - TYPE_CODE_REF, /**< C++ Reference types */ - - TYPE_CODE_RVALUE_REF, /**< C++ rvalue reference types */ - - TYPE_CODE_CHAR, /**< *real* character type */ - - /* * Boolean type. 0 is false, 1 is true, and other values are - non-boolean (e.g. FORTRAN "logical" used as unsigned int). */ - TYPE_CODE_BOOL, - - /* Fortran */ - TYPE_CODE_COMPLEX, /**< Complex float */ - - TYPE_CODE_TYPEDEF, - - TYPE_CODE_NAMESPACE, /**< C++ namespace. */ - - TYPE_CODE_DECFLOAT, /**< Decimal floating point. */ - - TYPE_CODE_MODULE, /**< Fortran module. */ - - /* * Internal function type. */ - TYPE_CODE_INTERNAL_FUNCTION, - - /* * Methods implemented in extension languages. */ - TYPE_CODE_XMETHOD, - - /* * Fixed Point type. */ - TYPE_CODE_FIXED_POINT, - - /* * Fortran namelist is a group of variables or arrays that can be - read or written. - - Namelist syntax: NAMELIST / groupname / namelist_items ... - NAMELIST statement assign a group name to a collection of variables - called as namelist items. The namelist items can be of any data type - and can be variables or arrays. - - Compiler emit DW_TAG_namelist for group name and DW_TAG_namelist_item - for each of the namelist items. GDB process these namelist dies - and print namelist variables during print and ptype commands. */ - TYPE_CODE_NAMELIST, }; /* * Some bits for the type's instance_flags word. See the macros diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c index 68a5b918e5b..050501ab027 100644 --- a/gdb/guile/scm-type.c +++ b/gdb/guile/scm-type.c @@ -1297,35 +1297,12 @@ gdbscm_lookup_type (SCM name_scm, SCM rest) static const scheme_integer_constant type_integer_constants[] = { -#define X(SYM) { #SYM, SYM } - X (TYPE_CODE_BITSTRING), - X (TYPE_CODE_PTR), - X (TYPE_CODE_ARRAY), - X (TYPE_CODE_STRUCT), - X (TYPE_CODE_UNION), - X (TYPE_CODE_ENUM), - X (TYPE_CODE_FLAGS), - X (TYPE_CODE_FUNC), - X (TYPE_CODE_INT), - X (TYPE_CODE_FLT), - X (TYPE_CODE_VOID), - X (TYPE_CODE_SET), - X (TYPE_CODE_RANGE), - X (TYPE_CODE_STRING), - X (TYPE_CODE_ERROR), - X (TYPE_CODE_METHOD), - X (TYPE_CODE_METHODPTR), - X (TYPE_CODE_MEMBERPTR), - X (TYPE_CODE_REF), - X (TYPE_CODE_RVALUE_REF), - X (TYPE_CODE_CHAR), - X (TYPE_CODE_BOOL), - X (TYPE_CODE_COMPLEX), - X (TYPE_CODE_TYPEDEF), - X (TYPE_CODE_NAMESPACE), - X (TYPE_CODE_DECFLOAT), - X (TYPE_CODE_INTERNAL_FUNCTION), -#undef X + /* This is kept for backward compatibility. */ + { "TYPE_CODE_BITSTRING", -1 }, + +#define OP(SYM) { #SYM, SYM }, +#include "type-codes.def" +#undef OP END_INTEGER_CONSTANTS }; diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 3e558dee7ad..928efacfe8a 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -74,7 +74,7 @@ extern PyTypeObject type_iterator_object_type struct pyty_code { /* The code. */ - enum type_code code; + int code; /* The name. */ const char *name; }; @@ -82,37 +82,14 @@ struct pyty_code /* Forward declarations. */ static PyObject *typy_make_iter (PyObject *self, enum gdbpy_iter_kind kind); -#define ENTRY(X) { X, #X } - static struct pyty_code pyty_codes[] = { - ENTRY (TYPE_CODE_BITSTRING), - ENTRY (TYPE_CODE_PTR), - ENTRY (TYPE_CODE_ARRAY), - ENTRY (TYPE_CODE_STRUCT), - ENTRY (TYPE_CODE_UNION), - ENTRY (TYPE_CODE_ENUM), - ENTRY (TYPE_CODE_FLAGS), - ENTRY (TYPE_CODE_FUNC), - ENTRY (TYPE_CODE_INT), - ENTRY (TYPE_CODE_FLT), - ENTRY (TYPE_CODE_VOID), - ENTRY (TYPE_CODE_SET), - ENTRY (TYPE_CODE_RANGE), - ENTRY (TYPE_CODE_STRING), - ENTRY (TYPE_CODE_ERROR), - ENTRY (TYPE_CODE_METHOD), - ENTRY (TYPE_CODE_METHODPTR), - ENTRY (TYPE_CODE_MEMBERPTR), - ENTRY (TYPE_CODE_REF), - ENTRY (TYPE_CODE_RVALUE_REF), - ENTRY (TYPE_CODE_CHAR), - ENTRY (TYPE_CODE_BOOL), - ENTRY (TYPE_CODE_COMPLEX), - ENTRY (TYPE_CODE_TYPEDEF), - ENTRY (TYPE_CODE_NAMESPACE), - ENTRY (TYPE_CODE_DECFLOAT), - ENTRY (TYPE_CODE_INTERNAL_FUNCTION), + /* This is kept for backward compatibility. */ + { -1, "TYPE_CODE_BITSTRING" }, + +#define OP(X) { X, #X }, +#include "type-codes.def" +#undef OP }; diff --git a/gdb/type-codes.def b/gdb/type-codes.def new file mode 100644 index 00000000000..a6f9a42a3a1 --- /dev/null +++ b/gdb/type-codes.def @@ -0,0 +1,131 @@ +/* Type codes for GDB. + + Copyright (C) 1992-2022 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +OP (TYPE_CODE_PTR) /**< Pointer type */ + +/* * Array type with lower & upper bounds. + + Regardless of the language, GDB represents multidimensional + array types the way C does: as arrays of arrays. So an + instance of a GDB array type T can always be seen as a series + of instances of T->target_type () laid out sequentially in + memory. + + Row-major languages like C lay out multi-dimensional arrays so + that incrementing the rightmost index in a subscripting + expression results in the smallest change in the address of the + element referred to. Column-major languages like Fortran lay + them out so that incrementing the leftmost index results in the + smallest change. + + This means that, in column-major languages, working our way + from type to target type corresponds to working through indices + from right to left, not left to right. */ +OP (TYPE_CODE_ARRAY) + +OP (TYPE_CODE_STRUCT) /**< C struct or Pascal record */ +OP (TYPE_CODE_UNION) /**< C union or Pascal variant part */ +OP (TYPE_CODE_ENUM) /**< Enumeration type */ +OP (TYPE_CODE_FLAGS) /**< Bit flags type */ +OP (TYPE_CODE_FUNC) /**< Function type */ +OP (TYPE_CODE_INT) /**< Integer type */ + +/* * Floating type. This is *NOT* a complex type. */ +OP (TYPE_CODE_FLT) + +/* * Void type. The length field specifies the length (probably + always one) which is used in pointer arithmetic involving + pointers to this type, but actually dereferencing such a + pointer is invalid; a void type has no length and no actual + representation in memory or registers. A pointer to a void + type is a generic pointer. */ +OP (TYPE_CODE_VOID) + +OP (TYPE_CODE_SET) /**< Pascal sets */ +OP (TYPE_CODE_RANGE) /**< Range (integers within spec'd bounds). */ + +/* * A string type which is like an array of character but prints + differently. It does not contain a length field as Pascal + strings (for many Pascals, anyway) do; if we want to deal with + such strings, we should use a new type code. */ +OP (TYPE_CODE_STRING) + +/* * Unknown type. The length field is valid if we were able to + deduce that much about the type, or 0 if we don't even know + that. */ +OP (TYPE_CODE_ERROR) + +/* C++ */ +OP (TYPE_CODE_METHOD) /**< Method type */ + +/* * Pointer-to-member-function type. This describes how to access a + particular member function of a class (possibly a virtual + member function). The representation may vary between different + C++ ABIs. */ +OP (TYPE_CODE_METHODPTR) + +/* * Pointer-to-member type. This is the offset within a class to + some particular data member. The only currently supported + representation uses an unbiased offset, with -1 representing + NULL; this is used by the Itanium C++ ABI (used by GCC on all + platforms). */ +OP (TYPE_CODE_MEMBERPTR) + +OP (TYPE_CODE_REF) /**< C++ Reference types */ + +OP (TYPE_CODE_RVALUE_REF) /**< C++ rvalue reference types */ + +OP (TYPE_CODE_CHAR) /**< *real* character type */ + +/* * Boolean type. 0 is false, 1 is true, and other values are + non-boolean (e.g. FORTRAN "logical" used as unsigned int). */ +OP (TYPE_CODE_BOOL) + +/* Fortran */ +OP (TYPE_CODE_COMPLEX) /**< Complex float */ + +OP (TYPE_CODE_TYPEDEF) + +OP (TYPE_CODE_NAMESPACE) /**< C++ namespace. */ + +OP (TYPE_CODE_DECFLOAT) /**< Decimal floating point. */ + +OP (TYPE_CODE_MODULE) /**< Fortran module. */ + +/* * Internal function type. */ +OP (TYPE_CODE_INTERNAL_FUNCTION) + +/* * Methods implemented in extension languages. */ +OP (TYPE_CODE_XMETHOD) + +/* * Fixed Point type. */ +OP (TYPE_CODE_FIXED_POINT) + +/* * Fortran namelist is a group of variables or arrays that can be + read or written. + + Namelist syntax: NAMELIST / groupname / namelist_items ... + NAMELIST statement assign a group name to a collection of variables + called as namelist items. The namelist items can be of any data type + and can be variables or arrays. + + Compiler emit DW_TAG_namelist for group name and DW_TAG_namelist_item + for each of the namelist items. GDB process these namelist dies + and print namelist variables during print and ptype commands. */ +OP (TYPE_CODE_NAMELIST) -- 2.34.3