From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27281 invoked by alias); 5 Jul 2012 00:38:07 -0000 Received: (qmail 27234 invoked by uid 22791); 5 Jul 2012 00:38:05 -0000 X-SWARE-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-we0-f169.google.com (HELO mail-we0-f169.google.com) (74.125.82.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 05 Jul 2012 00:37:46 +0000 Received: by werl57 with SMTP id l57so270937wer.0 for ; Wed, 04 Jul 2012 17:37:45 -0700 (PDT) Received: by 10.180.78.161 with SMTP id c1mr37711417wix.1.1341448664607; Wed, 04 Jul 2012 17:37:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.122.193 with HTTP; Wed, 4 Jul 2012 17:37:04 -0700 (PDT) In-Reply-To: <83a9zo8x8j.fsf@gnu.org> References: <83a9zo8x8j.fsf@gnu.org> From: Hui Zhu Date: Thu, 05 Jul 2012 00:38:00 -0000 Message-ID: Subject: Re: [PATCH]Add option "-at" to "maint agent" and "maint agent-eval" To: Eli Zaretskii Cc: gdb-patches@sourceware.org, stan_shebs@mentor.com, Yao_Qi@mentor.com Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-07/txt/msg00065.txt.bz2 On Thu, Jun 28, 2012 at 1:45 AM, Eli Zaretskii wrote: >> From: Hui Zhu >> Date: Sun, 24 Jun 2012 14:59:08 +0800 >> Cc: Stan Shebs , Yao Qi , >> Eli Zaretskii >> 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 >> >> * 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 >> >> * 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 >> >> * 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