This is the mail archive of the
gdb-prs@sourceware.org
mailing list for the GDB project.
[Bug gdb/21341] New: C++ vector elements wrongly evaluated with MI2
- From: "vljubovic at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: gdb-prs at sourceware dot org
- Date: Sat, 01 Apr 2017 08:28:11 +0000
- Subject: [Bug gdb/21341] New: C++ vector elements wrongly evaluated with MI2
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=21341
Bug ID: 21341
Summary: C++ vector elements wrongly evaluated with MI2
Product: gdb
Version: 7.12.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: vljubovic at gmail dot com
Target Milestone: ---
While debugging C++ programs, when options -q --interpreter=mi2 gdb will return
wrong values while inspecting vector elements.
Consider the following simple C++ program (bugdemo.cpp):
#include <iostream>
#include <vector>
int main() {
std::vector<int> v{1,2,3,4}; // test
int x;
std::cin>>x;
std::cout<<"Value of " << x << "-th element is "<<v[x]<<std::endl;
return 0;
}
Compile with: g++ -g --std=c++11 bugdemo.cpp -o bugdemo
Now consider the following simple gdb session (gdb bugdemo):
GNU gdb (GDB) 7.12
Copyright (C) 2016 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-pc-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"...
Reading symbols from bugdemo...done.
(gdb) break 7
Breakpoint 1 at 0x400bc1: file main.cpp, line 7.
(gdb) run
Starting program: /rhome/t/test/workspace/TP/T1/Z1/bugdemo
3
Breakpoint 1, main () at main.cpp:7
7 std::cout<<"Value of " << x << "-th element is "<<v[x]<<std::endl;
(gdb) print v[1]
$1 = (__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type &) @0x603014:
2
(gdb) q
A debugging session is active.
Inferior 1 [process 10116] will be killed.
Quit anyway? (y or n) y
So far soo good, everthing seems to work. Now the same session with command
line: gdb -q --interpreter=mi2 bugdemo
=thread-group-added,id="i1"
~"Reading symbols from bugdemo..."
~"done.\n"
(gdb)
-break-insert 8
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000400c1a",func="main()",file="main.cpp",fullname="/rhome/t/test/workspace/TP/T1/Z1/main.cpp",line="8",thread-groups=["i1"],times="0",original-location="/rhome/t/test/workspace/TP/T1/Z1/main.cpp:8"}
(gdb)
-exec-run
=thread-group-started,id="i1",pid="10574"
=thread-created,id="1",group-id="i1"
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
^running
*running,thread-id="all"
(gdb)
=library-loaded,id="/usr/lib/x86_64-linux-gnu/libstdc++.so.6",target-name="/usr/lib/x86_64-linux-gnu/libstdc++.so.6",host-name="/usr/lib/x86_64-linux-gnu/libstdc++.so.6",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib/x86_64-linux-gnu/libgcc_s.so.1",target-name="/lib/x86_64-linux-gnu/libgcc_s.so.1",host-name="/lib/x86_64-linux-gnu/libgcc_s.so.1",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib/x86_64-linux-gnu/libc.so.6",target-name="/lib/x86_64-linux-gnu/libc.so.6",host-name="/lib/x86_64-linux-gnu/libc.so.6",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib/x86_64-linux-gnu/libm.so.6",target-name="/lib/x86_64-linux-gnu/libm.so.6",host-name="/lib/x86_64-linux-gnu/libm.so.6",symbols-loaded="0",thread-group="i1"
3
Value of 3-th element is 4
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000400c1a",func="main()",file="main.cpp",fullname="/rhome/t/test/workspace/TP/T1/Z1/main.cpp",line="8",thread-groups=["i1"],times="1",original-location="/rhome/t/test/workspace/TP/T1/Z1/main.cpp:8"}
~"\n"
~"Breakpoint 1, main () at main.cpp:8\n"
~"8\t return 0;\n"
*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame={addr="0x0000000000400c1a",func="main",args=[],file="main.cpp",fullname="/rhome/t/test/workspace/TP/T1/Z1/main.cpp",line="8"},thread-id="1",stopped-threads="all",core="1"
(gdb)
-data-evaluate-expression v[1]
^done,value="@0x603014"
(gdb)
q
&"q\n"
=thread-exited,id="1",group-id="i1"
=thread-group-exited,id="i1"
Notice the line:
^done,value="@0x603014"
expected result should be:
^done,value="2"
--
You are receiving this mail because:
You are on the CC list for the bug.