public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Eliminate -var-create error for optzd ptr to struct
@ 2016-02-24  0:19 Don Breazeal
  2016-02-24  1:14 ` Luis Machado
  0 siblings, 1 reply; 26+ messages in thread
From: Don Breazeal @ 2016-02-24  0:19 UTC (permalink / raw)
  To: gdb-patches

Problem:
This patch eliminates an error thrown when accessing the value of a
pointer to a structure where the pointer has been optimized out.
The error shows up as the rather ugly value of the pointer variable
in Eclipse.

With this change such an access will return "<optimized out>" like
other optimized out variables.  We should throw an error when
dereferencing an optimized-out pointer, but not when just looking
at its value.

Cause:
The error only occurs when '-gdb-set print object on' has been set.
This setting requires GDB to "identify the actual (derived) type of
the object rather than the declared type".  Part of this process
is to dereference the pointer in order to get the type of the thing
that is pointed-to.  Since the pointer has been optimized out, this
is impossible, and an error is thrown.

Fix:
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.

Results:
Attempts to dereference the optimized-out pointer using -var-create
or -data-evaluate-expression will throw an error, but a dereference
using -var-evaluate-expression will return an empty value.  To be
consistent, this last case would also throw an error.  I looked into
this some, enough to confirm that there isn't an obvious fix.  Given
that my goal is just to eliminate the unnecessary error, I stopped here.

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.

Testing:
I looked at creating a test case for this, but so far haven't been
able to create anything general enough to include in the test suite.

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

OK?

thanks
--Don

gdb/ChangeLog:
2016-02-23  Don Breazeal  <donb@codesourcery.com>

	* gdb/value.c (value_actual_type): Ignore the 'print object
	  on' setting for pointers and references to structures.

---
 gdb/value.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/value.c b/gdb/value.c
index 738b2b2..50e4f8a 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types,
       /* 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 (result) == TYPE_CODE_REF)
 	  && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
-	     == TYPE_CODE_STRUCT)
+	     == TYPE_CODE_STRUCT
+	  && !value_optimized_out (value))
         {
           struct type *real_type;
 
-- 
1.8.1.1

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

end of thread, other threads:[~2016-04-07 14:12 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-24  0:19 [PATCH] Eliminate -var-create error for optzd ptr to struct 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 2/2] Optzd-out ptr: Eliminate -var-create error 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-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
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

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