Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: "Abid, Hafiz" <hafiz_abid@mentor.com>
Cc: gdb-patches@sourceware.org, stan@codesourcery.com,
	yao@codesourcery.com,        eliz@gnu.org
Subject: Re: [patch] Change trace buffer size(v2)
Date: Fri, 01 Mar 2013 20:02:00 -0000	[thread overview]
Message-ID: <51310936.40406@redhat.com> (raw)
In-Reply-To: <1362157623.18212.0@abidh-ubunto1104>

On 03/01/2013 05:07 PM, Abid, Hafiz wrote:

>>   if (*rs->buf == '\0')
>>
>> but, OTOH, new packets should really be using packet_ok.

I think you missed this note.

>> This test doesn't seem to really test that much.  I wonder if
>> you have ideas on expanding it?
> I have tried to expand the test by setting the buffer size to be very small and then testing the buffer to be full.

Good idea.

I think it'd be even better to run the test twice, once with
a larger buffer that fits the same trace frames, and make sure
the buffer doesn't end up full, and then another time with the
small buffer.  That'd cover the case of the target's buffer being
small by default, and the buffer size packet failing to work.

> 


> +* New remote packets
> +  A new packet has been defined to set the trace buffer size.
> +

Please model from previous examples:

* New remote packets
...
QTBuffer:circular
   Set the trace buffer to be linear or circular.

It's good to actually show the packet here, so the user
can quite find it in the manual, and, makes it easier to
answer the question in a few years "when was packet FOO added?".

> +@item QTBuffer:size:@var{size}
> +This packet directs the target to make the trace buffer be of size
> +@var{size} if possible. A value of @code{-1} tells the target to
> +use whatever size it likes.

Double space after period.  I think "prefers" is more natural in the
manual.

