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

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