public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: pebolle@tiscali.nl
Subject: [patch] Fix uiout for execute_command_to_string
Date: Fri, 03 Sep 2010 20:03:00 -0000	[thread overview]
Message-ID: <20100903180619.GA15409@host1.dyn.jankratochvil.net> (raw)

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

             reply	other threads:[~2010-09-03 18:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-03 20:03 Jan Kratochvil [this message]
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

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=20100903180619.GA15409@host1.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pebolle@tiscali.nl \
    /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).