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