public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/11792] New: Provide access to the dynamic type of an object
@ 2010-07-06 16:00 andre dot poenitz at nokia dot com
  2010-07-07 10:26 ` [Bug python/11792] " andre dot poenitz at nokia dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: andre dot poenitz at nokia dot com @ 2010-07-06 16:00 UTC (permalink / raw)
  To: gdb-prs

There seems to be no easy way to get access to the dynamic type of a C++ object.
The problem is visible in the following script:

=================== snip ======================

rm -rf s && mkdir s && cd s

echo -e "
    class Base { public: virtual ~Base() {} };
    class Derived : public Base {};
    int main() {
        Base *b = new Derived;
        return (int)b;
    }" | g++ -g -xc++ -

gdb -ex 'file a.out' \
    -ex 'start' \
    -ex 'next' \
    -ex 'print b' \
    -ex 'set print object on' \
    -ex 'print b' \
    -ex 'python import gdb' \
    -ex 'python print "Python says: '%s'" % gdb.parse_and_eval("b").type' \
    -ex 'set confirm off' \
    -ex 'quit' 

=================== snip ======================


The result is:

  $1 = (Base *) 0x804b008
  $2 = (Derived *) 0x804b008
  Python says: Base *



It would be nice if there was a method accessible by Python that produces
"Derived *"

-- 
           Summary: Provide access to the dynamic type of an object
           Product: gdb
           Version: 7.1
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: python
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: andre dot poenitz at nokia dot com
                CC: gdb-prs at sourceware dot org
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=11792

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug python/11792] Provide access to the dynamic type of an object
  2010-07-06 16:00 [Bug python/11792] New: Provide access to the dynamic type of an object andre dot poenitz at nokia dot com
@ 2010-07-07 10:26 ` andre dot poenitz at nokia dot com
  2010-08-20 21:56 ` tromey at redhat dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: andre dot poenitz at nokia dot com @ 2010-07-07 10:26 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From andre dot poenitz at nokia dot com  2010-07-07 10:26 -------
Created an attachment (id=4872)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=4872&action=view)
proof-of-concept code, mainly copied code from a path triggered by 'set print
object on'

With the attached patch and adding 

  -ex 'python print "Python says: '%s'" % gdb.parse_and_eval("b").dynamic_type'


to the test script I get

Temporary breakpoint 1, main () at <stdin>:5
5	<stdin>: No such file or directory.
	in <stdin>
6	in <stdin>
$1 = (Base *) 0x804b008
$2 = (Derived *) 0x804b008
Python says: Base *
Python says: Derived *


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=11792

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug python/11792] Provide access to the dynamic type of an object
  2010-07-06 16:00 [Bug python/11792] New: Provide access to the dynamic type of an object andre dot poenitz at nokia dot com
  2010-07-07 10:26 ` [Bug python/11792] " andre dot poenitz at nokia dot com
@ 2010-08-20 21:56 ` tromey at redhat dot com
  2010-08-23  9:02 ` andre dot poenitz at nokia dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at redhat dot com @ 2010-08-20 21:56 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From tromey at redhat dot com  2010-08-20 21:56 -------
This patch looks pretty good.
Do you have paperwork in place?  If not, can you get it?


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at redhat dot com
             Status|UNCONFIRMED                 |WAITING


http://sourceware.org/bugzilla/show_bug.cgi?id=11792

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug python/11792] Provide access to the dynamic type of an object
  2010-07-06 16:00 [Bug python/11792] New: Provide access to the dynamic type of an object andre dot poenitz at nokia dot com
  2010-07-07 10:26 ` [Bug python/11792] " andre dot poenitz at nokia dot com
  2010-08-20 21:56 ` tromey at redhat dot com
@ 2010-08-23  9:02 ` andre dot poenitz at nokia dot com
  2010-08-23 17:58 ` tromey at redhat dot com
  2010-08-30 20:30 ` tromey at redhat dot com
  4 siblings, 0 replies; 6+ messages in thread
From: andre dot poenitz at nokia dot com @ 2010-08-23  9:02 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From andre dot poenitz at nokia dot com  2010-08-23 09:02 -------
(In reply to comment #2)
> This patch looks pretty good.

It's mostly original gdb code.

> Do you have paperwork in place?  

Yes, there's one for the company.




-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=11792

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug python/11792] Provide access to the dynamic type of an object
  2010-07-06 16:00 [Bug python/11792] New: Provide access to the dynamic type of an object andre dot poenitz at nokia dot com
                   ` (2 preceding siblings ...)
  2010-08-23  9:02 ` andre dot poenitz at nokia dot com
@ 2010-08-23 17:58 ` tromey at redhat dot com
  2010-08-30 20:30 ` tromey at redhat dot com
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at redhat dot com @ 2010-08-23 17:58 UTC (permalink / raw)
  To: gdb-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at sourceware dot|tromey at redhat dot com
                   |org                         |
             Status|WAITING                     |ASSIGNED
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-08-23 17:58:14
               date|                            |


http://sourceware.org/bugzilla/show_bug.cgi?id=11792

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug python/11792] Provide access to the dynamic type of an object
  2010-07-06 16:00 [Bug python/11792] New: Provide access to the dynamic type of an object andre dot poenitz at nokia dot com
                   ` (3 preceding siblings ...)
  2010-08-23 17:58 ` tromey at redhat dot com
@ 2010-08-30 20:30 ` tromey at redhat dot com
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at redhat dot com @ 2010-08-30 20:30 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2010-08-30 20:28 -------
Subject: Bug 11792

CVSROOT:	/cvs/src
Module name:	src
Changes by:	tromey@sourceware.org	2010-08-30 20:28:32

Modified files:
	gdb            : ChangeLog 
	gdb/doc        : ChangeLog gdb.texinfo 
	gdb/python     : py-value.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.python: py-value.exp 

Log message:
	gdb
	2010-08-30  Andre Poenitz  <andre.poenitz@nokia.com>
	Tom Tromey  <tromey@redhat.com>
	
	PR python/11792:
	* python/py-value.c (valpy_get_dynamic_type): New function.
	(value_object_getset): Add "dynamic_type".
	(valpy_get_type): Fail on error.
	gdb/doc
	PR python/11792:
	* gdb.texinfo (Values From Inferior): Document dynamic_type.
	gdb/testsuite
	PR python/11792:
	* gdb.python/py-value.exp (test_subscript_regression): Add
	dynamic_type test.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12126&r2=1.12127
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/ChangeLog.diff?cvsroot=src&r1=1.1106&r2=1.1107
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/gdb.texinfo.diff?cvsroot=src&r1=1.759&r2=1.760
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/python/py-value.c.diff?cvsroot=src&r1=1.15&r2=1.16
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2432&r2=1.2433
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.python/py-value.exp.diff?cvsroot=src&r1=1.15&r2=1.16


------- Additional Comments From tromey at redhat dot com  2010-08-30 20:30 -------
Fix checked in.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|7.1                         |7.3


http://sourceware.org/bugzilla/show_bug.cgi?id=11792

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

end of thread, other threads:[~2010-08-30 20:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-06 16:00 [Bug python/11792] New: Provide access to the dynamic type of an object andre dot poenitz at nokia dot com
2010-07-07 10:26 ` [Bug python/11792] " andre dot poenitz at nokia dot com
2010-08-20 21:56 ` tromey at redhat dot com
2010-08-23  9:02 ` andre dot poenitz at nokia dot com
2010-08-23 17:58 ` tromey at redhat dot com
2010-08-30 20:30 ` tromey at redhat dot com

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