]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Decode Ada types in Python layer
authorTom Tromey <tromey@adacore.com>
Fri, 25 Jun 2021 14:01:15 +0000 (08:01 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 25 Jun 2021 14:07:21 +0000 (08:07 -0600)
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.

2021-06-25  Tom Tromey  <tromey@adacore.com>

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

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

* gdb.ada/py_range.exp: Add type name test cases.

gdb/ChangeLog
gdb/python/py-type.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/py_range.exp

index 9d56f1c7bc32febaaa6751df492b743f5dfa5c69..c973f4381b20744526722d1e6736f75c4f9eda50 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-25  Tom Tromey  <tromey@adacore.com>
+
+       * python/py-type.c (typy_get_name): Decode an Ada type name.
+
 2021-06-25  Tom Tromey  <tromey@adacore.com>
 
        * ada-lang.c (ada_decode): Add wrap parameter.
index 4f5f42529c27352eb92ff93024957d12c3c761a7..04d1c7a0ee7d3ac0f0d64d06532769ce3ab80b2d 100644 (file)
@@ -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 ());
 }
 
index d12aba9f8ac23f2cfeb73f57d68cf9981e42b0dd..e5164c731adb1cce7b070a074dc5e031d14ec882 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-25  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.ada/py_range.exp: Add type name test cases.
+
 2021-06-24  Tom de Vries  <tdevries@suse.de>
 
        * gdb.base/info-macros.exp: Add <EOL> after trailing whitespace in
index 1a619b70ef7f03290bef49658db8663961f3ee84..3e6efa3e9325318c9cdda99a012289ecb6a647a6 100644 (file)
@@ -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"