Bug 582052

Summary: gdb can't print std::string
Product: [Fedora] Fedora Reporter: igor.redhat <igor.redhat>
Component: gdbAssignee: Jan Kratochvil <jan.kratochvil>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 12CC: jan.kratochvil, pmuldoon
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: gdb-7.0.1-44.fc12 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-04-15 03:12:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
tiny C++ program to demonstrate the problem
none
quick hack of a patch none

Description igor.redhat@gmail.com 2010-04-14 00:15:24 UTC
Created attachment 406385 [details]
tiny C++ program to demonstrate the problem

Description of problem:

When trying to print an std::string variable in gdb one gets something like the following:

  File "/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py", line 549, in to_string
    return self.val['_M_dataplus']['_M_p'].lazy_string (length = len)
AttributeError: 'gdb.Value' object has no attribute 'lazy_string'

Version-Release number of selected component (if applicable):

gdb: 7.0.1.43.fc12

How reproducible:

Always.

Steps to Reproduce:

1. Compile the attached program with -g option (e.g., "g++ -g -o string string.cpp")
2. open in gdb, break in main and step through 8
3. issue "print str" in gdb, observe the above error
  
Actual results:

(gdb) break main
Breakpoint 1 at 0x40075f: file string.cpp, line 7.
(gdb) run
Starting program: /home/igor/code/Junk/string 

Breakpoint 1, main () at string.cpp:7
7	    string str = "foobar";
(gdb) n
8	    return 0;
(gdb) print str
$1 = Traceback (most recent call last):
  File "/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py", line 549, in to_string
    return self.val['_M_dataplus']['_M_p'].lazy_string (length = len)
AttributeError: 'gdb.Value' object has no attribute 'lazy_string'


Expected results:

I expected the string's value, i.e., "foobar" in this case, to be printed.

Additional info:

It sounds like this might be relevant: http://old.nabble.com/-Bug-python-11248--New:-Error-while-printing-std::string-with-printers-td27451999.html

Comment 1 igor.redhat@gmail.com 2010-04-14 00:27:18 UTC
Created attachment 406386 [details]
quick hack of a patch

For those who need a quick patch to make this work before a proper fix is available, the attached one fixed the problem for me. YMMV.

Comment 2 Phil Muldoon 2010-04-14 09:54:49 UTC
lazy_string() does not appear to be in the F12 GDB Python API, but the libstdc++ printers use it.  The solution here is either to temporarily revert to using string() or import a newer GDB from upstream.

This bug was caused by (my) request for Jan to import the std::tuple printer into F12.  This brought with in this one unwanted change in as well.

GCC patch that changed std::string from using string to lazy_string:

http://gcc.gnu.org/viewcvs?view=revision&revision=155951

diff:

http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/python/libstdcxx/v6/printers.py?r1=155951&r2=155950&pathrev=155951

Jan, maybe you can reverse the string -> lazy_strings patch for F12?

Comment 3 Jan Kratochvil 2010-04-14 10:43:03 UTC
Thanks, verified as applicable:
(gdb) p str
$1 = Traceback (most recent call last):
  File "/usr/lib64/../share/gdb/python/libstdcxx/v6/printers.py", line 549, in to_string
    return self.val['_M_dataplus']['_M_p'].lazy_string (length = len)
AttributeError: 'gdb.Value' object has no attribute 'lazy_string'
->
(gdb) p str
$1 = "foobar"

Comment 4 Fedora Update System 2010-04-14 10:58:02 UTC
gdb-7.0.1-44.fc12 has been submitted as an update for Fedora 12.
http://admin.fedoraproject.org/updates/gdb-7.0.1-44.fc12

Comment 5 Fedora Update System 2010-04-15 03:12:17 UTC
gdb-7.0.1-44.fc12 has been pushed to the Fedora 12 stable repository.  If problems still persist, please make note of it in this bug report.