public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/2] Decode Ada types in Python layer
Date: Thu, 17 Jun 2021 13:12:30 -0600	[thread overview]
Message-ID: <20210617191230.71887-3-tromey@adacore.com> (raw)
In-Reply-To: <20210617191230.71887-1-tromey@adacore.com>

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  <tromey@adacore.com>

	* python/py-type.c (typy_get_name): Decode an Ada type name.

gdb/testsuite/ChangeLog
2021-06-17  Tom Tromey  <tromey@adacore.com>

	* 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


  parent reply	other threads:[~2021-06-17 19:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17 19:12 [PATCH 0/2] Change Ada type names reported by Python Tom Tromey
2021-06-17 19:12 ` [PATCH 1/2] Add non-wrapping mode to ada_decode Tom Tromey
2021-06-17 19:12 ` Tom Tromey [this message]
2021-06-17 21:10   ` [PATCH 2/2] Decode Ada types in Python layer Christian Biesinger
2021-06-18 15:09     ` Tom Tromey
2021-06-18 16:25       ` Christian Biesinger
2021-06-22 16:56         ` Tom Tromey
2021-06-25 14:02 ` [PATCH 0/2] Change Ada type names reported by Python Tom Tromey

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=20210617191230.71887-3-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).