public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix printing of non pointer types when memory tagging is enabled
@ 2021-05-18 20:20 Luis Machado
  2021-05-27 11:31 ` [PING] " Luis Machado
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Luis Machado @ 2021-05-18 20:20 UTC (permalink / raw)
  To: gdb-patches

When the architecture supports memory tagging, we handle pointer types
in a special way, so we can validate tags and show mismatches.

I noticed some errors while printing composite types, floats, references,
member functions and other things that implicitly get dereferenced by GDB to
show the contents rather than the pointer.

Vector registers:

(gdb) p $v0
Value can't be converted to integer.

Non-existent internal variables:

(gdb) p $foo
Value can't be converted to integer.

The same happens for complex types and printing struct/union types.

There are a couple problems. The first one is that we try to evaluate the
expression to print and eventually call value_as_address (...) before making
sure we have a suitable TYPE_CODE_PTR type. That may throw for some types. We
fix this by making sure we have a TYPE_CODE_PTR first, and then proceed to
check if we need to validate tags.

The second problem is that the evaluation process may naturally throw an
error.  One such case is when we have an optimized out variable. Thus we
guard the evaluation path with a try/catch.

If the evaluation throws, we want to resume the default expression printing
path instead of erroring out and printing nothing useful.

This isn't ideal, but GDB does some magic, internally, in order to provide an
improved user experience. This allows users to print the contents of some types
without having to use the dereference operator.

With the patch, printing works correctly again:

(gdb) p $v0
$1 = {d = {f = {2.0546950501119882e-81, 2.0546950501119882e-81}, u = {3399988123389603631, 3399988123389603631}, s = {
      3399988123389603631, 3399988123389603631}}, s = {f = {1.59329203e-10, 1.59329203e-10, 1.59329203e-10, 1.59329203e-10}, u = {
      791621423, 791621423, 791621423, 791621423}, s = {791621423, 791621423, 791621423, 791621423}}, h = {bf = {1.592e-10,
      1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10}, f = {0.11224, 0.11224, 0.11224, 0.11224, 0.11224,
      0.11224, 0.11224, 0.11224}, u = {12079, 12079, 12079, 12079, 12079, 12079, 12079, 12079}, s = {12079, 12079, 12079, 12079,
      12079, 12079, 12079, 12079}}, b = {u = {47 <repeats 16 times>}, s = {47 <repeats 16 times>}}, q = {u = {
      62718710765820030520700417840365121327}, s = {62718710765820030520700417840365121327}}}
(gdb) p $foo
$2 = void
(gdb) p 2 + 2i
$3 = 2 + 2i

gdb/ChangeLog

YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

	* printcmd.c (should_validate_memtags): Make more robust against
	exceptions.
---
 gdb/printcmd.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a5c03c3a830..1194c18358d 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1266,18 +1266,22 @@ print_value (value *val, const value_print_options &opts)
 static bool
 should_validate_memtags (struct value *value)
 {
-  if (target_supports_memory_tagging ()
-      && gdbarch_tagged_address_p (target_gdbarch (), value))
-    {
-      gdb_assert (value != nullptr && value_type (value) != nullptr);
+  gdb_assert (value != nullptr && value_type (value) != nullptr);
 
-      enum type_code code = value_type (value)->code ();
+  enum type_code code = value_type (value)->code ();
 
-      return (code == TYPE_CODE_PTR
-	      || code == TYPE_CODE_REF
-	      || code == TYPE_CODE_METHODPTR
-	      || code == TYPE_CODE_MEMBERPTR);
+  try
+    {
+      if (code == TYPE_CODE_PTR
+	  && target_supports_memory_tagging ()
+	  && gdbarch_tagged_address_p (target_gdbarch (), value))
+	return true;
     }
+  catch (gdb_exception_error &ex)
+    {
+      /* Ignore the error and don't validate tags.  */
+    }
+
   return false;
 }
 
-- 
2.25.1


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

end of thread, other threads:[~2021-07-19 18:50 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 20:20 [PATCH] Fix printing of non pointer types when memory tagging is enabled Luis Machado
2021-05-27 11:31 ` [PING] " Luis Machado
2021-05-28 19:08 ` John Baldwin
2021-05-28 19:18   ` Luis Machado
2021-05-28 22:11     ` John Baldwin
2021-05-29  1:26 ` Simon Marchi
2021-05-29  6:26   ` Luis Machado
2021-06-20 16:19     ` Joel Brobecker
2021-06-21 13:28       ` Luis Machado
2021-06-22  1:37 ` Luis Machado
2021-07-01 13:50   ` [PING][PATCH] " Luis Machado
2021-07-01 19:52   ` [PATCH] " Pedro Alves
2021-07-02 12:47     ` Luis Machado
2021-07-02 13:19       ` Pedro Alves
2021-07-02 13:45         ` Luis Machado
2021-07-02 15:14           ` Pedro Alves
2021-07-05 14:32             ` Luis Machado
2021-07-05 23:06               ` Pedro Alves
2021-07-06 16:32                 ` Luis Machado
2021-07-07 10:49                   ` [PATCH v3] Fix printing of non-address " Pedro Alves
2021-07-17 18:53                     ` Joel Brobecker
2021-07-19  9:37                       ` Luis Machado
2021-07-19 18:50                     ` Luis Machado

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