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

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