From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8820 invoked by alias); 26 Oct 2010 22:02:03 -0000 Received: (qmail 8794 invoked by uid 22791); 26 Oct 2010 22:02:00 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-qy0-f176.google.com (HELO mail-qy0-f176.google.com) (209.85.216.176) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Oct 2010 22:01:52 +0000 Received: by qyk4 with SMTP id 4so3067380qyk.0 for ; Tue, 26 Oct 2010 15:01:50 -0700 (PDT) Received: by 10.229.96.72 with SMTP id g8mr7991013qcn.190.1288130510216; Tue, 26 Oct 2010 15:01:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.191.131 with HTTP; Tue, 26 Oct 2010 15:01:30 -0700 (PDT) From: Eran Ifrah Date: Tue, 26 Oct 2010 22:02:00 -0000 Message-ID: Subject: GDB/MI - var-update/create BUG To: gdb@sourceware.org Cc: eran.ifrah@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00103.txt.bz2 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 void foo() { std::string mystr =3D " second value "; mystr +=3D " appended content"; } int main(int argc, char **argv) { std::string mystr =3D " first value "; foo(); mystr +=3D " 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=3D"var1",numchild=3D"1",value=3D"0x28ff28 \"h\\377(\"",type=3D"c= har *",thread-id=3D"1",has_more=3D"0" (gdb) -exec-next (gdb) *stopped,reason=3D"end-stepping-range",frame=3D{addr=3D"0x004014a3",func=3D= "main",args=3D[{name=3D"argc",value=3D"1"},{name=3D"argv",value=3D"0xb21868= "}],file=3D"C:/Users/eran/src/TestArea/GDB_MI/main.cpp",fullname=3D"C:/User= s/eran/src/TestArea/GDB_MI/main.cpp",line=3D"13"},thread-id=3D"1",stopped-t= hreads=3D"all" (gdb) -var-update * ^done,changelist=3D[{name=3D"var1",in_scope=3D"true",type_changed=3D"false"= ,has_more=3D"0" }] (gdb) -var-evaluate-expression "var1" ^done,value=3D"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=3D{addr=3D"0x0040134d",func=3D"foo",args=3D[],file=3D"C:/Use= rs/eran/src/TestArea/GDB_MI/main.cpp",fullname=3D"C:/Users/eran/src/TestAre= a/GDB_MI/main.cpp",line=3D"5"},thread-id=3D"1",stopped-threads=3D"all" (gdb) -var-update * ^done,changelist=3D[] (gdb) -exec-next ^running *running,thread-id=3D"all" (gdb) *stopped,frame=3D{addr=3D"0x00401384",func=3D"foo",args=3D[],file=3D"C:/Use= rs/eran/src/TestArea/GDB_MI/main.cpp",fullname=3D"C:/Users/eran/src/TestAre= a/GDB_MI/main.cpp",line=3D"6"},thread-id=3D"1",stopped-threads=3D"all" (gdb) -var-update * ^done,changelist=3D[] (gdb) -var-evaluate-expression "var1" ^done,value=3D"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? --=20 Eran Ifrah Cross platform, open source C++ IDE: http://www.codelite.org