Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* GDB/MI - var-update/create BUG
@ 2010-10-26 22:02 Eran Ifrah
  2010-10-27  7:50 ` Andrew Burgess
  2010-10-27 17:28 ` Jan Kratochvil
  0 siblings, 2 replies; 6+ messages in thread
From: Eran Ifrah @ 2010-10-26 22:02 UTC (permalink / raw)
  To: gdb; +Cc: eran.ifrah

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: GDB/MI - var-update/create BUG
  2010-10-26 22:02 GDB/MI - var-update/create BUG Eran Ifrah
@ 2010-10-27  7:50 ` Andrew Burgess
  2010-10-27  8:09   ` Eran Ifrah
  2010-10-27 17:28 ` Jan Kratochvil
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2010-10-27  7:50 UTC (permalink / raw)
  To: Eran Ifrah, gdb

> On 26 October 2010 23:02, Behalf Of Eran Ifrah wrote:
> 
> 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"

Using "*" ties the creation of the variable to the current frame. Changing to use "@" will create a floating variable that will use the current _active_ frame. This seems to produce the result you are looking for.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: GDB/MI - var-update/create BUG
  2010-10-27  7:50 ` Andrew Burgess
@ 2010-10-27  8:09   ` Eran Ifrah
  0 siblings, 0 replies; 6+ messages in thread
From: Eran Ifrah @ 2010-10-27  8:09 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb

On Wed, Oct 27, 2010 at 9:50 AM, Andrew Burgess <aburgess@broadcom.com> wrote:
>> On 26 October 2010 23:02, Behalf Of Eran Ifrah wrote:
>>
>> 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"
>
> Using "*" ties the creation of the variable to the current frame. Changing to use "@" will create a floating variable that will use the current _active_ frame. This seems to produce the result you are looking for.
>

Thank you! this was exactly what I was overlooked.

I was using the wrong docs link:
http://www.delorie.com/gnu/docs/gdb/gdb_235.html

While I should have looked at:
http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Variable-Objects.html#GDB_002fMI-Variable-Objects

> Thanks,
> Andrew
>
>



-- 
Eran Ifrah
Cross platform, open source C++ IDE: http://www.codelite.org


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: GDB/MI - var-update/create BUG
  2010-10-27 17:28 ` Jan Kratochvil
@ 2010-10-27 17:18   ` Eran Ifrah
  2010-10-27 17:31     ` Robert Dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Eran Ifrah @ 2010-10-27 17:18 UTC (permalink / raw)
  To: Jan Kratochvil, gdb

On Wed, Oct 27, 2010 at 7:03 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Tue, 26 Oct 2010 18:01:30 -0400, Eran Ifrah wrote:
>> 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.
>
> This is correct from the GDB's point of view,

As you can see from the my signature I am coming from the IDE point-of-view.

> normally you want to track that
> _variable_, not that _name_. Anywhere you are.
>
Not really, thats depends on what you are trying to achieve - since
variable object were designed to ease the task of the IDE, then I say
this is incorrect (at least to me).
In my case, I actually never want to track 'variable object' I want to
track 'expressions' in the code.

In codelite IDE, there are 3 main views which use the 'Variable Objects':
- The Locals view
- Watches (user adds expressions)
- The debugger tooltip (codelite uses a tree form tree which suits
perfectly with the variable object concept)

As for the 'Locals' view, I would expect the variable-object to
present the values based on the expression used during the creation of
the variable object, otherwise it does not make any sense of putting
it in the Locals view in the first place.

For the 'watches' view (which are more of a 'persistent' entries) it
make sense to use the scope of creation - but this is also debatable.
I am currently using floating variable object in the watches view and
it seems "natural" to me

The tooltip - well its nature is a transient window, so it does not
really matter - since the variable object is destroyed as soon as the
tool tip is dismissed.

> You should use '@' instead of '*' for frame if you want to track it by name,
> see "floating" in: info '(gdb)GDB/MI Variable Objects'
>

Already did and it is working as expected

>
> Thanks,
> Jan
>
>
> g++ -o 2 2.C -Wall -g
> gdb -nx -i=mi <2.cmd ./2
>
> ==> 2.C <==
> #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;
> }
>
> ==> 2.cmd <==
> -break-insert -t 8
> -exec-run
> -var-create - * mystr._M_dataplus._M_p
> -break-insert -t 4
> -exec-continue
> -var-update *
> -var-evaluate-expression "var1"
>
> ->
> ^done,value="0x601028 \" first value \""
>
> ==> 2-floating.cmd <==
> -break-insert -t 8
> -exec-run
> -var-create - @ mystr._M_dataplus._M_p
> -break-insert -t 4
> -exec-continue
> -var-update *
> -var-evaluate-expression "var1"
>
> ->
> ^done,value="0x601058 \" second value \""
>



-- 
Eran Ifrah
Cross platform, open source C++ IDE: http://www.codelite.org


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: GDB/MI - var-update/create BUG
  2010-10-26 22:02 GDB/MI - var-update/create BUG Eran Ifrah
  2010-10-27  7:50 ` Andrew Burgess
@ 2010-10-27 17:28 ` Jan Kratochvil
  2010-10-27 17:18   ` Eran Ifrah
  1 sibling, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2010-10-27 17:28 UTC (permalink / raw)
  To: Eran Ifrah; +Cc: gdb

On Tue, 26 Oct 2010 18:01:30 -0400, Eran Ifrah wrote:
> 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.

This is correct from the GDB's point of view, normally you want to track that
_variable_, not that _name_. Anywhere you are.

You should use '@' instead of '*' for frame if you want to track it by name,
see "floating" in: info '(gdb)GDB/MI Variable Objects'


Thanks,
Jan


g++ -o 2 2.C -Wall -g
gdb -nx -i=mi <2.cmd ./2

==> 2.C <==
#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;
}

==> 2.cmd <==
-break-insert -t 8
-exec-run
-var-create - * mystr._M_dataplus._M_p
-break-insert -t 4
-exec-continue
-var-update *
-var-evaluate-expression "var1"

->
^done,value="0x601028 \" first value \""

==> 2-floating.cmd <==
-break-insert -t 8
-exec-run
-var-create - @ mystr._M_dataplus._M_p
-break-insert -t 4
-exec-continue
-var-update *
-var-evaluate-expression "var1"

->
^done,value="0x601058 \" second value \""


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: GDB/MI - var-update/create BUG
  2010-10-27 17:18   ` Eran Ifrah
@ 2010-10-27 17:31     ` Robert Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 2010-10-27 17:31 UTC (permalink / raw)
  To: Eran Ifrah; +Cc: Jan Kratochvil, gdb

On 10/27/2010 1:17 PM, Eran Ifrah wrote:

>> normally you want to track that _variable_, not that _name_.
>> Anywhere you are.

I agree with that viewpoint
>>
> Not really, thats depends on what you are trying to achieve - since
> variable object were designed to ease the task of the IDE, then I
> say this is incorrect (at least to me). In my case, I actually never
> want to track 'variable object' I want to track 'expressions' in the
> code.

OK, but this seems quite bizarre to me, and I would not want GDB
to do this by default


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-10-27 17:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-26 22:02 GDB/MI - var-update/create BUG Eran Ifrah
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox