This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Variables created with -var-create going out of scope unexpectedly?


Hi,

I am trying to play around with GDB/MI recently, in particular with
the -var-create command. I see that a variable created with
-var-create goes out of scope too quickly. In particular, if I later
do -var-update, I see that in_scope="false"... The following is the
test program and the GDB session which illustrates my question.

Basically, I put a breakpoint in the function foo below. This function
gets called 4 times with 2 different stacks. If I use "display a" the
first time I hit the breakpoint, the variable a gets displayed on all
subsequent hits. However, if I do instead "-var-create - * a" the
first time the breakpoint is hit and then do "-var-update 1 *" each
subsequent time the break-point is hit, I only see 'in_scope="true"'
the two times when foo() is reached with exactly the same stack. Is
this expected? Is there an equivalent of gdb's "display" command for
GDB/MI?

The program versions are:

gdb: GNU gdb 6.4.90-debian
g++: g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Regards,
Srinath

~/code/gdbmiserver/test
$ cat -n foo.cpp
     1  #include <stdio.h>
     2
     3  void foo(double a)
     4  {
     5      printf("a = %g\n", a);
     6  }
     7
     8  void bar(double a)
     9  {
    10      foo(a);
    11  }
    12
    13  int main()
    14  {
    15      foo(2.5);
    16      bar(3.5);
    17      foo(4.5);
    18      bar(5.5);
    19  }

~/code/gdbmiserver/test
$ g++ -g -o foo foo.cpp

~/code/gdbmiserver/test
$ gdb foo
GNU gdb 6.4.90-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...Using host
libthread_db library "/lib/libthread_db.so.1".

(gdb) b foo.cpp:5
Breakpoint 1 at 0x400565: file foo.cpp, line 5.
(gdb) r
Starting program: /mathworks/home/savadhan/code/gdbmiserver/test/foo

Breakpoint 1, foo (a=2.5) at foo.cpp:5
5           printf("a = %g\n", a);
(gdb) display a
1: a = 2.5
(gdb) interpreter mi '-var-create - * a'
^done,name="var1",numchild="0",type="double"
(gdb)
(gdb) interpreter mi '-var-update 1 *'
^done,changelist=[]
(gdb)
(gdb) c
Continuing.
a = 2.5

Breakpoint 1, foo (a=3.5) at foo.cpp:5
5           printf("a = %g\n", a);
1: a = 3.5
(gdb) interpreter mi '-var-update 1 *'
^done,changelist=[{name="var1",in_scope="false"}]
(gdb)
(gdb) c
Continuing.
a = 3.5

Breakpoint 1, foo (a=4.5) at foo.cpp:5
5           printf("a = %g\n", a);
1: a = 4.5
(gdb) interpreter mi '-var-update 1 *'
^done,changelist=[{name="var1",value="4.5",in_scope="true",type_changed="false"}]
(gdb)
(gdb) c
Continuing.
a = 4.5

Breakpoint 1, foo (a=5.5) at foo.cpp:5
5           printf("a = %g\n", a);
1: a = 5.5
(gdb) interpreter mi '-var-update 1 *'
^done,changelist=[{name="var1",in_scope="false"}]
(gdb)
(gdb) c
Continuing.
a = 5.5

Program exited normally.
(gdb) q

~/code/gdbmiserver/test
$


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]