From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 629 invoked by alias); 1 Mar 2012 14:04:33 -0000 Received: (qmail 617 invoked by uid 22791); 1 Mar 2012 14:04:31 -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-wi0-f169.google.com (HELO mail-wi0-f169.google.com) (209.85.212.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Mar 2012 14:04:15 +0000 Received: by wibhi20 with SMTP id hi20so528320wib.0 for ; Thu, 01 Mar 2012 06:04:14 -0800 (PST) Received-SPF: pass (google.com: domain of teawater@gmail.com designates 10.180.85.35 as permitted sender) client-ip=10.180.85.35; Authentication-Results: mr.google.com; spf=pass (google.com: domain of teawater@gmail.com designates 10.180.85.35 as permitted sender) smtp.mail=teawater@gmail.com; dkim=pass header.i=teawater@gmail.com Received: from mr.google.com ([10.180.85.35]) by 10.180.85.35 with SMTP id e3mr2719119wiz.6.1330610654450 (num_hops = 1); Thu, 01 Mar 2012 06:04:14 -0800 (PST) Received: by 10.180.85.35 with SMTP id e3mr2175752wiz.6.1330610654383; Thu, 01 Mar 2012 06:04:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.115.75 with HTTP; Thu, 1 Mar 2012 06:03:34 -0800 (PST) In-Reply-To: <4F4DCDD5.2040807@earthlink.net> References: <4F4DCDD5.2040807@earthlink.net> From: Hui Zhu Date: Thu, 01 Mar 2012 14:04: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/msg00014.txt.bz2 Hi Stan, This work is really cool! I will try to make KGTP support it when it commit to trunk. + case gdb_agent_op_printf: + { + int chan, nargs, slen, i; + int args[100]; Just use support 10 args, I suggest this line should be: int args[10]; + char *format; + + chan =3D aexpr->bytes[pc++]; + nargs =3D aexpr->bytes[pc++]; + slen =3D aexpr->bytes[pc++]; + format =3D (char *) &(aexpr->bytes[pc]); + pc +=3D slen; + for (i =3D 0; i < nargs; ++i) + { + args[i] =3D top; Suggest add a check in this part, then when i bigger than 9, stop set top tp args[i] + if (--sp >=3D 0) + top =3D stack[sp]; + } I think this part need keep, because all to value that in the stack need be clean. + /* (should re-check format before calling?) */ + printf (format, + args[0], args[1], args[2], args[3], args[4], + args[5], args[6], args[7], args[8], args[9]); + } + 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 r= esult > 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. =A0It= also > points up our continuing need for being able to define types of breakpoin= ts > 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 modificatio= ns. > :-) > > 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. >