Blame SOURCES/gdb-rhbz1187581-power8-regs-5of7.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:17:46 +0200
190f2a
Subject: gdb-rhbz1187581-power8-regs-5of7.patch
190f2a
190f2a
;; Add GDB support to access/display POWER8 registers (IBM, RH BZ 1187581).
190f2a
190f2a
commit a04b9d62a234923826e431a209d396a628661548
190f2a
Author: Pedro Franco de Carvalho <pedromfc@linux.ibm.com>
190f2a
Date:   Mon Aug 6 16:24:55 2018 -0300
190f2a
190f2a
    Variable size for regs mask in collection list
190f2a
190f2a
    This patch changes collection_list to allow larger register masks.
190f2a
190f2a
    The mask is changed from an array to a vector and is initialized to
190f2a
    hold the maximum possible remote register number.  The stringify
190f2a
    method is updated to resize temp_buf if needed.
190f2a
190f2a
    gdb/ChangeLog:
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
            std::vector<unsigned char>.
190f2a
            * tracepoint.c (collection_list::collection_list): Remove
190f2a
            m_regs_mask initializer from initializer list.  Resize
190f2a
            m_regs_mask using the largest remote register number.
190f2a
            (collection_list::add_remote_register): Remove size check on
190f2a
            m_regs_mask.  Use at to access element.
190f2a
            (collection_list::stringify): Change type of temp_buf to
190f2a
            gdb::char_vector.  Update uses of temp_buf.  Resize if needed to
190f2a
            stringify the register mask.  Use pack_hex_byte for the register
190f2a
            mask.
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
+	std::vector<unsigned char>.
190f2a
+	* tracepoint.c (collection_list::collection_list): Remove
190f2a
+	m_regs_mask initializer from initializer list.  Resize
190f2a
+	m_regs_mask using the largest remote register number.
190f2a
+	(collection_list::add_remote_register): Remove size check on
190f2a
+	m_regs_mask.  Use at to access element.
190f2a
+	(collection_list::stringify): Change type of temp_buf to
190f2a
+	gdb::char_vector.  Update uses of temp_buf.  Resize if needed to
190f2a
+	stringify the register mask.  Use pack_hex_byte for the register
190f2a
+	mask.
190f2a
+
190f2a
 2018-08-06  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>
190f2a
190f2a
 	* tracepoint.h (class collection_list) <add_register>: Remove.
190f2a
190f2a
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
190f2a
--- a/gdb/tracepoint.c
190f2a
+++ b/gdb/tracepoint.c
190f2a
@@ -822,10 +822,8 @@ collection_list::add_remote_register (unsigned int regno)
190f2a
 {
190f2a
   if (info_verbose)
190f2a
     printf_filtered ("collect register %d\n", regno);
190f2a
-  if (regno >= (8 * sizeof (m_regs_mask)))
190f2a
-    error (_("Internal: register number %d too large for tracepoint"),
190f2a
-	   regno);
190f2a
-  m_regs_mask[regno / 8] |= 1 << (regno % 8);
190f2a
+
190f2a
+  m_regs_mask.at (regno / 8) |= 1 << (regno % 8);
190f2a
 }
190f2a
 
190f2a
 /* Add all the registers from the mask in AEXPR to the mask in the
190f2a
@@ -1136,9 +1134,20 @@ collection_list::add_static_trace_data ()
190f2a
 }
190f2a
 
190f2a
 collection_list::collection_list ()
190f2a
-  : m_regs_mask (),
190f2a
-    m_strace_data (false)
190f2a
+  : m_strace_data (false)
190f2a
 {
190f2a
+  int max_remote_regno = 0;
190f2a
+  for (int i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++)
190f2a
+    {
190f2a
+      int remote_regno = (gdbarch_remote_register_number
190f2a
+			  (target_gdbarch (), i));
190f2a
+
190f2a
+      if (remote_regno >= 0 && remote_regno > max_remote_regno)
190f2a
+	max_remote_regno = remote_regno;
190f2a
+    }
190f2a
+
190f2a
+  m_regs_mask.resize ((max_remote_regno / 8) + 1);
190f2a
+
190f2a
   m_memranges.reserve (128);
190f2a
   m_aexprs.reserve (128);
190f2a
 }
190f2a
@@ -1148,7 +1157,8 @@ collection_list::collection_list ()
190f2a
 std::vector<std::string>
190f2a
 collection_list::stringify ()
190f2a
 {
190f2a
-  char temp_buf[2048];
190f2a
+  gdb::char_vector temp_buf (2048);
190f2a
+
190f2a
   int count;
190f2a
   char *end;
190f2a
   long i;
190f2a
@@ -1158,35 +1168,45 @@ collection_list::stringify ()
190f2a
     {
190f2a
       if (info_verbose)
190f2a
 	printf_filtered ("\nCollecting static trace data\n");
190f2a
-      end = temp_buf;
190f2a
+      end = temp_buf.data ();
190f2a
       *end++ = 'L';
190f2a
-      str_list.emplace_back (temp_buf, end - temp_buf);
190f2a
+      str_list.emplace_back (temp_buf.data (), end - temp_buf.data ());
190f2a
     }
190f2a
 
190f2a
-  for (i = sizeof (m_regs_mask) - 1; i > 0; i--)
190f2a
+  for (i = m_regs_mask.size () - 1; i > 0; i--)
190f2a
     if (m_regs_mask[i] != 0)    /* Skip leading zeroes in regs_mask.  */
