Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Franco de Carvalho <pedromfc@linux.ibm.com>
To: gdb-patches@sourceware.org
Cc: uweigand@de.ibm.com
Subject: [PATCH v2 6/6] Allow larger regblock sizes when saving tracefiles
Date: Fri, 27 Jul 2018 21:03:00 -0000	[thread overview]
Message-ID: <20180727210318.2960-7-pedromfc@linux.ibm.com> (raw)
In-Reply-To: <20180727210318.2960-1-pedromfc@linux.ibm.com>

The tracefile.c:trace_save function assumes trace_regblock_size won't
be larger than the MAX_TRACE_UPLOAD constant, used to size the buffer
which holds trace data.  This can cause buffer overruns when this is
not the case.  This patch changes this function so that the larger
size is used to size the buffer.

gdb/ChangeLog:
YYYY-MM-DD  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* tracepoint.c: Include common/byte-vector.h.
	(trace_save): Change type of buf to gdb::byte_vector.  Initialize
	with trace_regblock_size if needed.  Update uses of buf.
---
 gdb/tracefile.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/gdb/tracefile.c b/gdb/tracefile.c
index ecd2f5c678..b367f6e403 100644
--- a/gdb/tracefile.c
+++ b/gdb/tracefile.c
@@ -22,6 +22,7 @@
 #include "ctf.h"
 #include "exec.h"
 #include "regcache.h"
+#include "common/byte-vector.h"
 
 /* Helper macros.  */
 
@@ -67,7 +68,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 
   ULONGEST offset = 0;
 #define MAX_TRACE_UPLOAD 2000
-  gdb_byte buf[MAX_TRACE_UPLOAD];
+  gdb::byte_vector buf (std::max (MAX_TRACE_UPLOAD, trace_regblock_size));
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
 
   /* If the target is to save the data to a file on its own, then just
@@ -144,7 +145,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 	  /* We ask for big blocks, in the hopes of efficiency, but
 	     will take less if the target has packet size limitations
 	     or some such.  */
-	  gotten = target_get_raw_trace_data (buf, offset,
+	  gotten = target_get_raw_trace_data (buf.data (), offset,
 					      MAX_TRACE_UPLOAD);
 	  if (gotten < 0)
 	    error (_("Failure to get requested trace buffer data"));
@@ -152,7 +153,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 	  if (gotten == 0)
 	    break;
 
-	  writer->ops->write_trace_buffer (writer, buf, gotten);
+	  writer->ops->write_trace_buffer (writer, buf.data (), gotten);
 
 	  offset += gotten;
 	}
@@ -163,7 +164,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 	  /* Parse the trace buffers according to how data are stored
 	     in trace buffer in GDBserver.  */
 
-	  gotten = target_get_raw_trace_data (buf, offset, 6);
+	  gotten = target_get_raw_trace_data (buf.data (), offset, 6);
 
 	  if (gotten == 0)
 	    break;
@@ -171,10 +172,10 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 	  /* Read the first six bytes in, which is the tracepoint
 	     number and trace frame size.  */
 	  tp_num = (uint16_t)
-	    extract_unsigned_integer (&buf[0], 2, byte_order);
+	    extract_unsigned_integer (&((buf.data ())[0]), 2, byte_order);
 
 	  tf_size = (uint32_t)
-	    extract_unsigned_integer (&buf[2], 4, byte_order);
+	    extract_unsigned_integer (&((buf.data ())[2]), 4, byte_order);
 
 	  writer->ops->frame_ops->start (writer, tp_num);
 	  gotten = 6;
@@ -192,7 +193,8 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 		  /* We'll fetch one block each time, in order to
 		     handle the extremely large 'M' block.  We first
 		     fetch one byte to get the type of the block.  */
-		  gotten = target_get_raw_trace_data (buf, offset, 1);
+		  gotten = target_get_raw_trace_data (buf.data (),
+						      offset, 1);
 		  if (gotten < 1)
 		    error (_("Failure to get requested trace buffer data"));
 
