From: Hui Zhu <teawater@gmail.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Joel Brobecker <brobecker@adacore.com>,
Michael Snyder <msnyder@vmware.com>,
gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [RFC] Let "gcore" command accept a suffix argument
Date: Sat, 12 Dec 2009 08:33:00 -0000 [thread overview]
Message-ID: <daef60380912120033r1ac03f1ao1f995381db879c82@mail.gmail.com> (raw)
In-Reply-To: <m3tyvxz8kp.fsf@fleche.redhat.com>
[-- Attachment #1: Type: text/plain, Size: 377 bytes --]
Hi guys,
I change it to:
eval echo "++$a"
Thanks,
Hui
On Sat, Dec 12, 2009 at 02:09, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
>
> Joel> I don't think it seems weird. I find this pretty nice, and since
> Joel> we already have printf, I wonder how hard it would be to implement
> Joel> this?
>
> Easy :-)
>
> Tom
>
[-- Attachment #2: eval.txt --]
[-- Type: text/plain, Size: 2680 bytes --]
---
printcmd.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
--- a/printcmd.c
+++ b/printcmd.c
@@ -50,6 +50,8 @@
#include "parser-defs.h"
#include "charset.h"
+#include <ctype.h>
+
#ifdef TUI
#include "tui/tui.h" /* For tui_active et.al. */
#endif
@@ -2625,6 +2627,88 @@ printf_command (char *arg, int from_tty)
do_cleanups (old_cleanups);
}
+static void
+eval_command (char *exp, int from_tty)
+{
+#define CMDSIZE 1024
+ char *cmd;
+ char *cmdp;
+ int is_eval = 0;
+ char *eval_begin;
+
+ if (!exp)
+ return;
+
+ cmd = xmalloc (CMDSIZE + 1);
+ make_cleanup (xfree, cmd);
+ cmdp = cmd;
+
+ while (cmdp - cmd < CMDSIZE)
+ {
+ if (is_eval)
+ {
+ if (!exp[0] || exp[0]== '"')
+ {
+ struct value *value;
+ gdb_byte *buffer;
+ int length = -1;
+ struct type *char_type = NULL;
+ const char *la_encoding = NULL;
+ char tmp = exp[0];
+
+ exp[0] = '\0';
+ value = parse_and_eval (eval_begin);
+
+ switch (TYPE_CODE (value_type (value)))
+ {
+ case TYPE_CODE_ARRAY:
+ LA_GET_STRING (value, &buffer, &length,
+ &char_type, &la_encoding);
+ break;
+ case TYPE_CODE_INT:
+ buffer = plongest (value_as_long (value));
+ length = strlen (buffer);
+ break;
+ default:
+ buffer = eval_begin;
+ length = exp - eval_begin;
+ break;
+ }
+
+ if (length > CMDSIZE - (cmdp - cmd))
+ length = CMDSIZE - (cmdp - cmd);
+ memcpy (cmdp, buffer, length);
+ cmdp += length;
+
+ exp[0] = tmp;
+ is_eval = 0;
+ }
+
+ exp ++;
+ }
+ else
+ {
+ if (!exp[0])
+ break;
+
+ if (exp[0] == '"')
+ {
+ is_eval = 1;
+ eval_begin = exp + 1;
+ }
+ else
+ {
+ cmdp[0] = exp[0];
+ cmdp ++;
+ }
+ exp ++;
+ }
+ }
+ cmdp[0] = '\0';
+
+ execute_command (cmd, from_tty);
+}
+
void
_initialize_printcmd (void)
{
@@ -2788,4 +2872,7 @@ Show printing of source filename and lin
NULL,
show_print_symbol_filename,
&setprintlist, &showprintlist);
+
+ add_com ("eval", no_class, eval_command, _("\
+Call command with variable."));
}
next prev parent reply other threads:[~2009-12-12 8:33 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 [this message]
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
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=daef60380912120033r1ac03f1ao1f995381db879c82@mail.gmail.com \
--to=teawater@gmail.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=msnyder@vmware.com \
--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