GDB/MI - var-update/create BUG
Eran Ifrah
eran.ifrah@gmail.com
Tue Oct 26 22:02:00 GMT 2010
Hi All,
I found an annoying bug which I was not able solve (however, I found a
reasonable workaround)
This email is a bit long, so please execute me.
In brief:
If I have a local variable with the same name in different scopes,
when switching between the scopes the content of the variable object
does not reflect the new variable.
Here is a code snippet that demonstrates what I mean:
#include <string>
void foo() {
std::string mystr = " second value ";
mystr += " appended content";
}
int main(int argc, char **argv) {
std::string mystr = " first value ";
foo();
mystr += " appended content";
return 0;
}
In the above code snippet, the variable 'mystr' exists in both 'main'
and 'foo' functions.
If I create a variable object while inside 'main' and then I am
stepping into 'foo' the content of the variable object is not updated
to the new value.
(Obviously, I called -var-update var1 and -var-update * without a success)
It is as if 'var1' is pointing to the 'mystr' from the 'main' scope
and refuses to update. The only workaround is to delete the variable
object and then recreate it.
However, to implement this, I need my code to keep track on the
current frame and depth level - which is a tedious task (not to
mention that the scope is only provided in the form of method name so
overloaded methods can break this logic as well)
Here is the debug session for the above code:
( starting from first line of main() )
(gdb)
-var-create - * mystr._M_dataplus._M_p
^done,name="var1",numchild="1",value="0x28ff28 \"h\\377(\"",type="char
*",thread-id="1",has_more="0"
(gdb)
-exec-next
(gdb)
*stopped,reason="end-stepping-range",frame={addr="0x004014a3",func="main",args=[{name="argc",value="1"},{name="argv",value="0xb21868"}],file="C:/Users/eran/src/TestArea/GDB_MI/main.cpp",fullname="C:/Users/eran/src/TestArea/GDB_MI/main.cpp",line="13"},thread-id="1",stopped-threads="all"
(gdb)
-var-update *
^done,changelist=[{name="var1",in_scope="true",type_changed="false",has_more="0"
}]
(gdb)
-var-evaluate-expression "var1"
^done,value="0xb218fc \" first value \""
(gdb)
// SO FAR all is OK, var1 contains the correct value, " first value "
// Next, I will enter the method 'foo' which also has a variable named
// 'mystr'
-exec-step
(gdb)
*stopped,frame={addr="0x0040134d",func="foo",args=[],file="C:/Users/eran/src/TestArea/GDB_MI/main.cpp",fullname="C:/Users/eran/src/TestArea/GDB_MI/main.cpp",line="5"},thread-id="1",stopped-threads="all"
(gdb)
-var-update *
^done,changelist=[]
(gdb)
-exec-next
^running
*running,thread-id="all"
(gdb)
*stopped,frame={addr="0x00401384",func="foo",args=[],file="C:/Users/eran/src/TestArea/GDB_MI/main.cpp",fullname="C:/Users/eran/src/TestArea/GDB_MI/main.cpp",line="6"},thread-id="1",stopped-threads="all"
(gdb)
-var-update *
^done,changelist=[]
(gdb)
-var-evaluate-expression "var1"
^done,value="0xb218fc \" first value \""
(gdb)
// At this point, we are still inside 'foo' method, however the
content of mystr is still " first value "
Any ideas what am I doing wrong?
--
Eran Ifrah
Cross platform, open source C++ IDE: http://www.codelite.org
More information about the Gdb
mailing list