Blame SOURCES/gdb-rhbz1842691-corefile-mem-access-3of15.patch

0efd7d
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
0efd7d
From: Keith Seitz <keiths@redhat.com>
0efd7d
Date: Mon, 27 Jul 2020 16:52:18 -0400
0efd7d
Subject: gdb-rhbz1842691-corefile-mem-access-3of15.patch
0efd7d
0efd7d
;; section_table_xfer_memory: Replace section name with callback predicate
0efd7d
;; Kevin Buettner, RH BZ 1842691
0efd7d
0efd7d
   Author: Kevin Buettner <kevinb@redhat.com>
0efd7d
   Date:   Wed Mar 4 17:42:41 2020 -0700
0efd7d
0efd7d
    section_table_xfer_memory: Replace section name with callback predicate
0efd7d
0efd7d
    This patch is motivated by the need to be able to select sections
0efd7d
    that section_table_xfer_memory_partial should consider for memory
0efd7d
    transfers.  I'll use this facility in the next patch in this series.
0efd7d
0efd7d
    section_table_xfer_memory_partial() can currently be passed a section
0efd7d
    name which may be used to make name-based selections.  This is similar
0efd7d
    to what I want to do, except that I want to be able to consider
0efd7d
    section flags instead of the name.
0efd7d
0efd7d
    I'm replacing the section name parameter with a predicate that,
0efd7d
    when passed a pointer to a target_section struct, will return
0efd7d
    true if that section should be further considered, or false which
0efd7d
    indicates that it shouldn't.
0efd7d
0efd7d
    I've converted the one existing use where a non-NULL section
0efd7d
    name is passed to section_table_xfer_memory_partial().   Instead
0efd7d
    of passing the section name, it now looks like this:
0efd7d
0efd7d
    	  auto match_cb = [=] (const struct target_section *s)
0efd7d
    	    {
0efd7d
    	      return (strcmp (section_name, s->the_bfd_section->name) == 0);
0efd7d
    	    };
0efd7d
0efd7d
    	  return section_table_xfer_memory_partial (readbuf, writebuf,
0efd7d
    						    memaddr, len, xfered_len,
0efd7d
    						    table->sections,
0efd7d
    						    table->sections_end,
0efd7d
    						    match_cb);
0efd7d
0efd7d
    The other callers all passed NULL; they've been simplified somewhat
0efd7d
    in that they no longer need to pass NULL.
0efd7d
0efd7d
    gdb/ChangeLog:
0efd7d
0efd7d
    	* exec.h (section_table_xfer_memory): Revise declaration,
0efd7d
    	replacing section name parameter with an optional callback
0efd7d
    	predicate.
0efd7d
    	* exec.c (section_table_xfer_memory): Likewise.
0efd7d
    	* bfd-target.c, exec.c, target.c, corelow.c: Adjust all callers
0efd7d
    	of section_table_xfer_memory.
0efd7d
0efd7d
diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
0efd7d
--- a/gdb/bfd-target.c
0efd7d
+++ b/gdb/bfd-target.c
0efd7d
@@ -77,8 +77,7 @@ target_bfd::xfer_partial (target_object object,
0efd7d
 	return section_table_xfer_memory_partial (readbuf, writebuf,
0efd7d
 						  offset, len, xfered_len,
0efd7d
 						  m_table.sections,
0efd7d
-						  m_table.sections_end,
0efd7d
-						  NULL);
0efd7d
+						  m_table.sections_end);
0efd7d
       }
0efd7d
     default:
0efd7d
       return TARGET_XFER_E_IO;
0efd7d
diff --git a/gdb/corelow.c b/gdb/corelow.c
0efd7d
--- a/gdb/corelow.c
0efd7d
+++ b/gdb/corelow.c
0efd7d
@@ -758,8 +758,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
0efd7d
 	      (readbuf, writebuf,
0efd7d
 	       offset, len, xfered_len,
0efd7d
 	       m_core_section_table.sections,
0efd7d
-	       m_core_section_table.sections_end,
0efd7d
-	       NULL));
0efd7d
+	       m_core_section_table.sections_end));
0efd7d
 
0efd7d
     case TARGET_OBJECT_AUXV:
0efd7d
       if (readbuf)
0efd7d
diff --git a/gdb/exec.c b/gdb/exec.c
0efd7d
--- a/gdb/exec.c
0efd7d
+++ b/gdb/exec.c
0efd7d
@@ -792,7 +792,8 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
0efd7d
 				   ULONGEST *xfered_len,
