From: Hui Zhu <teawater@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>,
brobecker@adacore.com, Pedro Alves <pedro@codesourcery.com>,
Tom Tromey <tromey@redhat.com>
Cc: stanshebs@earthlink.net, stan@codesourcery.com,
msnyder@vmware.com, gdb-patches@sourceware.org
Subject: Re: [RFC] Let "gcore" command accept a suffix argument
Date: Wed, 23 Jun 2010 02:03:00 -0000 [thread overview]
Message-ID: <AANLkTinoKYjbihTEom4iVndEXYTdfeM7ziIzyw7ve9Yw@mail.gmail.com> (raw)
In-Reply-To: <83zkyndjx2.fsf@gnu.org>
On Wed, Jun 23, 2010 at 02:03, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Hui Zhu <teawater@gmail.com>
>> Date: Tue, 22 Jun 2010 15:29:03 +0800
>> Cc: Stan Shebs <stanshebs@earthlink.net>, Stan Shebs <stan@codesourcery.com>,
>> Michael Snyder <msnyder@vmware.com>, gdb-patches ml <gdb-patches@sourceware.org>
>>
>> I make a new patch according to your mails.
>>
>> It include the code, doc and test. Please help me review it.
>
> Thanks. The doc parts are okay, with these two comments:
>
>> +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.
> ^
> A comma here, please.
>
>> +@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.
> ^
> Same here.
>
Hi guys,
I make a new patch according to your mails.
Please help me review it. Thanks.
Best,
Hui
2010-06-23 Hui Zhu <teawater@gmail.com>
* printcmd.c (ui_printf): New function.
(printf_command): Call ui_printf.
(_initialize_printcmd): New command "eval".
2010-06-23 Hui Zhu <teawater@gmail.com>
* gdb.texinfo: (Commands for Controlled Output): Add
documentation for command "eval".
2010-06-23 Hui Zhu <teawater@gmail.com>
* gdb.base/eval.exp: New file.
---
NEWS | 4 ++
doc/gdb.texinfo | 5 +++
printcmd.c | 64 ++++++++++++++++++++++++++++++++++----------
testsuite/gdb.base/eval.exp | 22 +++++++++++++++
4 files changed, 81 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 = NULL;
char *s = arg;
@@ -2340,7 +2342,7 @@ printf_command (char *arg, int from_tty)
read_memory (tem, str, j);
str[j] = 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 = 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 = value_as_long (val_args[i]);
- printf_filtered (current_substring, val);
+ fprintf_filtered (stream, current_substring, val);
break;
}
case long_arg:
{
long val = 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++ = 'l';
*fmt_p++ = 'x';
*fmt_p++ = '\0';
- printf_filtered (fmt, val);
+ fprintf_filtered (stream, fmt, val);
}
else
{
*fmt_p++ = 's';
*fmt_p++ = '\0';
- printf_filtered (fmt, "(nil)");
+ fprintf_filtered (stream, fmt, "(nil)");
}
break;
@@ -2658,11 +2663,38 @@ 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 = mem_fileopen ();
+ struct cleanup *cleanups = make_cleanup_ui_file_delete (ui_out);
+ char *expanded;
+
+ ui_printf (arg, ui_out);
+
+ expanded = ui_file_xstrdup (ui_out, NULL);
+ make_cleanup (xfree, expanded);
+
+ execute_command (expanded, from_tty);
+
+ do_cleanups (cleanups);
+}
+
void
_initialize_printcmd (void)
{
@@ -2826,4 +2858,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 <http://www.gnu.org/licenses/>.
+
+gdb_exit
+gdb_start
+
+gdb_test_no_output "set \$a = 10" "Initialize \$a."
+
+gdb_test "eval \"echo %d\\n\", \$a++" "10"
+gdb_test "eval \"echo %d\\n\", ++\$a" "12"
next prev parent reply other threads:[~2010-06-23 2:03 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4B11DA3C.3000203@vmware.com>
[not found] ` <daef60380911300437o4c616eb2v5ad7bfe99bd3c5e9@mail.gmail.com>
[not found] ` <20091130162246.GE4034@adacore.com>
[not found] ` <4B141157.3070709@vmware.com>
[not found] ` <20091130185341.GI4034@adacore.com>
[not found] ` <4B141469.5030402@vmware.com>
[not found] ` <20091130190619.GJ4034@adacore.com>
[not found] ` <4B1428F0.7090608@vmware.com>
[not found] ` <daef60380912091827u6ff7127bp1d03998a40932914@mail.gmail.com>
2009-12-10 2:32 ` Hui Zhu
2009-12-10 17:08 ` Tom Tromey
2009-12-11 10:06 ` Joel Brobecker
2009-12-11 18:25 ` Tom Tromey
2009-12-12 8:33 ` Hui Zhu
2009-12-13 4:05 ` Hui Zhu
2009-12-14 17:09 ` Tom Tromey
2009-12-15 1:57 ` Hui Zhu
2009-12-15 19:21 ` Tom Tromey
2009-12-16 3:58 ` Hui Zhu
2009-12-16 15:49 ` Stan Shebs
2009-12-17 2:45 ` Hui Zhu
2009-12-17 4:26 ` Joel Brobecker
2009-12-17 4:29 ` Michael Snyder
2009-12-17 9:32 ` Andreas Schwab
2009-12-21 20:15 ` Tom Tromey
2009-12-31 0:18 ` Stan Shebs
2010-01-04 14:42 ` Hui Zhu
2010-01-06 6:57 ` Hui Zhu
2010-01-06 7:58 ` Joel Brobecker
2010-01-09 9:55 ` Hui Zhu
2010-01-09 10:56 ` Joel Brobecker
2010-01-09 15:18 ` Hui Zhu
2010-01-10 5:43 ` Joel Brobecker
2010-01-10 13:30 ` Hui Zhu
2010-01-10 14:00 ` Joel Brobecker
2010-01-10 14:16 ` Hui Zhu
2010-06-21 15:05 ` Hui Zhu
2010-06-21 16:57 ` Joel Brobecker
2010-06-21 21:34 ` Joel Brobecker
2010-06-21 21:40 ` Tom Tromey
2010-06-22 7:29 ` Hui Zhu
2010-06-22 9:50 ` Pedro Alves
2010-06-22 15:21 ` Joel Brobecker
2010-06-22 18:05 ` Eli Zaretskii
2010-06-23 2:03 ` Hui Zhu [this message]
2010-06-23 16:59 ` Joel Brobecker
2010-06-24 6:13 ` Hui Zhu
2010-01-06 10:13 ` Eli Zaretskii
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=AANLkTinoKYjbihTEom4iVndEXYTdfeM7ziIzyw7ve9Yw@mail.gmail.com \
--to=teawater@gmail.com \
--cc=brobecker@adacore.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=msnyder@vmware.com \
--cc=pedro@codesourcery.com \
--cc=stan@codesourcery.com \
--cc=stanshebs@earthlink.net \
--cc=tromey@redhat.com \
/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