public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "aburgess at redhat dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug python/28620] logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults)
Date: Tue, 23 Nov 2021 10:29:31 +0000	[thread overview]
Message-ID: <bug-28620-4717-FTaYub3Y5a@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28620-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=28620

Andrew Burgess <aburgess at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-11-23
             Status|UNCONFIRMED                 |NEW
                 CC|                            |aburgess at redhat dot com
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Burgess <aburgess at redhat dot com> ---
This problem can be simplified to just doing:

  (gdb) python gdb.execute("set logging on", False, True)
  (gdb) set logging off

The second 'True' in the gdb.execute is critical for reproducing this bug.

What happens is that in execute_control_commands_to_string (cli/cli-script.c)
we redirect all of the gdb_std* streams into a string_file, then we execute the
command.

The command in question is 'set logging on', this ends up in
cli_interp_base::set_logging (cli/cli-interp.c) where the values of the
gdb_std* streams are stashed away and then replaced with new logging specific
values.

At this point we have already gone wrong, we think we are writing to a
string_file, but we're now writing to the log file instead.

We then return to execute_control_commands_to_string where we restore the old
values of the gdb_std* streams, this restores the write to the terminal
streams, we've now gone wrong for a second time - logging should be on, but
instead we are writing to the terminal.  The string_file is destroyed as it
goes out of scope.

Finally, when we execute the 'set logging off' we end up back in
cli_interp_base::set_logging where we restore the stashed gdb_std* stream
values, in our case, the stashed values are the now deleted, string_file
stream.  This is the third time we go wrong.

At some future point we try to write to the stream, the contents of which are
now undefined, at some point this usually triggers a segfault.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  reply	other threads:[~2021-11-23 10:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23  9:37 [Bug python/28620] New: " plasmahh at gmx dot net
2021-11-23 10:29 ` aburgess at redhat dot com [this message]
2022-05-13 17:51 ` [Bug python/28620] " keith.hanlan at ericsson dot com
2022-08-12 20:03 ` tromey at sourceware dot 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-28620-4717-FTaYub3Y5a@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.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).