Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Stan Shebs <stanshebs@earthlink.net>
Cc: Yao Qi <yao@codesourcery.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Dynamic printf for a target agent
Date: Wed, 27 Jun 2012 20:45:00 -0000	[thread overview]
Message-ID: <87mx3o5vsk.fsf@fleche.redhat.com> (raw)
In-Reply-To: <4FE8841A.7090100@earthlink.net> (Stan Shebs's message of "Mon,	25 Jun 2012 08:30:34 -0700")

>>>>> "Stan" == Stan Shebs <stanshebs@earthlink.net> writes:

Stan> +static void
Stan> +maint_agent_printf_command (char *exp, int from_tty)
Stan> +{
[...]
Stan> +      expr = parse_exp_1 (&cmd1, (struct block *) 0, 1);

Now that Hui's "-at" patch is going in, perhaps this function should
have the same treatment.

Stan> +void
Stan> +ax_string (struct agent_expr *x, char *str, int slen)
Stan> +{
Stan> +  int i;
Stan> +
Stan> +  grow_expr (x, slen + 3);
Stan> +  x->buf[x->len++] = ((slen + 1) >> 8) & 0xff;
Stan> +  x->buf[x->len++] = (slen + 1) & 0xff;

I think this should check that the length fits in 2 bytes.

Stan> +@item @code{printf} (0x34)  @var{numargs} @var{string} @result{}
Stan> +Do a formatted print, in the style of the C function @code{printf}).
Stan> +The value of @var{numargs} is the number of arguments to expect on the
Stan> +stack, while @var{string} is the format string, prefixed with a
Stan> +two-byte length, and suffixed with a zero byte.  The format string

I think the docs should whether the length includes the zero byte.

Stan> +	case string_arg:
Stan> +	  {
Stan> +	    gdb_byte *str;
Stan> +	    CORE_ADDR tem;
Stan> +	    int j;
Stan> +
Stan> +	    tem = args[i];
Stan> +
Stan> +	    /* This is a %s argument.  Find the length of the string.  */
Stan> +	    for (j = 0;; j++)
Stan> +	      {
Stan> +		gdb_byte c;
Stan> +
Stan> +		read_inferior_memory (tem + j, &c, 1);
Stan> +		if (c == 0)
Stan> +		  break;
Stan> +	      }
Stan> +
Stan> +	      /* Copy the string contents into a string inside GDB.  */
Stan> +	      str = (gdb_byte *) alloca (j + 1);
Stan> +	      if (j != 0)
Stan> +		read_inferior_memory (tem, str, j);
Stan> +	      str[j] = 0;
Stan> +
Stan> +              printf (current_substring, (char *) str);

Is it ever possible for the argument to "%s" to be NULL?  It seems like
it should be; but then the length-finding code seems wrong, and the
printing of a NULL should be handled directly, not left to the host
printf.

Stan> +	case gdb_agent_op_printf:
Stan> +	  {
Stan> +	    int nargs, slen, i;
Stan> +	    CORE_ADDR fn = 0, chan = 0;
Stan> +	    /* Can't have more args than the entire size of the stack.  */
Stan> +	    ULONGEST args[STACK_MAX];
Stan> +	    char *format;
Stan> +
Stan> +	    nargs = aexpr->bytes[pc++];
Stan> +	    slen = aexpr->bytes[pc++];
Stan> +	    slen = (slen << 8) + aexpr->bytes[pc++];
Stan> +	    format = (char *) &(aexpr->bytes[pc]);

Perhaps double-check that the terminating \0 byte is in fact present.

Stan> +if $target_can_dprintf {
Stan> +
Stan> +    gdb_run_cmd
Stan> +
Stan> +    gdb_test "" "Breakpoint"

This seems weird.

FWIW I rather liked the format-parsing refactoring.

Tom


  reply	other threads:[~2012-06-27 20:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30  1:10 Stan Shebs
2012-05-31  6:02 ` Yao Qi
2012-06-25 15:31   ` Stan Shebs
2012-06-27 20:45     ` Tom Tromey [this message]
2012-07-02 18:19       ` Stan Shebs
2012-07-18 19:18         ` 7.4->7.5 Regression gdb.base/pending.exp with gdbserver [Re: [PATCH] Dynamic printf for a target agent] Jan Kratochvil
2012-07-20  2:28           ` Yao Qi
2012-07-25 19:50             ` Jan Kratochvil
2012-07-27  2:32               ` [committed]: " Yao Qi
2012-07-27 16:36             ` Pedro Alves
2012-07-28 10:24               ` Yao Qi
2012-07-28 11:41                 ` Yao Qi
2012-07-02 16:41     ` Build regression on 64-bit hosts " Jan Kratochvil

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=87mx3o5vsk.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=stanshebs@earthlink.net \
    --cc=yao@codesourcery.com \
    /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