[all-commits] [llvm/llvm-project] a64db4: [lldb][Mach-O] Allow "process metadata" LC_NOTE to...

Jason Molenda via All-commits all-commits at lists.llvm.org
Fri Jun 27 18:44:02 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a64db49371f040859a9de7c0f4fbfb655d8dda17
      https://github.com/llvm/llvm-project/commit/a64db49371f040859a9de7c0f4fbfb655d8dda17
  Author: Jason Molenda <jmolenda at apple.com>
  Date:   2025-06-27 (Fri, 27 Jun 2025)

  Changed paths:
    M lldb/include/lldb/Symbol/ObjectFile.h
    M lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    M lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
    M lldb/source/Plugins/Process/mach-core/CMakeLists.txt
    A lldb/source/Plugins/Process/mach-core/RegisterContextUnifiedCore.cpp
    A lldb/source/Plugins/Process/mach-core/RegisterContextUnifiedCore.h
    M lldb/source/Plugins/Process/mach-core/ThreadMachCore.cpp
    A lldb/test/API/macosx/lc-note/additional-registers/Makefile
    A lldb/test/API/macosx/lc-note/additional-registers/TestMetadataRegisters.py
    A lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp
    A lldb/test/API/macosx/lc-note/additional-registers/main.c

  Log Message:
  -----------
  [lldb][Mach-O] Allow "process metadata" LC_NOTE to supply registers (#144627)

The "process metadata" LC_NOTE allows for thread IDs to be specified in
a Mach-O corefile. This extends the JSON recognzied in that LC_NOTE to
allow for additional registers to be supplied on a per-thread basis.

The registers included in a Mach-O corefile LC_THREAD load command can
only be one of the register flavors that the kernel (xnu) defines in
<mach/arm/thread_status.h> for arm64 -- the general purpose registers,
floating point registers, exception registers.

JTAG style corefile producers may have access to many additional
registers beyond these that EL0 programs typically use, for instance
TCR_EL1 on AArch64, and people developing low level code need access to
these registers. This patch defines a format for including these
registers for any thread.

The JSON in "process metadata" is a dictionary that must have a
`threads` key. The value is an array of entries, one per LC_THREAD in
the Mach-O corefile. The number of entries must match the LC_THREADs so
they can be correctly associated.

Each thread's dictionary must have two keys, `sets`, and `registers`.
`sets` is an array of register set names. If a register set name matches
one from the LC_THREAD core registers, any registers that are defined
will be added to that register set. e.g. metadata can add a register to
the "General Purpose Registers" set that lldb shows users.

`registers` is an array of dictionaries, one per register. Each register
must have the keys `name`, `value`, `bitsize`, and `set`. It may provide
additional keys like `alt-name`, that
`DynamicRegisterInfo::SetRegisterInfo` recognizes.

This `sets` + `registers` formatting is the same that is used by the
`target.process.python-os-plugin-path` script interface uses, both are
parsed by `DynamicRegisterInfo`. The one addition is that in this
LC_NOTE metadata, each register must also have a `value` field, with the
value provided in big-endian base 10, as usual with JSON.

In RegisterContextUnifiedCore, I combine the register sets & registers
from the LC_THREAD for a specific thread, and the metadata sets &
registers for that thread from the LC_NOTE. Even if no LC_NOTE is
present, this class ingests the LC_THREAD register contexts and
reformats it to its internal stores before returning itself as the
RegisterContex, instead of shortcutting and returning the core's native
RegisterContext. I could have gone either way with that, but in the end
I decided if the code is correct, we should live on it always.

I added a test where we process save-core to create a userland corefile,
then use a utility "add-lcnote" to strip the existing "process metadata"
LC_NOTE that lldb put in it, and adds a new one from a JSON string.

rdar://74358787

---------

Co-authored-by: Jonas Devlieghere <jonas at devlieghere.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list