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