>  static void
> +cmd_bigqtbuffer_size (char *own_buf)
> +{
> +  ULONGEST val;
> +  LONGEST sval;
> +  char *packet = own_buf;
> +
> +  packet += strlen ("QTBuffer:size:");
> +
> +  /* -1 is sent as literal "-1".  */
> +  if (strcmp (packet, "-1") == 0)
> +    sval = -1;
> +  else
> +    {
> +      unpack_varlen_hex (packet, &val);
> +      sval = (LONGEST)val;
> +    }
> +  /* If we don't care about the size, or the size is unchanged,
> +     all is happy and nothing to do.  */

     s/all is happy and/there's/

> +  if (sval < 0 || sval == trace_buffer_size)
> +    {
> +      write_ok (own_buf);
> +      return;
> +    }
> +  /* Right now we can't change the size during a tracing run.  */

Let's drop distracting speculation:

  s/Right now we can't/Can't/

> +  if (tracing)
> +    {
> +       write_enn (own_buf);
> +       return;
> +    }

Better do this check before anything else, avoid
unnecessary special cases.

Also, if sval is < 0, this is not checking for "tracing" (fixed
by doing the check earlier), but also,

> +  init_trace_buffer (sval);

... nor does init_trace_buffer have any logic to
set the trace buffer size to whatever the "target likes":

 static void
-init_trace_buffer (unsigned char *buf, int bufsize)
+init_trace_buffer (LONGEST bufsize)
 {
-  trace_buffer_lo = buf;
+  trace_buffer_size = bufsize;
+
+  /* If we already have a trace buffer, try realloc'ing.  */
+  trace_buffer_lo = xrealloc (trace_buffer_lo, bufsize);
+
   trace_buffer_hi = trace_buffer_lo + bufsize;

   clear_trace_buffer ();


Please make sure to test that at least manually, though
it'd be better if the testsuite also exercised this.


> +static void
> +remote_set_trace_buffer_size (LONGEST val)
> +{
> +  struct remote_state *rs = get_remote_state ();
> +  char *reply;
> +  char *buf = rs->buf;
> +  char *endbuf = rs->buf + get_remote_packet_size ();
> +
> +  buf += xsnprintf (buf, endbuf - buf, "QTBuffer:size:");
> +  /* Send -1 as literal "-1" to avoid host size dependency.  */
> +  if (val == -1)
> +    buf += xsnprintf (buf, endbuf - buf, "-1");
> +  else
> +    buf += hexnumstr (buf, (ULONGEST) val);

This would mishandle other negative numbers (though
something else should be preventing those.
var_zuinteger_unlimited would be one way, though it'd
probably be a good idea to check for val<0 && val != -1 here too.

FYI, there's no need to special case -1 actually:

  if (val < 0)
    buf += hexnumstr (buf, (ULONGEST) -val);
  else
    buf += hexnumstr (buf, (ULONGEST) val);


> +
> +  putpkt (rs->buf);
> +  reply = remote_get_noisy_reply (&rs->buf, &rs->buf_size);
> +  if (*rs->buf == '\0')

Did you try packet_ok?  Really new commands/packets should be
using it.

> +    warning (_("Target does not support setting trace buffer size."));
> +  if (strcmp (reply, "OK") != 0)
> +    warning (_("Bogus reply from target: %s"), reply);
> +}
> +


> +
> +set BUFFER_SIZE 4
> +gdb_test_no_output "set trace-buffer-size $BUFFER_SIZE" "Set Trace Buffer Size"
> +gdb_test "show trace-buffer-size $BUFFER_SIZE" "Requested size of trace buffer is $BUFFER_SIZE.*" \
> +"Show Trace Buffer Size"

I think this overflows 80 columns.  Since you're breaking the line, could
you break it so it doesn't overflow 80 columns, please?

I'd write as:

gdb_test_no_output \
   "set trace-buffer-size $BUFFER_SIZE"
   "Set Trace Buffer Size"

gdb_test \
  "show trace-buffer-size $BUFFER_SIZE" \
  "Requested size of trace buffer is $BUFFER_SIZE.*" \
  "Show Trace Buffer Size"

> +
> +# We set trace buffer to very small size. Then after running trace, we check
> +# if it is full. This will show if setting trace buffer size really worked.

Double space after period.

> +gdb_breakpoint ${srcfile}:[gdb_get_line_number "breakpoint1"]
> +gdb_test "trace test_function" \
> +    "Tracepoint \[0-9\]+ at .*" \
> +    "set tracepoint at test_function"
> +gdb_trace_setactions "1. Set action for trace point" "" \
> +    "collect var" "^$"
> +gdb_test "tstart"     ".*" ""

gdb_test_no_output "tstart"

> +gdb_test "continue"   ".*" ""

Better to match something rather than ".*".

Look for "run trace experiment" on other tests.

> +gdb_test "tstatus"    ".*Trace stopped because the buffer was full.*" \
> +"Buffer full check"

Column overflow again, I think.

> +gdb_test "tstop"    ".*" ""

gdb_test_test_no_output.


>  
> +  add_setshow_zinteger_cmd ("trace-buffer-size", no_class,
> +			    &trace_buffer_size, _("\
> +Set requested size of trace buffer."), _("\
> +Show requested size of trace buffer."), _("\
> +Use this to choose a size for the trace buffer.  Some targets\n\
> +may have fixed or limited buffer sizes.  A value of -1 disables\n\
> +any attempt to set the buffer size and lets the target choose."),
> +			    set_trace_buffer_size, NULL,
> +			    &setlist, &showlist);
> +

As I mentioned elsewhere, I think it'd be better to use the
new var_zuinteger_unlimited.

We should really fix the broken -1 handling too, before 7.6.

>    add_setshow_string_cmd ("trace-user", class_trace,
>  			  &trace_user, _("\
>  Set the user name to use for current and future trace runs"), _("\

-- 
Pedro Alves


  parent reply	other threads:[~2013-03-01 20:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-18 18:13 [patch] Change trace buffer size Abid, Hafiz
2013-02-18 20:00 ` Eli Zaretskii
2013-02-19  2:53 ` Yao Qi
2013-02-27 16:55   ` Pedro Alves
2013-02-28  0:52     ` Yao Qi
2013-02-27 16:39 ` Pedro Alves
2013-03-01 17:07   ` [patch] Change trace buffer size(v2) Abid, Hafiz
2013-03-01 18:13     ` zinteger setshow commands broken Pedro Alves
2013-03-04 10:10       ` Abid, Hafiz
2013-03-04 10:16         ` Yao Qi
2013-03-04 10:28         ` Pedro Alves
2013-03-01 20:02     ` Pedro Alves [this message]
2013-03-04 19:03       ` [patch] Change trace buffer size(v3) Abid, Hafiz
2013-03-04 20:43         ` Pedro Alves
2013-03-05 14:12           ` [patch] Change trace buffer size(v4) Abid, Hafiz
2013-03-05 20:13             ` Pedro Alves
2013-03-08 11:30               ` [patch] Change trace buffer size(v5) Abid, Hafiz
2013-03-08 14:09                 ` Eli Zaretskii
2013-03-08 14:27                   ` Abid, Hafiz
2013-03-08 14:28                 ` Pedro Alves
2013-03-08 14:52                 ` Yao Qi
2013-03-08 15:15                   ` Abid, Hafiz
2013-03-08 15:27                     ` Yao Qi
2013-05-02 17:31                     ` Pedro Alves
2013-05-03 11:38                       ` Abid, Hafiz
2013-05-03 14:05                         ` Pedro Alves
2013-05-03 15:08                           ` Abid, Hafiz
2013-05-03 15:26                             ` Pedro Alves
2013-03-09  2:06                 ` Joel Brobecker
2013-03-09  8:27                   ` Eli Zaretskii
2013-03-09 10:20                     ` Abid, Hafiz
2013-03-09 10:39                       ` Abid, Hafiz
2013-03-09 11:11                         ` Eli Zaretskii
2013-03-09 11:07                       ` Eli Zaretskii
2013-03-11 18:33                         ` Tom Tromey
2013-03-11 19:44                           ` Eli Zaretskii

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=51310936.40406@redhat.com \
    --to=palves@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=hafiz_abid@mentor.com \
    --cc=stan@codesourcery.com \
    --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