Author Topic: GDB not displaying std::string values  (Read 18591 times)

DKLind

  • Community Member
  • Posts: 18
  • Hero Points: 0
GDB not displaying std::string values
« on: May 26, 2011, 11:19:14 PM »
I have SE v16 running on Ubuntu 10.10. When debugging a program that uses standard strings, the value for the string is "Expecting ',' or ')' in function call expression". I have to assign the values to a const char * variable in order to see the string value.

Dennis

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
Re: GDB not displaying std::string values
« Reply #1 on: May 27, 2011, 02:09:57 PM »
Could you provide a short sample program where this happens?

Dennis

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
Re: GDB not displaying std::string values
« Reply #2 on: May 31, 2011, 08:35:40 PM »
I tried to reproduce this problem with a small sample on my machine, but did not see the same issue.

If you don't want to provide me with an example program, turn on the debugger logging option and send in a log file.

   Got to "Macro > Set Macro Variable..." and set def_debug_logging to 1

   Run the debugger up to the pointer where you see the error with STL strings.

   Send in the contents of .slickedit/16.0.0/logs/vs.log

   Remember to set def_debug_logging back to 0 when you are done.

You could also try configuring a different GDB to use with SlickEdit.  On Linux, by default, we use the version of GDB that is on your machine, but you might have better luck with the version that we ship with the editor.

   Debug > Debugger Options... > GDB Configurations

   Then make SlickEdit GDB your default native debugger.

DKLind

  • Community Member
  • Posts: 18
  • Hero Points: 0
Re: GDB not displaying std::string values
« Reply #3 on: May 31, 2011, 10:41:58 PM »
I have set SE to use the GDB that comes with it with no success. Where do I send the log to? Should I post it here?

Dennis

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
Re: GDB not displaying std::string values
« Reply #4 on: June 01, 2011, 01:40:01 PM »
Send it in to support@slickedit.com or post it here, whichever you prefer.

sbh

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: GDB not displaying std::string values
« Reply #5 on: October 04, 2011, 07:06:42 PM »
Do you know if there are a solution to this issue?
I have the same problem.
Im using openSuse 11.4
g++ (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]
GNU gdb (GDB) SUSE (7.2-3.3)
slickEdit 2011 (v16.0.2.0)

when you do:
 string sName = "Hello World.";
 myFancName (sName);

and add watch for sName I can't see any information about the string.

Thanks

lambertia

  • Senior Community Member
  • Posts: 382
  • Hero Points: 14
  • I have nothing sufficiently witty to say.
Re: GDB not displaying std::string values
« Reply #6 on: October 05, 2011, 06:42:19 AM »
Do you know if there are a solution to this issue?
I have the same problem.
Im using openSuse 11.4
g++ (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]
GNU gdb (GDB) SUSE (7.2-3.3)
slickEdit 2011 (v16.0.2.0)

when you do:
 string sName = "Hello World.";
 myFancName (sName);

and add watch for sName I can't see any information about the string.

Thanks

Hi.

In this particular case it could be that your compiler has been very clever. The compiler is allowed to construct sName directly rather than doing a default construction then an assignment. sName is then being  passed into myFancName (which is another std::string?). If sName is not subsequently used it may be possible for the compiler to be very clever and construct a temporary string from "Hello World" in the call/construction to myFancName. Or, if you've finished with sName once the call to myFancName the compiler may decide to destruct it right there?

Hence there would be nothing to watch.

If you use sName (for example assign it a new value) after myFancName is there any difference in behaviour?

What is the behaviour if you use ddd/gdb directly?

sbh

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: GDB not displaying std::string values
« Reply #7 on: October 05, 2011, 06:22:37 PM »
I don't think its issue of how smart the compiler as I try to use it in the next 5 lines after define it.
string s = "Hello World.";
string d = s;
cout << s << endl;
cout << d << endl;
and more games with it.

when I debug with my GDB (version 7.2-3.3) I see a structure that contain information and part of it its the data part "Hello World."
but when I debug the same code on a box with GDB (version 7.0) I don't see all the exstra information, only the data part "Hello World."

Thanks

mwb1100

  • Senior Community Member
  • Posts: 156
  • Hero Points: 13
Re: GDB not displaying std::string values
« Reply #8 on: October 05, 2011, 10:25:46 PM »
Which compiler or compilers are you using?  This sounds more like you have different libraries that use different representations for std::string than any kind of problem with SE.

sbh

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: GDB not displaying std::string values
« Reply #9 on: October 06, 2011, 02:13:09 PM »
This is the compiler that I use there.
g++ (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]

mwb1100

  • Senior Community Member
  • Posts: 156
  • Hero Points: 13
Re: GDB not displaying std::string values
« Reply #10 on: October 06, 2011, 05:40:02 PM »
Are you using that compiler on both boxes?  even if you are, are there different library versions on the different boxes?  I, for one, am still not clear on what you see on one box that you don't see on another.

But here's an example session (having nothing to do with SlickEdit) of GCC and GDB using your second example snippet of code. This on on a windows box using MinGW/GCC 4.6.1.

The code:

Code: [Select]
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s = "Hello World.";
    string d = s;
    cout << s << endl;
    cout << d << endl;
}

The GDB session:

Code: [Select]
C:\temp>gdb test.exe
GNU gdb (GDB) 7.2
Reading symbols from C:\temp/test.exe...done.
(gdb) start
Temporary breakpoint 1 at 0x40134e: file C:\temp\test.cpp, line 7.
Starting program: C:\temp/test.exe
[New Thread 6216.0x708]

Temporary breakpoint 1, main () at C:\temp\test.cpp:7
7       {
(gdb) n
8           string s = "Hello World.";
(gdb) n
9           string d = s;
(gdb) print s
$1 = {static npos = 4294967295,
  _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0xa3180c "Hello World."}}
(gdb) n
10          cout << s << endl;
(gdb) print d
$2 = {static npos = 4294967295,
  _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0xa3180c "Hello World."}}
(gdb)

Note that GDB doesn't show any data fields for the `std::string` objects except the C-style string data pointed to by `_M_p`.  That's because the `<string>` header is using some trickery that hides the other data in memory that resides before the string data.  When member functions need to access that data other fields, they call an inline function, `_M_rep()` that adjusts the `_M_p` pointer to get at the other data (which includes such things as `_M_length`, `_M_capacity`, and `_M_refcount`). If this is what's causing your problem, take a look at the `<c++/4.6.1/bits/basic_string.h>` header (or wherever basic_string.h might live on your system) for details on what's going on.

woodbot

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Re: GDB not displaying std::string values
« Reply #11 on: April 26, 2012, 05:04:52 PM »
I had the same problem recently on Red Hat 6. By switching from the slickedit version of gdb (/opt/slickedit/gdb) to the built in one (/usr/bin/gdb), the problem went away. This can be done via the menu Debug->Debugger Options. Then navigate to Debugging->Configurations and add a new configuration.