Discussion:
[Bug gdb/21506] New: python execute(to_string=True) no longer captures certain output since e7ea3ec7
sourceware-bugzilla at zulan dot net
2017-05-20 14:54:59 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

Bug ID: 21506
Summary: python execute(to_string=True) no longer captures
certain output since e7ea3ec7
Product: gdb
Version: HEAD
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: sourceware-bugzilla at zulan dot net
Target Milestone: ---

python gdb.execute(to_string=True) no longer captures all output, in particular
for the 'step' command, since f7c382926d. This is limits functionality, e.g.
http://stackoverflow.com/questions/39602306/tracing-program-function-execution-on-source-line-level

Expected result (f7c382926d)

$ ./gdb/gdb ../a.out
GNU gdb (GDB) 7.11.50.20160331-git
Reading symbols from ../a.out...done.
(gdb) break main
Breakpoint 1 at 0x4004aa: file test.c, line 3.
(gdb) run
Starting program: /home/tilsche/code/gdb/a.out

Breakpoint 1, main () at test.c:3
3 return 4;
(gdb) python x = gdb.execute('step', to_string=True)
(gdb) python print(x)
4 }

Result since e7ea3ec7c6

$ ./gdb/gdb ../a.out
GNU gdb (GDB) 7.11.50.20160331-git
Reading symbols from ../a.out...done.
(gdb) break main
Breakpoint 1 at 0x4004aa: file test.c, line 3.
(gdb) run
Starting program: /home/tilsche/code/gdb/a.out

Breakpoint 1, main () at test.c:3
3 return 4;
(gdb) python x = gdb.execute('step', to_string=True)
4 }
(gdb) python print(x)

Test code:

int main()
{
return 4;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2017-09-03 18:51:06 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2017-09-03
CC| |tromey at sourceware dot org
Ever confirmed|0 |1

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
I've also noticed this when using my python gdb gui --
the gui uses to_string=True for some commands to suppress output,
but gdb still emits the output anyway now.

For example in my case it happens in tui_on_normal_stop, which
calls print_stop_event for each UI.

I'm not sure what can be done about this. if nothing, it's worth
noting that the output is sub-par as well:

(top) 30 args.argv = argv;
31 args.interpreter_p = INTERP_CONSOLE;


... that is, it doesn't try to erase the prompt first.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-04-01 17:40:21 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Component|gdb |python
--
You are receiving this mail because:
You are on the CC list for the bug.
simon.marchi at ericsson dot com
2018-04-01 19:43:21 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

Simon Marchi <simon.marchi at ericsson dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |simon.marchi at ericsson dot com

--- Comment #2 from Simon Marchi <simon.marchi at ericsson dot com> ---
I don't understand all the interps/uiouts dynamics yet, so I'm not sure what
the solution should be, but the problem seems to be that:

- We install the "console" interpreter's uiout in execute_gdb_command as the
current_uiout.
- We set up the redirection on the "tui" interpreter's uiout (in
execute_command_to_string).

They are two different cli_ui_out instances. When the print is done, the
active uiout is therefore the one that doesn't have the redirection.

It's probably not the right fix, but just to illustrate, this change makes it
work for me (though probably break other stuff):

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9eae8a1aef2d..5ca58578040f 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -587,7 +587,7 @@ execute_gdb_command (PyObject *self, PyObject *args,
PyObject *kw)

/* Use the console interpreter uiout to have the same print format
for console or MI. */
- interp = interp_lookup (current_ui, "console");
+ interp = interp_lookup (current_ui, "tui");
current_uiout = interp_ui_out (interp);

scoped_restore preventer = prevent_dont_repeat ();
--
You are receiving this mail because:
You are on the CC list for the bug.
autkin at undo dot io
2018-08-16 15:35:31 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

Andrey Utkin <autkin at undo dot io> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |autkin at undo dot io
--
You are receiving this mail because:
You are on the CC list for the bug.
autkin at undo dot io
2018-08-16 10:13:15 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

Andrey Utkin <autkin at undo dot io> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |catalin.udma at freescale dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
autkin at undo dot io
2018-08-17 18:00:41 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

--- Comment #3 from Andrey Utkin <autkin at undo dot io> ---
(In reply to Simon Marchi from comment #2)
Post by simon.marchi at ericsson dot com
It's probably not the right fix, but just to illustrate, this change makes
Indeed, this patch makes one of our tests work, but causes segfaults in other
cases.

Program terminated with signal SIGSEGV, Segmentation fault.
#0 ui_out::redirect (this=0x0, outstream=***@entry=0x7ffc20a6da90) at
ui-out.c:611
611 do_redirect (outstream);
(gdb) bt
#0 ui_out::redirect (this=0x0, outstream=***@entry=0x7ffc20a6da90) at
ui-out.c:611
#1 0x000055a450e2589f in execute_command_to_string[abi:cxx11](char const*,
int) (p=0x7f8ab460bc24 "info proc", from_tty=***@entry=0) at top.c:673
#2 0x000055a450c28368 in execute_gdb_command (self=<optimized out>,
args=<optimized out>, kw=<optimized out>) at python/python.c:600
...
--
You are receiving this mail because:
You are on the CC list for the bug.
autkin at undo dot io
2018-08-23 18:00:47 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21506

--- Comment #4 from Andrey Utkin <autkin at undo dot io> ---
Created attachment 11206
--> https://sourceware.org/bugzilla/attachment.cgi?id=11206&action=edit
a hacky fix

The patch which I won't recommend to upstream, but it happens to help in this
specific situation while not causing noticeable issues in other tests I have
run.

Alternative, and perhaps better, solutiuon may be to temporarily replace
ui_list.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...