Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Seeing std::string values while debugging
Seeing std::string values while debugging [message #197268] Sun, 15 July 2007 13:25 Go to next message
Eclipse UserFriend
Originally posted by: usenet.aristeia.com

I've just started playing with the CDT Europa debugger (atop mingw g++ on
WinXP), and it seems that std::string variables are not displayed as strings.
Googling around yielded this posting from Leo von Klenze from last October:

> has anybody an idea by getting a wellformat output for stl strings in
> the variable view? It always prints something like that:
>
> {static npos = 4294967295, _M_dataplus = {<allocator<char>> =
> {<new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p =
> 0x6c2704 "Hello World"}}
>
> I think this is because std::string is a class not a simple type but
> this is very nasty if you have a lot of these strings to debug. I know
> you can use the cast to type feature but eclipse forget it after each
> session.
>
> Perhaps anybody has a good idea for improving string debugging. Or isn't
> it interesting for most people? Perhaps an option will be fine for
> special handling of strings?

I didn't see any followups to this posting, but I'm hoping the problem of
viewing the values of std::strings has since been resolved. If not, can
somebody please elaborate on Leo's comment about "cast to type feature" so I can
see the value of my std::strings as strings?

Thanks,

Scott
Re: Seeing std::string values while debugging [message #197446 is a reply to message #197268] Mon, 16 July 2007 11:06 Go to previous messageGo to next message
Eclipse UserFriend
Scott Meyers wrote:
> I've just started playing with the CDT Europa debugger (atop mingw g++
> on WinXP), and it seems that std::string variables are not displayed as
> strings. Googling around yielded this posting from Leo von Klenze from
> last October:
>
>> has anybody an idea by getting a wellformat output for stl strings in
>> the variable view? It always prints something like that:
>>
>> {static npos = 4294967295, _M_dataplus = {<allocator<char>> =
>> {<new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p =
>> 0x6c2704 "Hello World"}}
>>
>> I think this is because std::string is a class not a simple type but
>> this is very nasty if you have a lot of these strings to debug. I know
>> you can use the cast to type feature but eclipse forget it after each
>> session.
>>
>> Perhaps anybody has a good idea for improving string debugging. Or isn't
>> it interesting for most people? Perhaps an option will be fine for
>> special handling of strings?
>
> I didn't see any followups to this posting, but I'm hoping the problem
> of viewing the values of std::strings has since been resolved. If not,
> can somebody please elaborate on Leo's comment about "cast to type
> feature" so I can see the value of my std::strings as strings?

The only 2 thing I have found to see the actual value of my strings:

1. Click on the triangle of the string variable to expand it, do the
same for _M_dataplus (is this the same for all GCC versions?) and choose
_M_p. The contents/value of the string buffer (?) is displayed in the window

or

2. type "p theStringVariableName.c_str()" or "call
theStringVariableName.c_str()" in the gdb command window and the string
contents/vaue will be displayed.

It might be a neat feature if gdb (or Eclipse) would do that by default.

Joost
Re: Seeing std::string values while debugging [message #197485 is a reply to message #197446] Mon, 16 July 2007 14:43 Go to previous message
Eclipse UserFriend
Originally posted by: usenet.aristeia.com

Joost Kraaijeveld wrote:
> 1. Click on the triangle of the string variable to expand it, do the
> same for _M_dataplus (is this the same for all GCC versions?) and choose
> _M_p. The contents/value of the string buffer (?) is displayed in the
> window

I'm beginning to think that something is wacky with my installation of CDT as
regards debugging. Consider this program:

#include <string>
#include <iostream>

int main()
{
std::string s("Hello");
std::cout << s.c_str();
}

When I set a breakpoint on the std::cout line and run to that breakpoint, there
are no variables displayed in the Variables tab. If I then select a different
tab (e.g., Breakpoints) and then select the Variables tab again, the variable s
is shown twice. The substructure of both is the same, so this looks like a
duplicate entry, but _M_p is out of bounds, and looking at *_M_p (by clicking on
it in the Variables window) yields this message:

Target request failed: Cannot access memory at address 0x5dd4d6.

Something is clearly wrong.

The only thing unusual about my configuration is that I'm running g++ 4.1.1 and
gdb 6.3, the former build per
http://aristeia.com/Misc/gcc4ForWindows_frames.html and the latter downloaded
per that same page.

Am I doing something fundamentally wrong, is there some incompatibility between
CDT/Europa and the versions of g++/gdb I'm using, or is something else at work here?

Thanks,

Scott
Previous Topic:Cannot debug generated "Hello world" CDT 4.0, Debian Lenny, x86_64
Next Topic:Shell errors during builds
Goto Forum:
  


Current Time: Thu May 08 09:13:20 EDT 2025

Powered by FUDForum. Page generated in 0.03372 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top