This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] Change trace buffer size
- From: "Abid, Hafiz" <hafiz_abid at mentor dot com>
- To: <gdb-patches at sourceware dot org>
- Cc: <stan at codesourcery dot com>
- Date: Mon, 18 Feb 2013 18:13:36 +0000
- Subject: [patch] Change trace buffer size
Hi All,
This patch adds support for QTBuffer:size in gdbserver and adds
commands in gdb to use this packet to change the trace buffer size.
The default value of the buffer size in gdb is -1 which means that
target will use whatever size it likes.
I notice that there are some tests that are using "maint packet" to
send QTBuffer:size. I was not sure what to do with them so I have left
them alone. If reviewers suggest, I can update/remove them.
Regards,
Abid
2012-02-18 Stan Shebs <stan@codesourcery.com>
Hafiz Abid Qadeer <abidh@codesourcery.com>
gdb/
* NEWS: Mention set and show trace-buffer-size commands.
* target.h (struct target_ops): New method
to_set_trace_buffer_size.
(target_set_trace_buffer_size): New macro.
* target.c (update_current_target): Set up new method.
* tracepoint.c (trace_buffer_size): New global.
(start_tracing): Send it to the target.
(set_trace_buffer_size): New function.
(_initialize_tracepoint): Add new setshow for trace-buffer-size.
* remote.c (remote_set_trace_buffer_size): New function.
(_initialize_remote): Use it.
(remote_set_trace_notes): Handle no-op case better.
gdb/gdbserver/
* tracepoint.c (trace_buffer_size): New global.
(init_trace_buffer): Change to one-argument function, add
realloc option.
(handle_tracepoint_general_set): Call cmd_bigqtbuffer_size to
handle QTBuffer:size packet.
(cmd_bigqtbuffer_size): New function.
(initialize_tracepoint): Default to a smaller buffer.
gdb/doc/
* gdb.texinfo (Starting and Stopping Trace Experiments):
Document
trace-buffer-size set and show commands.
(Tracepoint Packets): Document QTBuffer:size .
gdb/testsuite/
* gdb.trace/trace-buffer-size.exp: New file.
* gdb.trace/trace-buffer-size.c: New file.
diff --git a/gdb/NEWS b/gdb/NEWS
index 0877aa2..ea565ea 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -104,6 +104,10 @@ set debug notification
show debug notification
Control display of debugging info for async remote notification.
+set trace-buffer-size
+show trace-buffer-size
+ Request target to change the size of trace buffer.
+
* Removed commands
** For the Renesas Super-H architecture, the "regs" command has been removed
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index e8ac8c5..2a924e7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -11729,6 +11729,25 @@ for instance if you are looking at frames from a trace file.
@end table
@table @code
+@item set trace-buffer-size @var{n}
+@kindex set trace-buffer-size
+Request that the target use a trace buffer of @var{n} bytes. Not all
+targets will honor the request; they may have a compiled-in size for
+the trace buffer, or some other limitation. Set to a value of
+@code{-1} to let the target use whatever size it likes. This is also
+the default.
+
+@item show trace-buffer-size
+@kindex show trace-buffer-size
+Show the current requested size for the trace buffer. Note that this
+will only match the actual size if the target supports size-setting,
+and was able to handle the requested size. For instance, if the
+target can only change buffer size between runs, this variable will
+not reflect until the next run starts. Use @code{tstatus} to get a
+report of the actual buffer size.
+@end table
+
+@table @code
@item set trace-user @var{text}
@kindex set trace-user
@@ -38461,6 +38480,10 @@ available.
This packet directs the target to use a circular trace buffer if
@var{value} is 1, or a linear buffer if the value is 0.
+@item QTBuffer:size:@var{size}
+This packet directs the target to make the trace buffer be of size
+@var{size} if possible.
+
@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
@cindex @samp{QTNotes} packet
This packet adds optional textual notes to the trace run. Allowable
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index 95c55ad..5f88264 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -992,6 +992,8 @@ int current_traceframe = -1;
static int circular_trace_buffer;
#endif
+static int trace_buffer_size;
+
/* Pointer to the block of memory that traceframes all go into. */
static unsigned char *trace_buffer_lo;
@@ -1478,9 +1480,16 @@ clear_inferior_trace_buffer (void)
#endif
static void
-init_trace_buffer (unsigned char *buf, int bufsize)
+init_trace_buffer (int bufsize)
{
- trace_buffer_lo = buf;
+ trace_buffer_size = bufsize;
+
+ /* If we already have a trace buffer, try realloc'ing. */
+ if (trace_buffer_lo)
+ trace_buffer_lo = xrealloc (trace_buffer_lo, bufsize);
+ else
+ trace_buffer_lo = xmalloc (bufsize);
+
trace_buffer_hi = trace_buffer_lo + bufsize;
clear_trace_buffer ();
@@ -4021,6 +4030,36 @@ cmd_bigqtbuffer_circular (char *own_buf)
}
static void
+cmd_bigqtbuffer_size (char *own_buf)
+{
+ ULONGEST val;
+ LONGEST sval;
+ char *packet = own_buf;
+
+ packet += strlen ("QTBuffer:size:");
+
+ 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. */
+ if (sval < 0 || sval == trace_buffer_size)
+ {
+ write_ok (own_buf);
+ return;
+ }
+ /* Right now we can't change the size during a tracing run. */
+ if (tracing)
+ {
+ write_enn (own_buf);
+ return;
+ }
+ init_trace_buffer (sval);
+ trace_debug ("Trace buffer is now %s bytes",
+ plongest (trace_buffer_size));
+ write_ok (own_buf);
+}
+
+static void
cmd_qtnotes (char *own_buf)
{
size_t nbytes;
@@ -4144,6 +4183,11 @@ handle_tracepoint_general_set (char *packet)
cmd_bigqtbuffer_circular (packet);
return 1;
}
+ else if (strncmp ("QTBuffer:size:", packet, strlen ("QTBuffer:size:")) == 0)
+ {
+ cmd_bigqtbuffer_size (packet);
+ return 1;
+ }
else if (strncmp ("QTNotes:", packet, strlen ("QTNotes:")) == 0)
{
cmd_qtnotes (packet);
@@ -7229,10 +7273,9 @@ get_timestamp (void)
void
initialize_tracepoint (void)
{
- /* There currently no way to change the buffer size. */
- const int sizeOfBuffer = 5 * 1024 * 1024;
- unsigned char *buf = xmalloc (sizeOfBuffer);
- init_trace_buffer (buf, sizeOfBuffer);
+ /* Start with a size that's not too large. */
+ const int sizeOfBuffer = 1024 * 1024;
+ init_trace_buffer (sizeOfBuffer);
/* Wire trace state variable 1 to be the timestamp. This will be
uploaded to GDB upon connection and become one of its trace state
diff --git a/gdb/remote.c b/gdb/remote.c
index 88a57c8..e0ddaf9 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -11042,6 +11042,23 @@ remote_get_min_fast_tracepoint_insn_len (void)
}
}
+static void
+remote_set_trace_buffer_size (LONGEST val)
+{
+ struct remote_state *rs = get_remote_state ();
+ char *p, *reply;
+
+ sprintf (rs->buf, "QTBuffer:size:");
+ p = rs->buf + strlen (rs->buf);
+ p += hexnumstr (p, (ULONGEST) val);
+ putpkt (rs->buf);
+ reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (*reply == '\0')
+ error (_("Target does not support setting trace buffer size."));
+ if (strcmp (reply, "OK") != 0)
+ error (_("Bogus reply from target: %s"), reply);
+}
+
static int
remote_set_trace_notes (char *user, char *notes, char *stop_notes)
{
@@ -11050,6 +11067,7 @@ remote_set_trace_notes (char *user, char *notes, char *stop_notes)
char *buf = rs->buf;
char *endbuf = rs->buf + get_remote_packet_size ();
int nbytes;
+ int any = 0;
buf += xsnprintf (buf, endbuf - buf, "QTNotes:");
if (user)
@@ -11058,6 +11076,7 @@ remote_set_trace_notes (char *user, char *notes, char *stop_notes)
nbytes = bin2hex (user, buf, 0);
buf += 2 * nbytes;
*buf++ = ';';
+ any = 1;
}
if (notes)
{
@@ -11065,6 +11084,7 @@ remote_set_trace_notes (char *user, char *notes, char *stop_notes)
nbytes = bin2hex (notes, buf, 0);
buf += 2 * nbytes;
*buf++ = ';';
+ any = 1;
}
if (stop_notes)
{
@@ -11072,7 +11092,10 @@ remote_set_trace_notes (char *user, char *notes, char *stop_notes)
nbytes = bin2hex (stop_notes, buf, 0);
buf += 2 * nbytes;
*buf++ = ';';
+ any = 1;
}
+ if (any == 0)
+ return 0;
/* Ensure the buffer is terminated. */
*buf = '\0';
@@ -11219,6 +11242,7 @@ Specify the serial device it is connected to\n\
remote_ops.to_get_min_fast_tracepoint_insn_len = remote_get_min_fast_tracepoint_insn_len;
remote_ops.to_set_disconnected_tracing = remote_set_disconnected_tracing;
remote_ops.to_set_circular_trace_buffer = remote_set_circular_trace_buffer;
+ remote_ops.to_set_trace_buffer_size = remote_set_trace_buffer_size;
remote_ops.to_set_trace_notes = remote_set_trace_notes;
remote_ops.to_core_of_thread = remote_core_of_thread;
remote_ops.to_verify_memory = remote_verify_memory;
diff --git a/gdb/target.c b/gdb/target.c
index 9d8bf6e..2e507e0 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -693,6 +693,7 @@ update_current_target (void)
INHERIT (to_get_min_fast_tracepoint_insn_len, t);
INHERIT (to_set_disconnected_tracing, t);
INHERIT (to_set_circular_trace_buffer, t);
+ INHERIT (to_set_trace_buffer_size, t);
INHERIT (to_set_trace_notes, t);
INHERIT (to_get_tib_address, t);
INHERIT (to_set_permissions, t);
@@ -912,6 +913,9 @@ update_current_target (void)
de_fault (to_set_circular_trace_buffer,
(void (*) (int))
target_ignore);
+ de_fault (to_set_trace_buffer_size,
+ (void (*) (LONGEST))
+ target_ignore);
de_fault (to_set_trace_notes,
(int (*) (char *, char *, char *))
return_zero);
diff --git a/gdb/target.h b/gdb/target.h
index 1971265..03b3d78 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -806,6 +806,7 @@ struct target_ops
disconnection - set VAL to 1 to keep tracing, 0 to stop. */
void (*to_set_disconnected_tracing) (int val);
void (*to_set_circular_trace_buffer) (int val);
+ void (*to_set_trace_buffer_size) (LONGEST val);
/* Add/change textual notes about the trace run, returning 1 if
successful, 0 otherwise. */
@@ -1700,6 +1701,9 @@ extern char *target_fileio_read_stralloc (const char *filename);
#define target_set_circular_trace_buffer(val) \
(*current_target.to_set_circular_trace_buffer) (val)
+#define target_set_trace_buffer_size(val) \
+ (*current_target.to_set_trace_buffer_size) (val)
+
#define target_set_trace_notes(user,notes,stopnotes) \
(*current_target.to_set_trace_notes) ((user), (notes), (stopnotes))
diff --git a/gdb/testsuite/gdb.trace/trace-buffer-size.c b/gdb/testsuite/gdb.trace/trace-buffer-size.c
new file mode 100644
index 0000000..79a9ed1
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/trace-buffer-size.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+main ()
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.trace/trace-buffer-size.exp b/gdb/testsuite/gdb.trace/trace-buffer-size.exp
new file mode 100644
index 0000000..5c6c989
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/trace-buffer-size.exp
@@ -0,0 +1,40 @@
+# Copyright 1998-2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+load_lib "trace-support.exp"
+
+standard_testfile
+
+if [prepare_for_testing ${testfile}.exp $testfile $srcfile \
+ {debug nowarnings}] {
+ untested "failed to prepare for trace tests"
+ return -1
+}
+
+if ![runto_main] {
+ fail "can't run to main to check for trace support"
+ return -1
+}
+
+if ![gdb_target_supports_trace] {
+ unsupported "target does not support trace"
+ return -1;
+}
+
+set BUFFER_SIZE 1024
+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"
+
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index ca104aa..f9320a3 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -173,6 +173,11 @@ static int disconnected_tracing;
static int circular_trace_buffer;
+/* This variable is the requested trace buffer size, or -1 to indicate
+ that we don't care and leave it up to the target to set a size. */
+
+static int trace_buffer_size = -1;
+
/* Textual notes applying to the current and/or future trace runs. */
char *trace_user = NULL;
@@ -1829,6 +1834,7 @@ start_tracing (char *notes)
/* Set some mode flags. */
target_set_disconnected_tracing (disconnected_tracing);
target_set_circular_trace_buffer (circular_trace_buffer);
+ target_set_trace_buffer_size (trace_buffer_size);
if (!notes)
notes = trace_notes;
@@ -3231,6 +3237,13 @@ set_circular_trace_buffer (char *args, int from_tty,
}
static void
+set_trace_buffer_size (char *args, int from_tty,
+ struct cmd_list_element *c)
+{
+ target_set_trace_buffer_size (trace_buffer_size);
+}
+
+static void
set_trace_user (char *args, int from_tty,
struct cmd_list_element *c)
{
@@ -5405,6 +5418,16 @@ up and stopping the trace run."),
&setlist,
&showlist);
+ 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);
+
add_setshow_string_cmd ("trace-user", class_trace,
&trace_user, _("\
Set the user name to use for current and future trace runs"), _("\