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! ;)


On Mon, Jan 19, 2004 at 12:11:45PM +0100, Paolo Carlini wrote:
> Hi again,
> 
> 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...

Yes, but to discover the length of the string (which may have
embedded NULs, or may be longer than the debugger is willing
to display) you must say something like

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

or worse.  (Probably a global function would be better than a member.)
It would be nicer for users to be able to type

(gdb) p __string_rep(&str)

to find out about string length, capacity, and refcount details.

Nathan Myers
ncm-nospam@cantrip.org


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