This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] dynamic printf


+/* 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 <teawater@gmail.com> wrote:
> 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 = aexpr->bytes[pc++];
> + ? ? ? ? ? nargs = aexpr->bytes[pc++];
> + ? ? ? ? ? slen = aexpr->bytes[pc++];
> + ? ? ? ? ? format = (char *) &(aexpr->bytes[pc]);
> + ? ? ? ? ? pc += slen;
> + ? ? ? ? ? for (i = 0; i < nargs; ++i)
> + ? ? ? ? ? ? {
> + ? ? ? ? ? ? ? args[i] = top;
> Suggest add a check in this part, then when i bigger than 9, stop set
> top tp args[i]
>
> + ? ? ? ? ? ? ? if (--sp >= 0)
> + ? ? ? ? ? ? ? ? top = 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 <stanshebs@earthlink.net> 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. ?First, 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
>>
>> ? ?dprintf <location> <format>,<arg>,<arg>...
>>
>> where the location is as for breakpoints, while the format and args are as
>> for the printf command. ?So you could have something like
>>
>> ? ?dprintf 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. :-) ?Partly 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. ?It also
>> points up our continuing need for being able to define types of breakpoints
>> by properties rather than adding enums... ?I 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. ?I've skipped the
>> testsuite for now, as I expect everybody will want nontrivial modifications.
>> :-)
>>
>> Stan
>>
>> 2012-02-28 ?Stan Shebs <stan@codesourcery.com>
>>
>> ? ?Add dynamic printf.
>> ? ?* breakpoint.h (enum bptype): New type bp_dprintf.
>> ? ?(struct bp_target_info): New field commands and persist.
>> ? ?(struct bp_location): New field cmd_bytecode.
>> ? ?(struct breakpoint): New field extra_string.
>> ? ?* breakpoint.c (dprintf_breakpoint_ops): New.
>> ? ?(disconnected_dprintf): New global.
>> ? ?(is_breakpoint): Add bp_dprintf.
>> ? ?(parse_format_string): New function.
>> ? ?(parse_cmd_to_aexpr): New function.
>> ? ?(build_target_command_list): New function.
>> ? ?(insert_bp_location): Call it.
>> ? ?(remove_breakpoints_pid): Skip dprintf breakpoints.
>> ? ?(bpstat_what): Add dprintf case.
>> ? ?(bptype_string): Ditto.
>> ? ?(print_one_breakpoint_location): Ditto.
>> ? ?(init_bp_location): Ditto.
>> ? ?(bkpt_print_mention): Ditto.
>> ? ?(dprintf_style_enums): New array.
>> ? ?(dprintf_style): New global.
>> ? ?(glob_extra_string): New global.
>> ? ?(init_breakpoint_sal): Handle extra string.
>> ? ?(addr_string_to_sals): Ditto.
>> ? ?(find_condition_and_thread): Add extra argument.
>> ? ?(create_breakpoint): Save away additional text at end of command.
>> ? ?(dprintf_command): New function.
>> ? ?(_initialize_breakpoint): Add new commands.
>> ? ?* common/ax.def (printf): New bytecode.
>> ? ?* ax-gdb.c (gen_printf): New function.
>> ? ?(agent_print_command): New function.
>> ? ?(_initialize_ax_gdb): Add maint agent-printf command.
>> ? ?* ax-gdb.h (gen_printf): Declare.
>> ? ?* ax-general.c (ax_print): Add printf disassembly.
>> ? ?* remote.c (remote_state) <cond_breakpoints>: New field.
>> ? ?(PACKET_BreakpointCommandss): New enum.
>> ? ?(remote_breakpoint_commands_feature): New function.
>> ? ?(remote_protocol_features): Add new BreakpointCommands entry.
>> ? ?(remote_can_run_breakpoint_commands): New function.
>> ? ?(remote_add_target_side_commands): New function.
>> ? ?(remote_insert_breakpoint): Call it.
>> ? ?(remote_insert_hw_breakpoint): Ditto.
>> ? ?(_initialize_remote): Add new packet configuration for
>> ? ?target-side breakpoint commands.
>> ? ?* target.h (struct target_ops): New field
>> ? ?to_can_run_breakpoint_commands.
>> ? ?(target_can_run_breakpoint_commands): New macro.
>> ? ?* target.c (update_current_target): Handle
>> ? ?to_can_run_breakpoint_commands.
>>
>> ? ?[gdbserver]
>> ? ?* server.c (handle_query): Claim support for breakpoint commands.
>> ? ?(process_point_options): Add command case.
>> ? ?(process_serial_event): Leave running if there are printfs in
>> ? ?effect.
>> ? ?* mem-break.c (struct point_command_list): New struct.
>> ? ?(struct breakpoint): New field command_list.
>> ? ?(any_persistent_commands): New function.
>> ? ?(add_commands_to_breakpoint): New function.
>> ? ?(add_breakpoint_commands): New function.
>> ? ?(gdb_no_commands_at_breakpoint): New function.
>> ? ?(run_breakpoint_commands): New function.
>> ? ?* mem-break.h (any_persistent_commands): Declare.
>> ? ?(add_breakpoint_commands): Declare.
>> ? ?(gdb_no_commands_at_breakpoint): Declare.
>> ? ?(run_breakpoint_commands): Declare.
>> ? ?* linux-low.c (linux_wait_1): Test for and run breakpoint commands
>> ? ?locally.
>> ? ?* ax.c (gdb_eval_agent_expr): Add printf opcode.
>>
>> ? ?[doc]
>> ? ?* gdb.texinfo (Dynamic Printf): New subsection.
>>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]