public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/28620] New: logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults)
@ 2021-11-23  9:37 plasmahh at gmx dot net
  2021-11-23 10:29 ` [Bug python/28620] " aburgess at redhat dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: plasmahh at gmx dot net @ 2021-11-23  9:37 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 28620
           Summary: logging/output redirect interaction between python and
                    stepping commands is broken (and sometimes segfaults)
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: plasmahh at gmx dot net
  Target Milestone: ---

Tried with todays HEAD too.

While developing my python plugin I noticed that output redirection of stepping
commands does not work in python (e.g. gdb.execute("si",False,True). Since all
I needed at that point was supressing the output, I tried using the logging
redirect mechanism and things crashed on me.

To reproduce, start any program within gdb (-nh) to a point where stepping is
possible. Then do

python for c in "set logging redirect on\nset logging on\nsi".splitlines():
gdb.execute(c,False,True)

and after that 

set logging off


This will reliably segfault for me (and some others on IRC too)

Further I noticed that when doing 

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

and then do a 

show logging

Half of the output goes to the redirected file, and half of  it is displayed on
the terminal (the prefix for each entry that is)

A "set logging off" after that will crash too.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug python/28620] logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults)
  2021-11-23  9:37 [Bug python/28620] New: logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults) plasmahh at gmx dot net
@ 2021-11-23 10:29 ` aburgess at redhat dot com
  2022-05-13 17:51 ` keith.hanlan at ericsson dot com
  2022-08-12 20:03 ` tromey at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: aburgess at redhat dot com @ 2021-11-23 10:29 UTC (permalink / raw)
  To: gdb-prs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug python/28620] logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults)
  2021-11-23  9:37 [Bug python/28620] New: logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults) plasmahh at gmx dot net
  2021-11-23 10:29 ` [Bug python/28620] " aburgess at redhat dot com
@ 2022-05-13 17:51 ` keith.hanlan at ericsson dot com
  2022-08-12 20:03 ` tromey at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: keith.hanlan at ericsson dot com @ 2022-05-13 17:51 UTC (permalink / raw)
  To: gdb-prs

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

Keith Hanlan <keith.hanlan at ericsson dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |keith.hanlan at ericsson dot com

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug python/28620] logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults)
  2021-11-23  9:37 [Bug python/28620] New: logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults) plasmahh at gmx dot net
  2021-11-23 10:29 ` [Bug python/28620] " aburgess at redhat dot com
  2022-05-13 17:51 ` keith.hanlan at ericsson dot com
@ 2022-08-12 20:03 ` tromey at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: tromey at sourceware dot org @ 2022-08-12 20:03 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
The plan in bug#28948 should fix this.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-12 20:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23  9:37 [Bug python/28620] New: logging/output redirect interaction between python and stepping commands is broken (and sometimes segfaults) plasmahh at gmx dot net
2021-11-23 10:29 ` [Bug python/28620] " aburgess at redhat dot com
2022-05-13 17:51 ` keith.hanlan at ericsson dot com
2022-08-12 20:03 ` tromey at sourceware dot org

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).