public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix uiout for execute_command_to_string
@ 2010-09-03 20:03 Jan Kratochvil
  2010-09-04 15:36 ` Paul Bolle
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2010-09-03 20:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: pebolle

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

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

end of thread, other threads:[~2010-09-11 16:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-03 20:03 [patch] Fix uiout for execute_command_to_string Jan Kratochvil
2010-09-04 15:36 ` Paul Bolle
2010-09-10 13:02   ` Jan Kratochvil
2010-09-10 22:05     ` Tom Tromey
2010-09-11 18:34       ` Jan Kratochvil

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