0efd7d
 				   struct target_section *sections,
0efd7d
 				   struct target_section *sections_end,
0efd7d
-				   const char *section_name)
0efd7d
+				   gdb::function_view
0efd7d
+				     (const struct target_section *)> match_cb)
0efd7d
 {
0efd7d
   int res;
0efd7d
   struct target_section *p;
0efd7d
@@ -808,7 +809,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
0efd7d
       struct bfd_section *asect = p->the_bfd_section;
0efd7d
       bfd *abfd = asect->owner;
0efd7d
 
0efd7d
-      if (section_name && strcmp (section_name, asect->name) != 0)
0efd7d
+      if (match_cb != nullptr && !match_cb (p))
0efd7d
 	continue;		/* not the section we need.  */
0efd7d
       if (memaddr >= p->addr)
0efd7d
         {
0efd7d
@@ -881,8 +882,7 @@ exec_target::xfer_partial (enum target_object object,
0efd7d
     return section_table_xfer_memory_partial (readbuf, writebuf,
0efd7d
 					      offset, len, xfered_len,
0efd7d
 					      table->sections,
0efd7d
-					      table->sections_end,
0efd7d
-					      NULL);
0efd7d
+					      table->sections_end);
0efd7d
   else
0efd7d
     return TARGET_XFER_E_IO;
0efd7d
 }
0efd7d
diff --git a/gdb/exec.h b/gdb/exec.h
0efd7d
--- a/gdb/exec.h
0efd7d
+++ b/gdb/exec.h
0efd7d
@@ -58,8 +58,13 @@ extern enum target_xfer_status
0efd7d
    Request to transfer up to LEN 8-bit bytes of the target sections
0efd7d
    defined by SECTIONS and SECTIONS_END.  The OFFSET specifies the
0efd7d
    starting address.
0efd7d
-   If SECTION_NAME is not NULL, only access sections with that same
0efd7d
-   name.
0efd7d
+
0efd7d
+   The MATCH_CB predicate is optional; when provided it will be called
0efd7d
+   for each section under consideration.  When MATCH_CB evaluates as
0efd7d
+   true, the section remains under consideration; a false result
0efd7d
+   removes it from consideration for performing the memory transfers
0efd7d
+   noted above.  See memory_xfer_partial_1() in target.c for an
0efd7d
+   example.
0efd7d
 
0efd7d
    Return the number of bytes actually transfered, or zero when no
0efd7d
    data is available for the requested range.
0efd7d
@@ -76,7 +81,9 @@ extern enum target_xfer_status
0efd7d
 				     ULONGEST, ULONGEST, ULONGEST *,
0efd7d
 				     struct target_section *,
0efd7d
 				     struct target_section *,
0efd7d
-				     const char *);
0efd7d
+				     gdb::function_view
0efd7d
+				       (const struct target_section *)> match_cb
0efd7d
+				         = nullptr);
0efd7d
 
0efd7d
 /* Read from mappable read-only sections of BFD executable files.
0efd7d
    Similar to exec_read_partial_read_only, but return
0efd7d
diff --git a/gdb/target.c b/gdb/target.c
0efd7d
--- a/gdb/target.c
0efd7d
+++ b/gdb/target.c
0efd7d
@@ -1022,11 +1022,17 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
0efd7d
 	  const char *section_name = section->the_bfd_section->name;
0efd7d
 
0efd7d
 	  memaddr = overlay_mapped_address (memaddr, section);
0efd7d
+
0efd7d
+	  auto match_cb = [=] (const struct target_section *s)
0efd7d
+	    {
0efd7d
+	      return (strcmp (section_name, s->the_bfd_section->name) == 0);
0efd7d
+	    };
0efd7d
+
0efd7d
 	  return section_table_xfer_memory_partial (readbuf, writebuf,
0efd7d
 						    memaddr, len, xfered_len,
0efd7d
 						    table->sections,
0efd7d
 						    table->sections_end,
0efd7d
-						    section_name);
0efd7d
+						    match_cb);
0efd7d
 	}
0efd7d
     }
0efd7d
 
0efd7d
@@ -1044,8 +1050,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
0efd7d
 	  return section_table_xfer_memory_partial (readbuf, writebuf,
0efd7d
 						    memaddr, len, xfered_len,
0efd7d
 						    table->sections,
0efd7d
-						    table->sections_end,
0efd7d
-						    NULL);
0efd7d
+						    table->sections_end);
0efd7d
 	}
0efd7d
     }
0efd7d