* [PATCH]Add option "-at" to "maint agent" and "maint agent-eval"
@ 2012-06-24 7:00 Hui Zhu
2012-06-27 17:46 ` Eli Zaretskii
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Hui Zhu @ 2012-06-24 7:00 UTC (permalink / raw)
To: gdb-patches ml; +Cc: Stan Shebs, Yao Qi, Eli Zaretskii
[-- Attachment #1: Type: text/plain, Size: 877 bytes --]
Hi,
According the comments form Stan in
http://sourceware.org/ml/gdb/2012-06/msg00060.html
I post these patches for add option "-at" to "maint agent" and "maint
agent-eval".
Thanks,
Hui
2012-06-24 Hui Zhu <hui_zhu@mentor.com>
* breakpoint.c (check_for_argument): Move to file cli/cli-utils.c.
* cli/cli-utils.c (check_for_argument): New function.
* cli/cli-utils.h (check_for_argument): Ditto.
2012-06-24 Hui Zhu <hui_zhu@mentor.com>
* ax-gdb.c (cli/cli-utils.h): New include.
(linespec.h): Ditto.
(agent_eval_command_one): New function.
(agent_command_1): Ditto.
(agent_command): Call function agent_command_1.
(agent_eval_command): Ditto.
(_initialize_ax_gdb): Change help for "maint agent"
and "maint agent-eval".
2012-06-24 Hui Zhu <hui_zhu@mentor.com>
* gdb.texinfo (Maintenance Commands): Change help for "maint agent"
and "maint agent-eval".
[-- Attachment #2: check_for_argument_move_cli_utils.txt --]
[-- Type: text/plain, Size: 1891 bytes --]
---
breakpoint.c | 17 -----------------
cli/cli-utils.c | 14 ++++++++++++++
cli/cli-utils.h | 6 ++++++
3 files changed, 20 insertions(+), 17 deletions(-)
--- a/breakpoint.c
+++ b/breakpoint.c
@@ -10862,23 +10862,6 @@ watch_command_wrapper (char *arg, int fr
watch_command_1 (arg, hw_write, from_tty, 0, internal);
}
-/* A helper function that looks for an argument at the start of a
- string. The argument must also either be at the end of the string,
- or be followed by whitespace. Returns 1 if it finds the argument,
- 0 otherwise. If the argument is found, it updates *STR. */
-
-static int
-check_for_argument (char **str, char *arg, int arg_len)
-{
- if (strncmp (*str, arg, arg_len) == 0
- && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
- {
- *str += arg_len;
- return 1;
- }
- return 0;
-}
-
/* A helper function that looks for the "-location" argument and then
calls watch_command_1. */
--- a/cli/cli-utils.c
+++ b/cli/cli-utils.c
@@ -286,3 +286,17 @@ extract_arg (char **arg)
return copy;
}
+
+/* See documentation in cli-utils.h. */
+
+int
+check_for_argument (char **str, char *arg, int arg_len)
+{
+ if (strncmp (*str, arg, arg_len) == 0
+ && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
+ {
+ *str += arg_len;
+ return 1;
+ }
+ return 0;
+}
--- a/cli/cli-utils.h
+++ b/cli/cli-utils.h
@@ -114,4 +114,10 @@ extern char *remove_trailing_whitespace
extern char *extract_arg (char **arg);
+/* A helper function that looks for an argument at the start of a
+ string. The argument must also either be at the end of the string,
+ or be followed by whitespace. Returns 1 if it finds the argument,
+ 0 otherwise. If the argument is found, it updates *STR. */
+extern int check_for_argument (char **str, char *arg, int arg_len);
+
#endif /* CLI_UTILS_H */
[-- Attachment #3: agent-at.txt --]
[-- Type: text/plain, Size: 5725 bytes --]
---
ax-gdb.c | 117 ++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 72 insertions(+), 45 deletions(-)
--- a/ax-gdb.c
+++ b/ax-gdb.c
@@ -41,6 +41,8 @@
#include "tracepoint.h"
#include "cp-support.h"
#include "arch-utils.h"
+#include "cli/cli-utils.h"
+#include "linespec.h"
#include "valprint.h"
#include "c-lang.h"
@@ -2504,40 +2506,32 @@ gen_trace_for_return_address (CORE_ADDR
}
static void
-agent_command (char *exp, int from_tty)
+agent_eval_command_one (char *exp, int eval, CORE_ADDR pc)
{
struct cleanup *old_chain = 0;
struct expression *expr;
struct agent_expr *agent;
- struct frame_info *fi = get_current_frame (); /* need current scope */
-
- /* We don't deal with overlay debugging at the moment. We need to
- think more carefully about this. If you copy this code into
- another command, change the error message; the user shouldn't
- have to know anything about agent expressions. */
- if (overlay_debugging)
- error (_("GDB can't do agent expression translation with overlays."));
-
- if (exp == 0)
- error_no_arg (_("expression to translate"));
- trace_string_kludge = 0;
- if (*exp == '/')
- exp = decode_agent_options (exp);
+ if (!eval)
+ {
+ trace_string_kludge = 0;
+ if (*exp == '/')
+ exp = decode_agent_options (exp);
+ }
- /* Recognize the return address collection directive specially. Note
- that it is not really an expression of any sort. */
- if (strcmp (exp, "$_ret") == 0)
+ if (!eval && strcmp (exp, "$_ret") == 0)
{
- agent = gen_trace_for_return_address (get_frame_pc (fi),
- get_current_arch ());
+ agent = gen_trace_for_return_address (pc, get_current_arch ());
old_chain = make_cleanup_free_agent_expr (agent);
}
else
{
- expr = parse_expression (exp);
+ expr = parse_exp_1 (&exp, block_for_pc (pc), 0);
old_chain = make_cleanup (free_current_contents, &expr);
- agent = gen_trace_for_expr (get_frame_pc (fi), expr);
+ if (eval)
+ agent = gen_eval_for_expr (pc, expr);
+ else
+ agent = gen_trace_for_expr (pc, expr);
make_cleanup_free_agent_expr (agent);
}
@@ -2551,18 +2545,9 @@ agent_command (char *exp, int from_tty)
dont_repeat ();
}
-/* Parse the given expression, compile it into an agent expression
- that does direct evaluation, and display the resulting
- expression. */
-
static void
-agent_eval_command (char *exp, int from_tty)
+agent_command_1 (char *exp, int eval)
{
- struct cleanup *old_chain = 0;
- struct expression *expr;
- struct agent_expr *agent;
- struct frame_info *fi = get_current_frame (); /* need current scope */
-
/* We don't deal with overlay debugging at the moment. We need to
think more carefully about this. If you copy this code into
another command, change the error message; the user shouldn't
@@ -2573,19 +2558,55 @@ agent_eval_command (char *exp, int from_
if (exp == 0)
error_no_arg (_("expression to translate"));
- expr = parse_expression (exp);
- old_chain = make_cleanup (free_current_contents, &expr);
- agent = gen_eval_for_expr (get_frame_pc (fi), expr);
- make_cleanup_free_agent_expr (agent);
- ax_reqs (agent);
- ax_print (gdb_stdout, agent);
+ if (check_for_argument (&exp, "-at", sizeof ("-at") - 1))
+ {
+ struct linespec_result canonical;
+ int ix;
+ struct linespec_sals *iter;
+ struct cleanup *old_chain;
- /* It would be nice to call ax_reqs here to gather some general info
- about the expression, and then print out the result. */
+ exp = skip_spaces (exp);
+ init_linespec_result (&canonical);
+ decode_line_full (&exp, DECODE_LINE_FUNFIRSTLINE,
+ (struct symtab *) NULL, 0, &canonical,
+ NULL, NULL);
+ old_chain = make_cleanup_destroy_linespec_result (&canonical);
+ exp = skip_spaces (exp);
+ if (exp[0] == ',')
+ {
+ exp++;
+ exp = skip_spaces (exp);
+ }
+ for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
+ {
+ int i;
+
+ for (i = 0; i < iter->sals.nelts; i++)
+ agent_eval_command_one (exp, eval, iter->sals.sals[i].pc);
+ }
+ do_cleanups (old_chain);
+ }
+ else
+ agent_eval_command_one (exp, eval, get_frame_pc (get_current_frame ()));
- do_cleanups (old_chain);
dont_repeat ();
}
+
+static void
+agent_command (char *exp, int from_tty)
+{
+ agent_command_1 (exp, 0);
+}
+
+/* Parse the given expression, compile it into an agent expression
+ that does direct evaluation, and display the resulting
+ expression. */
+
+static void
+agent_eval_command (char *exp, int from_tty)
+{
+ agent_command_1 (exp, 1);
+}
\f
/* Initialization code. */
@@ -2595,12 +2616,18 @@ void
_initialize_ax_gdb (void)
{
add_cmd ("agent", class_maintenance, agent_command,
- _("Translate an expression into "
- "remote agent bytecode for tracing."),
+ _("\
+Translate an expression into remote agent bytecode for tracing.\n\
+Usage: maint agent [-at location,] EXPRESSION\n\
+If -at is given, generate remote agent bytecode for this loation.\n\
+If not, generate remote agent bytecode for current frame pc address."),
&maintenancelist);
add_cmd ("agent-eval", class_maintenance, agent_eval_command,
- _("Translate an expression into remote "
- "agent bytecode for evaluation."),
+ _("\
+Translate an expression into remote agent bytecode for evaluation.\n\
+Usage: maint agent-eval [-at location,] EXPRESSION\n\
+If -at is given, generate remote agent bytecode for this loation.\n\
+If not, generate remote agent bytecode for current frame pc address."),
&maintenancelist);
}
[-- Attachment #4: agent-at-doc.txt --]
[-- Type: text/plain, Size: 1143 bytes --]
---
doc/gdb.texinfo | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--- a/doc/gdb.texinfo
+++ b/doc/gdb.texinfo
@@ -34395,8 +34395,8 @@ messages, see @ref{Debugging Output}.)
@table @code
@kindex maint agent
@kindex maint agent-eval
-@item maint agent @var{expression}
-@itemx maint agent-eval @var{expression}
+@item maint agent @r{[}-at location@r{,}@r{]} @var{expression}
+@itemx maint agent-eval @r{[}-at location@r{,}@r{]} @var{expression}
Translate the given @var{expression} into remote agent bytecodes.
This command is useful for debugging the Agent Expression mechanism
(@pxref{Agent Expressions}). The @samp{agent} version produces an
@@ -34407,6 +34407,8 @@ globb} will include bytecodes to record
of the addresses of @code{globa} and @code{globb}, while discarding
the result of the addition, while an evaluation expression will do the
addition and return the sum.
+If @code{-at} is given, generate remote agent bytecode for this loation.
+If not, generate remote agent bytecode for current frame pc address.
@kindex maint info breakpoints
@item @anchor{maint info breakpoints}maint info breakpoints
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH]Add option "-at" to "maint agent" and "maint agent-eval"
2012-06-24 7:00 [PATCH]Add option "-at" to "maint agent" and "maint agent-eval" Hui Zhu
@ 2012-06-27 17:46 ` Eli Zaretskii
2012-07-05 0:38 ` Hui Zhu
2012-06-27 18:28 ` Tom Tromey
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2012-06-27 17:46 UTC (permalink / raw)
To: Hui Zhu; +Cc: gdb-patches, stan_shebs, Yao_Qi
> From: Hui Zhu <teawater@gmail.com>
> Date: Sun, 24 Jun 2012 14:59:08 +0800
> Cc: Stan Shebs <stan_shebs@mentor.com>, Yao Qi <Yao_Qi@mentor.com>,
> Eli Zaretskii <eliz@gnu.org>
> According the comments form Stan in
> http://sourceware.org/ml/gdb/2012-06/msg00060.html
> I post these patches for add option "-at" to "maint agent" and "maint
> agent-eval".
Thanks.
>
> Thanks,
> Hui
>
> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>
> * breakpoint.c (check_for_argument): Move to file cli/cli-utils.c.
> * cli/cli-utils.c (check_for_argument): New function.
> * cli/cli-utils.h (check_for_argument): Ditto.
>
> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>
> * ax-gdb.c (cli/cli-utils.h): New include.
> (linespec.h): Ditto.
> (agent_eval_command_one): New function.
> (agent_command_1): Ditto.
> (agent_command): Call function agent_command_1.
> (agent_eval_command): Ditto.
> (_initialize_ax_gdb): Change help for "maint agent"
> and "maint agent-eval".
>
> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>
> * gdb.texinfo (Maintenance Commands): Change help for "maint agent"
> and "maint agent-eval".
>
> [2:text/plain Hide Save:check_for_argument_move_cli_utils.txt (2kB)]
>
> ---
> breakpoint.c | 17 -----------------
> cli/cli-utils.c | 14 ++++++++++++++
> cli/cli-utils.h | 6 ++++++
> 3 files changed, 20 insertions(+), 17 deletions(-)
>
> --- a/breakpoint.c
> +++ b/breakpoint.c
> @@ -10862,23 +10862,6 @@ watch_command_wrapper (char *arg, int fr
> watch_command_1 (arg, hw_write, from_tty, 0, internal);
> }
>
> -/* A helper function that looks for an argument at the start of a
> - string. The argument must also either be at the end of the string,
> - or be followed by whitespace. Returns 1 if it finds the argument,
> - 0 otherwise. If the argument is found, it updates *STR. */
> -
> -static int
> -check_for_argument (char **str, char *arg, int arg_len)
> -{
> - if (strncmp (*str, arg, arg_len) == 0
> - && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
> - {
> - *str += arg_len;
> - return 1;
> - }
> - return 0;
> -}
> -
> /* A helper function that looks for the "-location" argument and then
> calls watch_command_1. */
>
> --- a/cli/cli-utils.c
> +++ b/cli/cli-utils.c
> @@ -286,3 +286,17 @@ extract_arg (char **arg)
>
> return copy;
> }
> +
> +/* See documentation in cli-utils.h. */
> +
> +int
> +check_for_argument (char **str, char *arg, int arg_len)
> +{
> + if (strncmp (*str, arg, arg_len) == 0
> + && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
> + {
> + *str += arg_len;
> + return 1;
> + }
> + return 0;
> +}
> --- a/cli/cli-utils.h
> +++ b/cli/cli-utils.h
> @@ -114,4 +114,10 @@ extern char *remove_trailing_whitespace
>
> extern char *extract_arg (char **arg);
>
> +/* A helper function that looks for an argument at the start of a
> + string. The argument must also either be at the end of the string,
> + or be followed by whitespace. Returns 1 if it finds the argument,
> + 0 otherwise. If the argument is found, it updates *STR. */
> +extern int check_for_argument (char **str, char *arg, int arg_len);
> +
> #endif /* CLI_UTILS_H */
>
> [3:text/plain Hide Save:agent-at.txt (6kB)]
>
> ---
> ax-gdb.c | 117 ++++++++++++++++++++++++++++++++++++++-------------------------
> 1 file changed, 72 insertions(+), 45 deletions(-)
>
> --- a/ax-gdb.c
> +++ b/ax-gdb.c
> @@ -41,6 +41,8 @@
> #include "tracepoint.h"
> #include "cp-support.h"
> #include "arch-utils.h"
> +#include "cli/cli-utils.h"
> +#include "linespec.h"
>
> #include "valprint.h"
> #include "c-lang.h"
> @@ -2504,40 +2506,32 @@ gen_trace_for_return_address (CORE_ADDR
> }
>
> static void
> -agent_command (char *exp, int from_tty)
> +agent_eval_command_one (char *exp, int eval, CORE_ADDR pc)
> {
> struct cleanup *old_chain = 0;
> struct expression *expr;
> struct agent_expr *agent;
> - struct frame_info *fi = get_current_frame (); /* need current scope */
> -
> - /* We don't deal with overlay debugging at the moment. We need to
> - think more carefully about this. If you copy this code into
> - another command, change the error message; the user shouldn't
> - have to know anything about agent expressions. */
> - if (overlay_debugging)
> - error (_("GDB can't do agent expression translation with overlays."));
> -
> - if (exp == 0)
> - error_no_arg (_("expression to translate"));
>
> - trace_string_kludge = 0;
> - if (*exp == '/')
> - exp = decode_agent_options (exp);
> + if (!eval)
> + {
> + trace_string_kludge = 0;
> + if (*exp == '/')
> + exp = decode_agent_options (exp);
> + }
>
> - /* Recognize the return address collection directive specially. Note
> - that it is not really an expression of any sort. */
> - if (strcmp (exp, "$_ret") == 0)
> + if (!eval && strcmp (exp, "$_ret") == 0)
> {
> - agent = gen_trace_for_return_address (get_frame_pc (fi),
> - get_current_arch ());
> + agent = gen_trace_for_return_address (pc, get_current_arch ());
> old_chain = make_cleanup_free_agent_expr (agent);
> }
> else
> {
> - expr = parse_expression (exp);
> + expr = parse_exp_1 (&exp, block_for_pc (pc), 0);
> old_chain = make_cleanup (free_current_contents, &expr);
> - agent = gen_trace_for_expr (get_frame_pc (fi), expr);
> + if (eval)
> + agent = gen_eval_for_expr (pc, expr);
> + else
> + agent = gen_trace_for_expr (pc, expr);
> make_cleanup_free_agent_expr (agent);
> }
>
> @@ -2551,18 +2545,9 @@ agent_command (char *exp, int from_tty)
> dont_repeat ();
> }
>
> -/* Parse the given expression, compile it into an agent expression
> - that does direct evaluation, and display the resulting
> - expression. */
> -
> static void
> -agent_eval_command (char *exp, int from_tty)
> +agent_command_1 (char *exp, int eval)
> {
> - struct cleanup *old_chain = 0;
> - struct expression *expr;
> - struct agent_expr *agent;
> - struct frame_info *fi = get_current_frame (); /* need current scope */
> -
> /* We don't deal with overlay debugging at the moment. We need to
> think more carefully about this. If you copy this code into
> another command, change the error message; the user shouldn't
> @@ -2573,19 +2558,55 @@ agent_eval_command (char *exp, int from_
> if (exp == 0)
> error_no_arg (_("expression to translate"));
>
> - expr = parse_expression (exp);
> - old_chain = make_cleanup (free_current_contents, &expr);
> - agent = gen_eval_for_expr (get_frame_pc (fi), expr);
> - make_cleanup_free_agent_expr (agent);
> - ax_reqs (agent);
> - ax_print (gdb_stdout, agent);
> + if (check_for_argument (&exp, "-at", sizeof ("-at") - 1))
> + {
> + struct linespec_result canonical;
> + int ix;
> + struct linespec_sals *iter;
> + struct cleanup *old_chain;
>
> - /* It would be nice to call ax_reqs here to gather some general info
> - about the expression, and then print out the result. */
> + exp = skip_spaces (exp);
> + init_linespec_result (&canonical);
> + decode_line_full (&exp, DECODE_LINE_FUNFIRSTLINE,
> + (struct symtab *) NULL, 0, &canonical,
> + NULL, NULL);
> + old_chain = make_cleanup_destroy_linespec_result (&canonical);
> + exp = skip_spaces (exp);
> + if (exp[0] == ',')
> + {
> + exp++;
> + exp = skip_spaces (exp);
> + }
> + for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
> + {
> + int i;
> +
> + for (i = 0; i < iter->sals.nelts; i++)
> + agent_eval_command_one (exp, eval, iter->sals.sals[i].pc);
> + }
> + do_cleanups (old_chain);
> + }
> + else
> + agent_eval_command_one (exp, eval, get_frame_pc (get_current_frame ()));
>
> - do_cleanups (old_chain);
> dont_repeat ();
> }
> +
> +static void
> +agent_command (char *exp, int from_tty)
> +{
> + agent_command_1 (exp, 0);
> +}
> +
> +/* Parse the given expression, compile it into an agent expression
> + that does direct evaluation, and display the resulting
> + expression. */
> +
> +static void
> +agent_eval_command (char *exp, int from_tty)
> +{
> + agent_command_1 (exp, 1);
> +}
> \f
>
> /* Initialization code. */
> @@ -2595,12 +2616,18 @@ void
> _initialize_ax_gdb (void)
> {
> add_cmd ("agent", class_maintenance, agent_command,
> - _("Translate an expression into "
> - "remote agent bytecode for tracing."),
> + _("\
> +Translate an expression into remote agent bytecode for tracing.\n\
> +Usage: maint agent [-at location,] EXPRESSION\n\
> +If -at is given, generate remote agent bytecode for this loation.\n\
^^^^^^^
A typo.
> +If -at is given, generate remote agent bytecode for this loation.\n\
And here.
> +@item maint agent @r{[}-at location@r{,}@r{]} @var{expression}
> +@itemx maint agent-eval @r{[}-at location@r{,}@r{]} @var{expression}
"location" should be in @var, as it is a parameter, like
"expression".
> +If @code{-at} is given, generate remote agent bytecode for this loation.
Same typo as before, and please use "... for @var{location}", without
"this".
Btw, what does it mean to generate bytecode "for LOCATION"? how does
the location come into play when bytecode is generated?
> +If not, generate remote agent bytecode for current frame pc address.
Don't we use "PC", in caps, usually?
OK with those changes.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH]Add option "-at" to "maint agent" and "maint agent-eval"
2012-06-27 17:46 ` Eli Zaretskii
@ 2012-07-05 0:38 ` Hui Zhu
0 siblings, 0 replies; 7+ messages in thread
From: Hui Zhu @ 2012-07-05 0:38 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches, stan_shebs, Yao_Qi
On Thu, Jun 28, 2012 at 1:45 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Hui Zhu <teawater@gmail.com>
>> Date: Sun, 24 Jun 2012 14:59:08 +0800
>> Cc: Stan Shebs <stan_shebs@mentor.com>, Yao Qi <Yao_Qi@mentor.com>,
>> Eli Zaretskii <eliz@gnu.org>
>> According the comments form Stan in
>> http://sourceware.org/ml/gdb/2012-06/msg00060.html
>> I post these patches for add option "-at" to "maint agent" and "maint
>> agent-eval".
>
> Thanks.
>
>>
>> Thanks,
>> Hui
>>
>> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>>
>> * breakpoint.c (check_for_argument): Move to file cli/cli-utils.c.
>> * cli/cli-utils.c (check_for_argument): New function.
>> * cli/cli-utils.h (check_for_argument): Ditto.
>>
>> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>>
>> * ax-gdb.c (cli/cli-utils.h): New include.
>> (linespec.h): Ditto.
>> (agent_eval_command_one): New function.
>> (agent_command_1): Ditto.
>> (agent_command): Call function agent_command_1.
>> (agent_eval_command): Ditto.
>> (_initialize_ax_gdb): Change help for "maint agent"
>> and "maint agent-eval".
>>
>> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>>
>> * gdb.texinfo (Maintenance Commands): Change help for "maint agent"
>> and "maint agent-eval".
>>
>> [2:text/plain Hide Save:check_for_argument_move_cli_utils.txt (2kB)]
>>
>> ---
>> breakpoint.c | 17 -----------------
>> cli/cli-utils.c | 14 ++++++++++++++
>> cli/cli-utils.h | 6 ++++++
>> 3 files changed, 20 insertions(+), 17 deletions(-)
>>
>> --- a/breakpoint.c
>> +++ b/breakpoint.c
>> @@ -10862,23 +10862,6 @@ watch_command_wrapper (char *arg, int fr
>> watch_command_1 (arg, hw_write, from_tty, 0, internal);
>> }
>>
>> -/* A helper function that looks for an argument at the start of a
>> - string. The argument must also either be at the end of the string,
>> - or be followed by whitespace. Returns 1 if it finds the argument,
>> - 0 otherwise. If the argument is found, it updates *STR. */
>> -
>> -static int
>> -check_for_argument (char **str, char *arg, int arg_len)
>> -{
>> - if (strncmp (*str, arg, arg_len) == 0
>> - && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
>> - {
>> - *str += arg_len;
>> - return 1;
>> - }
>> - return 0;
>> -}
>> -
>> /* A helper function that looks for the "-location" argument and then
>> calls watch_command_1. */
>>
>> --- a/cli/cli-utils.c
>> +++ b/cli/cli-utils.c
>> @@ -286,3 +286,17 @@ extract_arg (char **arg)
>>
>> return copy;
>> }
>> +
>> +/* See documentation in cli-utils.h. */
>> +
>> +int
>> +check_for_argument (char **str, char *arg, int arg_len)
>> +{
>> + if (strncmp (*str, arg, arg_len) == 0
>> + && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
>> + {
>> + *str += arg_len;
>> + return 1;
>> + }
>> + return 0;
>> +}
>> --- a/cli/cli-utils.h
>> +++ b/cli/cli-utils.h
>> @@ -114,4 +114,10 @@ extern char *remove_trailing_whitespace
>>
>> extern char *extract_arg (char **arg);
>>
>> +/* A helper function that looks for an argument at the start of a
>> + string. The argument must also either be at the end of the string,
>> + or be followed by whitespace. Returns 1 if it finds the argument,
>> + 0 otherwise. If the argument is found, it updates *STR. */
>> +extern int check_for_argument (char **str, char *arg, int arg_len);
>> +
>> #endif /* CLI_UTILS_H */
>>
>> [3:text/plain Hide Save:agent-at.txt (6kB)]
>>
>> ---
>> ax-gdb.c | 117 ++++++++++++++++++++++++++++++++++++++-------------------------
>> 1 file changed, 72 insertions(+), 45 deletions(-)
>>
>> --- a/ax-gdb.c
>> +++ b/ax-gdb.c
>> @@ -41,6 +41,8 @@
>> #include "tracepoint.h"
>> #include "cp-support.h"
>> #include "arch-utils.h"
>> +#include "cli/cli-utils.h"
>> +#include "linespec.h"
>>
>> #include "valprint.h"
>> #include "c-lang.h"
>> @@ -2504,40 +2506,32 @@ gen_trace_for_return_address (CORE_ADDR
>> }
>>
>> static void
>> -agent_command (char *exp, int from_tty)
>> +agent_eval_command_one (char *exp, int eval, CORE_ADDR pc)
>> {
>> struct cleanup *old_chain = 0;
>> struct expression *expr;
>> struct agent_expr *agent;
>> - struct frame_info *fi = get_current_frame (); /* need current scope */
>> -
>> - /* We don't deal with overlay debugging at the moment. We need to
>> - think more carefully about this. If you copy this code into
>> - another command, change the error message; the user shouldn't
>> - have to know anything about agent expressions. */
>> - if (overlay_debugging)
>> - error (_("GDB can't do agent expression translation with overlays."));
>> -
>> - if (exp == 0)
>> - error_no_arg (_("expression to translate"));
>>
>> - trace_string_kludge = 0;
>> - if (*exp == '/')
>> - exp = decode_agent_options (exp);
>> + if (!eval)
>> + {
>> + trace_string_kludge = 0;
>> + if (*exp == '/')
>> + exp = decode_agent_options (exp);
>> + }
>>
>> - /* Recognize the return address collection directive specially. Note
>> - that it is not really an expression of any sort. */
>> - if (strcmp (exp, "$_ret") == 0)
>> + if (!eval && strcmp (exp, "$_ret") == 0)
>> {
>> - agent = gen_trace_for_return_address (get_frame_pc (fi),
>> - get_current_arch ());
>> + agent = gen_trace_for_return_address (pc, get_current_arch ());
>> old_chain = make_cleanup_free_agent_expr (agent);
>> }
>> else
>> {
>> - expr = parse_expression (exp);
>> + expr = parse_exp_1 (&exp, block_for_pc (pc), 0);
>> old_chain = make_cleanup (free_current_contents, &expr);
>> - agent = gen_trace_for_expr (get_frame_pc (fi), expr);
>> + if (eval)
>> + agent = gen_eval_for_expr (pc, expr);
>> + else
>> + agent = gen_trace_for_expr (pc, expr);
>> make_cleanup_free_agent_expr (agent);
>> }
>>
>> @@ -2551,18 +2545,9 @@ agent_command (char *exp, int from_tty)
>> dont_repeat ();
>> }
>>
>> -/* Parse the given expression, compile it into an agent expression
>> - that does direct evaluation, and display the resulting
>> - expression. */
>> -
>> static void
>> -agent_eval_command (char *exp, int from_tty)
>> +agent_command_1 (char *exp, int eval)
>> {
>> - struct cleanup *old_chain = 0;
>> - struct expression *expr;
>> - struct agent_expr *agent;
>> - struct frame_info *fi = get_current_frame (); /* need current scope */
>> -
>> /* We don't deal with overlay debugging at the moment. We need to
>> think more carefully about this. If you copy this code into
>> another command, change the error message; the user shouldn't
>> @@ -2573,19 +2558,55 @@ agent_eval_command (char *exp, int from_
>> if (exp == 0)
>> error_no_arg (_("expression to translate"));
>>
>> - expr = parse_expression (exp);
>> - old_chain = make_cleanup (free_current_contents, &expr);
>> - agent = gen_eval_for_expr (get_frame_pc (fi), expr);
>> - make_cleanup_free_agent_expr (agent);
>> - ax_reqs (agent);
>> - ax_print (gdb_stdout, agent);
>> + if (check_for_argument (&exp, "-at", sizeof ("-at") - 1))
>> + {
>> + struct linespec_result canonical;
>> + int ix;
>> + struct linespec_sals *iter;
>> + struct cleanup *old_chain;
>>
>> - /* It would be nice to call ax_reqs here to gather some general info
>> - about the expression, and then print out the result. */
>> + exp = skip_spaces (exp);
>> + init_linespec_result (&canonical);
>> + decode_line_full (&exp, DECODE_LINE_FUNFIRSTLINE,
>> + (struct symtab *) NULL, 0, &canonical,
>> + NULL, NULL);
>> + old_chain = make_cleanup_destroy_linespec_result (&canonical);
>> + exp = skip_spaces (exp);
>> + if (exp[0] == ',')
>> + {
>> + exp++;
>> + exp = skip_spaces (exp);
>> + }
>> + for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
>> + {
>> + int i;
>> +
>> + for (i = 0; i < iter->sals.nelts; i++)
>> + agent_eval_command_one (exp, eval, iter->sals.sals[i].pc);
>> + }
>> + do_cleanups (old_chain);
>> + }
>> + else
>> + agent_eval_command_one (exp, eval, get_frame_pc (get_current_frame ()));
>>
>> - do_cleanups (old_chain);
>> dont_repeat ();
>> }
>> +
>> +static void
>> +agent_command (char *exp, int from_tty)
>> +{
>> + agent_command_1 (exp, 0);
>> +}
>> +
>> +/* Parse the given expression, compile it into an agent expression
>> + that does direct evaluation, and display the resulting
>> + expression. */
>> +
>> +static void
>> +agent_eval_command (char *exp, int from_tty)
>> +{
>> + agent_command_1 (exp, 1);
>> +}
>>
>>
>> /* Initialization code. */
>> @@ -2595,12 +2616,18 @@ void
>> _initialize_ax_gdb (void)
>> {
>> add_cmd ("agent", class_maintenance, agent_command,
>> - _("Translate an expression into "
>> - "remote agent bytecode for tracing."),
>> + _("\
>> +Translate an expression into remote agent bytecode for tracing.\n\
>> +Usage: maint agent [-at location,] EXPRESSION\n\
>> +If -at is given, generate remote agent bytecode for this loation.\n\
> ^^^^^^^
> A typo.
>
>> +If -at is given, generate remote agent bytecode for this loation.\n\
>
> And here.
>
>> +@item maint agent @r{[}-at location@r{,}@r{]} @var{expression}
>> +@itemx maint agent-eval @r{[}-at location@r{,}@r{]} @var{expression}
>
> "location" should be in @var, as it is a parameter, like
> "expression".
>
>> +If @code{-at} is given, generate remote agent bytecode for this loation.
>
> Same typo as before, and please use "... for @var{location}", without
> "this".
>
> Btw, what does it mean to generate bytecode "for LOCATION"? how does
> the location come into play when bytecode is generated?
The location will come into play when generate bytecode about the local var.
>
>> +If not, generate remote agent bytecode for current frame pc address.
>
> Don't we use "PC", in caps, usually?
>
> OK with those changes.
Thanks. All of them are fixed.
Best,
Hui
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH]Add option "-at" to "maint agent" and "maint agent-eval"
2012-06-24 7:00 [PATCH]Add option "-at" to "maint agent" and "maint agent-eval" Hui Zhu
2012-06-27 17:46 ` Eli Zaretskii
@ 2012-06-27 18:28 ` Tom Tromey
2012-06-27 18:37 ` Tom Tromey
2012-06-28 2:46 ` Yao Qi
3 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2012-06-27 18:28 UTC (permalink / raw)
To: Hui Zhu; +Cc: gdb-patches ml, Stan Shebs, Yao Qi, Eli Zaretskii
>>>>> ">" == Hui Zhu <teawater@gmail.com> writes:
>> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>> * breakpoint.c (check_for_argument): Move to file cli/cli-utils.c.
>> * cli/cli-utils.c (check_for_argument): New function.
>> * cli/cli-utils.h (check_for_argument): Ditto.
This one is ok.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH]Add option "-at" to "maint agent" and "maint agent-eval"
2012-06-24 7:00 [PATCH]Add option "-at" to "maint agent" and "maint agent-eval" Hui Zhu
2012-06-27 17:46 ` Eli Zaretskii
2012-06-27 18:28 ` Tom Tromey
@ 2012-06-27 18:37 ` Tom Tromey
2012-07-05 1:15 ` Hui Zhu
2012-06-28 2:46 ` Yao Qi
3 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2012-06-27 18:37 UTC (permalink / raw)
To: Hui Zhu; +Cc: gdb-patches ml, Stan Shebs, Yao Qi, Eli Zaretskii
>>>>> ">" == Hui Zhu <teawater@gmail.com> writes:
>> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>> * ax-gdb.c (cli/cli-utils.h): New include.
>> (linespec.h): Ditto.
>> (agent_eval_command_one): New function.
>> (agent_command_1): Ditto.
>> (agent_command): Call function agent_command_1.
>> (agent_eval_command): Ditto.
>> (_initialize_ax_gdb): Change help for "maint agent"
>> and "maint agent-eval".
This is also ok. I think it may slightly abuse linespec parsing, but
considering that it is a 'maint' command, I don't think it matters, as
we are free to say "don't do that", or change it as needed.
>> + expr = parse_exp_1 (&exp, block_for_pc (pc), 0);
You'll need a minor tweak to get it to compile, since I changed
parse_exp_1 today.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH]Add option "-at" to "maint agent" and "maint agent-eval"
2012-06-27 18:37 ` Tom Tromey
@ 2012-07-05 1:15 ` Hui Zhu
0 siblings, 0 replies; 7+ messages in thread
From: Hui Zhu @ 2012-07-05 1:15 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches ml, Stan Shebs, Yao Qi, Eli Zaretskii
On Thu, Jun 28, 2012 at 2:37 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> ">" == Hui Zhu <teawater@gmail.com> writes:
>
>>> 2012-06-24 Hui Zhu <hui_zhu@mentor.com>
>>> * ax-gdb.c (cli/cli-utils.h): New include.
>>> (linespec.h): Ditto.
>>> (agent_eval_command_one): New function.
>>> (agent_command_1): Ditto.
>>> (agent_command): Call function agent_command_1.
>>> (agent_eval_command): Ditto.
>>> (_initialize_ax_gdb): Change help for "maint agent"
>>> and "maint agent-eval".
>
> This is also ok. I think it may slightly abuse linespec parsing, but
> considering that it is a 'maint' command, I don't think it matters, as
> we are free to say "don't do that", or change it as needed.
>
>>> + expr = parse_exp_1 (&exp, block_for_pc (pc), 0);
>
> You'll need a minor tweak to get it to compile, since I changed
> parse_exp_1 today.
>
> Tom
OK. Thanks for your help.
Checked in.
http://sourceware.org/ml/gdb-cvs/2012-07/msg00037.html
http://sourceware.org/ml/gdb-cvs/2012-07/msg00038.html
http://sourceware.org/ml/gdb-cvs/2012-07/msg00039.html
Best,
Hui
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH]Add option "-at" to "maint agent" and "maint agent-eval"
2012-06-24 7:00 [PATCH]Add option "-at" to "maint agent" and "maint agent-eval" Hui Zhu
` (2 preceding siblings ...)
2012-06-27 18:37 ` Tom Tromey
@ 2012-06-28 2:46 ` Yao Qi
3 siblings, 0 replies; 7+ messages in thread
From: Yao Qi @ 2012-06-28 2:46 UTC (permalink / raw)
To: gdb-patches; +Cc: Hui Zhu
On Sunday, June 24, 2012 02:59:08 PM Hui Zhu wrote:
> According the comments form Stan in
> http://sourceware.org/ml/gdb/2012-06/msg00060.html
> I post these patches for add option "-at" to "maint agent" and "maint
> agent-eval".
Do we need to add a test for this '-at location,'?
--
Yao Qi (齐尧)
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-07-05 1:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-24 7:00 [PATCH]Add option "-at" to "maint agent" and "maint agent-eval" Hui Zhu
2012-06-27 17:46 ` Eli Zaretskii
2012-07-05 0:38 ` Hui Zhu
2012-06-27 18:28 ` Tom Tromey
2012-06-27 18:37 ` Tom Tromey
2012-07-05 1:15 ` Hui Zhu
2012-06-28 2:46 ` Yao Qi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox