Blame SOURCES/gdb-rhbz1187581-power8-regs-not-in-8.2-03of15.patch

7cb06c
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
7cb06c
From: Keith Seitz <keiths@redhat.com>
7cb06c
Date: Fri, 11 Jan 2019 17:02:13 -0500
7cb06c
Subject: gdb-rhbz1187581-power8-regs-not-in-8.2-03of15.patch
7cb06c
7cb06c
;; Zero-initialize linux note sections
7cb06c
;; Pedro Franco de Carvalho, RH BZ 1187581
7cb06c
7cb06c
Zero-initialize linux note sections
7cb06c
7cb06c
This patches changes linux-tdep.c so that the buffer used to write
7cb06c
note sections when generating a core file is zero-initialized.  This
7cb06c
way, bytes that are not collected won't contain random
7cb06c
data (e.g. padding bytes).
7cb06c
7cb06c
gdb/ChangeLog:
7cb06c
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>
7cb06c
7cb06c
    * linux-tdep.c (linux_collect_regset_section_cb): Use
7cb06c
    std::vector<gdb_byte> instead of char * and malloc for buf.
7cb06c
    Remove xfree.
7cb06c
7cb06c
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
7cb06c
--- a/gdb/linux-tdep.c
7cb06c
+++ b/gdb/linux-tdep.c
7cb06c
@@ -1584,7 +1584,6 @@ linux_collect_regset_section_cb (const char *sect_name, int supply_size,
7cb06c
 				 int collect_size, const struct regset *regset,
7cb06c
 				 const char *human_name, void *cb_data)
7cb06c
 {
7cb06c
-  char *buf;
7cb06c
   struct linux_collect_regset_section_cb_data *data
7cb06c
     = (struct linux_collect_regset_section_cb_data *) cb_data;
7cb06c
   bool variable_size_section = (regset != NULL
7cb06c
@@ -1598,19 +1597,22 @@ linux_collect_regset_section_cb (const char *sect_name, int supply_size,
7cb06c
 
7cb06c
   gdb_assert (regset && regset->collect_regset);
7cb06c
 
7cb06c
-  buf = (char *) xmalloc (collect_size);
7cb06c
-  regset->collect_regset (regset, data->regcache, -1, buf, collect_size);
7cb06c
+  /* This is intentionally zero-initialized by using std::vector, so
7cb06c
+     that any padding bytes in the core file will show as 0.  */
7cb06c
+  std::vector<gdb_byte> buf (collect_size);
7cb06c
+
7cb06c
+  regset->collect_regset (regset, data->regcache, -1, buf.data (),
7cb06c
+			  collect_size);
7cb06c
 
7cb06c
   /* PRSTATUS still needs to be treated specially.  */
7cb06c
   if (strcmp (sect_name, ".reg") == 0)
7cb06c
     data->note_data = (char *) elfcore_write_prstatus
7cb06c
       (data->obfd, data->note_data, data->note_size, data->lwp,
7cb06c
-       gdb_signal_to_host (data->stop_signal), buf);
7cb06c
+       gdb_signal_to_host (data->stop_signal), buf.data ());
7cb06c
   else
7cb06c
     data->note_data = (char *) elfcore_write_register_note
7cb06c
       (data->obfd, data->note_data, data->note_size,
7cb06c
-       sect_name, buf, collect_size);
7cb06c
-  xfree (buf);
7cb06c
+       sect_name, buf.data (), collect_size);
7cb06c
 
7cb06c
   if (data->note_data == NULL)
7cb06c
     data->abort_iteration = 1;