This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB 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]

[Bug c++/11836] New: gdb cannot access variables that are subject to return value optimization


#include <string>

std::string foo()
{
    std::string s;
    s = "hello";
    s += "world";
    return s;
}

std::string bar()
{
    std::string s;
    s = "hello";
    s += "world";
    return "something else";
}

int main()
{
    int a = foo().size();
    int b = bar().size();
    return a + b;
}

/*

Gcc seems to apply return value optimization (even at -O0) but there is
some problem with either the generated debug information or the way
gdb handles it. 

To reproduce it, save this file here as rvo.cpp and run

    g++ -g -O0 rvo.cpp -o rvo 

    gdb -ex 'set confirm off' -ex 'file ./rvo' \
        -ex 'b rvo.cpp:8' -ex 'b rvo.cpp:16' \
        -ex 'run' -ex 'print s'  \
        -ex 'cont' -ex 'print s' \
        -ex 'quit'


The result will look like:

    Breakpoint 1, foo () at rvo.cpp:8
    8           s += "world";
    $1 = {static npos = <optimized out>, 
      _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>>
    = {<No daa fields>}, <No data fields>}, _M_p = 0x1 <Address 0x1 out of
    bounds>}}

    Breakpoint 2, bar () at rvo.cpp:16
    16          s += "world";
    $2 = {static npos = <optimized out>, 
      _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>>
    = {<No data fields>}, <No data fields>}, _M_p = 0x804b014 "hello"}}

    Program exited with code 030.

RVO seems to be applied in the first case with "dangling" debug information.
If no RVO is used (second case), all is fine.


*/

-- 
           Summary: gdb cannot access variables that are subject to return
                    value optimization
           Product: gdb
           Version: 7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: andre dot poenitz at nokia dot com
                CC: gdb-prs at sourceware dot org
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=11836

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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