From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 813 invoked by alias); 4 Mar 2012 06:31:32 -0000 Received: (qmail 804 invoked by uid 22791); 4 Mar 2012 06:31:30 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW 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; Sun, 04 Mar 2012 06:31:16 +0000 Received: by werj55 with SMTP id j55so2301855wer.0 for ; Sat, 03 Mar 2012 22:31:15 -0800 (PST) Received: by 10.180.85.35 with SMTP id e3mr5967639wiz.6.1330842675327; Sat, 03 Mar 2012 22:31:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.115.75 with HTTP; Sat, 3 Mar 2012 22:30:28 -0800 (PST) In-Reply-To: References: <4F4DCDD5.2040807@earthlink.net> From: Hui Zhu Date: Sun, 04 Mar 2012 06:31:00 -0000 Message-ID: Subject: Re: [PATCH] dynamic printf To: Stan Shebs Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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-03/txt/msg00125.txt.bz2 +/* Both the argument and consumed numbers are dynamic for this one. */ +DEFOP (printf, 0, 0, 0, 0, 0x34) If I remember is right: /* We need something here just to make the tables come out ok. */ DEFOP (invalid2, 0, 0, 0, 0, 0x31) 0x31 is keep for printf, I suggest use 0x31 as the opcode of printf. Thanks, Hui On Thu, Mar 1, 2012 at 22:03, Hui Zhu wrote: > Hi Stan, > > This work is really cool! > > I will try to make KGTP support it when it commit to trunk. > > > + =A0 =A0 =A0 case gdb_agent_op_printf: > + =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 int chan, nargs, slen, i; > + =A0 =A0 =A0 =A0 =A0 int args[100]; > > Just use support 10 args, I suggest this line should be: int args[10]; > > + =A0 =A0 =A0 =A0 =A0 char *format; > + > + =A0 =A0 =A0 =A0 =A0 chan =3D aexpr->bytes[pc++]; > + =A0 =A0 =A0 =A0 =A0 nargs =3D aexpr->bytes[pc++]; > + =A0 =A0 =A0 =A0 =A0 slen =3D aexpr->bytes[pc++]; > + =A0 =A0 =A0 =A0 =A0 format =3D (char *) &(aexpr->bytes[pc]); > + =A0 =A0 =A0 =A0 =A0 pc +=3D slen; > + =A0 =A0 =A0 =A0 =A0 for (i =3D 0; i < nargs; ++i) > + =A0 =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 args[i] =3D top; > Suggest add a check in this part, then when i bigger than 9, stop set > top tp args[i] > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (--sp >=3D 0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 top =3D stack[sp]; > + =A0 =A0 =A0 =A0 =A0 =A0 } > I think this part need keep, because all to value that in the stack > need be clean. > > > + =A0 =A0 =A0 =A0 =A0 /* (should re-check format before calling?) */ > + =A0 =A0 =A0 =A0 =A0 printf (format, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 args[0], args[1], args[2], args[3],= args[4], > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 args[5], args[6], args[7], args[8],= args[9]); > + =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 break; > + > > Best, > Hui > > On Wed, Feb 29, 2012 at 15:03, Stan Shebs wrote: >> This patch implements a "dynamic printf", which is basically a breakpoint >> with a printf;continue as its command list - but with additional features >> that make it more interesting. =A0First, there is an option to send the = result >> to the inferior's output stream rather than to the GDB console; second, >> there is an option to do the printing in a remote agent/stub; and third,= the >> agent version can continue printf'ing even after GDB detaches(!). >> >> (For those who pay attention to the competitive landscape, this is an >> Ericsson-requested GDBification of a Wind River feature.) >> >> The syntax of the command is >> >> =A0 =A0dprintf ,,... >> >> where the location is as for breakpoints, while the format and args are = as >> for the printf command. =A0So you could have something like >> >> =A0 =A0dprintf myfun "myfun args are %d,%d\n",arg1,arg2 >> >> A setshow variable dprintf-style controls whether the printing is done by >> GDB, the inferior, or by a remote agent, and another variable >> disconnected-dprintf controls persistence upon disconnection, similarly = to >> disconnected tracing. >> >> The patch itself is somewhat of a hack-n-slash through the middle of GDB, >> and there is much to critique. :-) =A0Partly this is because I wanted to= push >> through to a genuinely useful example of target-side breakpoint commands, >> rather than doing limited-functionality "commands" in the abstract. =A0I= t also >> points up our continuing need for being able to define types of breakpoi= nts >> by properties rather than adding enums... =A0I borrowed some of Luis' >> target-side conditional code, and got some inspiration from Hui Zhu's >> previous try at a printf bytecode. >> >> Anyway, without further ado, here's the patch itself. =A0I've skipped the >> testsuite for now, as I expect everybody will want nontrivial modificati= ons. >> :-) >> >> Stan >> >> 2012-02-28 =A0Stan Shebs >> >> =A0 =A0Add dynamic printf. >> =A0 =A0* breakpoint.h (enum bptype): New type bp_dprintf. >> =A0 =A0(struct bp_target_info): New field commands and persist. >> =A0 =A0(struct bp_location): New field cmd_bytecode. >> =A0 =A0(struct breakpoint): New field extra_string. >> =A0 =A0* breakpoint.c (dprintf_breakpoint_ops): New. >> =A0 =A0(disconnected_dprintf): New global. >> =A0 =A0(is_breakpoint): Add bp_dprintf. >> =A0 =A0(parse_format_string): New function. >> =A0 =A0(parse_cmd_to_aexpr): New function. >> =A0 =A0(build_target_command_list): New function. >> =A0 =A0(insert_bp_location): Call it. >> =A0 =A0(remove_breakpoints_pid): Skip dprintf breakpoints. >> =A0 =A0(bpstat_what): Add dprintf case. >> =A0 =A0(bptype_string): Ditto. >> =A0 =A0(print_one_breakpoint_location): Ditto. >> =A0 =A0(init_bp_location): Ditto. >> =A0 =A0(bkpt_print_mention): Ditto. >> =A0 =A0(dprintf_style_enums): New array. >> =A0 =A0(dprintf_style): New global. >> =A0 =A0(glob_extra_string): New global. >> =A0 =A0(init_breakpoint_sal): Handle extra string. >> =A0 =A0(addr_string_to_sals): Ditto. >> =A0 =A0(find_condition_and_thread): Add extra argument. >> =A0 =A0(create_breakpoint): Save away additional text at end of command. >> =A0 =A0(dprintf_command): New function. >> =A0 =A0(_initialize_breakpoint): Add new commands. >> =A0 =A0* common/ax.def (printf): New bytecode. >> =A0 =A0* ax-gdb.c (gen_printf): New function. >> =A0 =A0(agent_print_command): New function. >> =A0 =A0(_initialize_ax_gdb): Add maint agent-printf command. >> =A0 =A0* ax-gdb.h (gen_printf): Declare. >> =A0 =A0* ax-general.c (ax_print): Add printf disassembly. >> =A0 =A0* remote.c (remote_state) : New field. >> =A0 =A0(PACKET_BreakpointCommandss): New enum. >> =A0 =A0(remote_breakpoint_commands_feature): New function. >> =A0 =A0(remote_protocol_features): Add new BreakpointCommands entry. >> =A0 =A0(remote_can_run_breakpoint_commands): New function. >> =A0 =A0(remote_add_target_side_commands): New function. >> =A0 =A0(remote_insert_breakpoint): Call it. >> =A0 =A0(remote_insert_hw_breakpoint): Ditto. >> =A0 =A0(_initialize_remote): Add new packet configuration for >> =A0 =A0target-side breakpoint commands. >> =A0 =A0* target.h (struct target_ops): New field >> =A0 =A0to_can_run_breakpoint_commands. >> =A0 =A0(target_can_run_breakpoint_commands): New macro. >> =A0 =A0* target.c (update_current_target): Handle >> =A0 =A0to_can_run_breakpoint_commands. >> >> =A0 =A0[gdbserver] >> =A0 =A0* server.c (handle_query): Claim support for breakpoint commands. >> =A0 =A0(process_point_options): Add command case. >> =A0 =A0(process_serial_event): Leave running if there are printfs in >> =A0 =A0effect. >> =A0 =A0* mem-break.c (struct point_command_list): New struct. >> =A0 =A0(struct breakpoint): New field command_list. >> =A0 =A0(any_persistent_commands): New function. >> =A0 =A0(add_commands_to_breakpoint): New function. >> =A0 =A0(add_breakpoint_commands): New function. >> =A0 =A0(gdb_no_commands_at_breakpoint): New function. >> =A0 =A0(run_breakpoint_commands): New function. >> =A0 =A0* mem-break.h (any_persistent_commands): Declare. >> =A0 =A0(add_breakpoint_commands): Declare. >> =A0 =A0(gdb_no_commands_at_breakpoint): Declare. >> =A0 =A0(run_breakpoint_commands): Declare. >> =A0 =A0* linux-low.c (linux_wait_1): Test for and run breakpoint commands >> =A0 =A0locally. >> =A0 =A0* ax.c (gdb_eval_agent_expr): Add printf opcode. >> >> =A0 =A0[doc] >> =A0 =A0* gdb.texinfo (Dynamic Printf): New subsection. >>