[Lldb-commits] [PATCH] D158785: [lldb] Add a "thread extrainfo" LC_NOTE for Mach-O corefiles, to store the thread IDs of the threads

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 24 15:10:45 PDT 2023

jasonmolenda created this revision.
jasonmolenda added reviewers: JDevlieghere, bulbazord.
jasonmolenda added a project: LLDB.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

This adds a new LC_NOTE to ObjectFileMachO to save the thread IDs of threads, and restore them in ProcessMachCore when reading the corefile back.  The LC_NOTE payload format is

  struct thread_extrainfo {
      uint32_t version;    // currently 1
      uint32_t elem_size;  // size of each array element
      struct {
          uint64_t tid;    // tid override for each LC_THREAD, 0 means none provided
      } __attribute__((packed)) thread_extras[NUM_LC_THREADS];

My intention is that we can add additional fields in the future without bumping the version number; existing fields must always be included.  Each field will have sentinel values to indicate that they are unspecified -- if we add a "thread priority" uint64_t next year, but a producer only wants to specify thread priorities and not thread IDs, they can put 0 values for the thread IDs.  Consumers can skip fields that they don't know about.

The one down side to this layout is that variable-length fields can't be incorporated well -- thread names, libdispatch queue names on macOS for instance.  It might be better to have each element specify its size, so we can have variable length entries.  I'd love to hear opinions, the more I think about it, the more I worry someone is going to request thread names in corefiles about a week after I land this.

The patch adds support to ObjectFileMachO to emit this new LC_NOTE when creating a corefile for `process save-core`, and support to ObjectFileMachO/ProcessMachCore/ThreadMachCore to read those values back in again.  It adds a check to an existing API test that has sixteen threads for confirming that we select the faulting thread in a corefile.

  rG LLVM Github Monorepo



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158785.553273.patch
Type: text/x-patch
Size: 12743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230824/6f45377c/attachment.bin>

More information about the lldb-commits mailing list