[all-commits] [llvm/llvm-project] 7281e0: [lldb] [debugserver] Use "full" x86_64 GPR state w...

Brendan Shanks via All-commits all-commits at lists.llvm.org
Wed Sep 18 22:57:22 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7281e0cb3bbcce396aab8b3ea0967d7a17cd287a
      https://github.com/llvm/llvm-project/commit/7281e0cb3bbcce396aab8b3ea0967d7a17cd287a
  Author: Brendan Shanks <mrpippy at gmail.com>
  Date:   2024-09-18 (Wed, 18 Sep 2024)

  Changed paths:
    M lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
    M lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h
    M lldb/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h

  Log Message:
  -----------
  [lldb] [debugserver] Use "full" x86_64 GPR state when available. (#108663)

macOS 10.15 added a "full" x86_64 GPR thread state flavor, equivalent to
the normal one but with DS, ES, SS, and GSbase added. This flavor can
only be used with processes that install a custom LDT (functionality
that was also added in 10.15 and is used by apps like Wine to execute
32-bit code).

Along with allowing DS, ES, SS, and GSbase to be viewed/modified, using
the full flavor is necessary when debugging a thread executing 32-bit
code.
If thread_set_state() is used with the regular thread state flavor, the
kernel resets CS to the 64-bit code segment (see
[set_thread_state64()](https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/osfmk/i386/pcb.c#L723),
which makes debugging impossible.

There's no way to detect whether the full flavor is available, try to
use it and fall back to the regular one if it's not available.

A downside is that this patch exposes the DS, ES, SS, and GSbase
registers for all x86_64 processes, even though they are not populated
unless the full thread state is available.
I'm not sure if there's a way to tell LLDB that a register is
unavailable. The classic GDB `g` command [allows returning
`x`](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#Packets)
to denote unavailable registers, but it seems like the debug server uses
newer commands like `jThreadsInfo` and I'm not sure if those have the
same support.

Fixes #57591
(also filed as Apple FB11464104)

@jasonmolenda



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