Blame SOURCES/gdb-rhbz1187581-power8-regs-6of7.patch

190f2a
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
190f2a
From: Jan Kratochvil <jan.kratochvil@redhat.com>
190f2a
Date: Thu, 9 Aug 2018 17:18:15 +0200
190f2a
Subject: gdb-rhbz1187581-power8-regs-6of7.patch
190f2a
190f2a
;; Add GDB support to access/display POWER8 registers (IBM, RH BZ 1187581).
190f2a
190f2a
commit 296956befef3711ed458c7cba8041fde0dab9c50
190f2a
Author: Pedro Franco de Carvalho <pedromfc@linux.ibm.com>
190f2a
Date:   Mon Aug 6 16:24:55 2018 -0300
190f2a
190f2a
    Allow larger regblock sizes when saving tracefiles
190f2a
190f2a
    The tracefile.c:trace_save function assumes trace_regblock_size won't
190f2a
    be larger than the MAX_TRACE_UPLOAD constant, used to size the buffer
190f2a
    which holds trace data.  This can cause buffer overruns when this is
190f2a
    not the case.  This patch changes this function so that the larger
190f2a
    size is used to size the buffer.
190f2a
190f2a
    gdb/ChangeLog:
190f2a
    2018-08-06  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>
190f2a
190f2a
            * tracefile.c: Include common/byte-vector.h.
190f2a
            (trace_save): Change type of buf to gdb::byte_vector.  Initialize
190f2a
            with trace_regblock_size if needed.  Update uses of buf.
190f2a
190f2a
+2018-08-06  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>
190f2a
+
190f2a
+	* tracefile.c: Include common/byte-vector.h.
190f2a
+	(trace_save): Change type of buf to gdb::byte_vector.  Initialize
190f2a
+	with trace_regblock_size if needed.  Update uses of buf.
190f2a
+
190f2a
 2018-08-06  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>
190f2a
190f2a
 	* tracepoint.h (collection_list) <m_regs_mask>: Change type to
190f2a
190f2a
diff --git a/gdb/tracefile.c b/gdb/tracefile.c
190f2a
--- a/gdb/tracefile.c
190f2a
+++ b/gdb/tracefile.c
190f2a
@@ -22,6 +22,7 @@
190f2a
 #include "ctf.h"
190f2a
 #include "exec.h"
190f2a
 #include "regcache.h"
190f2a
+#include "common/byte-vector.h"
190f2a
 
190f2a
 /* Helper macros.  */
190f2a
 
190f2a
@@ -67,7 +68,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 
190f2a
   ULONGEST offset = 0;
190f2a
 #define MAX_TRACE_UPLOAD 2000
190f2a
-  gdb_byte buf[MAX_TRACE_UPLOAD];
190f2a
+  gdb::byte_vector buf (std::max (MAX_TRACE_UPLOAD, trace_regblock_size));
190f2a
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
190f2a
 
190f2a
   /* If the target is to save the data to a file on its own, then just
190f2a
@@ -144,7 +145,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 	  /* We ask for big blocks, in the hopes of efficiency, but
190f2a
 	     will take less if the target has packet size limitations
190f2a
 	     or some such.  */
190f2a
-	  gotten = target_get_raw_trace_data (buf, offset,
190f2a
+	  gotten = target_get_raw_trace_data (buf.data (), offset,
190f2a
 					      MAX_TRACE_UPLOAD);
190f2a
 	  if (gotten < 0)
190f2a
 	    error (_("Failure to get requested trace buffer data"));
190f2a
@@ -152,7 +153,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 	  if (gotten == 0)
190f2a
 	    break;
190f2a
 
190f2a
-	  writer->ops->write_trace_buffer (writer, buf, gotten);
190f2a
+	  writer->ops->write_trace_buffer (writer, buf.data (), gotten);
190f2a
 
190f2a
 	  offset += gotten;
190f2a
 	}
190f2a
@@ -163,7 +164,7 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 	  /* Parse the trace buffers according to how data are stored
190f2a
 	     in trace buffer in GDBserver.  */
190f2a
 
190f2a
-	  gotten = target_get_raw_trace_data (buf, offset, 6);
190f2a
+	  gotten = target_get_raw_trace_data (buf.data (), offset, 6);
190f2a
 
190f2a
 	  if (gotten == 0)
190f2a
 	    break;
190f2a
@@ -171,10 +172,10 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 	  /* Read the first six bytes in, which is the tracepoint
190f2a
 	     number and trace frame size.  */
190f2a
 	  tp_num = (uint16_t)
190f2a
-	    extract_unsigned_integer (&buf[0], 2, byte_order);
190f2a
+	    extract_unsigned_integer (&((buf.data ())[0]), 2, byte_order);
190f2a
 
