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

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