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

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