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

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