https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107965

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reading symbols from p...
(gdb) start
Temporary breakpoint 1 at 0x4022ea: file p.cc, line 18.
Starting program: /tmp/p 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at p.cc:18
18          }

Why is the location for the 'start' breakpoint the closing brace of main() ?!

(gdb) n
9               vector<string> test{"test", "test2"};
(gdb) info locals
test = std::vector of length 5, capacity 38 = {" ", <error: Cannot access
memory at address 0x2e00000000>, "", 
  <error: Cannot access memory at address 0x400030200000000>, <error: Cannot
access memory at address 0x3500000034>}
blabla = ""
b = 32767

The errors here seem reasonable, but they depend entirely on the garbage that
happens to be in the uninitialized variables. Different garbage will produce
worse errors.


(gdb) disable pretty-printer
200 printers disabled
0 of 200 printers enabled
(gdb) info locals
test = {<std::_Vector_base<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >> = {
    _M_impl = {<std::allocator<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > >> =
{<std::__new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > >> = {<No data fields>}, <No data fields>},
<std::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >::_Vector_impl_data> =
{_M_start = 0x7ffff7e2e9a0 <(anonymous namespace)::moneypunct_cache_wf>, 
        _M_finish = 0x7ffff7e2ea40 <(anonymous
namespace)::moneypunct_cache_wt>, 
        _M_end_of_storage = 0x7ffff7e2ee60 <(anonymous
namespace)::moneypunct_cache_ct>}, <No data fields>}}, <No data fields>}

Even with the printers disabled (which is what would happen if the printers
caught all exceptions and didn't show anything) we get nonsense.
moneypunct_cache_wf, moneypunct_cache_wt, and moneypunch_cache_ct are global
variables inside libstdc++.so, but the uninitialized pointers in the
std::vector just happen to point at them.

blabla = {_M_dataplus = {<std::allocator<char>> = {<std::__new_allocator<char>>
= {<No data fields>}, <No data fields>}, 
    _M_p = 0x7ffff7e2ede0 <(anonymous namespace)::moneypunct_cache_cf>
"x9\342\367\377\177"}, _M_string_length = 140737352232672, {
    _M_local_buf =
"\300\357\342\367\377\177\000\000\002\316\314\367\377\177\000",
_M_allocated_capacity = 140737352232896}}

This is all garbage.

b = 32767

At least with an uninitialized int we just get an arbitrary int value, not
nonsense.

But none of these variables should be live yet, so gdb shouldn't even try to
show their values.

Reply via email to