Bug 13708 - Erasing an element from std::vector isn't reported by -var-update, when pretty printing is enabled
Summary: Erasing an element from std::vector isn't reported by -var-update, when prett...
Status: RESOLVED INVALID
Alias: None
Product: gdb
Classification: Unclassified
Component: varobj (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-18 13:29 UTC by Dodji Seketeli
Modified: 2023-08-31 16:37 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dodji Seketeli 2012-02-18 13:29:34 UTC
Consider this short code snippet:

     1  #include <vector>
     2  #include <string>
     3  #include <iostream>
     4
     5  int
     6  main()
     7  {
     8      std::string s1 = "kélé", s2 = "fila", s3 = "saba";
     9      std::vector<std::string> v;
    10      v.push_back(s1);
    11      v.push_back(s2);
    12      v.push_back(s3);
    13
    14      std::vector<std::string>::iterator i = v.begin ();
    15      i += 2;
    16
    17      v.erase (i);
    18
    19      unsigned s = v.size ();
    20      std::cout << "v.size (): " << s;
    21
    22      return 0;
    23  }


Here are the actions I perform:

First, I enable pretty printing in MI2 mode.  

Then I create a variable object for vector 'v' right after executing line 9 and I -var-list-children it there.

Then after each step, I -var-update the varobj.  Everything goes fine.  -var-update correctly reports the new string being appended to the vector 'v' at each step.

But then after line 17, (that erases the last element of the vector), -var-update on the varobj does not report the fact that the variable got deleted.

This is annoying as the front end can not update their graphical representation of the variable 'v' accordingly.

Below is the detail of the GDB session.


$ libtool e gdb --interpreter=mi2 ./prettyprint 
=thread-group-added,id="i1"
~"GNU gdb (GDB) Fedora (7.3.50.20110722-10.fc16)\n"
~"Copyright (C) 2011 Free Software Foundation, Inc.\n"
~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n"
~"This GDB was configured as \"x86_64-redhat-linux-gnu\".\nFor bug reporting instructions, please see:\n"
~"<http://www.gnu.org/software/gdb/bugs/>...\n"
~"Reading symbols from /devel/dodji/git/nemiver/better-variable-update/build/tests/prettyprint..."
~"done.\n"
(gdb) 
-enable-pretty-printing
^done
(gdb) 
b main
&"b main\n"
~"Breakpoint 1 at 0x400c4d: file /home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc, line 8.\n"
=breakpoint-created,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000400c4d",func="main()",file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="8",times="0",original-location="main"}
^done
(gdb) 
run
&"run\n"
~"Starting program: /devel/dodji/git/nemiver/better-variable-update/build/tests/prettyprint \n"
=thread-group-started,id="i1",pid="13812"
=thread-created,id="1",group-id="i1"
^running
*running,thread-id="all"
(gdb) 
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib64/libstdc++.so.6",target-name="/usr/lib64/libstdc++.so.6",host-name="/usr/lib64/libstdc++.so.6",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib64/libm.so.6",target-name="/lib64/libm.so.6",host-name="/lib64/libm.so.6",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib64/libgcc_s.so.1",target-name="/lib64/libgcc_s.so.1",host-name="/lib64/libgcc_s.so.1",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib64/libc.so.6",target-name="/lib64/libc.so.6",host-name="/lib64/libc.so.6",symbols-loaded="0",thread-group="i1"
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000400c4d",func="main()",file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="8",times="1",original-location="main"}
~"\nBreakpoint "
~"1, main () at /home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc:8\n"
~"8\t    std::string s1 = \"k\303\251l\303\251\", s2 = \"fila\", s3 = \"saba\";\n"
*stopped,frame={addr="0x0000000000400c4d",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="8"},thread-id="1",stopped-threads="all",core="2"
(gdb) 
-enable-pretty-printing
^done
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"9\t    std::vector<std::string> v;\n"
*stopped,frame={addr="0x0000000000400cd4",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="9"},thread-id="1",stopped-threads="all",core="3"
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"10\t    v.push_back(s1);\n"
*stopped,frame={addr="0x0000000000400ce0",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="10"},thread-id="1",stopped-threads="all",core="2"
(gdb) 
-var-create - * v
^done,name="var1",numchild="0",value="{...}",type="std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >",thread-id="1",displayhint="array",dynamic="1",has_more="0"
(gdb) 
-var-list-children --all-values var1
^done,numchild="0",displayhint="array",has_more="0"
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"11\t    v.push_back(s2);\n"
*stopped,frame={addr="0x0000000000400cf3",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="11"},thread-id="1",stopped-threads="all",core="0"
(gdb) 
-var-update --all-values var1
^done,changelist=[{name="var1",value="{...}",in_scope="true",type_changed="false",new_num_children="1",displayhint="array",dynamic="1",has_more="0",new_children=[{name="var1.[0]",exp="[0]",numchild="0",value=" \"k\303\251l\303\251\"",type="std::basic_string<char, std::char_traits<char>, std::allocator<char> >",thread-id="1",displayhint="string",dynamic="1"}]}]
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"12\t    v.push_back(s3);\n"
*stopped,frame={addr="0x0000000000400d06",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="12"},thread-id="1",stopped-threads="all",core="1"
(gdb) 
-var-update --all-values var1
^done,changelist=[{name="var1",value="{...}",in_scope="true",type_changed="false",new_num_children="2",displayhint="array",dynamic="1",has_more="0",new_children=[{name="var1.[1]",exp="[1]",numchild="0",value=" \"fila\"",type="std::basic_string<char, std::char_traits<char>, std::allocator<char> >",thread-id="1",displayhint="string",dynamic="1"}]}]
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"14\t    std::vector<std::string>::iterator i = v.begin ();\n"
*stopped,frame={addr="0x0000000000400d19",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="14"},thread-id="1",stopped-threads="all",core="2"
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"15\t    i += 2;\n"
*stopped,frame={addr="0x0000000000400d29",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="15"},thread-id="1",stopped-threads="all",core="0"
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"17\t    v.erase (i);\n"
*stopped,frame={addr="0x0000000000400d44",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="17"},thread-id="1",stopped-threads="all",core="2"
(gdb) 
n
&"n\n"
^running
*running,thread-id="1"
(gdb) 
~"19\t    unsigned s = v.size ();\n"
*stopped,frame={addr="0x0000000000400d57",func="main",args=[],file="/home/dodji/devel/git/nemiver/better-variable-update/tests/pretty-print.cc",fullname="/devel/dodji/git/nemiver/better-variable-update/tests/pretty-print.cc",line="19"},thread-id="1",stopped-threads="all",core="2"
(gdb) 
-var-update --all-values var1
^done,changelist=[]
(gdb) 


Note here, how, after erasing the last element of the vector,
-var-update --all-values var1 says that nothing has changed in the
variable.

I think it should report the change, somehow.
Comment 1 Tom Tromey 2012-02-21 19:25:56 UTC
I think gdb is correct here.  Here's my analysis.
I'm moving this to WAITING pending your agreement.

> But then after line 17, (that erases the last element of the vector),
> -var-update on the varobj does not report the fact that the variable got
> deleted.

Here are the last two -var-update calls:

-var-update --all-values var1
^done,changelist=[{name="var1",value="{...}",in_scope="true",type_changed="false",new_num_children="2",displayhint="array",dynamic="1",has_more="0",new_children=[{name="var1.[1]",exp="[1]",numchild="0",value="
\"fila\"",type="std::basic_string<char, std::char_traits<char>,
std::allocator<char> >",thread-id="1",displayhint="string",dynamic="1"}]}]

-var-update --all-values var1
^done,changelist=[]


The first -var-update shown reports 2 elements.  Then the inferior
adds an element and removes it.  Then we do another -var-update.  At
this point, the vector is identical to the last time it was updated.

If I instead -var-update at line 14 in the inferior, I get:

^done,changelist=[{name="var1",value="{...}",in_scope="true",type_changed="false",new_num_children="2",displayhint="array",dynamic="1",has_more="0"}]


Here is the test input I am using, run like: gdb -i=mi2 ./pr < script:

set data-directory /usr/share/gdb
-enable-pretty-printing
b 10
run
-var-create - * v
-var-list-children --all-values var1
b 14
cont
-var-update --all-values var1
b 22
cont
p/r v
p v
-var-update --all-values var1
Comment 2 Sergio Durigan Junior 2014-09-12 23:08:06 UTC
Hey Dodji, could you take a look at this bug and see if Tom's comments make sense to you?  Thanks!
Comment 3 Tom Tromey 2023-08-31 16:37:13 UTC
Closing now.