Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: Stan Shebs <stanshebs@earthlink.net>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] dynamic printf
Date: Sun, 04 Mar 2012 06:31:00 -0000	[thread overview]
Message-ID: <CANFwon0yF1fJJ_dscaXpbv=yxdh3revNQwcr=ZrB_W=1ZeAw3g@mail.gmail.com> (raw)
In-Reply-To: <CANFwon3aN+T1Yf+Sr4ehMkpC4SEvoAPvcaLerBYf=xMr47HcpQ@mail.gmail.com>

+/* 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.
>>


  reply	other threads:[~2012-03-04  6:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  9:14 Stan Shebs
2012-02-29 10:28 ` Andreas Schwab
2012-03-13 23:09   ` Stan Shebs
2012-03-14 14:47     ` Marc Khouzam
2012-03-14 15:28     ` Tom Tromey
2012-02-29 16:16 ` Joel Brobecker
2012-03-13 23:15   ` Stan Shebs
2012-03-13 23:40     ` Joel Brobecker
2012-02-29 18:21 ` Eli Zaretskii
2012-03-13 23:20   ` Stan Shebs
2012-03-01 14:04 ` Hui Zhu
2012-03-04  6:31   ` Hui Zhu [this message]
2012-03-08 21:08 ` Tom Tromey
2012-03-13 23:51   ` Stan Shebs
2012-03-14 15:24     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANFwon0yF1fJJ_dscaXpbv=yxdh3revNQwcr=ZrB_W=1ZeAw3g@mail.gmail.com' \
    --to=teawater@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=stanshebs@earthlink.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox