From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aEjaGiejy2BPMgAAWB0awg (envelope-from ) for ; Thu, 17 Jun 2021 15:31:51 -0400 Received: by simark.ca (Postfix, from userid 112) id 6C0B71E54D; Thu, 17 Jun 2021 15:31:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9D8661E54D for ; Thu, 17 Jun 2021 15:31:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1735F398B8BF for ; Thu, 17 Jun 2021 19:31:50 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id 6631A3988006 for ; Thu, 17 Jun 2021 19:12:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6631A3988006 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 3ACC3116968; Thu, 17 Jun 2021 15:12:32 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id z3FYcbBMK2wx; Thu, 17 Jun 2021 15:12:32 -0400 (EDT) Received: from murgatroyd.Home (97-122-70-83.hlrn.qwest.net [97.122.70.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id E95BB116894; Thu, 17 Jun 2021 15:12:31 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Decode Ada types in Python layer Date: Thu, 17 Jun 2021 13:12:30 -0600 Message-Id: <20210617191230.71887-3-tromey@adacore.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210617191230.71887-1-tromey@adacore.com> References: <20210617191230.71887-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" GNAT emits encoded type names, but these aren't usually of interest to users. The Ada language code in gdb hides this oddity -- but the Python layer does not. This patch changes the Python code to use the decoded Ada type name, when appropriate. I looked at decoding Ada type names during construction, as that would be cleaner. However, the Ada support in gdb relies on the encodings at various points, so this isn't really doable right now. gdb/ChangeLog 2021-06-17 Tom Tromey * python/py-type.c (typy_get_name): Decode an Ada type name. gdb/testsuite/ChangeLog 2021-06-17 Tom Tromey * gdb.ada/py_range.exp: Add type name test cases. --- gdb/ChangeLog | 4 ++++ gdb/python/py-type.c | 9 +++++++++ gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.ada/py_range.exp | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 4f5f42529c2..04d1c7a0ee7 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -27,6 +27,7 @@ #include "objfiles.h" #include "language.h" #include "typeprint.h" +#include "ada-lang.h" struct type_object { @@ -393,6 +394,14 @@ typy_get_name (PyObject *self, void *closure) if (type->name () == NULL) Py_RETURN_NONE; + /* Ada type names are encoded, but it is better for users to see the + decoded form. */ + if (ADA_TYPE_P (type)) + { + std::string name = ada_decode (type->name (), false); + if (!name.empty ()) + return PyString_FromString (name.c_str ()); + } return PyString_FromString (type->name ()); } diff --git a/gdb/testsuite/gdb.ada/py_range.exp b/gdb/testsuite/gdb.ada/py_range.exp index 1a619b70ef7..3e6efa3e932 100644 --- a/gdb/testsuite/gdb.ada/py_range.exp +++ b/gdb/testsuite/gdb.ada/py_range.exp @@ -40,3 +40,8 @@ gdb_test "python print(int(gdb.parse_and_eval('si')))" \ gdb_test "python print(int(gdb.parse_and_eval('ir')))" \ "974" + +gdb_test "python print(gdb.parse_and_eval('si').type)" \ + "foo\\.small_integer" "print type" +gdb_test "python print(gdb.parse_and_eval('si').type.name)" \ + "foo\\.small_integer" "print type name" -- 2.26.3