This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Another comment that... needs a comment! ;)


Paolo wrote:
> in basic_string.h:
> 
>   *  The reason you want _M_data pointing to the character array and
>   *  not the _Rep is so that the debugger can see the string
>   *  contents. (Probably we should add a non-inline member to get
>   *  the _Rep for the debugger to use, so users can check the actual
>   *  string length.)
> 
> Now, if I do, with gdb6.0 (from DDD):
> 
> (gdb) p str
> $1 = {static npos = 4294967295, _M_dataplus = {<allocator<char>> = {<No
> data fields>}, _M_p = 0x400f78dc ""}}
> 
> therefore, it looks like current gdbs is able to look inside
> _M_dataplus (struct _Alloc_hider) and display _M_p directly...
 
You can look at the string contents easily in gdb, but it is not
so easy to see the length, capacity, or refcount.  In fact, I have
not yet discovered the right way to get gdb 6 to display them at
all.  I used to say something like

  (gdb) p ((std::string::_Rep*) str._M_dataplus._M_p)[-1]

but that doesn't seem to work any more, and I have to resort to
the more primitive 

  (gdb) p (((int*)s._M_dataplus._M_p)-3)@3

which prints (e.g.) {13, 13, 0}, corresponding to members
_M_length, _M_capacity, and _M_refcount.  So, it would be a help 
if there were a global, non-inline function __string_rep that I 
could call from gdb to print out the string's _Rep:

  (gdb) p __string_rep(&str)

It might be nicer yet if gdb knew about std::string, but we probably
need a couple more years' ABI stability before we ask for any such
thing.  

By the way, the Invariants listed for string::_Rep have rotted.
In particular, most of item 1 is now false.  (Grr.)

Nathan Myers
ncm-nospam@cantrip.org

p.s. Apologies if another message like this shows up; my ISP has had
e-mail queue problems today.  At the moment it appears to have lost 
all my outgoing mail from today.  (We can hope so.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]