From: Eran Ifrah <eran.ifrah@gmail.com>
To: gdb@sourceware.org
Cc: eran.ifrah@gmail.com
Subject: GDB/MI - var-update/create BUG
Date: Tue, 26 Oct 2010 22:02:00 -0000 [thread overview]
Message-ID: <AANLkTinUo3LMBBmDWPm_jp2md3Xzi=06NBf2qJ2S6NF2@mail.gmail.com> (raw)
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
next reply other threads:[~2010-10-26 22:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-26 22:02 Eran Ifrah [this message]
2010-10-27 7:50 ` Andrew Burgess
2010-10-27 8:09 ` Eran Ifrah
2010-10-27 17:28 ` Jan Kratochvil
2010-10-27 17:18 ` Eran Ifrah
2010-10-27 17:31 ` Robert Dewar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTinUo3LMBBmDWPm_jp2md3Xzi=06NBf2qJ2S6NF2@mail.gmail.com' \
--to=eran.ifrah@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox