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

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