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

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