public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Change Ada type names reported by Python
@ 2021-06-17 19:12 Tom Tromey
  2021-06-17 19:12 ` [PATCH 1/2] Add non-wrapping mode to ada_decode Tom Tromey
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tom Tromey @ 2021-06-17 19:12 UTC (permalink / raw)
  To: gdb-patches

This series changes the Python code to report the "decoded" (aka
"demangled") Ada type names.  This is arguably more correct, as the
encoded names are compiler-synthesized and surprising to users; also
it is less fragile, because the type names are generally changing
anyway as we move the compiler to "minimal encodings".

This is split in 2 parts because originally the first patch came from
my psymtab scanner rewrite; however, we realized in review that that
series will actually require a second parameter to ada_decode.  At
that point, though, it was more convenient to keep the patches
separate.

Tested on x86-64 Fedora 32.

Tom



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] Add non-wrapping mode to ada_decode
  2021-06-17 19:12 [PATCH 0/2] Change Ada type names reported by Python Tom Tromey
@ 2021-06-17 19:12 ` Tom Tromey
  2021-06-17 19:12 ` [PATCH 2/2] Decode Ada types in Python layer Tom Tromey
  2021-06-25 14:02 ` [PATCH 0/2] Change Ada type names reported by Python Tom Tromey
  2 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2021-06-17 19:12 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

When ada_decode encounters a name that it cannot decode, it simply
wraps it in <...>, which is used elsewhere in the Ada code to indicate
that a verbatim match should be done.

A subequent patch needed the ability to suppress this wrapping, so
this patch adds a new mode to ada_decode.

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

	* ada-lang.c (ada_decode): Add wrap parameter.
	* ada-lang.h (ada_decode): Add wrap parameter.
---
 gdb/ChangeLog  |  5 +++++
 gdb/ada-lang.c | 10 +++++-----
 gdb/ada-lang.h |  7 ++++++-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6ed6b65e705..49a7d5b36b6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -976,12 +976,10 @@ ada_remove_po_subprogram_suffix (const char *encoded, int *len)
     *len = *len - 1;
 }
 
-/* If ENCODED follows the GNAT entity encoding conventions, then return
-   the decoded form of ENCODED.  Otherwise, return "<%s>" where "%s" is
-   replaced by ENCODED.  */
+/* See ada-lang.h.  */
 
 std::string
-ada_decode (const char *encoded)
+ada_decode (const char *encoded, bool wrap)
 {
   int i, j;
   int len0;
@@ -1216,12 +1214,14 @@ ada_decode (const char *encoded)
   return decoded;
 
 Suppress:
+  if (!wrap)
+    return {};
+
   if (encoded[0] == '<')
     decoded = encoded;
   else
     decoded = '<' + std::string(encoded) + '>';
   return decoded;
-
 }
 
 /* Table for keeping permanent unique copies of decoded names.  Once
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index 156c9b0cec7..a89ed29119a 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -216,7 +216,12 @@ extern struct type *ada_get_decoded_type (struct type *type);
 
 extern const char *ada_decode_symbol (const struct general_symbol_info *);
 
-extern std::string ada_decode (const char*);
+/* Decode the GNAT-encoded name NAME, returning the decoded name.  If
+   the name does not appear to be GNAT-encoded, then the result
+   depends on WRAP.  If WRAP is true (the default), then the result is
+   simply wrapped in <...>.  If WRAP is false, then the empty string
+   will be returned.  */
+extern std::string ada_decode (const char *name, bool wrap = true);
 
 extern std::vector<struct block_symbol> ada_lookup_symbol_list
      (const char *, const struct block *, domain_enum);
-- 
2.26.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/2] Decode Ada types in Python layer
  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
  2021-06-17 21:10   ` Christian Biesinger
  2021-06-25 14:02 ` [PATCH 0/2] Change Ada type names reported by Python Tom Tromey
  2 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2021-06-17 19:12 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] Decode Ada types in Python layer
  2021-06-17 19:12 ` [PATCH 2/2] Decode Ada types in Python layer Tom Tromey
@ 2021-06-17 21:10   ` Christian Biesinger
  2021-06-18 15:09     ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Biesinger @ 2021-06-17 21:10 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Thu, Jun 17, 2021 at 2:31 PM Tom Tromey <tromey@adacore.com> wrote:
> @@ -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);

Would type->demangled_name() do the right thing? (And should this
respect the demangle option, maybe by calling type->print_name()?)

Christian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] Decode Ada types in Python layer
  2021-06-17 21:10   ` Christian Biesinger
@ 2021-06-18 15:09     ` Tom Tromey
  2021-06-18 16:25       ` Christian Biesinger
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2021-06-18 15:09 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Tom Tromey, gdb-patches

>> +  /* 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);

Christian> Would type->demangled_name() do the right thing? (And should this
Christian> respect the demangle option, maybe by calling type->print_name()?)

I don't think there is a demangled_name method on type, only on symbol.
It may make sense to add one, though this is really only an issue for
Ada AFAIK.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] Decode Ada types in Python layer
  2021-06-18 15:09     ` Tom Tromey
@ 2021-06-18 16:25       ` Christian Biesinger
  2021-06-22 16:56         ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Biesinger @ 2021-06-18 16:25 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Fri, Jun 18, 2021 at 10:09 AM Tom Tromey <tromey@adacore.com> wrote:
>
> >> +  /* 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);
>
> Christian> Would type->demangled_name() do the right thing? (And should this
> Christian> respect the demangle option, maybe by calling type->print_name()?)
>
> I don't think there is a demangled_name method on type, only on symbol.
> It may make sense to add one, though this is really only an issue for
> Ada AFAIK.

Oops, yes, I got myself confused. But even so, should it respect the
"demangle" setting?

Christian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] Decode Ada types in Python layer
  2021-06-18 16:25       ` Christian Biesinger
@ 2021-06-22 16:56         ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2021-06-22 16:56 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Tom Tromey, gdb-patches

>> I don't think there is a demangled_name method on type, only on symbol.
>> It may make sense to add one, though this is really only an issue for
>> Ada AFAIK.

Christian> Oops, yes, I got myself confused. But even so, should it respect the
Christian> "demangle" setting?

I don't think that would be all that useful really.
For one thing, that would mean some user option affects the python
API -- this can already happen, but it's a pain when it does.
If the encoded Ada name is needed, it would be better to add a separate
method.  But, I don't think it's needed.  It's just an artifact of the
way that GNAT worked around DWARF limitations in a particular era (an
ongoing era in some ways).

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] Change Ada type names reported by Python
  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 ` [PATCH 2/2] Decode Ada types in Python layer Tom Tromey
@ 2021-06-25 14:02 ` Tom Tromey
  2 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2021-06-25 14:02 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> This series changes the Python code to report the "decoded" (aka
Tom> "demangled") Ada type names.  This is arguably more correct, as the
Tom> encoded names are compiler-synthesized and surprising to users; also
Tom> it is less fragile, because the type names are generally changing
Tom> anyway as we move the compiler to "minimal encodings".

I'm checking these in now.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-25 14:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] Decode Ada types in Python layer Tom Tromey
2021-06-17 21:10   ` 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

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).