263 Commits

Author SHA1 Message Date
Jason Molenda
e405a11957
[lldb][debugserver] Get the size of the shared cache in mapped VM (#187419)
Fetch the size of the shared cache address range in VM in the inferior
process and return it, if possible. This allows for a simple call to
DynamicLoader::GetSharedCacheInformation to get the virtual address
extent of the shared cache in the inferior. It's a minor addition to the
method that fetches the shared cache filepath from the inferior, plus
piping it up through lldb's layers.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2026-03-19 10:41:57 -07:00
Jonas Devlieghere
f002fc0ee8
[lldb] Skip tests that are incompatible with MTE (#186043)
Skip tests that are incompatible with MTE. 

Depends on:
- https://github.com/llvm/llvm-project/pull/185780
2026-03-14 11:19:26 -07:00
Med Ismail Bennani
702e4ec5f7
[lldb/test] Skip TestDelayInitDependency on remote platforms (#183885)
This test exercises macOS-specific linker functionality (-delay_library)
and uses a hardcoded local working directory for the launch info. It
should not run against a remote platform where neither condition holds.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-02-28 06:53:36 +00:00
Jason Molenda
c5588becb8 [lldb] Add skip shared build to more API tests
Fixing test failures on my local desktop with incremental
building.
2026-02-27 14:37:54 -08:00
Dave Lee
b9225e8607
[lldb] Allow tests to share a single build (#181720)
This changes Python API tests to use a single build shared across all
test functions, instead of the previous default behavior of a separate
build dir for each test function.

This build behavior opt-out, tests can use the previous behavior of one
individual (unshared) build directory per test function, by setting
`SHARED_BUILD_TESTCASE` to False (in the test class).

The motivation is to make the test suite more efficient, by not
repeatedly building the same test source. When running tests on my macOS
machine, this reduces the time of `ninja check-lldb-api` by almost 60%
(sample numbers: from ~492s down to ~207s = 58%). Almost 5min time
saved.

Each test function still calls `self.build()`, but only the first call
will do a build, in the subsequent tests `make` will be a no-op because
the sources won't have changed.
2026-02-18 10:38:45 -08:00
David Spickett
4677fc3d83
Revert "[lldb] Step over non-lldb breakpoints" (#180944)
Reverts llvm/llvm-project#174348 due to reported failures on MacOS and
Arm 32-bit Linux.
2026-02-11 14:03:01 +00:00
Duncan McBain
304c680809
[lldb] Step over non-lldb breakpoints (#174348)
Several languages support some sort of "breakpoint" function, which adds
ISA-specific instructions to generate an interrupt at runtime. However,
on some platforms, these instructions don't increment the program
counter. When LLDB sets these instructions it isn't a problem, as we
remove them before continuing, then re-add them after stepping over the
location. However, for breakpoint sequences that are part of the
inferior process, this doesn't happen - and so users might be left
unable to continue past the breakpoint without manually interfering with
the program counter.

This patch adds logic to LLDB to intercept SIGTRAPs, inspect the bytes
of the inferior at the program counter, and if the instruction looks
like a BRK or BKPT or similar, increment the pc by the size of the
instruction we found. This unifies platform behaviour (e.g. on x86_64,
LLDB debug sessions already look like this) and improves UX (in my
opinion, but I think it beats messing with stuff every break).

Some ISAs (like AArch64) require slightly different handling, as while
there are multiple possible instructions, we should be careful only to
find the ones likely to have been emitted by a compiler backend, and not
those inserted from (for example) the UB sanitizer, or any others.

There is an existing builtin-debugtrap test which was under the macos
folder before. I've now moved that to "functionalities", made it pure C
only, and updated it a little bit so that it works regardless of
platform.

What I've not done is change the existing code in debugserver which was
added by Jason Molenda about five years ago
(https://reviews.llvm.org/D91238, 92b036d). It might not be required any
more after this change. Reading the history there, it seems like it was
agreed that this behaviour (skipping over unknown bps) was the desired
end goal.

Fixes #56268

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2026-02-11 10:18:41 +00:00
Michael Buch
0a3b376015 [lldb][test] Skip TestLaunchProcessPosixSpawn.py
Fails on public green dragon arm64 bot with:
```
08:53:39  "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/./bin/dsymutil"  -o "fat.out.dSYM" "fat.out"
08:53:39  warning: no debug symbols in executable (-arch x86_64)
08:53:39  warning: no debug symbols in executable (-arch x86_64h)
08:53:39  warning: no debug symbols in executable (-arch arm64)
08:53:39
08:53:39
08:53:39  runCmd: file -arch x86_64 /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lldb-test-build.noindex/macosx/posix_spawn/TestLaunchProcessPosixSpawn.test_apple_silicon/fat.out
08:53:39
08:53:39  warning: (x86_64) /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lldb-test-build.noindex/macosx/posix_spawn/TestLaunchProcessPosixSpawn.test_apple_silicon/fat.out empty dSYM file detected, dSYM was created with an executable with no debug info.
08:53:39  output: Current executable set to '/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lldb-test-build.noindex/macosx/posix_spawn/TestLaunchProcessPosixSpawn.test_apple_silicon/fat.out' (x86_64).
08:53:39
08:53:39
08:53:39  <bound method SBProcess.Kill of SBProcess: pid = 73406, state = exited, threads = 0, executable = fat.out>: success
08:53:39
08:53:39  FAIL: LLDB (/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang-arm64) :: test_apple_silicon (TestLaunchProcessPosixSpawn.TestLaunchProcessPosixSpawn)
08:53:39  runCmd: settings clear --all
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set symbols.enable-external-lookup false
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set target.inherit-tcc true
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set target.disable-aslr false
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set target.detach-on-error false
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set target.auto-apply-fixits false
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set plugin.process.gdb-remote.packet-timeout 60
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set symbols.clang-modules-cache-path "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lldb-test-build.noindex/module-cache-lldb/lldb-api"
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set use-color false
08:53:39
08:53:39  output:
08:53:39
08:53:39  runCmd: settings set show-statusline false
08:53:39
08:53:39  output:
08:53:39
08:53:39  UNSUPPORTED: LLDB (/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang-arm64) :: test_haswell (TestLaunchProcessPosixSpawn.TestLaunchProcessPosixSpawn) (Current CPU is not Haswell)
08:53:39  Restore dir to: /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/test
08:53:39  ======================================================================
08:53:39  FAIL: test_apple_silicon (TestLaunchProcessPosixSpawn.TestLaunchProcessPosixSpawn)
08:53:39  ----------------------------------------------------------------------
08:53:39  Traceback (most recent call last):
08:53:39    File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 160, in wrapper
08:53:39      return func(*args, **kwargs)
08:53:39    File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/macosx/posix_spawn/TestLaunchProcessPosixSpawn.py", line 72, in test_apple_silicon
08:53:39      self.run_arch(exe, "x86_64")
08:53:39    File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/macosx/posix_spawn/TestLaunchProcessPosixSpawn.py", line 48, in run_arch
08:53:39      self.assertTrue(error.Success(), str(error))
08:53:39  AssertionError: False is not true : error: process exited with status -1 (lost connection)
08:53:39  Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang
08:53:39  ----------------------------------------------------------------------
08:53:39  Ran 2 tests in 5.686s
08:53:39
08:53:39  FAILED (failures=1, skipped=1)
```
2026-02-10 09:13:40 +00:00
jimingham
85d94e1714
Make StopInfoMachException return the right data. (#180088)
When I changed lldb so that the StopInfo's compute their own stop reason
data (before it was oddly done in SBThread::GetStopReasonData...) I
didn't notice that StopInfoMachException was relying on that routine's
default of returning the Value as the 0th exception data, and didn't
actually return its own data.
This fixes that, and makes us report the exception type, and the code
and subcode if the exception has them. I also added a test for this.

rdar://169755672
2026-02-06 11:27:33 -08:00
Med Ismail Bennani
c373d7632a
[lldb] Fix variable access in old SBFrames after inferior function calls (#178823)
When a user holds an SBFrame reference and then triggers an inferior
function
call (via expression evaluation or GetExtendedBacktraceThread),
variables in
that frame become inaccessible with "register fp is not available"
errors.

This happens because inferior function calls execute through
ThreadPlanCallFunction, which calls ClearStackFrames() during cleanup to
invalidate the unwinder state. ExecutionContextRef objects in the old
SBFrames
were tracking StackFrameLists via weak_ptr, which became stale when
ClearStackFrames() created new instances.

The fix uses stable StackFrameList identifiers that persist across
ClearStackFrames():
- ID = 0: Normal unwinder frames (constant across all instances)
- ID = sequential counter: Scripted frame provider instances

ExecutionContextRef now stores the frame list ID instead of a weak_ptr,
allowing
it to resolve to the current StackFrameList with fresh unwinder state
after an
inferior function call completes.

The Thread object preserves the provider chain configuration
(m_provider_chain_ids and m_next_provider_id) across ClearStackFrames()
so
that recreated StackFrameLists get the same IDs. When providers need to
be
recreated, GetStackFrameList() rebuilds them from the persisted
configuration.

This commit also fixes a deadlock when Python scripted frame providers
call
back into LLDB during frame fetching. The m_list_mutex is now released
before
calling GetFrameAtIndex() on the Python scripted frame provider to
prevent
same-thread deadlock. A dedicated m_unwinder_frames_sp member ensures
GetFrameListByIdentifier(0) always returns the current unwinder frames,
and
proper cleanup in DestroyThread() and ClearStackFrames() to prevent
modules
from lingering after a Thread (and its StackFrameLists) gets destroyed.

Added test validates that variables remain accessible after
GetExtendedBacktraceThread triggers an inferior function call to fetch
libdispatch Queue Info.

rdar://167027676

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-02-03 03:12:35 +00:00
Austin Jiang
e6cdfb75ac
Fix typos and spelling errors across codebase (#156270)
Corrected various spelling mistakes such as 'occurred', 'receiver',
'initialized', 'length', and others in comments, variable names,
function names, and documentation throughout the project. These
changes improve code readability and maintain consistency in naming
and documentation.

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-01-13 11:52:46 -05:00
Adrian Prantl
54c2c7cf0d
[LLDB] Fix test compilation errors under asan (NFC) (#168408)
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake-sanitized/2744/consoleText
2025-11-17 13:01:52 -08:00
Adrian Prantl
8c13b75b61 [LLDB] Fix condition in test 2025-10-27 12:43:19 -07:00
Adrian Prantl
3d26e6c717 Revert "[LLDB] Add debug output to test to diagnose bot failure"
This reverts commit d8184343755ababad6479d07451f36dd695f75c1.
2025-10-27 12:43:19 -07:00
Adrian Prantl
d818434375 [LLDB] Add debug output to test to diagnose bot failure 2025-10-27 11:53:59 -07:00
Adrian Prantl
43f119baa6 [LLDB] Disable rosetta test on green dragon 2025-10-27 10:32:47 -07:00
Adrian Prantl
a868e7ed59 Revert "[LLDB] Disable rosetta test on green dragon"
This reverts commit 9a0aa922ed3e0accc2d2fbfffa619e249a7c84ac.
2025-10-27 10:32:47 -07:00
Adrian Prantl
9a0aa922ed [LLDB] Disable rosetta test on green dragon 2025-10-27 09:48:19 -07:00
Adrian Prantl
9b80fc3960 [lldb] Add missing function call in test (NFC) 2025-10-24 15:29:14 -07:00
Adrian Prantl
4e7a8456b3 [lldb] Improve error logging in test (NFC) 2025-10-24 11:29:11 -07:00
Felipe de Azevedo Piovezan
5e668fe84f
[debugserver] Implement MultiMemRead packet (#162670)
This commit implements, in debugserver, the packet as discussed in the
RFC [1].

[1]:
https://discourse.llvm.org/t/rfc-a-new-vectorized-memory-read-packet/88441
2025-10-15 08:45:35 -07:00
Julian Lettner
ced01f3671
[lldb][Darwin] Add process launch --memory-tagging option (#162944)
For debugging and bug-finding workflows on Darwin, support
launching processes with memory tagging for binaries that are
not entitled.

This will cause the process to behave as if the binary was entitled
with:
```
<key>com.apple.security.hardened-process.checked-allocations</key>
<true/>
```

This has no effect on hardware without MTE support.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-10-14 13:01:24 -07:00
Julian Lettner
267fa8dd1e
[lldb][Darwin] Refine naming of test
Update name of `TestDarwinMTE` test method to
`test_memory_read_show_tags` to correspond to LLDB
command invocation:
```
memory read <start-addr> <end-addr> --show-tags
```
2025-10-13 09:54:41 -07:00
Julian Lettner
f4784fd13f
[debugserver] Support for qMemTags packet (#160952)
Support for `qMemTags` packet in debugserver which allows usage of
LLDB's `memory tag read` on Darwin.
2025-10-02 13:57:40 -07:00
Julian Lettner
5d511b6736
[lldb][test] Unify test infrastructure for checking CPU features (#153914)
This addresses limitations in our testing infrastructure for checking
CPU features. Before this
* `getCPUInfo()` was Linux-only, and the
* `@skipUnlessFeature` decorator was Darwin-only and did not consider
the remote (on device) testing use case.

Introduce `CPUFeature` class as an abstraction to hide the
platform-specific implementations to check for CPU features. Unify local
(on host) and remote (on device) test execution by always going through
`test.run_platform_command()` which uses LLDB's `platform shell <cmd>`
command.

Potential future cleanups: I think `@skipUnlessFeature` decorator could
be used in place of code like this:
```
if not self.isAArch64SME():
    self.skipTest("SME must be present.")
if not self.isAArch64SME2():
    self.skipTest("SME2 must be present.")
```
2025-09-24 13:31:02 -07:00
David Spickett
b21dd44dbc
[lldb][test] Enable non-address bit WritePointerToMemory test on Linux (#157435)
First added in #153585 for Darwin only. All Linux AArch64 systems also
have Top Byte Ignore enabled in userspace so the test "just works"
there.

FreeBSD has very recently gained Top Byte Ignore support:
4c6c27d3fb

However it's so recent, I don't want to assume it'll be available on any
random FreeBSD system out there.

There isn't really a good place to put this test, so I put it in the top
level of API, next to the other non-address bit test that didn't have a
good home either.
2025-09-19 16:00:33 +01:00
Sirraide
9b95e10d5e
[LLDB] [Tests] Downgrade -Wincompatible-pointer-types to a warning in some tests (#158756)
These no longer compile because the warning now defaults to an error
after #157364, so downgrade the error to a warning for now; I’m not
familiar enough with either LLDB or MacOS to fix these warnings properly
(assuming they’re unintended).
2025-09-16 02:02:01 +02:00
Felipe de Azevedo Piovezan
5d088ba304
[lldb] Track CFA pointer metadata in StackID (#157498)
[lldb] Track CFA pointer metadata in StackID

    In this commit:

9c8e71644227 [lldb] Make StackID call Fix{Code,Data} pointers (#152796)

We made StackID keep track of the CFA without any pointer metadata in
it. This is necessary when comparing two StackIDs to determine which one
    is "younger".

However, the CFA inside StackIDs is also used in other contexts through
    the method StackID::GetCallFrameAddress. One notable case is
DWARFExpression: the computation of `DW_OP_call_frame_address` is done
    using StackID. This feeds into many other places, e.g. expression
evaluation may require the address of a variable that is computed from
    the CFA; to access the variable without faulting, we may need to
preserve the pointer metadata. As such, StackID must be able to provide
    both versions of the CFA.

    In the spirit of allowing consumers of pointers to decide what to do
with pointer metadata, this patch changes StackID to store both versions
of the cfa pointer. Two getter methods are provided, and all call sites
    except DWARFExpression preserve their existing behavior (stripped
    pointer). Other alternatives were considered:

    * Just store the raw pointer. This would require changing the
comparisong operator `<` to also receive a Process, as the comparison
requires stripped pointers. It wasn't clear if all call-sites had a
non-null process, whereas we know we have a process when creating a
      StackID.

* Store a weak pointer to the process inside the class, and then strip
      metadata as needed. This would require a `weak_ptr::lock` in many
operations of LLDB, and it felt wasteful. It also prevents stripping
      of the pointer if the process has gone away.

This patch also changes RegisterContextUnwind::ReadFrameAddress, which
is the method computing the CFA fed into StackID, to also preserve the
    signature pointers.
2025-09-12 09:17:48 -07:00
Jason Molenda
693146dcc0 [lldb][yaml2macho-core] Address bug when run on Windows
The two API tests I converted to use yaml2macho-core were failing
on windows.  I was writing the output corefile with fopen(filename,
"w"), and it turns out there was some newline conversion happening
on Windows if a linefeed character was present. Charles Zablit
helped to identify the issue and confirm the fix.  Re-enabling the
two tests on all platforms.

https://github.com/llvm/llvm-project/pull/153911
2025-09-08 10:37:16 -07:00
Jason Molenda
e7572d73b5 [lldb][yaml2macho-core] fix typeo in API test 2025-09-04 19:57:05 -07:00
Jason Molenda
4c17749b6d [lldb][yaml2macho-core] change the two API tests to skipUnlessDarwin
These two 32-bit macho corefile tests are still failing on the
lldb-remote-linux-win bot, I'd expect the @skipIfWindows decorator
to skip the tests there until I can debug this, but somehow because
it's a remote windows execution it's not working.  Change these tests
back to skipUnlessDarwin until I can figure out whether it's
yaml2macho-core or lldb's 32-bit mach-o corefile reader support on
windows which is the problem.
2025-09-04 19:53:16 -07:00
Jason Molenda
53efe0a892 [lldb][yaml2macho-core] Disable two API tests on Windows
I changed two tests that were previously @skipUnlessDarwin
to run on all systems, using yaml2macho-core.  I'm seeing
failures on these tests on the Windows bots.  I'm skipping
them on Windows for now to unblock the CI, while I try to
understand if this is a yaml2macho-core bug, or an existing
problem with lldb's macho corefile reading on windows bug.
v. https://github.com/llvm/llvm-project/pull/153911
2025-09-04 17:21:44 -07:00
Felipe de Azevedo Piovezan
f88eadda35
[lldb] Call FixUpPointer in WritePointerToMemory (try 2) (#153585)
In architectures where pointers may contain metadata, such as arm64e,
the metadata may need to be cleaned prior to sending this pointer to be
used in expression evaluation generated code.

This patch is a step towards allowing consumers of pointers to decide
whether they want to keep or remove metadata, as opposed to discarding
metadata at the moment pointers are created. See #150537.

This was tested running the LLDB test suite on arm64e.

(The first attempt at this patch caused a failure in
TestScriptedProcessEmptyMemoryRegion.py. This test exercises a case
where IRMemoryMap uses host memory in its allocations; pointers to such
allocations should not be fixed, which is what the original patch failed
to account for).
2025-09-04 13:05:10 -07:00
Jason Molenda
a0c2d6e369
[lldb] Add utility to create Mach-O corefile from YAML desc (#153911)
I've wanted a utility to create a corefile for test purposes given a bit
of memory and regsters, for a while. I've written a few API tests over
the years that needed exactly this capability -- we have several one-off
Mach-O corefile creator utility in the API testsuite to do this. But
it's a lot of boilerplate when you only want to specify some register
contents and memory contents, to create an API test.

This adds yaml2mach-core, a tool that should build on any system, takes
a yaml description of register values for one or more threads,
optionally memory values for one or more memory regions, and can take a
list of UUIDs that will be added as LC_NOTE "load binary" metadata to
the corefile so binaries can be loaded into virtual address space in a
test scenario.

The format of the yaml file looks like

```
cpu: armv7m

# optionally specify the number of bits used for addressing
# (this line is from a different, 64-bit, yaml file)
addressable-bits: 
    num-bits: 39

# optionally specify one or more binary UUID and slide/virtual address to be added as an LC_NOTE
# (this line is from a different, 64-bit, yaml file)
binaries:
  - name: debug-binary.development
    uuid: 67942352-5857-3D3D-90CB-A3F80BA67B04
    virtual-address: 0xfffffff01840c000

threads:
  - regsets: 
     - flavor: gpr 
        registers: [{name: sp, value: 0x2000fe70}, {name: r7, value: 0x2000fe80}, 
                    {name: pc, value: 0x0020392c}, {name: lr, value: 0x0020392d}]

memory-regions:
  # stack memory
  - addr: 0x2000fe70 
    UInt32: [ 0x0000002a, 0x20010e58, 0x00203923, 
              0x00000001, 0x2000fe88, 0x00203911, 
              0x2000ffdc, 0xfffffff9 ]
  # instructions of a function
  - addr: 0x203910 
     UInt8: [ 0xf8, 0xb5, 0x04, 0xaf, 0x06, 0x4c, 0x07, 0x49, 
              0x74, 0xf0, 0x2e, 0xf8, 0x01, 0xac, 0x74, 0xf0 ]
```

and that's all that is needed to specify a corefile where four register
values are specified (the others will be set to 0), and two memory
regions will be emitted.

The memory can be specified as an array of UInt8, UInt32, or UInt64, I
anticipate that some of these corefiles may have stack values
constructed manually and it may be simpler for a human to write them in
a particular grouping of values.

I needed this utility for an upcoming patch for ARM Cortex-M processors,
to create a test for the change. I took the opportunity to remove two of
the "trivial mach-o corefile" creator utilities I've written in the
past, which also restricted the tests to only run on Darwin systems
because I was using the system headers for Mach-O constant values.

rdar://110663219
2025-09-04 11:42:26 -07:00
Dave Lee
68b9bb5e9b
[lldb] Add stop_description Python property to SBThread (#151568)
Add `stop_description` as a Python convenience property to `SBThread`.
2025-07-31 13:10:04 -07:00
Jason Molenda
8461c00435
[lldb] Pass address expression command args through FixAnyAddress (#147011)
Commands that take an address expression/address through the
OptionArgParser::ToAddress method, which has filtered this
user-specified address through one of the Process Fix methods to clear
non-addressable bits (MTE, PAC, top byte ignore, etc). We don't know
what class of address this is, IMEM or DMEM, but this method is passing
the addresses through Process::FixCodeAddress, and on at least one
target, FixCodeAddress clears low bits which are invalid for
instructions.

Correct this to use FixAnyAddress, which doesn't make alignment
assumptions.

The actual issue found was by people debugging on a 32-bit ARM Cortex-M
part, who tried to do a memory read from an odd address, and lldb
returned results starting at the next lower even address.

rdar://154885727
2025-07-08 16:21:45 -07:00
Michael Buch
24fd3437c3 [lldb][test] TestMetadataRegisters.py: add missing include
The macOS Clang-17 matrix bot was failing with:
```
07:33:28  /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp:79:12: error: implicit instantiation of undefined template 'std::vector<unsigned char>'
07:33:28     79 |     payload.resize(payload_str->size(), 0);
07:33:28        |            ^
07:33:28  /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1706_build/include/c++/v1/iosfwd:133:28: note: template is declared here
07:33:28    133 | class _LIBCPP_TEMPLATE_VIS vector;
07:33:28        |                            ^
07:33:28  /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp:80:19: error: implicit instantiation of undefined template 'std::vector<unsigned char>'
07:33:28     80 |     memcpy(payload.data(), payload_str->c_str(), payload_str->size());
07:33:28        |                   ^
07:33:28  /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1706_build/include/c++/v1/iosfwd:133:28: note: template is declared here
07:33:28    133 | class _LIBCPP_TEMPLATE_VIS vector;
07:33:28        |                            ^
07:33:28  /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp:87:12: error: implicit instantiation of undefined template 'std::vector<unsigned char>'
07:33:28     87 |     payload.resize(sb.st_size, 0);
07:33:28        |            ^
07:33:28  /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1706_build/include/c++/v1/iosfwd:133:28: note: template is declared here
07:33:28    133 | class _LIBCPP_TEMPLATE_VIS vector;
```
2025-06-30 10:46:17 +01:00
Jason Molenda
a64db49371
[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@devlieghere.com>
2025-06-27 18:43:41 -07:00
royitaqi
f63bc84b0d
[lldb] Fix FindProcessImpl() for iOS simulators (#139174)
# Benefit

This patch fixes:
1. After `platform select ios-simulator`, `platform process list` will
now print processes which are running in the iOS simulator. Previously,
no process will be listed.
2. After `platform select ios-simulator`, `platform attach --name
<name>` will succeed. Previously, it will error out saying no process is
found.


# Several bugs that is being fixed

1. During the process listing, add `aarch64` to the list of CPU types
for which iOS simulators are checked for.
2. Given a candidate process, when checking for simulators, the original
code will find the desired environment variable (`SIMULATOR_UDID`) and
set the OS to iOS, but then the immediate next environment variable will
set it back to macOS.
3. For processes running on simulator, set the triple's `Environment` to
`Simulator`, so that such processes can pass the filtering [in this
line](https://fburl.com/8nivnrjx). The original code leave it as the
default `UnknownEnvironment`.



# Manual test

**With this patch:**
```
royshi-mac-home ~/public_llvm/build % bin/lldb
(lldb) platform select ios-simulator

(lldb) platform process list
240 matching processes were found on "ios-simulator"

PID    PARENT USER       TRIPLE                         NAME
====== ====== ========== ============================== ============================
40511  28844  royshi     arm64-apple-ios-simulator      FocusPlayground // my toy iOS app running on simulator
... // omit
28844  1      royshi     arm64-apple-ios-simulator      launchd_sim

(lldb) process attach --name FocusPlayground
Process 40511 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x0000000104e3cb70 libsystem_kernel.dylib`mach_msg2_trap + 8
libsystem_kernel.dylib`mach_msg2_trap:
->  0x104e3cb70 <+8>: ret
... // omit
```

**Without this patch:**
```
$ bin/lldb
(lldb) platform select ios-simulator

(lldb) platform process list
error: no processes were found on the "ios-simulator" platform

(lldb) process attach --name FocusPlayground
error: attach failed: could not find a process named FocusPlayground
```


# Unittest

See PR.
2025-06-25 16:38:29 -07:00
Jonas Devlieghere
a7f495f170
[lldb] Revive TestSimulatorPlatform.py (#142244)
This test was incorrectly disabled and bitrotted since then. This PR
fixes up the test and re-enables it.

 - Build against the system libc++ (which can target the simulator)
 - Bump the deployment target for iOS and tvOS on Apple Silicon
 - Skip backdeploying to pre-Apple Silicon OS on Apple Silicon.
2025-06-10 13:30:31 -07:00
Jason Molenda
6d6feaf7e3 [lldb][NFC] update API tests which skip/expect-fail arm
The architectures provided to skipIf / expectedFail are regular
expressions (v. _match_decorator_property() in decorators.py
so on Darwin systems "arm64" would match the skips for "arm" (32-bit
Linux).  Update these to "arm$" to prevent this, and also update
three tests (TestBuiltinFormats.py, TestCrossDSOTailCalls.py,
TestCrossObjectTailCalls.py) that were skipped for arm64 via this
behavior, and need to be skipped or they will fail.

This was moviated by the new TestDynamicValue.py test which has
an expected-fail for arm, but the test was passing on arm64 Darwin
resulting in failure for the CIs.
2025-05-27 18:41:16 -07:00
jimingham
952b680fd1
Support stepping through Darwin "branch islands" (#139301)
When an intra-module jump doesn't fit in the immediate branch slot, the
Darwin linker inserts "branch island" symbols, and emits code to jump
from branch island to branch island till it makes it to the actual
function.

The previous submissions failed because in that environment the linker
was putting the `foo.island` symbol at the same address as the `padding`
symbol we we emitting to make our faked-up large binary. This submission
jams a byte after the padding symbol so that the other symbols can't
overlap it.
2025-05-13 13:32:53 -07:00
jimingham
74120d0a38
Revert branch island experiments (#139192)
This test is failing because when we step to what is the branch island
address and ask for its symbol, we can't resolve the symbol, and just
call it the last padding symbol plus a bajillion.

That has nothing to do with the changes in this patch, but I'll revert
this and keep trying to figure out why symbol reading on this bot is
wrong.
2025-05-08 18:37:43 -07:00
jimingham
803fd732ae
Branch island no dsym (#139191)
When we get to the branch island, we don't see the symbol for
    it.
    
    The only other thing I can think of that would be a dsymutil bug?
Let's try this just with dwarf, and then I'll have to revert all this
    and see if I can reproduce this locally somehow.
2025-05-08 18:22:10 -07:00
jimingham
b80c3c576f
Branch no lld (#139187)
I suspect the test may be failing because lld doesn't behave the same
way the native Darwin linker does. Trying that theory here...
2025-05-08 18:00:52 -07:00
jimingham
b6922b7170
Add more logging so I can figure out why TestBranchIslands.py is (#139178)
failing but only on the bot.
2025-05-08 17:03:21 -07:00
jimingham
6bb3019691
Branch island debug (#139166)
This patch allows lldb to step in across "branch islands" which is the
Darwin linker's way of dealing with immediate branches to targets that
are too far away for the immediate slot to make the jump.

I submitted this a couple days ago and it failed on the arm64 bot. I was
able to match the bot OS and Tool versions (they are a bit old at this
point) and ran the test there but sadly it succeeded. The x86_64 bot
also failed but that was my bad, I did @skipUnlessDarwin when I should
have done @skipUnlessAppleSilicon.

So this resubmission is with the proper decoration for the test, and
with a bunch of debug output printed in case of failure. With any luck,
if this resubmission fails again I'll be able to see what's going on.
2025-05-08 16:22:39 -07:00
Felipe de Azevedo Piovezan
a1238911f4 Revert "Branch island with numbers (#138781)"
This reverts commit 11f33ab3850886510a831122078a155be7dc1167.

This is failing on CI.
2025-05-06 18:20:25 -07:00
jimingham
11f33ab385
Branch island with numbers (#138781)
Reapply the support for stepping through branch islands, add support for
a branch that takes multiple hops to get to the target.
2025-05-06 16:58:01 -07:00
jimingham
1ff2953f5e
Revert "Handle step-in over a Darwin "branch island". (#138330)" (#138569)
This reverts commit 1ba89ad2c6e405bd5ac0c44e2ee5aa5504c7aba1.

This was failing on the Green Dragon bot, which has an older OS than
have on hand, so I'll have to dig up one and see why it's failing there.
2025-05-05 12:45:17 -07:00