From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11147 invoked by alias); 22 Jun 2010 07:29:34 -0000 Received: (qmail 11129 invoked by uid 22791); 22 Jun 2010 07:29:31 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-pw0-f41.google.com (HELO mail-pw0-f41.google.com) (209.85.160.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 07:29:26 +0000 Received: by pwi7 with SMTP id 7so4934020pwi.0 for ; Tue, 22 Jun 2010 00:29:24 -0700 (PDT) Received: by 10.142.149.40 with SMTP id w40mr4680630wfd.334.1277191763213; Tue, 22 Jun 2010 00:29:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.143.32.8 with HTTP; Tue, 22 Jun 2010 00:29:03 -0700 (PDT) In-Reply-To: References: <4B3BEDCC.9040103@earthlink.net> <20100106075757.GF24777@adacore.com> <20100109105557.GA2007@adacore.com> <20100110054328.GD2007@adacore.com> <20100110140029.GF2007@adacore.com> From: Hui Zhu Date: Tue, 22 Jun 2010 07:29:00 -0000 Message-ID: Subject: Re: [RFC] Let "gcore" command accept a suffix argument To: Tom Tromey , Joel Brobecker , Eli Zaretskii Cc: Stan Shebs , Stan Shebs , Michael Snyder , gdb-patches ml Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-06/txt/msg00472.txt.bz2 On Tue, Jun 22, 2010 at 05:39, Tom Tromey wrote: >>>>>> ">" =3D=3D Hui Zhu writes: > >>> =A0static void >>> -printf_command (char *arg, int from_tty) >>> +ui_printf_maybe_filtered (char *arg, struct ui_file *stream, int filte= r) > > I don't think you really need the 'filter' argument. > > fprintf_filtered will actually work unfiltered unless printing to > gdb_stdout. =A0(One of several bad things about this API -- but we already > rely on it.) > > I think this argument uglifies the code quite a bit. > >>> +static void >>> +eval_command (char *arg, int from_tty) >>> +{ >>> + =A0struct ui_file *ui_out =3D mem_fileopen (); >>> + =A0char *expanded; >>> + =A0struct cleanup *old_chain; >>> + >>> + =A0ui_printf_maybe_filtered (arg, ui_out, 0); >>> + =A0expanded =3D ui_file_xstrdup (ui_out, NULL); >>> + =A0old_chain =3D make_cleanup (xfree, expanded); >>> + =A0execute_command (expanded, from_tty); >>> + =A0do_cleanups (old_chain); > > You need a cleanup in there to destroy the new ui_out. > >>> + =A0add_com ("eval", no_class, eval_command, _("\ >>> +Call command with variable.")); >>> =A0} > > This needs a better doc string. > > I think this approach is good overall. =A0It needs a documentation patch, > a NEWS entry, and some tests. > > Tom > Hi guys, I make a new patch according to your mails. It include the code, doc and test. Please help me review it. Thanks, Hui 2010-06-22 Hui Zhu * printcmd.c (ui_printf): New function. (printf_command): Call ui_printf. (_initialize_printcmd): New command "eval". 2010-06-22 Hui Zhu * gdb.texinfo: (Commands for Controlled Output): Add documentation for command "eval". 2010-06-22 Hui Zhu * gdb.base/eval.exp: New file. --- NEWS | 4 ++ doc/gdb.texinfo | 5 +++ printcmd.c | 63 ++++++++++++++++++++++++++++++++++-----= ----- testsuite/gdb.base/eval.exp | 22 +++++++++++++++ 4 files changed, 80 insertions(+), 14 deletions(-) --- a/NEWS +++ b/NEWS @@ -84,6 +84,10 @@ qRelocInsn * New commands +eval template, expressions... + Convert the values of one or more expressions under the control + of the string template to a command line and call it. + set target-file-system-kind unix|dos-based|auto show target-file-system-kind Set or show the assumed file system kind for target reported file --- a/doc/gdb.texinfo +++ b/doc/gdb.texinfo @@ -20073,6 +20073,11 @@ Here's an example of printing DFP types printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl @end smallexample +@kindex eval +@item eval @var{template}, @var{expressions}@dots{} +Convert the values of one or more @var{expressions} under the control of +the string @var{template} to a command line and call it. + @end table @node Python --- a/printcmd.c +++ b/printcmd.c @@ -1956,8 +1956,10 @@ print_variable_and_value (const char *na fprintf_filtered (stream, "\n"); } +/* printf "printf format string" ARG to STREAM. */ + static void -printf_command (char *arg, int from_tty) +ui_printf (char *arg, struct ui_file *stream) { char *f =3D NULL; char *s =3D arg; @@ -2340,7 +2342,7 @@ printf_command (char *arg, int from_tty) read_memory (tem, str, j); str[j] =3D 0; - printf_filtered (current_substring, (char *) str); + fprintf_filtered (stream, current_substring, (char *) str); } break; case wide_string_arg: @@ -2384,7 +2386,8 @@ printf_command (char *arg, int from_tty) &output, translit_char); obstack_grow_str0 (&output, ""); - printf_filtered (current_substring, obstack_base (&output)); + fprintf_filtered (stream, current_substring, + obstack_base (&output)); do_cleanups (inner_cleanup); } break; @@ -2416,7 +2419,8 @@ printf_command (char *arg, int from_tty) &output, translit_char); obstack_grow_str0 (&output, ""); - printf_filtered (current_substring, obstack_base (&output)); + fprintf_filtered (stream, current_substring, + obstack_base (&output)); do_cleanups (inner_cleanup); } break; @@ -2433,7 +2437,7 @@ printf_command (char *arg, int from_tty) if (inv) error (_("Invalid floating value found in program.")); - printf_filtered (current_substring, (double) val); + fprintf_filtered (stream, current_substring, (double) val); break; } case long_double_arg: @@ -2450,7 +2454,8 @@ printf_command (char *arg, int from_tty) if (inv) error (_("Invalid floating value found in program.")); - printf_filtered (current_substring, (long double) val); + fprintf_filtered (stream, current_substring, + (long double) val); break; } #else @@ -2461,7 +2466,7 @@ printf_command (char *arg, int from_tty) { long long val =3D value_as_long (val_args[i]); - printf_filtered (current_substring, val); + fprintf_filtered (stream, current_substring, val); break; } #else @@ -2471,14 +2476,14 @@ printf_command (char *arg, int from_tty) { int val =3D value_as_long (val_args[i]); - printf_filtered (current_substring, val); + fprintf_filtered (stream, current_substring, val); break; } case long_arg: { long val =3D value_as_long (val_args[i]); - printf_filtered (current_substring, val); + fprintf_filtered (stream, current_substring, val); break; } @@ -2490,7 +2495,7 @@ printf_command (char *arg, int from_tty) #if defined (PRINTF_HAS_DECFLOAT) /* If we have native support for Decimal floating printing, handle it here. */ - printf_filtered (current_substring, param_ptr); + fprintf_filtered (stream, current_substring, param_ptr); #else /* As a workaround until vasprintf has native support for DFP @@ -2579,7 +2584,7 @@ printf_command (char *arg, int from_tty) decimal_to_string (dfp_ptr, dfp_len, byte_order, decstr); /* Print the DFP value. */ - printf_filtered (current_substring, decstr); + fprintf_filtered (stream, current_substring, decstr); break; #endif @@ -2634,13 +2639,13 @@ printf_command (char *arg, int from_tty) *fmt_p++ =3D 'l'; *fmt_p++ =3D 'x'; *fmt_p++ =3D '\0'; - printf_filtered (fmt, val); + fprintf_filtered (stream, fmt, val); } else { *fmt_p++ =3D 's'; *fmt_p++ =3D '\0'; - printf_filtered (fmt, "(nil)"); + fprintf_filtered (stream, fmt, "(nil)"); } break; @@ -2658,11 +2663,37 @@ printf_command (char *arg, int from_tty) puts_filtered here. Also, we pass a dummy argument because some platforms have modified GCC to include -Wformat-security by default, which will warn here if there is no argument. */ - printf_filtered (last_arg, 0); + fprintf_filtered (stream, last_arg, 0); } do_cleanups (old_cleanups); } +/* Implement the "printf" command. */ + +static void +printf_command (char *arg, int from_tty) +{ + ui_printf (arg, gdb_stdout); +} + +/* Implement the "eval" command. */ + +static void +eval_command (char *arg, int from_tty) +{ + struct ui_file *ui_out =3D mem_fileopen (); + struct cleanup *ui_out_cleanups =3D make_cleanup_ui_file_delete (ui_out); + char *expanded; + struct cleanup *expanded_chain; + + ui_printf (arg, ui_out); + expanded =3D ui_file_xstrdup (ui_out, NULL); + expanded_chain =3D make_cleanup (xfree, expanded); + execute_command (expanded, from_tty); + do_cleanups (expanded_chain); + do_cleanups (ui_out_cleanups); +} + void _initialize_printcmd (void) { @@ -2826,4 +2857,8 @@ Show printing of source filename and lin NULL, show_print_symbol_filename, &setprintlist, &showprintlist); + + add_com ("eval", no_class, eval_command, _("\ +Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\ +a command line and call it.")); } --- /dev/null +++ b/testsuite/gdb.base/eval.exp @@ -0,0 +1,22 @@ +# Copyright 2010 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +gdb_exit +gdb_start + +gdb_test_no_output "set \$a =3D 10" "Initialize \$a." + +gdb_test "eval \"echo %d\\n\", \$a++" "10" +gdb_test "eval \"echo %d\\n\", \$a++" "11"