@@ -205,13 +207,13 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 		    {
 		    case 'R':
 		      gotten
-			= target_get_raw_trace_data (buf, offset,
+			= target_get_raw_trace_data (buf.data (), offset,
 						     trace_regblock_size);
 		      if (gotten < trace_regblock_size)
 			error (_("Failure to get requested trace"
 				 " buffer data"));
 
-		      TRACE_WRITE_R_BLOCK (writer, buf,
+		      TRACE_WRITE_R_BLOCK (writer, buf.data (),
 					   trace_regblock_size);
 		      break;
 		    case 'M':
@@ -221,7 +223,8 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 			LONGEST t;
 			int j;
 
-			t = target_get_raw_trace_data (buf,offset, 10);
+			t = target_get_raw_trace_data (buf.data (),
+						       offset, 10);
 			if (t < 10)
 			  error (_("Failure to get requested trace"
 				   " buffer data"));
@@ -231,10 +234,10 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 
 			gotten = 0;
 			addr = (ULONGEST)
-			  extract_unsigned_integer (buf, 8,
+			  extract_unsigned_integer (buf.data (), 8,
 						    byte_order);
 			mlen = (unsigned short)
-			  extract_unsigned_integer (&buf[8], 2,
+			  extract_unsigned_integer (&((buf.data ())[8]), 2,
 						    byte_order);
 
 			TRACE_WRITE_M_BLOCK_HEADER (writer, addr,
@@ -252,14 +255,15 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 			    else
 			      read_length = mlen - j;
 
-			    t = target_get_raw_trace_data (buf,
+			    t = target_get_raw_trace_data (buf.data (),
 							   offset + j,
 							   read_length);
 			    if (t < read_length)
 			      error (_("Failure to get requested"
 				       " trace buffer data"));
 
-			    TRACE_WRITE_M_BLOCK_MEMORY (writer, buf,
+			    TRACE_WRITE_M_BLOCK_MEMORY (writer,
+							buf.data (),
 							read_length);
 
 			    j += read_length;
@@ -274,18 +278,18 @@ trace_save (const char *filename, struct trace_file_writer *writer,
 			LONGEST val;
 
 			gotten
-			  = target_get_raw_trace_data (buf, offset,
-						       12);
+			  = target_get_raw_trace_data (buf.data (),
+						       offset, 12);
 			if (gotten < 12)
 			  error (_("Failure to get requested"
 				   " trace buffer data"));
 
-			vnum  = (int) extract_signed_integer (buf,
+			vnum  = (int) extract_signed_integer (buf.data (),
 							      4,
 							      byte_order);
 			val
-			  = extract_signed_integer (&buf[4], 8,
-						    byte_order);
+			  = extract_signed_integer (&((buf.data ())[4]),
+						    8, byte_order);
 
 			TRACE_WRITE_V_BLOCK (writer, vnum, val);
 		      }
-- 
2.13.6


  parent reply	other threads:[~2018-07-27 21:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 21:03 [PATCH v2 0/6] Fix tracepoint register limitations Pedro Franco de Carvalho
2018-07-27 21:03 ` [PATCH v2 5/6] Variable size for regs mask in collection list Pedro Franco de Carvalho
2018-08-02 17:01   ` Ulrich Weigand
2018-07-27 21:03 ` Pedro Franco de Carvalho [this message]
2018-08-02 17:04   ` [PATCH v2 6/6] Allow larger regblock sizes when saving tracefiles Ulrich Weigand
2018-07-27 21:03 ` [PATCH v2 3/6] Use get_remote_packet_size in download_tracepoint Pedro Franco de Carvalho
2018-08-02 16:47   ` Ulrich Weigand
2018-08-03 21:41     ` Pedro Franco de Carvalho
2018-08-06 12:40       ` Ulrich Weigand
     [not found]       ` <feb8623a-b89e-7519-22de-0d6ede3d5768@arm.com>
2018-08-08 10:33         ` [committed] Fix gdb/remote.c build failure Szabolcs Nagy
2018-08-08 12:25           ` Ulrich Weigand
2018-08-08 15:55         ` [PATCH v2 3/6] Use get_remote_packet_size in download_tracepoint Pedro Franco de Carvalho
2018-08-03 21:41     ` Pedro Franco de Carvalho
2018-07-27 21:03 ` [PATCH v2 1/6] Fix indentation in remote_target::download_tracepoint Pedro Franco de Carvalho
2018-08-02 16:43   ` Ulrich Weigand
2018-07-27 21:03 ` [PATCH v2 2/6] Remove trailing '-' from the last QTDP action packet Pedro Franco de Carvalho
2018-08-02 16:44   ` Ulrich Weigand
2018-07-27 21:03 ` [PATCH v2 4/6] Use remote register numbers in tracepoint mask Pedro Franco de Carvalho
2018-08-02 16:58   ` Ulrich Weigand
2018-08-03 22:09     ` Pedro Franco de Carvalho
2018-08-03 22:10     ` Pedro Franco de Carvalho
2018-08-06 12:42       ` Ulrich Weigand
2018-08-06 20:18         ` Pedro Franco de Carvalho

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=20180727210318.2960-7-pedromfc@linux.ibm.com \
    --to=pedromfc@linux.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.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