exp/2258: more convenience variables documentation?

karsten_burger@gmx.de karsten_burger@gmx.de
Wed Apr 25 08:28:00 GMT 2007

>Number:         2258
>Category:       exp
>Synopsis:       more convenience variables documentation?
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 25 09:28:01 BST 2007
>Originator:     karsten_burger@gmx.de
>Release:        GNU gdb 6.5
Linux savitri #1 SMP Fri Mar 2 13:51:59 UTC 2007 i686 i686 i386 GNU/Linux
gcc version 4.1.2 20061115 (prerelease) (SUSE Linux)
This GDB was configured as "i586-suse-linux"...Using host libthread_db library "/lib/libthread_db.so.1".
If you set a convenience var $a to "some struct", which contains data elements i,j, it is possible to change the data elements, e.g. by "set $a.i = 1": 

However, when writing some macros to show the contents of an STL container, it occurred, that no error was printed, but the value of "$a.i" not changed. 

Example program:
 #include <iostream>
 #include <deque>
 using namespace std;

 int main()
     deque<int> d;
     for (int i =1000; i < 1128; ++i ) d.push_back(i);

     for (deque<int>::const_iterator it=d.begin(); it != d.end(); ++it)
     	cout << *it << " ";
     cout << endl;

Compile the program "g++ -g -O0 XX.cpp", start gdb, set breakpoint to line 11, run

(gdb) p d
$1 = {
  <std::_Deque_base<int,std::allocator<int> >> = {
    _M_impl = {
      <std::allocator<int>> = {
        <__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>},
      members of std::_Deque_base<int,std::allocator<int> >::_Deque_impl:
      _M_map = 0x804d008,
      _M_map_size = 8,
      _M_start = {
        _M_cur = 0x804d030,
        _M_first = 0x804d030,
        _M_last = 0x804d230,
        _M_node = 0x804d014
      _M_finish = {
        _M_cur = 0x804d030,
        _M_first = 0x804d030,
        _M_last = 0x804d230,
        _M_node = 0x804d014
  }, <No data fields>}

(gdb) set $iter=d._M_impl._M_start
(gdb) p $iter
$2 = {
  _M_cur = 0x804d030,
  _M_first = 0x804d030,
  _M_last = 0x804d230,
  _M_node = 0x804d014
(gdb) whatis $iter
type = std::_Deque_iterator<int,int&,int*>

(gdb) p $iter._M_cur
$3 = (int *) 0x804d030
(gdb) set $iter._M_cur=0    # try to change the value
(gdb) p $iter._M_cur
$4 = (int *) 0x804d030      # value is unchanged ????

A few lines in the documentation on convenience variables would be helpful.

Further question: I had the impression that a convenience variable's type may even change when used in an expression e.g. for an if condition. However, I cannot reproduce this.  If this is the case, a line in the documentation would be helpful. 



More information about the Gdb-prs mailing list