| [cdt-dev] Get variable type based on RTTI with gdb HEAD and Eclipse bug #376901 |
|
Hi, On HEAD gdb has a nice feature that might be useful for C++ developers. It can provide a variable type based on RTTI via MI interface (gdb can do it via CLI for many years, but this information ). This feature is turned on with a "set print object on" CLI command (it could be added to .gdbinit). Consider the following example: ÂÂÂ struct SuperInterface { ÂÂÂ ÂÂÂ virtual ~SuperInterface() {}Â // enable RTTI for SuperInterface ÂÂÂ }; ÂÂÂ ÂÂÂ struct TheImplementation : public SuperInterface { ÂÂÂ ÂÂÂ TheImplementation(int _v1, float _v2) ÂÂÂ ÂÂÂ ÂÂÂ : someField(_v1), anotherField(_v2) {} ÂÂÂ ÂÂÂ ÂÂÂ int someField; ÂÂÂ ÂÂÂ float anotherField; ÂÂÂ }; ÂÂÂ ÂÂÂ ÂÂÂ int main() { ÂÂÂ ÂÂÂ SuperInterface* i = new TheImplementation(42, 4.2); ÂÂÂ ÂÂÂ return 0;ÂÂÂÂ // [Run until here] ÂÂÂ } Here is the screenshot how it looks in Eclipse (upper - how it looks with gdb7.4 and will look with gdb7.5 with "set print object off"; lower - with "set print object on" on gdb HEAD): I am writing this because I think it is a nice feature and because there is a small bug in Eclipse with variables type update. I have filed it (https://bugs.eclipse.org/bugs/show_bug.cgi?id=376901) and I have provided a patch. Now I am asking the committers about the review. P.S. I didn't want to be annoying. Sorry if this information was not useful for you. Thanks, Anton. |