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

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