[AArch64] MTE corefile support

Teach GDB how to dump memory tags for AArch64 when using the gcore command
and how to read memory tag data back from a core file generated by GDB
(via gcore) or by the Linux kernel.

The format is documented in the Linux Kernel documentation [1].

Each tagged memory range (listed in /proc/<pid>/smaps) gets dumped to its
own PT_AARCH64_MEMTAG_MTE segment. A section named ".memtag" is created for each
of those segments when reading the core file back.

To save a little bit of space, given MTE tags only take 4 bits, the memory tags
are stored packed as 2 tags per byte.

When reading the data back, the tags are unpacked.

I've added a new testcase to exercise the feature.

Build-tested with --enable-targets=all and regression tested on aarch64-linux
Ubuntu 20.04.

[1] Documentation/arm64/memory-tagging-extension.rst (Core Dump Support)
This commit is contained in:
Luis Machado
2022-03-31 11:42:35 +01:00
parent d0ff5ca959
commit 68cffbbd44
17 changed files with 1048 additions and 8 deletions

View File

@ -1522,6 +1522,41 @@ Find core file memory regions
invalid=True,
)
Method(
comment="""
Given a bfd OBFD, segment ADDRESS and SIZE, create a memory tag section to be dumped to a core file
""",
type="asection *",
name="create_memtag_section",
params=[("bfd *", "obfd"), ("CORE_ADDR", "address"), ("size_t", "size")],
predicate=True,
invalid=True,
)
Method(
comment="""
Given a memory tag section OSEC, fill OSEC's contents with the appropriate tag data
""",
type="bool",
name="fill_memtag_section",
params=[("asection *", "osec")],
predicate=True,
invalid=True,
)
Method(
comment="""
Decode a memory tag SECTION and return the tags of type TYPE contained in
the memory range [ADDRESS, ADDRESS + LENGTH).
If no tags were found, return an empty vector.
""",
type="gdb::byte_vector",
name="decode_memtag_section",
params=[("bfd_section *", "section"), ("int", "type"), ("CORE_ADDR", "address"), ("size_t", "length")],
predicate=True,
invalid=True,
)
Method(
comment="""
Read offset OFFSET of TARGET_OBJECT_LIBRARIES formatted shared libraries list from