492 Commits

Author SHA1 Message Date
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
Pavel Labath
7e471c1fd0
[lldb/cmake] Use ADDITIONAL_HEADER(_DIR)?S (#142587)
Replace (questionable) header globs with an explicit argument supported
by llvm_add_library.
2025-06-10 11:58:39 +02:00
Pavel Labath
2c4f67794b
[lldb/cmake] Implicitly pass arguments to llvm_add_library (#142583)
If we're not touching them, we don't need to do anything special to pass
them along -- with one important caveat: due to how cmake arguments
work, the implicitly passed arguments need to be specified before
arguments that we handle.

This isn't particularly nice, but the alternative is enumerating all
arguments that can be used by llvm_add_library and the macros it calls
(it also relies on implicit passing of some arguments to
llvm_process_sources).
2025-06-04 11:33:37 +02:00
Pavel Labath
1eaa289472
[lldb/Host] Enable inheriting "non-inheritable" FDs (#126935)
Currently we're creating inheritable (`~FD_CLOEXEC`) file descriptors in
the (few) cases where we need to pass an FD to a subprocess. The problem
with these is that, in a multithreaded application such as lldb, there's
essentially no way to prevent them from being leaked into processes
other than the intended one.

A safer (though still not completely safe) approach is to mark the
descriptors as FD_CLOEXEC and only clear this flag in the subprocess. We
currently have something that almost does that, which is the ability to
add a `DuplicateFileAction` to our `ProcessLaunchInfo` struct (the
duplicated file descriptor will be created with the flag cleared). The
problem with *that* is that this approach is completely incompatible
with Windows.

Windows equivalents of file descriptors are `HANDLE`s, but these do not
have user controlled values -- applications are expected to work with
whatever HANDLE values are assigned by the OS. In unix terms, there is
no equivalent to the `dup2` syscall (only `dup`).

To find a way out of this conundrum, and create a miniscule API surface
that works uniformly across platforms, this PR proposes to extend the
`DuplicateFileAction` API to support duplicating a file descriptor onto
itself. Currently, this operation does nothing (it leaves the FD_CLOEXEC
flag set), because that's how `dup2(fd, fd)` behaves, but I think it's
not completely unreasonable to say that this operation should clear the
FD_CLOEXEC flag, just like it would do if one was using different fd
values. This would enable us to pass a windows HANDLE as itself through
the ProcessLaunchInfo API.

This PR implements the unix portion of this idea. Macos and non-macos
launchers are updated to clear FD_CLOEXEC flag when duplicating a file
descriptor onto itself, and I've created a test which enables passing a
FD_CLOEXEC file descritor to the subprocess. For the windows portion,
please see the follow-up PR.
2025-05-06 15:04:30 +02:00
Jonas Devlieghere
460c0f567c
[lldb] Move two methods from Platfrom -> Host (NFC) (#132119)
This moves two functions from Platform to Host:

  1. GetCurrentXcodeToolchainDirectory
  2. GetCurrentCommandLineToolsDirectory.

These two functions caused a layering violation in the Swift fork, which
added a dependency from lldbHost to lldbPlatform. As show by this PR,
there's no need for these two functions to live in Platform, and we
already have similar functions in Host.

We have various layering violations but this one is particularly bad,
because lldb-dap started depending on lldbHost. On the Swift fork, this
library was depending on lldbPlatform which pulled in various Swift
files, which libLLDB needs, but lldb-dap itself does not. We were
missing RPATHs to resume them, so in the current nightly, lldb-dap
crashes because the dynamic loader can't find the missing Swift libs.

rdar://146537366
2025-03-19 22:22:01 -07:00
John Harrison
502385c241
[lldb] Remove an extraneous printf statement. (#130453)
This was missed in review but is showing up in lldb-dap output.
2025-03-10 11:38:03 +00:00
Adrian Prantl
878a64f94a
[lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (#129601)
This patch pushes the error handling boundary for the GetBitSize()
methods from Runtime into the Type and CompilerType APIs. This makes it
easier to diagnose problems thanks to more meaningful error messages
being available. GetBitSize() is often the first thing LLDB asks about a
type, so this method is particularly important for a better user
experience.

rdar://145667239
2025-03-05 10:21:19 -08:00
Jonas Devlieghere
6c4febee29
[lldb-dap] Implement a MemoryMonitor (#129332)
This implements a memory monitor for macOS, Linux and Windows. It
registers a callback that invokes `SBDebugger::MemoryPressureDetected`
when a low memory event is detected. This is motivated by the new
server mode, where the lldb-dap process will live across multiple
debug sessions and will use more memory due to caching.
2025-03-05 08:49:49 -08:00
Med Ismail Bennani
41d5d2b5a2
[lldb/Host] Add ability to open URLs on macOS (#125893)
This patch adds the ability to open URLs from lldb on macOS. This can be
a website URL or a deep link to a particular application.

rdar://143327616

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2025-02-05 10:07:08 -08:00
Jonas Devlieghere
c7605bfd4e
[lldb] Fix cast-function-type-mismatch warning in Host.mm (NFC)
Fixes warning: cast from 'void (*)(xpc_object_t _Nonnull)' (aka 'void
(*)(NSObject<OS_xpc_object> * _Nonnull)') to 'xpc_finalizer_t' (aka
'void (*)(void * _Nullable)') converts to incompatible function type
[-Wcast-function-type-mismatch]
2024-11-14 11:12:58 -08:00
Jonas Devlieghere
4897fc44a9
[lldb] Narrow scope of -Wno-deprecated-declarations (NFC) (#112276)
Currently all of LLDB is being compiled with
-Wno-deprecated-declarations. That's not desirable, especially as part
of the LLVM monorepo, as we miss deprecation warnings from LLVM and
clang.

According to the git history, this was first introduced to suppress
warnings related to auto_ptr. Since then, other things have been
deprecated and gone unnoticed. This patch limits the flag to Host.mm
which uses a handful of LSApplication headers that have no replacement.

rdar://112040718
2024-10-17 08:22:56 -07:00
Adrian Prantl
a0dd90eb7d
[lldb] Make conversions from llvm::Error explicit with Status::FromEr… (#107163)
…ror() [NFC]
2024-09-05 12:19:31 -07:00
Adrian Prantl
0642cd768b
[lldb] Turn lldb_private::Status into a value type. (#106163)
This patch removes all of the Set.* methods from Status.

This cleanup is part of a series of patches that make it harder use the
anti-pattern of keeping a long-lives Status object around and updating
it while dropping any errors it contains on the floor.

This patch is largely NFC, the more interesting next steps this enables
is to:
1. remove Status.Clear()
2. assert that Status::operator=() never overwrites an error
3. remove Status::operator=()

Note that step (2) will bring 90% of the benefits for users, and step
(3) will dramatically clean up the error handling code in various
places. In the end my goal is to convert all APIs that are of the form

`    ResultTy DoFoo(Status& error)
`
to

`    llvm::Expected<ResultTy> DoFoo()
`
How to read this patch?

The interesting changes are in Status.h and Status.cpp, all other
changes are mostly

` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git
grep -l SetErrorString lldb/source)
`
plus the occasional manual cleanup.
2024-08-27 10:59:31 -07:00
Alex Langford
384d69fcbb
[lldb] Cleanup dyld_process_t after constructing SharedCacheInfo (#106157)
Without calling `dyld_process_dispose`, LLDB will leak the memory
associated with the `dyld_process_t`.

rdar://134738265
2024-08-27 09:59:17 -07:00
Daniel Wedzicha
b4dc986938
[LLDB][OSX] Removed semi colon generating a warning during build (#104398)
Singular warning I noticed when compiling lldb.

Co-authored-by: Daniel <d.wedzicha@efg.gg>
2024-08-15 00:23:40 -04:00
Walter Erquinigo
cce2271eab
[LLDB][OSX] Add a fallback support exe directory (#103458)
LLDB on OSX is looking at a `bin` directory sibling to the `lib` one
that contains liblldb for its supporting executables. This works well
for CMake, however, for other build systems like bazel, it's not that
easy to have that build structure, for which it's much easier to also
use the `lib` directory as a fallback under the absence of `bin`.
This shouldn't break anything, but instead should make it a bit easier
for LLDB to work with different build systems and folder structures.
2024-08-14 12:41:19 -04:00
Keith Smiley
f918c056f0
[lldb] Allow env override for LLDB_ARGDUMPER_PATH (#91688)
This mirrors the LLDB_DEBUGSERVER_PATH environment variable and allows
you to have lldb-argdumper in a non-standard location and still use it
at runtime.
2024-05-14 13:43:04 -07:00
Jonas Devlieghere
528f5ba7af
[lldb] Create a single Severity enum in lldb-enumerations (#90917)
We have 3 different enums all expressing severity (info, warning,
error). Remove all uses with a new Severity enum in lldb-enumerations.h.
2024-05-03 09:25:38 -07:00
Jonas Devlieghere
a7e9e3eb8b
[lldb] Add a log level to Host::SystemLog (#90904)
Add the ability to specify a log level to Host::SystemLog.
2024-05-02 16:07:11 -07:00
Jonas Devlieghere
3b6a8f823b
[lldb] Upstream xros support in lldb (#78389)
Upstream support for debugging xros applications through LLDB.
2024-01-17 09:47:08 -08:00
Adrian Prantl
15733fe5f3
Also log the error output from xcrun, if it fails. (#70716)
In the rare case that an Xcode installation is damaged, this output
could contain clues to further diagnose the issue.

rdar://117698630
2023-10-31 15:36:06 -07:00
Adrian Prantl
c42b640208
Fix the DEVELOPER_DIR computation (#70528)
The code was incorrectly going into the wrong direction by removing one
component instead of appendeing /Developer to it. Due to fallback
mechanisms in xcrun this never seemed to have caused any issues.
2023-10-30 10:00:40 -07:00
Adrian Prantl
b82c629786 Fix log format strings 2023-10-25 16:42:37 -07:00
Fangrui Song
678e3ee123 [lldb] Fix duplicate word typos; NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 21:32:24 -07:00
Alex Langford
d21ec35dcf [lldb][NFCI] Remove use of ifdef __cpluplus where unneeded
Just about every file in the lldb project is built with C++ enabled.
Unless I've missed something, these macro guards don't really accomplish
very much.

Differential Revision: https://reviews.llvm.org/D157538
2023-08-10 11:24:40 -07:00
Alex Langford
6c2e324916 [lldb] Re-add compile-time checks for SPI in HosInfoMacOSX
There were some checks removed previously in
bc196970b549782bffde5fdbfa450c565af11fc1.

However, all these SPIs are actually defined in macOS 12 and onward, not
macOSX 10.12 as the previous commit would suggest. As a result, if you
have access to these SPIs lldb will fail to compile correctly.

Instead of adding back the __builtin_availability checks, it seems
easier just to check the minimum deployment target with Availability
macros.

Differential Revision: https://reviews.llvm.org/D156838
2023-08-02 10:21:54 -07:00
Alex Langford
db9087a696 [lldb] Clean up uses of UuidCompatibility.h
This commit does a few related things:
- Removes unused function `uuid_is_null`
- Removes unneeded includes of UuidCompatibility.h
- Renames UuidCompatibility to AppleUuidCompatibility and adds a comment
  to clarify intent of header.
- Moves AppleUuidCompatibility to the include directory

Differential Revision: https://reviews.llvm.org/D156562
2023-07-31 10:30:07 -07:00
Jonas Devlieghere
7cd1d4231a
[lldb] Remove __FUNCTION__ from log messages in lldbHost (NFC)
LLDB's logging infrastructure supports prepending log messages with the
name of the file and function that generates the log (see help log
enable). Therefore it's unnecessary to include the current __FUNCTION__
in the log message itself. This patch removes __FUNCTION__ from log
messages in the Host library.

Differential revision: https://reviews.llvm.org/D151762
2023-06-06 13:02:43 -07:00
Adrian Prantl
7de43526e3 HostInfoMacOS: Add a utility function for finding an SDK-specific tool
This is an API needed by swift-lldb.

https://reviews.llvm.org/D151591
2023-05-31 14:46:35 -07:00
Adrian Prantl
a5e9f2c81e Factor out xcrun into a function (NFC)
https://reviews.llvm.org/D151588
2023-05-31 14:46:35 -07:00
Saleem Abdulrasool
cd21c0d30c Revert "Revert "Host: generalise GetXcodeSDKPath""
This reverts commit c46d9af26cefb0b24646d3235b75ae7a1b8548d4.

Rename the variable to avoid `-Wchanges-meaning` warning.  Although, it
might be better to squelch the warning as it is of low value IMO.
2023-05-29 10:16:41 -07:00
Adrian Prantl
d9c898ab60 Revert "Factor out xcrun into a function (NFC)"
This reverts commit 97ca34996dbe5a61e79d7c559af7b15dc39c08a5.
2023-05-26 13:51:46 -07:00
Adrian Prantl
c45a649a96 Revert "Make function static (NFC)"
This reverts commit cefd2802aa49274942da87edf5019b5a23315f01.
2023-05-26 13:51:46 -07:00
Adrian Prantl
cefd2802aa Make function static (NFC) 2023-05-26 13:12:12 -07:00
Adrian Prantl
97ca34996d Factor out xcrun into a function (NFC) 2023-05-26 13:02:50 -07:00
Jonas Devlieghere
b12b35ad4b
[lldb] Add debugger.external-editor setting
Add a new setting (debugger.external-editor) to specify an external
editor. The setting takes precedence over the existing
LLDB_EXTERNAL_EDITOR environment variable.

Differential revision: https://reviews.llvm.org/D149565
2023-05-01 14:11:11 -07:00
Douglas Yung
c46d9af26c Revert "Host: generalise GetXcodeSDKPath"
This reverts commit ade3c6a6a88ed3a9b06c076406f196da9d3cc1b9.

This breaks the build with GCC and affects at least 2 build bots:
https://lab.llvm.org/buildbot/#/builders/217/builds/20568
https://lab.llvm.org/buildbot/#/builders/243/builds/5576
2023-05-01 10:22:53 -07:00
Jonas Devlieghere
13dbc16b4d
[lldb] Refactor host::OpenFileInExternalEditor
This patch refactors the macOS implementation of
OpenFileInExternalEditor. It fixes an AppleEvent memory leak, the
caching of LLDB_EXTERNAL_EDITOR and speculatively fixes a crash when
CFURL is NULL (rdar://108633464). The new code also improves error
handling, readability and documents calls to the CoreFoundation Launch
Services APIs.

A bunch of the Launch Services APIs have been deprecated
(LSFindApplicationForInfo, LSOpenURLsWithRole). The preferred API is
LSOpenCFURLRef but it doesn't specifying the "location" Apple Event
which is used to highlight the current line and switching over would
regress the existing behavior.

rdar://108633464

Differential revision: https://reviews.llvm.org/D149482
2023-04-28 18:12:41 -07:00
Saleem Abdulrasool
ade3c6a6a8 Host: generalise GetXcodeSDKPath
This generalises the GetXcodeSDKPath hook to a GetSDKRoot path which
will be re-used for the Windows support to compute a language specific
SDK path on the platform. Because there may be other options that we
wish to use to compute the SDK path, sink the XcodeSDK parameter into
a structure which can pass a disaggregated set of options. Furthermore,
optionalise the parameter as Xcode is not available for all platforms.

Differential Revision: https://reviews.llvm.org/D149397
Reviewed By: JDevlieghere
2023-04-28 09:30:59 -07:00
Dave Lee
d03d98b71d [lldb] Replace sprintf with snprintf (NFC)
On macOS, `sprintf` is deprecated, using `snprintf` is recommended instead.

Differential Revision: https://reviews.llvm.org/D147246
2023-03-30 12:29:05 -07:00
Dave Lee
80b476a902 [lldb] Replace deprecated CFPropertyListWriteToStream (NFC)
Replace `CFPropertyListWriteToStream` with its recommended replacement, `CFPropertyListWrite`.

Differential Revision: https://reviews.llvm.org/D147249
2023-03-30 11:21:09 -07:00
Alex Langford
5499b026d2 [lldb][CMake] Enforce not linking against plugin libs in core libs
Non-plugin lldb libraries should generally not be linking against lldb
plugin libraries. Enforce this in CMake.

Differential Revision: https://reviews.llvm.org/D146553
2023-03-21 16:24:36 -07:00
Archibald Elliott
d768bf994f [NFC][TargetParser] Replace uses of llvm/Support/Host.h
The forwarding header is left in place because of its use in
`polly/lib/External/isl/interface/extract_interface.cc`, but I have
added a GCC warning about the fact it is deprecated, because it is used
in `isl` from where it is included by Polly.
2023-02-10 09:59:46 +00:00
Kazu Hirata
2fe8327406 [lldb] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to clean up the "using" declarations, #include
"llvm/ADT/Optional.h", etc.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 14:18:35 -08:00
Kazu Hirata
f190ce625a [lldb] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 13:43:00 -08:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00
Kazu Hirata
529ca5ad07 [lldb] Use std::nullopt instead of llvm::None (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-05 23:18:15 -08:00
Adrian Prantl
33cbda4cac Improve error logging when xcrun fails to execute successfully
Because Host::RunShellCommand runs commands through $SHELL there is an
opportunity for this to fail spectacularly on systems that use custom
shells with odd behaviors. This patch makes these situations easier to
debug by at least logging the result of the failed xcrun invocation.

It also doesn't run xcrun through a shell any more.

rdar://102389438

Differential Revision: https://reviews.llvm.org/D138060
2022-12-01 16:22:14 -08:00
Jason Molenda
bc196970b5 Remove compile-time and runtime checks for SPI in HostInfoMacOSX
There are conditionalized calls to an SPI in HostInfoMacOSX.mm
to test if lldb is being built against a pre-macOS 10.12 SDK,
or being run on a pre-macOS 10.12 system.  macOS 10.12 was released
six years ago, and I don't know of any active users of this system
so let's remove the checks.

Differential Revision: https://reviews.llvm.org/D136900
rdar://101652340
2022-10-27 16:57:48 -07:00
Jim Ingham
5ad6ed0e55 Change the meaning of a UUID with all zeros for data.
Previously, depending on how you constructed a UUID from data or a
StringRef, an input value of all zeros was valid (e.g. setFromData)
or not (e.g. setFromOptionalData).  Since there was no way to tell
which interpretation to use, it was done somewhat inconsistently.
This standardizes the meaning of a UUID of all zeros to Not Valid,
and removes all the Optional methods and their uses, as well as the
static factories that supported them.

Differential Revision: https://reviews.llvm.org/D132191
2022-08-30 10:17:58 -07:00