[patch] Fix uiout for execute_command_to_string

Jan Kratochvil
2010-09-03T18:06:44Z

Hi,

uiout is currently not redirected in execute_command_to_string. This function
is currently testable only using python.

(gdb) python gdb.execute("help",to_string=True)
Aliases of other commandsMaking program stop at certain pointsExamining dataSpecifying and examining filesMaintenance commandsObscure featuresRunning the programExamining the stackStatus inquiriesSupport facilitiesTracing of program execution without stopping the programUser-defined commands(gdb)

Bugreport (with patches posting) by Paul Bolle:
https://bugzilla.redhat.com/show_bug.cgi?id=627506

Redirected there also gdb_stdlog as it seems appropriate to me. That is
remain unredirected gdb_stdin, gdb_stdtargin, gdb_stdtarg and gdb_stdtargerr,
I do not much understand gdb_stdtarg* but it seems to +/- match other
redirections in GDB.

No regressions on {x86_64,x86_64-m32,i686}-fedora14snapshot-linux-gnu.

Thanks,
Jan

gdb/
2010-09-03 Jan Kratochvil <jan.kratochvil@redhat.com>

Redirect also uiout in execute_command_to_string.
* defs.h (struct ui_out, make_cleanup_ui_out_redirect_pop): New
declarations.
* top.c (execute_command_to_string): Move make_cleanup_ui_file_delete
to the top. Redirect also gdb_stdlog. Use ui_out_redirect, register
make_cleanup_ui_out_redirect_pop.
* utils.c (do_ui_out_redirect_pop, make_cleanup_ui_out_redirect_pop):
New functions.

gdb/testsuite/
2010-09-03 Jan Kratochvil <jan.kratochvil@redhat.com>

* gdb.python/python.exp (set height 0, collect help from uiout)
(verify help to uiout): New tests.

--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -337,6 +337,10 @@ extern struct cleanup *make_cleanup_freeargv (char **);
struct ui_file;
extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *);

+struct ui_out;
+extern struct cleanup *
+ make_cleanup_ui_out_redirect_pop (struct ui_out *uiout);
+
struct section_addr_info;
extern struct cleanup *(make_cleanup_free_section_addr_info
(struct section_addr_info *));
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -149,6 +149,12 @@ gdb_test_multiple "python print \"\\n\" * $lines" $test {
}
gdb_test "q" "Quit" "verify pagination afterwards: q"

+gdb_test_no_output "set height 0"
+
+gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect help from uiout"
+
+gdb_test "python print a" ".*aliases -- Aliases of other commands.*" "verify help to uiout"
+
# Start with a fresh gdb.
clean_restart ${testfile}

--- a/gdb/top.c
+++ b/gdb/top.c
@@ -475,12 +475,19 @@ execute_command_to_string (char *p, int from_tty)

str_file = mem_fileopen ();

+ make_cleanup_ui_file_delete (str_file);
make_cleanup_restore_ui_file (&gdb_stdout);
make_cleanup_restore_ui_file (&gdb_stderr);
- make_cleanup_ui_file_delete (str_file);
+ make_cleanup_restore_ui_file (&gdb_stdlog);
+
+ if (ui_out_redirect (uiout, str_file) < 0)
+ warning (_("Current output protocol does not support redirection"));
+ else
+ make_cleanup_ui_out_redirect_pop (uiout);

gdb_stdout = str_file;
gdb_stderr = str_file;
+ gdb_stdlog = str_file;

execute_command (p, from_tty);

--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -312,6 +312,21 @@ make_cleanup_ui_file_delete (struct ui_file *arg)
}

static void
+do_ui_out_redirect_pop (void *arg)
+{
+ struct ui_out *uiout = arg;
+
+ if (ui_out_redirect (uiout, NULL) < 0)
+ warning (_("Cannot restore redirection of the current output protocol"));
+}
+
+struct cleanup *
+make_cleanup_ui_out_redirect_pop (struct ui_out *uiout)
+{
+ return make_my_cleanup (&cleanup_chain, do_ui_out_redirect_pop, uiout);
+}
+
+static void
do_free_section_addr_info (void *arg)
{
free_section_addr_info (arg);