public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PING] [PATCH] [Python] Fix gdb.Value.dynamic_type for reference values
@ 2014-04-02 20:47 Siva Chandra
  2014-04-04 19:12 ` Doug Evans
  0 siblings, 1 reply; 4+ messages in thread
From: Siva Chandra @ 2014-04-02 20:47 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

Original post: https://sourceware.org/ml/gdb-patches/2014-03/msg00542.html

gdb.Value.dynamic_type is supposed to work for reference and pointer
values.  However, the value object in the function 'valpy_get_dynamic_type'
was being dereferenced using 'value_ind' irrespective of the value type
being TYPE_CODE_PTR or TYPE_CODE_REF.  This patch fixes that to use
'coerce_ref' for TYPE_CODE_REF values.

ChangeLog:
2014-04-02  Siva Chandra Reddy  <sivachandra@google.com>

        * python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
        dereference TYPE_CODE_REF values.

        testsuite/
        * gdb.python/py-value.c: Improve test case.
        * gdb.python/py-value.exp: Add new test.

[-- Attachment #2: fix_gdb_value_dynamic_type.txt --]
[-- Type: text/plain, Size: 1461 bytes --]

diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index a118f6c..54da67a 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -309,7 +309,10 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
 	  struct value *target;
 	  int was_pointer = TYPE_CODE (type) == TYPE_CODE_PTR;
 
-	  target = value_ind (val);
+	  if (was_pointer)
+	    target = value_ind (val);
+	  else
+	    target = coerce_ref (val);
 	  type = value_rtti_type (target, NULL, NULL, NULL);
 
 	  if (type)
diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c
index 90dc055..4d1c9c6 100644
--- a/gdb/testsuite/gdb.python/py-value.c
+++ b/gdb/testsuite/gdb.python/py-value.c
@@ -58,6 +58,8 @@ struct Derived : public Base {
 };
 
 Base *base = new Derived ();
+Derived derived;
+Base &base_ref = derived;
 
 void ptr_ref(int*& rptr_int)
 {
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index ed332db..13433fd 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -416,6 +416,8 @@ proc test_subscript_regression {exefile lang} {
      # Likewise.
      gdb_test "python print (gdb.parse_and_eval('base').dynamic_type)" \
 	 "Derived \[*\]"
+     gdb_test "python print (gdb.parse_and_eval('base_ref').dynamic_type)" \
+	 "Derived \[&\]"
      # A static type case.
      gdb_test "python print (gdb.parse_and_eval('5').dynamic_type)" \
 	 "int"

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

* Re: [PING] [PATCH] [Python] Fix gdb.Value.dynamic_type for reference values
  2014-04-02 20:47 [PING] [PATCH] [Python] Fix gdb.Value.dynamic_type for reference values Siva Chandra
@ 2014-04-04 19:12 ` Doug Evans
  2014-04-07 21:24   ` Siva Chandra
  0 siblings, 1 reply; 4+ messages in thread
From: Doug Evans @ 2014-04-04 19:12 UTC (permalink / raw)
  To: Siva Chandra; +Cc: gdb-patches

On Wed, Apr 2, 2014 at 1:46 PM, Siva Chandra <sivachandra@google.com> wrote:
> Original post: https://sourceware.org/ml/gdb-patches/2014-03/msg00542.html
>
> gdb.Value.dynamic_type is supposed to work for reference and pointer
> values.  However, the value object in the function 'valpy_get_dynamic_type'
> was being dereferenced using 'value_ind' irrespective of the value type
> being TYPE_CODE_PTR or TYPE_CODE_REF.  This patch fixes that to use
> 'coerce_ref' for TYPE_CODE_REF values.
>
> ChangeLog:
> 2014-04-02  Siva Chandra Reddy  <sivachandra@google.com>
>
>         * python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
>         dereference TYPE_CODE_REF values.
>
>         testsuite/
>         * gdb.python/py-value.c: Improve test case.
>         * gdb.python/py-value.exp: Add new test.

LGTM.

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

* Re: [PING] [PATCH] [Python] Fix gdb.Value.dynamic_type for reference values
  2014-04-04 19:12 ` Doug Evans
@ 2014-04-07 21:24   ` Siva Chandra
  2014-04-12 16:18     ` [commit] [Guile] Fix value-dynamic-type " Doug Evans
  0 siblings, 1 reply; 4+ messages in thread
