public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17734] New: Printing a std::string member hangs after clang compile
@ 2014-12-19 21:29 joel at walker9 dot net
  2014-12-20  2:27 ` [Bug c++/17734] " sivachandra at gmail dot com
  2014-12-20 21:19 ` joel at walker9 dot net
  0 siblings, 2 replies; 3+ messages in thread
From: joel at walker9 dot net @ 2014-12-19 21:29 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17734

            Bug ID: 17734
           Summary: Printing a std::string member hangs after clang
                    compile
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: joel at walker9 dot net

When the following code is compiled with clang++, breaking on MyClass::test
then printing str hangs GDB. It doesn't respond to sigterms/sigints and
consumes 100% cpu. Interestingly, the problem doesn't occur when I compile with
g++. In addition, the problem does not occur when printing a local std::string.

#include <iostream>
#include <string>

struct MyClass
{
    MyClass()
        : str("Hello World")
    {}

    void test()
    {
        std::cout << str << std::endl;
    }

    std::string str;
};

int main()
{
    MyClass inst;
    inst.test();
    return 0;
}

Here are some versions. Note that I tested with 2 GDB versions, including the
latest HEAD.

joel ~> uname -a
Linux walker11 3.16.0-28-generic #38-Ubuntu SMP Fri Dec 12 17:37:40 UTC 2014
x86_64 x86_64 x86_64 GNU/Linux
joel ~> clang++ --version
Ubuntu clang version 3.5.0-4ubuntu2 (tags/RELEASE_350/final) (based on LLVM
3.5.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
joel ~> gdb --version
GNU gdb (Ubuntu 7.8-1ubuntu4) 7.8.0.20141001-cvs
...
joel ~> /tmp/binutils-gdb/gdb/gdb --version
GNU gdb (GDB) 7.8.50.20141219-cvs
...

Compilation command:
clang++ -g -Wall test_string.cpp

GDB session:
joel /tmp> ./binutils-gdb/gdb/gdb ./a.out 
Python Exception <type 'exceptions.ImportError'> No module named gdb: 
./binutils-gdb/gdb/gdb: warning: 
Could not load the Python gdb module from `/usr/local/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.

GNU gdb (GDB) 7.8.50.20141219-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
/home/joel/.gdbinit:1: Error in sourced command file:
Undefined command: "".  Try "help".
Reading symbols from ./a.out...done.
(gdb) break MyClass::test() 
Breakpoint 1 at 0x400cea: file test_string.cpp, line 12.
(gdb) r
Starting program: /tmp/a.out 

Breakpoint 1, MyClass::test (this=0x7fffffffe3b0) at test_string.cpp:12
12              std::cout << str << std::endl;
(gdb) print str
fish: Job 1, “./binutils-gdb/gdb/gdb ./a.out ” terminated by signal SIGKILL
(Forced quit)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
>From gdb-prs-return-17164-listarch-gdb-prs=sources.redhat.com@sourceware.org Sat Dec 20 02:10:37 2014
Return-Path: <gdb-prs-return-17164-listarch-gdb-prs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-gdb-prs@sources.redhat.com
Received: (qmail 3468 invoked by alias); 20 Dec 2014 02:10:30 -0000
Mailing-List: contact gdb-prs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <gdb-prs.sourceware.org>
List-Subscribe: <mailto:gdb-prs-subscribe@sourceware.org>
List-Archive: <http://sourceware.org/ml/gdb-prs/>
List-Post: <mailto:gdb-prs@sourceware.org>
List-Help: <mailto:gdb-prs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: gdb-prs-owner@sourceware.org
Delivered-To: mailing list gdb-prs@sourceware.org
Received: (qmail 2786 invoked by uid 48); 20 Dec 2014 02:10:26 -0000
From: "joel at walker9 dot net" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug c++/17734] Printing a std::string member hangs after clang
 compile
Date: Sat, 20 Dec 2014 02:10:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gdb
X-Bugzilla-Component: c++
X-Bugzilla-Version: HEAD
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: joel at walker9 dot net
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P2
X-Bugzilla-Assigned-To: unassigned at sourceware dot org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-17734-4717-jZjorqv0y7@http.sourceware.org/bugzilla/>
In-Reply-To: <bug-17734-4717@http.sourceware.org/bugzilla/>
References: <bug-17734-4717@http.sourceware.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://sourceware.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-q4/txt/msg00407.txt.bz2
Content-length: 3787

https://sourceware.org/bugzilla/show_bug.cgi?id\x17734

--- Comment #1 from Joel <joel at walker9 dot net> ---
I just had the bright idea to debug GDB with GDB to see what's happening. I
re-compiled GDB with "-g -O0", and here's the backtrace:

(gdb) print str

Program received signal SIGFPE, Arithmetic exception.
0x00000000005b37b0 in value_primitive_field (arg1=0xfef6b0, offset=0,
fieldno=0, arg_type=0xf57a70) at value.c:2984
2984          if ((bitpos % container_bitsize) + v->bitsize <container_bitsize
(gdb) bt
Python Exception <type 'exceptions.ImportError'> No module named gdb.frames:
#0  0x00000000005b37b0 in value_primitive_field (arg1=0xfef6b0, offset=0,
fieldno=0, arg_type=0xf57a70) at value.c:2984
#1  0x00000000005c28ad in do_search_struct_field (name=0x1076780 "str",
arg1=0xfef6b0, offset=0, type=0xf57a70, looking_for_baseclass=0,
result_ptr=0x7fffffffd710, last_boffset=0x7fffffffd70c,
    outermost_type=0xf57a70) at valops.c:1822
#2  0x00000000005c2e91 in search_struct_field (name=0x1076780 "str",
arg1=0xfef6b0, offset=0, type=0xf57a70, looking_for_baseclass=0) at
valops.c:1966
#3  0x00000000005c38fa in value_struct_elt (argp=0x7fffffffd838, args=0x0,
name=0x1076780 "str", static_memfuncp=0x0, err=0x91cd49 "structure pointer") at
valops.c:2165
#4  0x00000000005ba643 in evaluate_subexp_standard (expect_type=0x0,
exp=0x1076740, pos=0x7fffffffdd74, noside=EVAL_NORMAL) at eval.c:1904
#5  0x00000000006f9d7d in evaluate_subexp_c (expect_type=0x0, exp=0x1076740,
pos=0x7fffffffdd74, noside=EVAL_NORMAL) at c-lang.c:717
#6  0x00000000005b594d in evaluate_subexp (expect_type=0x0, exp=0x1076740,
pos=0x7fffffffdd74, noside=EVAL_NORMAL) at eval.c:79
#7  0x00000000005b5bd6 in evaluate_expression (exp=0x1076740) at eval.c:163
#8  0x00000000005d3d43 in print_command_1 (exp=0xd71196 "str", voidprint=1) at
./printcmd.c:974
#9  0x00000000005d3e7b in print_command (exp=0xd71196 "str", from_tty=1) at
./printcmd.c:1006
#10 0x00000000004fc94d in do_cfunc (c=0xe164e0, args=0xd71196 "str",
from_tty=1) at ./cli/cli-decode.c:105
#11 0x00000000004ffcda in cmd_func (cmd=0xe164e0, args=0xd71196 "str",
from_tty=1) at ./cli/cli-decode.c:1893
#12 0x000000000073fc1b in execute_command (p=0xd71198 "r", from_tty=1) at
top.c:476
#13 0x000000000062c047 in command_handler (command=0xd71190 "print str") at
event-top.c:494
#14 0x000000000062c613 in command_line_handler (rl=0xf0bef0 "") at
event-top.c:692
#15 0x00000000007aa0c4 in rl_callback_read_char () at callback.c:220
#16 0x000000000062baa9 in rl_callback_read_char_wrapper (client_data=0x0) at
event-top.c:171
#17 0x000000000062bf58 in stdin_event_handler (error=0, client_data=0x0) at
event-top.c:432
#18 0x000000000062a9e8 in handle_file_event (data=...) at event-loop.c:762
#19 0x0000000000629e76 in process_event () at event-loop.c:339
#20 0x0000000000629f3d in gdb_do_one_event () at event-loop.c:403
#21 0x0000000000629f9c in start_event_loop () at event-loop.c:428
#22 0x000000000062badb in cli_command_loop (data=0x0) at event-top.c:186
#23 0x00000000006215ed in current_interp_command_loop () at interps.c:317
#24 0x00000000006229e8 in captured_command_loop (data=0x0) at main.c:321
#25 0x000000000061e2a1 in catch_errors (func=0x6229cd <captured_command_loop>,
func_args=0x0, errstring=0x935ae5 "", mask=RETURN_MASK_ALL) at exceptions.c:237
#26 0x0000000000623f90 in captured_main (data=0x7fffffffe350) at main.c:1149
#27 0x000000000061e2a1 in catch_errors (func=0x622e2e <captured_main>,
func_args=0x7fffffffe350, errstring=0x935ae5 "", mask=RETURN_MASK_ALL) at
exceptions.c:237
#28 0x0000000000623fb9 in gdb_main (args=0x7fffffffe350) at main.c:1157
#29 0x000000000045e3bc in main (argc=2, argv=0x7fffffffe458) at gdb.c:32

--
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/17734] Printing a std::string member hangs after clang compile
  2014-12-19 21:29 [Bug c++/17734] New: Printing a std::string member hangs after clang compile joel at walker9 dot net
@ 2014-12-20  2:27 ` sivachandra at gmail dot com
  2014-12-20 21:19 ` joel at walker9 dot net
  1 sibling, 0 replies; 3+ messages in thread
From: sivachandra at gmail dot com @ 2014-12-20  2:27 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17734

Siva Chandra <sivachandra at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sivachandra at gmail dot com

--- Comment #2 from Siva Chandra <sivachandra at gmail dot com> ---
FWIW, this is triggered by a Clang bug. I tried with Clang 3.4 and Clang ToT
and found that it only occurs with Clang ToT. The problem is that the 'str'
fields bit offset is too high:

< 1><0x000003d4>    DW_TAG_structure_type
                      DW_AT_name                  "MyClass"
                      DW_AT_byte_size             0x00000008
                      DW_AT_decl_file             0x00000006 
                      DW_AT_decl_line             0x00000004
< 2><0x000003dc>      DW_TAG_member
                        DW_AT_name                  "str"
                        DW_AT_type                  <0x00000090>
                        DW_AT_decl_file             0x00000006 
                        DW_AT_decl_line             0x0000000f
                        DW_AT_byte_size             0x00000000
                        DW_AT_bit_size              0x00000040
                        DW_AT_bit_offset            0xffffffffffffffc0
                        DW_AT_data_member_location  0

GDB should not hang (or, appear to hang) and hence it is a GDB bug also.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/17734] Printing a std::string member hangs after clang compile
  2014-12-19 21:29 [Bug c++/17734] New: Printing a std::string member hangs after clang compile joel at walker9 dot net
  2014-12-20  2:27 ` [Bug c++/17734] " sivachandra at gmail dot com
@ 2014-12-20 21:19 ` joel at walker9 dot net
  1 sibling, 0 replies; 3+ messages in thread
From: joel at walker9 dot net @ 2014-12-20 21:19 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17734

Joel <joel at walker9 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joel at walker9 dot net

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-20 21:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19 21:29 [Bug c++/17734] New: Printing a std::string member hangs after clang compile joel at walker9 dot net
2014-12-20  2:27 ` [Bug c++/17734] " sivachandra at gmail dot com
2014-12-20 21:19 ` joel at walker9 dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).