From: Hui Zhu <teawater@gmail.com>
To: Michael Snyder <msnyder@vmware.com>,
Joel Brobecker <brobecker@adacore.com>
Cc: "gdb@sourceware.org" <gdb@sourceware.org>
Subject: Re: [RFC] Let "gcore" command accept a suffix argument
Date: Thu, 10 Dec 2009 02:28:00 -0000 [thread overview]
Message-ID: <daef60380912091827u6ff7127bp1d03998a40932914@mail.gmail.com> (raw)
In-Reply-To: <4B1428F0.7090608@vmware.com>
[-- Attachment #1: Type: text/plain, Size: 3440 bytes --]
Hi guys,
I make a patch to make gdb support "eval gcore foo.$a" command.
(gdb) set $cmd="pwd"
(gdb) eval $cmd
Working directory /home/teawater/gdb/bgdbno/gdb.
(gdb) set $cmd="file ~/gdb/a.out"
(gdb) eval $cmd
Reading symbols from /home/teawater/gdb/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x80483be
Starting program: /home/teawater/gdb/a.out
Temporary breakpoint 1, 0x080483be in main ()
(gdb) set $name="eval"
(gdb) set $num=3
(gdb) eval gcore $name.$num
Saved corefile eval.3
Please post your comments about it.
And the help and file that include this command is not very well.
Please help me with them. :)
Thanks,
Hui
2009-12-10 Hui Zhu <teawater@gmail.com>
* printcmd.c (ctype.h): New include.
(eval_command): New function.
(_initialize_printcmd): New command "eval".
---
printcmd.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 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,84 @@ 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 = 0;
+ char *eval_begin;
+
+ if (!exp)
+ return;
+
+ while (cmdp - cmd < CMDSIZE)
+ {
+ if (is_eval)
+ {
+ if (!isalnum (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;
+ }
+ else
+ exp ++;
+ }
+ else
+ {
+ if (!exp[0])
+ break;
+
+ if (exp[0] == '$')
+ {
+ is_eval = 1;
+ eval_begin = exp;
+ }
+ else
+ {
+ cmdp[0] = exp[0];
+ cmdp ++;
+ }
+ exp ++;
+ }
+ }
+ cmdp[0] = '\0';
+
+ execute_command (cmd, from_tty);
+}
+
void
_initialize_printcmd (void)
{
@@ -2788,4 +2868,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."));
}
[-- Attachment #2: eval.txt --]
[-- Type: text/plain, Size: 2642 bytes --]
---
printcmd.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 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,84 @@ 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 = 0;
+ char *eval_begin;
+
+ if (!exp)
+ return;
+
+ while (cmdp - cmd < CMDSIZE)
+ {
+ if (is_eval)
+ {
+ if (!isalnum (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;
+ }
+ else
+ exp ++;
+ }
+ else
+ {
+ if (!exp[0])
+ break;
+
+ if (exp[0] == '$')
+ {
+ is_eval = 1;
+ eval_begin = exp;
+ }
+ else
+ {
+ cmdp[0] = exp[0];
+ cmdp ++;
+ }
+ exp ++;
+ }
+ }
+ cmdp[0] = '\0';
+
+ execute_command (cmd, from_tty);
+}
+
void
_initialize_printcmd (void)
{
@@ -2788,4 +2868,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-10 2:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-30 13:39 Michael Snyder
2009-11-30 16:22 ` Hui Zhu
2009-11-30 17:04 ` Joel Brobecker
2009-11-30 18:53 ` Tom Tromey
2009-11-30 19:06 ` Michael Snyder
2009-11-30 20:16 ` Joel Brobecker
2009-11-30 20:25 ` Michael Snyder
2009-11-30 20:31 ` Joel Brobecker
2009-11-30 20:46 ` Michael Snyder
2009-12-10 2:28 ` Hui Zhu [this message]
2009-11-30 18:44 ` Tom Tromey
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=daef60380912091827u6ff7127bp1d03998a40932914@mail.gmail.com \
--to=teawater@gmail.com \
--cc=brobecker@adacore.com \
--cc=gdb@sourceware.org \
--cc=msnyder@vmware.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