Bug 251398 - [variables] Variables type should be the implemented type instead of the declared type
Summary: [variables] Variables type should be the implemented type instead of the decl...
Status: ASSIGNED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 0 DD 1.1   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2008-10-20 10:09 EDT by Marc Khouzam CLA
Modified: 2020-09-04 15:20 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Khouzam CLA 2008-10-20 10:09:31 EDT
From the CDT dev list: 
http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg13534.html

In the variables view, when showing a variable, only the declared type is shown and dealt with, instead of the implemented type.  

class Client {
public:
  virtual ~Client() {}
};

class SpecificClient : public Client {
public:
  SpecificClient(int i) {mFive=i;}
  virtual ~SpecificClient() {};
private:
  int mFive;
};

int main() {
  Client *p = new SpecificClient(5);
  return 0;
}

In this case, variable 'p', will only be shown as a pointer, and will not be expandable.  To be able to see the member, one would have to cast it to (SpecificClient*).

In the JDT, the type is immediately shown to be SpecificClient.

Apparently, GDB does know this information as shown by the "set print object on" command.
Comment 1 Pawel Piech CLA 2008-10-20 11:18:40 EDT
Yeah, it'd be great if we could get this exposed in the variables view.  Even if GDB doesn't implement an easy way to retrieve this information any time soon, we should enhance the expression view API.
Comment 2 haitaowu266@gmail.com CLA 2010-11-11 01:38:32 EST
I saw this issue hasn't been updated for more than 1 year. I am using CDT on a very large project which heavily uses polymorphism. Is there a workaround for this issue if a fix is not available?
Comment 3 Marc Khouzam CLA 2010-11-11 08:08:55 EST
I think this is a good bug to get fixed.  I suggest you vote for it.

The workaround, although not very good, is to cast your variable manually.  Right-click on it and choose 'cast-to-type'.
Comment 4 Jens Elmenthaler CLA 2010-11-11 08:33:52 EST
(In reply to comment #3)
> I think this is a good bug to get fixed.  I suggest you vote for it.
> The workaround, although not very good, is to cast your variable manually. 
> Right-click on it and choose 'cast-to-type'.
Another workaround could be to use the python pretty printer infrastructure of gdb: register a pretty printer for all pointer types (or the ones you are interested in). In the pretty printer you can find out via rtti (gdb 7.3 has a method method for gdb.Value) what the implementation type is and return the casted value. Haven't tried it, though;-)
Comment 5 Jens Elmenthaler CLA 2010-11-11 08:36:11 EST
(In reply to comment #3)
> I think this is a good bug to get fixed.
How would this fix look like? Ideally the gdb guys would accomodate this in their MI varobjs, similar to what they do in their command line interface. But from what I perceive, they will not do it.
Comment 6 Marc Khouzam CLA 2010-11-11 09:24:33 EST
(In reply to comment #5)
> (In reply to comment #3)
> > I think this is a good bug to get fixed.
> How would this fix look like?

If we figure out what is the most specific type, we can maybe automatically cast to it.

-var-create --thread 1 --frame 0 - * "(SpecificClient *)(p)"

I'm not sure if we should do it directly in the MIVariableManager or re-use the "Cast to type" feature that we have.  We can start with the re-use because it may be simpler to implement.
Comment 7 Jens Elmenthaler CLA 2010-11-11 09:43:10 EST
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #3)
> > > I think this is a good bug to get fixed.
> > How would this fix look like?
> If we figure out what is the most specific type, we can maybe automatically
> cast to it.
> -var-create --thread 1 --frame 0 - * "(SpecificClient *)(p)"
> I'm not sure if we should do it directly in the MIVariableManager or re-use the
> "Cast to type" feature that we have.  We can start with the re-use because it
> may be simpler to implement.
I fear I broke it, won't work with children of pretty printers:-(