190f2a
 	  tf_size = (uint32_t)
190f2a
-	    extract_unsigned_integer (&buf[2], 4, byte_order);
190f2a
+	    extract_unsigned_integer (&((buf.data ())[2]), 4, byte_order);
190f2a
 
190f2a
 	  writer->ops->frame_ops->start (writer, tp_num);
190f2a
 	  gotten = 6;
190f2a
@@ -192,7 +193,8 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 		  /* We'll fetch one block each time, in order to
190f2a
 		     handle the extremely large 'M' block.  We first
190f2a
 		     fetch one byte to get the type of the block.  */
190f2a
-		  gotten = target_get_raw_trace_data (buf, offset, 1);
190f2a
+		  gotten = target_get_raw_trace_data (buf.data (),
190f2a
+						      offset, 1);
190f2a
 		  if (gotten < 1)
190f2a
 		    error (_("Failure to get requested trace buffer data"));
190f2a
 
190f2a
@@ -205,13 +207,13 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 		    {
190f2a
 		    case 'R':
190f2a
 		      gotten
190f2a
-			= target_get_raw_trace_data (buf, offset,
190f2a
+			= target_get_raw_trace_data (buf.data (), offset,
190f2a
 						     trace_regblock_size);
190f2a
 		      if (gotten < trace_regblock_size)
190f2a
 			error (_("Failure to get requested trace"
190f2a
 				 " buffer data"));
190f2a
 
190f2a
-		      TRACE_WRITE_R_BLOCK (writer, buf,
190f2a
+		      TRACE_WRITE_R_BLOCK (writer, buf.data (),
190f2a
 					   trace_regblock_size);
190f2a
 		      break;
190f2a
 		    case 'M':
190f2a
@@ -221,7 +223,8 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 			LONGEST t;
190f2a
 			int j;
190f2a
 
190f2a
-			t = target_get_raw_trace_data (buf,offset, 10);
190f2a
+			t = target_get_raw_trace_data (buf.data (),
190f2a
+						       offset, 10);
190f2a
 			if (t < 10)
190f2a
 			  error (_("Failure to get requested trace"
190f2a
 				   " buffer data"));
190f2a
@@ -231,10 +234,10 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 
190f2a
 			gotten = 0;
190f2a
 			addr = (ULONGEST)
190f2a
-			  extract_unsigned_integer (buf, 8,
190f2a
+			  extract_unsigned_integer (buf.data (), 8,
190f2a
 						    byte_order);
190f2a
 			mlen = (unsigned short)
190f2a
-			  extract_unsigned_integer (&buf[8], 2,
190f2a
+			  extract_unsigned_integer (&((buf.data ())[8]), 2,
190f2a
 						    byte_order);
190f2a
 
190f2a
 			TRACE_WRITE_M_BLOCK_HEADER (writer, addr,
190f2a
@@ -252,14 +255,15 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 			    else
190f2a
 			      read_length = mlen - j;
190f2a
 
190f2a
-			    t = target_get_raw_trace_data (buf,
190f2a
+			    t = target_get_raw_trace_data (buf.data (),
190f2a
 							   offset + j,
190f2a
 							   read_length);
190f2a
 			    if (t < read_length)
190f2a
 			      error (_("Failure to get requested"
190f2a
 				       " trace buffer data"));
190f2a
 
190f2a
-			    TRACE_WRITE_M_BLOCK_MEMORY (writer, buf,
190f2a
+			    TRACE_WRITE_M_BLOCK_MEMORY (writer,
190f2a
+							buf.data (),
190f2a
 							read_length);
190f2a
 
190f2a
 			    j += read_length;
190f2a
@@ -274,18 +278,18 @@ trace_save (const char *filename, struct trace_file_writer *writer,
190f2a
 			LONGEST val;
190f2a
 
190f2a
 			gotten
190f2a
-			  = target_get_raw_trace_data (buf, offset,
190f2a
-						       12);
190f2a
+			  = target_get_raw_trace_data (buf.data (),
190f2a
+						       offset, 12);
190f2a
 			if (gotten < 12)
190f2a
 			  error (_("Failure to get requested"
190f2a
 				   " trace buffer data"));
190f2a
 
190f2a
-			vnum  = (int) extract_signed_integer (buf,
190f2a
+			vnum  = (int) extract_signed_integer (buf.data (),
190f2a
 							      4,
190f2a
 							      byte_order);
190f2a
 			val
190f2a
-			  = extract_signed_integer (&buf[4], 8,
190f2a
-						    byte_order);
190f2a
+			  = extract_signed_integer (&((buf.data ())[4]),
190f2a
+						    8, byte_order);
190f2a
 
190f2a
 			TRACE_WRITE_V_BLOCK (writer, vnum, val);
190f2a
 		      }