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