public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Don Breazeal <donb@codesourcery.com>
To: <gdb-patches@sourceware.org>, <qiyaoltc@gmail.com>
Subject: Re: [PATCH] Eliminate -var-create error for optzd ptr to struct
Date: Fri, 01 Apr 2016 16:01:00 -0000	[thread overview]
Message-ID: <1459526505-19291-1-git-send-email-donb@codesourcery.com> (raw)
In-Reply-To: <86a8lgrq3f.fsf@gmail.com>

Hi Yao,

Thanks for the review.

> Please run regression test on x86-linux.  If the test is regression
> free, the patch is good to me.

Well, that was a good call, the test was not regression-free.  There
were failures in gdb.mi/mi-var-list-children-invalid-grandchild.exp.

The test resulted in a memory access error in the
call to value_optimized_out that I had added.  Before my change
there was a memory access error caught in value_rtti_indirect_type,
which returned NULL in that case.  The fix was to catch and ignore
errors from value_optimized_out.

Details:
The test had a pointer to a structure (p_outer), and the structure
contained a pointer to another structure (p_outer->inner).  The
p_outer pointer was set to 0x0, and -var-create and -var-list-children
were called for p_outer.

With 'set print object' set to 'on', GDB wants to check the actual
(rtti) type of p_outer->inner for -var-list-children.  Without my change,
value_rtti_indirect_type handled the memory access error when it
dereferenced p_outer (0x0).  With my change, value_optimized_out
threw an error trying to get the value of p_outer->inner, since
p_outer == 0x0.

The fix is to catch errors from value_optimized_out.  If we get
an error, then we can't tell if the value is optimized out and
we default to 'not optimized out'.  We let value_rtti_indirect_type
handle the memory error.

I assume that I didn't see this with my bare-metal testing because
it wasn't an error to access address 0x0.  I'll be sure to keep that
in mind in future testing.


Updated patch, patch description, and ChangeLog below.
OK with these changes?

BTW I will hold off pushing in the corresponding test until this
patch is finalized, to avoid introducing new failures.

thanks
--Don

----
This patch eliminates an error thrown when accessing the value of a
pointer to a structure where the pointer has been optimized out and
'set print object' is 'on'.  The error shows up as the rather ugly
value of the pointer variable in Eclipse.

If 'set print object' is 'on', GDB tries to determine the actual
(derived) type of the object rather than the declared type, which
requires dereferencing the pointer, which in this cases throws an
error because the pointer has been optimized out.

The fix is to simply ignore the 'print object on' setting for
pointers or references to structures when they have been optimized
out.  This means we just get the declared type instead of the actual
type, because in this case that's the best that we can do.

Note that we if value_optimized_out throws an error we just assume
the value is not optimized out.  We let value_rtti_indirect_type
handle any errors, and don't try to duplicate its error handling.

I'm working on setting things in motion for a patch to Eclipse that
recognizes optimized-out pointer-to-struct in this scenario and
prevents any subsequent attempt to dereference it from that end.

Tested on bare-metal powerpc board with Linux x86 host and Linux
native x86_64.

gdb/ChangeLog:
2016-04-01  Don Breazeal  <donb@codesourcery.com>

	* value.c (value_actual_type): Don't try to get rtti type
	of the value if it has been optimized out.

---
 gdb/value.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/gdb/value.c b/gdb/value.c
index 8268b08..018896e 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1192,6 +1192,7 @@ value_actual_type (struct value *value, int resolve_simple_types,
 {
   struct value_print_options opts;
   struct type *result;
+  int value_optzd_out;
 
   get_user_print_options (&opts);
 
@@ -1200,12 +1201,26 @@ value_actual_type (struct value *value, int resolve_simple_types,
   result = value_type (value);
   if (opts.objectprint)
     {
-      /* If result's target type is TYPE_CODE_STRUCT, proceed to
-	 fetch its rtti type.  */
-      if ((TYPE_CODE (result) == TYPE_CODE_PTR
-	   || TYPE_CODE (result) == TYPE_CODE_REF)
-	  && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
-	     == TYPE_CODE_STRUCT)
+      TRY
+	{
+	  value_optzd_out = value_optimized_out (value);
+	}
+      CATCH (ex, RETURN_MASK_ERROR)
+	{
+	  /* If we get an error, assume the value is not optimized out.
+	     If we call value_rtti_indirect_type, it will handle any
+	     errors there; otherwise it won't matter.  */
+	  value_optzd_out = 0;
+	}
+      END_CATCH
+
+       /* If result's target type is TYPE_CODE_STRUCT, proceed to
+	  fetch its rtti type.  */
+       if ((TYPE_CODE (result) == TYPE_CODE_PTR
+	    || TYPE_CODE (result) == TYPE_CODE_REF)
+	   && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
+	     == TYPE_CODE_STRUCT
+	   && !value_optzd_out)
         {
           struct type *real_type;
 
-- 
1.8.1.1

  reply	other threads:[~2016-04-01 16:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-24  0:19 Don Breazeal
2016-02-24  1:14 ` Luis Machado
2016-02-24 16:31   ` Don Breazeal
2016-02-25 12:22     ` Pedro Alves
2016-03-28 21:33       ` [PATCH v2 0/2] Optzd-out ptr: Error handling improvement Don Breazeal
2016-03-28 21:34         ` [PATCH v2 1/2] Optzd-out ptr: New test for error handling Don Breazeal
2016-03-29 11:58           ` Yao Qi
2016-03-29 17:13             ` Don Breazeal
2016-03-30 14:37               ` Yao Qi
2016-04-06 21:34                 ` Don Breazeal
2016-03-28 21:34         ` [PATCH v2 2/2] Optzd-out ptr: Eliminate -var-create error Don Breazeal
2016-03-29 12:01     ` [PATCH] Eliminate -var-create error for optzd ptr to struct Yao Qi
2016-03-29 17:14       ` Don Breazeal
2016-03-30 14:35         ` Yao Qi
2016-04-01 16:01           ` Don Breazeal [this message]
2016-04-04 10:42             ` Yao Qi
2016-04-04 17:16               ` Don Breazeal
2016-04-04 21:28           ` Don Breazeal
2016-04-05 12:53             ` Yao Qi
2016-04-05 18:51               ` Don Breazeal
2016-04-05 19:00                 ` Pedro Alves
2016-04-05 20:39                   ` Don Breazeal
2016-04-06  9:05                     ` Yao Qi
2016-04-06 21:41                       ` Don Breazeal
2016-04-06 22:24                         ` Pedro Alves
2016-04-07 14:12                         ` Yao Qi

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=1459526505-19291-1-git-send-email-donb@codesourcery.com \
    --to=donb@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    /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).