190f2a
       break;
190f2a
   if (m_regs_mask[i] != 0)	/* Prepare to send regs_mask to the stub.  */
190f2a
     {
190f2a
       if (info_verbose)
190f2a
 	printf_filtered ("\nCollecting registers (mask): 0x");
190f2a
-      end = temp_buf;
190f2a
+
190f2a
+      /* One char for 'R', one for the null terminator and two per
190f2a
+	 mask byte.  */
190f2a
+      std::size_t new_size = (i + 1) * 2 + 2;
190f2a
+      if (new_size > temp_buf.size ())
190f2a
+	temp_buf.resize (new_size);
190f2a
+
190f2a
+      end = temp_buf.data ();
190f2a
       *end++ = 'R';
190f2a
       for (; i >= 0; i--)
190f2a
 	{
190f2a
 	  QUIT;			/* Allow user to bail out with ^C.  */
190f2a
 	  if (info_verbose)
190f2a
 	    printf_filtered ("%02X", m_regs_mask[i]);
190f2a
-	  sprintf (end, "%02X", m_regs_mask[i]);
190f2a
-	  end += 2;
190f2a
+
190f2a
+	  end = pack_hex_byte (end, m_regs_mask[i]);
190f2a
 	}
190f2a
-      str_list.emplace_back (temp_buf);
190f2a
+      *end = '\0';
190f2a
+
190f2a
+      str_list.emplace_back (temp_buf.data ());
190f2a
     }
190f2a
   if (info_verbose)
190f2a
     printf_filtered ("\n");
190f2a
   if (!m_memranges.empty () && info_verbose)
190f2a
     printf_filtered ("Collecting memranges: \n");
190f2a
-  for (i = 0, count = 0, end = temp_buf; i < m_memranges.size (); i++)
190f2a
+  for (i = 0, count = 0, end = temp_buf.data ();
190f2a
+       i < m_memranges.size (); i++)
190f2a
     {
190f2a
       QUIT;			/* Allow user to bail out with ^C.  */
190f2a
       if (info_verbose)
190f2a
@@ -1200,9 +1220,9 @@ collection_list::stringify ()
190f2a
 	}
190f2a
       if (count + 27 > MAX_AGENT_EXPR_LEN)
190f2a
 	{
190f2a
-	  str_list.emplace_back (temp_buf, count);
190f2a
+	  str_list.emplace_back (temp_buf.data (), count);
190f2a
 	  count = 0;
190f2a
-	  end = temp_buf;
190f2a
+	  end = temp_buf.data ();
190f2a
 	}
190f2a
 
190f2a
       {
190f2a
@@ -1222,7 +1242,7 @@ collection_list::stringify ()
190f2a
       }
190f2a
 
190f2a
       count += strlen (end);
190f2a
-      end = temp_buf + count;
190f2a
+      end = temp_buf.data () + count;
190f2a
     }
190f2a
 
190f2a
   for (i = 0; i < m_aexprs.size (); i++)
190f2a
@@ -1230,9 +1250,9 @@ collection_list::stringify ()
190f2a
       QUIT;			/* Allow user to bail out with ^C.  */
190f2a
       if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN)
190f2a
 	{
190f2a
-	  str_list.emplace_back (temp_buf, count);
190f2a
+	  str_list.emplace_back (temp_buf.data (), count);
190f2a
 	  count = 0;
190f2a
-	  end = temp_buf;
190f2a
+	  end = temp_buf.data ();
190f2a
 	}
190f2a
       sprintf (end, "X%08X,", m_aexprs[i]->len);
190f2a
       end += 10;		/* 'X' + 8 hex digits + ',' */
190f2a
@@ -1244,9 +1264,9 @@ collection_list::stringify ()
190f2a
 
190f2a
   if (count != 0)
190f2a
     {
190f2a
-      str_list.emplace_back (temp_buf, count);
190f2a
+      str_list.emplace_back (temp_buf.data (), count);
190f2a
       count = 0;
190f2a
-      end = temp_buf;
190f2a
+      end = temp_buf.data ();
190f2a
     }
190f2a
 
190f2a
   return str_list;
190f2a
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
190f2a
--- a/gdb/tracepoint.h
190f2a
+++ b/gdb/tracepoint.h
190f2a
@@ -293,8 +293,9 @@ public:
190f2a
   { return m_computed; }
190f2a
 
190f2a
 private:
190f2a
-  /* room for up to 256 regs */
190f2a
-  unsigned char m_regs_mask[32];
190f2a
+  /* We need the allocator zero-initialize the mask, so we don't use
190f2a
+     gdb::byte_vector.  */
190f2a
+  std::vector<unsigned char> m_regs_mask;
190f2a
 
190f2a
   std::vector<memrange> m_memranges;
190f2a