Re: [RFC] Let "gcore" command accept a suffix argument

Hui Zhu
2010-01-06T06:57:59Z

[-- Attachment #1: Type: text/plain, Size: 2210 bytes --]

Hello,

I make a new patch that eval command use "" to point out the simple command.
If want add " in normal string. Use \"
If we want add \ in normal string. Use \\
It can be use like:
(gdb) eval "echo \""$a++"\""
"7"(gdb) eval "echo \""$a++"\""
"8"(gdb) eval "echo \""$a++"\""
"9"(gdb) eval "echo \""$a++"\""
"10"(gdb) eval "echo \""$a++"\""
"11"(gdb) eval "echo \""$a++"\""
"12"(gdb) eval "echo \""$a++"\""
"13"(gdb) eval "echo \""$a++"\""

Please help me review it.

Best regards,
Hui

2010-01-06 Hui Zhu <teawater@gmail.com>
* printcmd.c (ctype.h): New include.
(eval_command): New function.
(_initialize_printcmd): New command "eval".

On Mon, Jan 4, 2010 at 22:42, Hui Zhu <teawater@gmail.com> wrote:
> Sorry for my poor English, did you mean that we can use "eval" for this command?
>
> Thanks,
> Hui
>
> On Thu, Dec 31, 2009 at 08:18, Stan Shebs <stanshebs@earthlink.net> wrote:
>> Tom Tromey wrote:
>>>>>>>>
>>>>>>>> "Stan" == Stan Shebs <stan@codesourcery.com> writes:
>>>>>>>>
>>>
>>> Stan> BTW, Pedro nudges me out of my stupor and reminds me that the
>>> Stan> soon-to-be-posted tracepoint action to evaluate without collecting
>>> is
>>> Stan> also called "eval" (it was originally proposed as "do" but that
>>> Stan> ambiguates with "down", which seemed like a bad idea).
>>>
>>> Stan> The two versions are not necessarily mutually exclusive - the
>>> Stan> downloading at the start of a trace run gives us a chance to filter
>>> Stan> out eval's that don't make sense for the target agent - but if we go
>>> Stan> too afield on syntax (the tracepoint version is simply a
>>> Stan> comma-separated list of GDB expressions), then that's going to be
>>> more
>>> Stan> of a problem to reconcile.
>>>
>>> "eval" seems awfully generic for a command which is specific to
>>> tracepoints.
>>>  I'm not super familiar with tracepoints but a lot of the other commands
>>> seem to start with "t".  Why not "teval"?
>>>
>>
>> That's a good idea.  If we ever come up with a Grand Unified Semantics of
>> actions and commands for which generic "eval" matches tracepoint "teval", we
>> can simply alias the two.
>>
>> Stan
>>
>>
>

[-- Attachment #2: eval.txt --]
[-- Type: text/plain, Size: 3156 bytes --]

---
printcmd.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)

--- a/printcmd.c
+++ b/printcmd.c
@@ -51,6 +51,8 @@
#include "charset.h"
#include "arch-utils.h"

+#include <ctype.h>
+
#ifdef TUI
#include "tui/tui.h" /* For tui_active et.al. */
#endif
@@ -2649,6 +2651,104 @@ 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[CMDSIZE + 1];
+ char *cmdp = cmd;
+ int is_eval = 1;
+ int is_backslash = 0;
+ int is_quote = 0;
+ char *eval_begin = exp;
+
+ if (!exp)
+ return;
+
+ while (cmdp - cmd < CMDSIZE)
+ {
+ if (!is_backslash && exp[0] == '\\')
+ {
+ is_backslash = 1;
+ exp ++;
+ continue;
+ }
+
+ if (is_eval)
+ {
+ if (!exp[0] || (exp[0]== '"' && !is_backslash))
+ {
+ struct value *value;
+ gdb_byte *buffer;
+ int length = -1;
+ struct type *char_type = NULL;
+ const char *la_encoding = NULL;
+ int is_end = 0;
+
+ if (!exp[0])
+ is_end = 1;
+ else
+ exp[0] = '\0';
+ if (strlen (eval_begin))
+ {
+ 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;
+ }
+
+ if (is_end)
+ break;
+
+ is_eval = 0;
+ }
+
+ exp ++;
+ }
+ else
+ {
+ if (!exp[0])
+ break;
+
+ if (exp[0]== '"' && !is_backslash)
+ {
+ is_eval = 1;
+ eval_begin = exp + 1;
+ }
+ else
+ {
+ cmdp[0] = exp[0];
+ cmdp ++;
+ }
+ exp ++;
+ }
+
+ if (is_backslash)
+ is_backslash = 0;
+ }
+ cmdp[0] = '\0';
+
+ execute_command (cmd, from_tty);
+}
+
void
_initialize_printcmd (void)
{
@@ -2812,4 +2912,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."));
}