From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4FFD83858434 for ; Fri, 25 Feb 2022 11:31:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FFD83858434 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-323-wRAmmZWXMuG93-iOPAXzcQ-1; Fri, 25 Feb 2022 06:31:21 -0500 X-MC-Unique: wRAmmZWXMuG93-iOPAXzcQ-1 Received: by mail-wr1-f72.google.com with SMTP id g15-20020adfbc8f000000b001e9506e27ddso770340wrh.22 for ; Fri, 25 Feb 2022 03:31:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LYsIOV/6+0YkZm9NZ5gIFuDiCDcabv+MftG3+IiMcDM=; b=WeJugX3xUqzmfq0e68hXbC3ZMo9T6ZG6bY4UnTHpJ0ZHhNq3qxMNEKoam3ovecZFrv gzUW/H1vOp5iH0GorkRg5KqzW0KWPc4h2jMMQLUR9xP4Ch3zYQrybQvxc2sw4EmbFPet q3VBazccva1MtNIzMp6jWthuWRB9clqcRUiaofkmi528UqEMzdB4Ug9UO49MbaxVv+dR 8L3z4UJmXZufbJzLepzq/+WP1KxqmP7mapJR2RYqoTRBiO9g6gG4zqAkEdPuP50Qcy44 eVLoWYLVG1yEhtH+cQG4oXAH5tyc4X8kt3ImzdOmLYRWk3XiVwobz1XmLUQ88qHRLepK fWzg== X-Gm-Message-State: AOAM5329eQJUj04VEcpxsiJudAvugQePakjjDwmyC6eTP/Tcyr21lvLx OSqhbCwjAMVlScs98QtUNLn0fPQzbFR0TNkewpd1ZwKvibto4oYzyoC79sBaBr0kLrai6xve7Jz jShK/sqS3XuSjMI9j7xM7AfGBqw8TvgmPzZTeqRcZ+/HYDkmIPxa3FSmw/X5ffarKsh+4rg== X-Received: by 2002:a5d:4f01:0:b0:1ea:9c18:b792 with SMTP id c1-20020a5d4f01000000b001ea9c18b792mr5530221wru.160.1645788679833; Fri, 25 Feb 2022 03:31:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHh56DTlOtrm4/RW4J9DDsORte975x5FUzYZk+OdUi65PbMyJk8Pp9Pq8409ffQSjwlEO+Sg== X-Received: by 2002:a5d:4f01:0:b0:1ea:9c18:b792 with SMTP id c1-20020a5d4f01000000b001ea9c18b792mr5530192wru.160.1645788679513; Fri, 25 Feb 2022 03:31:19 -0800 (PST) Received: from localhost (host86-169-131-29.range86-169.btcentralplus.com. [86.169.131.29]) by smtp.gmail.com with ESMTPSA id bh7-20020a05600c3d0700b00380f6ec4d5asm5196405wmb.16.2022.02.25.03.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 03:31:18 -0800 (PST) From: Andrew Burgess To: binutils@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 1/3] gdb/python: add Type.is_scalar property Date: Fri, 25 Feb 2022 11:31:10 +0000 Message-Id: <1eeffb1d2496e11e63bd83f9ffb19d69cac7ba4c.1645788436.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Feb 2022 11:31:24 -0000 Add a new read-only property which is True for scalar types, otherwise, it's False. --- gdb/NEWS | 3 +++ gdb/doc/python.texi | 6 ++++++ gdb/python/py-type.c | 15 +++++++++++++++ gdb/testsuite/gdb.python/py-type.c | 16 ++++++++++++++++ gdb/testsuite/gdb.python/py-type.exp | 26 +++++++++++++++++++++++++- 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/gdb/NEWS b/gdb/NEWS index fdd42049994..874ec94b8a2 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -187,6 +187,9 @@ GNU/Linux/LoongArch loongarch*-*-linux* set styling'). When false, which is the default if the argument is not given, then no styling is applied to the returned string. + ** New read-only attribute gdb.Type.is_scalar, which is True for + scalar types, and False for all other types. + * New features in the GDB remote stub, GDBserver ** GDBserver is now supported on OpenRISC GNU/Linux. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index c1a3f5f2a7e..fa14dacf3ad 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -1263,6 +1263,12 @@ there is no associated objfile. @end defvar +@defvar Type.is_scalar +This property is @code{True} if the type is a scalar type, otherwise, +this property is @code{False}. Examples of non-scalar types include +structures, unions, and classes. +@end defvar + The following methods are provided: @defun Type.fields () diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 13dae1e2559..54761236d52 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -433,6 +433,19 @@ typy_get_objfile (PyObject *self, void *closure) return objfile_to_objfile_object (objfile).release (); } +/* Return true if this is a scalar type, otherwise, returns false. */ + +static PyObject * +typy_is_scalar (PyObject *self, void *closure) +{ + struct type *type = ((type_object *) self)->type; + + if (is_scalar_type (type)) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} + /* Return the type, stripped of typedefs. */ static PyObject * typy_strip_typedefs (PyObject *self, PyObject *args) @@ -1487,6 +1500,8 @@ static gdb_PyGetSetDef type_object_getset[] = "The tag name for this type, or None.", NULL }, { "objfile", typy_get_objfile, NULL, "The objfile this type was defined in, or None.", NULL }, + { "is_scalar", typy_is_scalar, nullptr, + "Is this a scalar type?", nullptr }, { NULL } }; diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c index 10cbd3b0875..92297d5ad4b 100644 --- a/gdb/testsuite/gdb.python/py-type.c +++ b/gdb/testsuite/gdb.python/py-type.c @@ -32,6 +32,13 @@ TS ts; int aligncheck; +union UU +{ + int i; + float f; + int a[5]; +}; + #ifdef __cplusplus struct C { @@ -72,6 +79,14 @@ Temargs temvar; #endif +unsigned char global_unsigned_char; +char global_char; +signed char global_signed_char; + +unsigned int global_unsigned_int; +int global_int; +signed int global_signed_int; + enum E { v1, v2, v3 }; @@ -91,6 +106,7 @@ main () int ar[2] = {1,2}; struct s st; struct SS ss; + union UU uu; #ifdef __cplusplus C c; c.c = 1; diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index 4990eeb7ddb..2bb2bf67218 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -270,6 +270,29 @@ proc test_template {} { gdb_test "python print (ttype.template_argument(2))" "&C::c" } +# Test the gdb.Type.is_scalar property. +proc test_is_scalar { lang } { + if {$lang == "c++"} { + gdb_test "python print(gdb.parse_and_eval ('c').type.is_scalar)" "False" + gdb_test "python print(gdb.parse_and_eval ('&c').type.is_scalar)" "True" + } + + foreach type { char int } { + gdb_test "python print(gdb.parse_and_eval('global_unsigned_${type}').type.is_scalar)" "True" + gdb_test "python print(gdb.parse_and_eval('global_${type}').type.is_scalar)" "True" + gdb_test "python print(gdb.parse_and_eval('global_signed_${type}').type.is_scalar)" "True" + } + + gdb_test "python print(gdb.parse_and_eval ('ss.x').type.is_scalar)" "True" + gdb_test "python print(gdb.parse_and_eval ('ss').type.is_scalar)" "False" + gdb_test "python print(gdb.parse_and_eval ('uu').type.is_scalar)" "False" + + gdb_test "python print(gdb.parse_and_eval ('uu.i').type.is_scalar)" "True" + gdb_test "python print(gdb.parse_and_eval ('uu.f').type.is_scalar)" "True" + gdb_test "python print(gdb.parse_and_eval ('uu.a').type.is_scalar)" "False" + gdb_test "python print(gdb.parse_and_eval ('&ss.x').type.is_scalar)" "True" +} + # Perform C Tests. if { [build_inferior "${binfile}" "c"] == 0 } { restart_gdb "${binfile}" @@ -296,10 +319,10 @@ if { [build_inferior "${binfile}" "c"] == 0 } { runto_bp "break to inspect struct and array." test_fields "c" test_enums + test_is_scalar "c" } } - # Perform C++ Tests. if { [build_inferior "${binfile}-cxx" "c++"] == 0 } { restart_gdb "${binfile}-cxx" @@ -310,5 +333,6 @@ if { [build_inferior "${binfile}-cxx" "c++"] == 0 } { test_range test_template test_enums + test_is_scalar "c++" } } -- 2.25.4