public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/107965] libstdc++ Python Pretty-Printers: Many Exceptions From Uninitialized Structures
Date: Mon, 05 Dec 2022 08:45:57 +0000	[thread overview]
Message-ID: <bug-107965-4-JB1f57a5S3@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 #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> They're nothing the printers can do. You're asking to print them out before
> they are initialized, so they try to interpret garbage as values. The
> OverflowError is just because some uninitialized std::string cannot be
> printed.
> 
> This should really be reported as a gdb bug. Gdb knows if the object's
> initialization had finished, so it should not try to print variables at all
> before their lifetime has begun, especially not via python printers.
> 
> It might make sense to display the variable name with a value like <before
> lifetime>, but even that is debatable. The C++ standard is very clear that
> none of those variables exists yet at your breakpoint, and gdb contradicts
> its own documentation:
> 
> "These are all variables (declared either static or automatic) accessible at
> the point of execution of the selected frame."

I'm not so sure.  For

struct X { X(); int i; };

X::X () { i = 42; }

int main()
{
  X x;
  return 0;
}

GCC emits

 <1><6e>: Abbrev Number: 9 (DW_TAG_subprogram)
    <6f>   DW_AT_external    : 1
    <6f>   DW_AT_name        : (indirect string, offset: 0xf): main
    <73>   DW_AT_decl_file   : 1
    <74>   DW_AT_decl_line   : 5
    <75>   DW_AT_decl_column : 5
    <76>   DW_AT_type        : <0x67>
    <7a>   DW_AT_low_pc      : 0x15
    <82>   DW_AT_high_pc     : 0x1b
    <8a>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
    <8c>   DW_AT_GNU_all_tail_call_sites: 1
    <8c>   DW_AT_sibling     : <0x9e>
 <2><90>: Abbrev Number: 10 (DW_TAG_variable)
    <91>   DW_AT_name        : x
    <93>   DW_AT_decl_file   : 1
    <94>   DW_AT_decl_line   : 7
    <95>   DW_AT_decl_column : 5
    <96>   DW_AT_type        : <0x2d>
    <9a>   DW_AT_location    : 2 byte block: 91 6c      (DW_OP_fbreg: -20)

so gdb has no idea that x only becomes live after the call to the CTOR
(or during that).  Instead GCC says it lives throughout the whole
function on the frame.  Even the original IL from the frontend has no
hint that would allow the middle-end to emit different DWARF.

  parent reply	other threads:[~2022-12-05  8:45 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 [this message]
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
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-JB1f57a5S3@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).