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

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