public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug debug/107965] libstdc++ Python Pretty-Printers: Many Exceptions From Uninitialized Structures
Date: Mon, 05 Dec 2022 10:37:45 +0000	[thread overview]
Message-ID: <bug-107965-4-al8JLSc2Yg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107965-4@http.gcc.gnu.org/bugzilla/>

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.

  parent reply	other threads:[~2022-12-05 10:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-04 19:46 [Bug libstdc++/107965] New: " gustaf.waldemarson at gmail dot com
2022-12-04 20:04 ` [Bug libstdc++/107965] " pinskia at gcc dot gnu.org
2022-12-05  8:24 ` redi at gcc dot gnu.org
2022-12-05  8:45 ` rguenth at gcc dot gnu.org
2022-12-05  8:48 ` rguenth at gcc dot gnu.org
2022-12-05  9:42 ` [Bug debug/107965] " redi at gcc dot gnu.org
2022-12-05 10:37 ` redi at gcc dot gnu.org [this message]
2023-01-17 19:37 ` gustaf.waldemarson at gmail dot com
2023-01-17 20:25 ` jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107965-4-al8JLSc2Yg@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).