Bug 18149 - The gdb cannot evaluate a C++ expression generated by the "-var-info-path-expression" for member of class.
Summary: The gdb cannot evaluate a C++ expression generated by the "-var-info-path-exp...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 7.10
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-19 19:19 UTC by Mihail-Marian Nistor
Modified: 2020-04-06 18:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
an example, gdb and gcc information (7.52 KB, application/x-7z-compressed)
2015-03-19 19:19 UTC, Mihail-Marian Nistor
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mihail-Marian Nistor 2015-03-19 19:19:16 UTC
Created attachment 8199 [details]
an example, gdb and gcc information

The Eclipse CDT C++ uses the "-var-info-path-expression" command from “mi” to obtain the expression for a certain variable. After that the expression is evaluated by using the "-data-evaluate-expression" command from mi and finally the result will be displayed in the detail panel from Variable/Expression View.

Let's have an example:

class A
{
public:
  A():_a(1) {}

private:
  int _a;
};

class B: public A
{
public:
  B(double b);

private:
  double _b;
};

B::B(double b):A()
{
  _b = b;  // line 23 in test.cpp is here !
}

The reproducible steps are below:
1) The command line to compile the test case
g++ -O0 -g -o test.elf test.cpp
2) Start the gdb
gdb test.elf
3) Set a break-point at line 23 in the test.cpp file
(gdb) b test.cpp:23
4) run
(gdb) run
5) Create a variable for "this" and explore the member of class;
   after that try to evaluate the expression obtained 
   from the "-var-info-path-expression" command
(gdb) interpreter-exec mi "-var-create --thread 1 --frame 0 - * this"
response from gdb == > ^done,name="var1",numchild="2",value="0x7fffffffe860",type="B * const",thread-id="1",has_more="0"
(gdb) interpreter-exec mi "-var-list-children var1"
response from gdb == > ^done,numchild="2",children=[child={name="var1.A",exp="A",numchild="1",type="A",thread-id="1"},child={name="var1.private",exp="private",numchild="1",thread-id="1"}],has_more="0"
(gdb) interpreter-exec mi "-var-list-children var1.A"
response from gdb == > ^done,numchild="1",children=[child={name="var1.A.private",exp="private",numchild="1",thread-id="1"}],has_more="0"
(gdb) interpreter-exec mi "-var-info-path-expression var1.A"
response from gdb == > ^done,path_expr="(*(class A*) this)"
(gdb) print (*(class A*) this)
response from gdb == > This context has class, union or enum A, not a struct.
(gdb) print (*(struct A*) this)
response from gdb == > This context has class, union or enum A, not a struct.
(gdb) interpreter-exec mi '-data-evaluate-expression --thread 1 --frame 0 "(*(struct A*) this)"'
response from gdb == > ^error,msg="This context has class, union or enum A, not a struct."
Here you can see the first type of C++ expression that cannot be evaluated!

(gdb) interpreter-exec mi "-var-list-children var1.A.private"
response from gdb == > ^done,numchild="1",children=[child={name="var1.A.private._a",exp="_a",numchild="0",type="int",thread-id="1"}],has_more="0"
(gdb) interpreter-exec mi "-var-list-children var1.A.private._a"
response from gdb == > ^done,numchild="0",has_more="0"
(gdb) interpreter-exec mi "-var-info-path-expression var1.A.private._a"
response from gdb == > ^done,path_expr="(((*(class A*) this))._a)"
(gdb) print (((*(class A*) this))._a)
response from gdb == > This context has class, union or enum A, not a struct.
(gdb) print (((*(struct A*) this))._a)
response from gdb == > This context has class, union or enum A, not a struct.
(gdb) interpreter-exec mi '-data-evaluate-expression --thread 1 --frame 0 "(((*(class A*) this))._a)"'
response from gdb == > ^error,msg="This context has class, union or enum A, not a struct."
Here you can see the second type of C++ expression that cannot be evaluated!
Comment 1 Hannes Domani 2020-04-06 18:07:47 UTC
This is fixed since 7.10:

(gdb) interpreter-exec mi '-data-evaluate-expression --thread 1 --frame 0 "(*(struct A*) this)"'
^done,value="{_a = 1}"
(gdb) interpreter-exec mi '-data-evaluate-expression --thread 1 --frame 0 "(((*(class A*) this))._a)"'
^done,value="1"