From: Siva Chandra @ 2014-04-07 21:24 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

On Fri, Apr 4, 2014 at 12:12 PM, Doug Evans <dje@google.com> wrote:
>> ChangeLog:
>> 2014-04-02  Siva Chandra Reddy  <sivachandra@google.com>
>>
>>         * python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
>>         dereference TYPE_CODE_REF values.
>>
>>         testsuite/
>>         * gdb.python/py-value.c: Improve test case.
>>         * gdb.python/py-value.exp: Add new test.
>
> LGTM.

Thank you. Pushed: 7af389b892404edc76e1a60c59b354b785378fa5

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

* [commit] [Guile] Fix value-dynamic-type for reference values
  2014-04-07 21:24   ` Siva Chandra
@ 2014-04-12 16:18     ` Doug Evans
  0 siblings, 0 replies; 4+ messages in thread
From: Doug Evans @ 2014-04-12 16:18 UTC (permalink / raw)
  To: Siva Chandra, gdb-patches

Siva Chandra <sivachandra@google.com> writes:

> On Fri, Apr 4, 2014 at 12:12 PM, Doug Evans <dje@google.com> wrote:
>>> ChangeLog:
>>> 2014-04-02  Siva Chandra Reddy  <sivachandra@google.com>
>>>
>>>         * python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
>>>         dereference TYPE_CODE_REF values.
>>>
>>>         testsuite/
>>>         * gdb.python/py-value.c: Improve test case.
>>>         * gdb.python/py-value.exp: Add new test.
>>
>> LGTM.
>
> Thank you. Pushed: 7af389b892404edc76e1a60c59b354b785378fa5

Thanks.

Copied to Guile side thusly.

2014-04-12  Siva Chandra Reddy  <sivachandra@google.com>
	    Doug Evans  <xdje42@gmail.com>

	* guile/scm-value.c (gdbscm_value_dynamic_type): Use coerce_ref to
	dereference TYPE_CODE_REF values.

        testsuite/
	* gdb.guile/scm-value.c: Improve test case.
	* gdb.guile/scm-value.exp: Add new test.

diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index 8ca0762..2160a1e 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -585,7 +585,10 @@ gdbscm_value_dynamic_type (SCM self)
 	  struct value *target;
 	  int was_pointer = TYPE_CODE (type) == TYPE_CODE_PTR;
 
-	  target = value_ind (value);
+	  if (was_pointer)
+	    target = value_ind (value);
+	  else
+	    target = coerce_ref (value);
 	  type = value_rtti_type (target, NULL, NULL, NULL);
 
 	  if (type)
diff --git a/gdb/testsuite/gdb.guile/scm-value.c b/gdb/testsuite/gdb.guile/scm-value.c
index 3c61911..e4f7530 100644
--- a/gdb/testsuite/gdb.guile/scm-value.c
+++ b/gdb/testsuite/gdb.guile/scm-value.c
@@ -49,6 +49,8 @@ struct Derived : public Base {
 };
 
 Base *base = new Derived ();
+Derived derived;
+Base &base_ref = derived;
 
 void ptr_ref(int*& rptr_int)
 {
diff --git a/gdb/testsuite/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp
index 0bcd381..2784da2 100644
--- a/gdb/testsuite/gdb.guile/scm-value.exp
+++ b/gdb/testsuite/gdb.guile/scm-value.exp
@@ -335,6 +335,8 @@ proc test_subscript_regression {exefile lang} {
 	# Likewise.
 	gdb_test "gu (print (value-dynamic-type (parse-and-eval \"base\")))" \
 	    "= Derived \[*\]"
+	gdb_test "gu (print (value-dynamic-type (parse-and-eval \"base_ref\")))" \
+	    "= Derived \[&\]"
 	# A static type case.
 	gdb_test "gu (print (value-dynamic-type (parse-and-eval \"5\")))" \
 	    "= int"

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

end of thread, other threads:[~2014-04-12 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-02 20:47 [PING] [PATCH] [Python] Fix gdb.Value.dynamic_type for reference values Siva Chandra
2014-04-04 19:12 ` Doug Evans
2014-04-07 21:24   ` Siva Chandra
2014-04-12 16:18     ` [commit] [Guile] Fix value-dynamic-type " Doug Evans

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