798 Commits
Author SHA1 Message Date
Ebuka Ezike f99b28997f [lldb] Fix crash on creating string error (#212503)
It crashes because the `default` error string may not be a format string
compared to the `fallback` error string

(cherry picked from commit 29bc0749034c4f2bda0752360ecacd4e89d7439c)
2026-08-04 12:28:51 +00:00
Med Ismail Bennani 25d50e7a0f [lldb] Unify ScriptedStopHookInterface with ScriptedHookInterface (#209341)
`ScriptedHookInterface` already carries a `HandleStop` entry point, so
`ScriptedStopHookInterface` is a proper subset. Delete
`ScriptedStopHookInterface`, `ScriptedStopHookPythonInterface`, and
`ScriptInterpreter::CreateScriptedStopHookInterface`, and route
`Target::StopHookScripted` through `ScriptedHookInterface` /
`CreateScriptedHookInterface` instead.

The `target stop-hook add -P <classname>` command is unchanged; it now
constructs a `ScriptedHookInterface` internally, so any existing
`ScriptedStopHook` subclass keeps working as long as it exposes a
`handle_stop` method. New scripts should subclass `ScriptedHook`
directly (which is a superset).

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-07-13 17:40:35 -07:00
Charles Zablit 0538275eca [lldb] Don't add the same module to a target twice (#208472)
`Target::GetOrCreateModule` uses `Append`, so a module already in the
target could be added again. Then `RemoveModule` dropped only one,
keeping the module (and its memory-mapped file) alive.
On Windows that mapped file can't be deleted, causing
`TestReplaceDLL.py` to fail with `LLDB_USE_LLDB_SERVER=1`.

This patch uses `AppendIfNeeded` instead.

rdar://181797592
2026-07-09 23:12:53 +01:00
Alex Langford 691bda5884 [lldb] Remove ConstString from remaining BreakpointName functionality (#206856) 2026-07-08 11:06:37 -07:00
Med Ismail Bennani cc27a240be [lldb] Push ExpressionEvaluation policy and remove identity check fallbacks (#195775)
Push `PolicyStack::Get().PushPublicStateRunningExpression()` at all
three expression evaluation entry points
(`LLVMUserExpression::DoExecute`, `FunctionCaller::ExecuteFunction`,
`IRInterpreter`). This policy sets `can_run_breakpoint_actions=false`,
preventing recursive breakpoint callback execution during expression
eval.

Push `PolicyStack::Get().PushPrivateState()` unconditionally for all
PSTs in `RunPrivateStateThread` (not just overrides), giving every PST
the private view while keeping frame providers and recognizers enabled
for normal stop processing. Override PSTs use
`PushPrivateStateRunningExpression()` which additionally disables
providers and recognizers.

With all PSTs and expression eval sites now covered by the policy,
remove all host thread identity check fallbacks:
  - `CurrentThreadPosesAsPrivateStateThread()` in `Process::GetState()`
  - `CurrentThreadIsPrivateStateThread()` in `Target::GetAPIMutex()`
  - `IsOnThread()` in `PrivateStateThread::GetRunLock()`
- `CurrentThreadPosesAsPrivateStateThread()` in
`SelectMostRelevantFrame()`
  - `IsRunningExpression()` in `StopInfoBreakpoint::PerformAction()`

`SelectMostRelevantFrame` now checks `!can_run_frame_recognizers`
instead of `View::Private`, so recognizers run during normal PST stop
processing but are skipped during expression evaluation.

----

The following PRs are related to the Policy feature:
- #195762
- #195771
- #198897
- #195774
- #195775

rdar://176223894

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-07-08 00:51:14 +00:00
jiminghamandJonas Devlieghere 9a896c3f53 Add a pre-filter to the breakpoint resolver overrides (#198845)
That way if an override only wants to override, say, file and line
breakpoints, it can say that when it registers itself, and we won't do
the work of creating the resolver and checking with it if the breakpoint
wasn't of the requested type.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2026-07-02 14:13:02 -07:00
Alex Langford 99e855f10c [lldb][NFC] Target::RemoveNameFromBreakpoint should take a StringRef (#206834) 2026-06-30 15:35:11 -07:00
Alex Langford f9b5264523 [lldb] Remove ConstString getters from FileSpec (#206802)
This finishes the removal of ConstString from FileSpec's interface. Note
that FileSpec is still _backed_ by ConstStrings, that will be changed in
a follow-up.

A non-goal for this change is to rewrite business logic, so I kept the
type of some variables as ConstString where a refactor would necessary
to change that. I converted printf-style formatting to formatv-style
formatting where required, and otherwise tried to leave callsites alone
to the extent that was possible.
2026-06-30 14:44:20 -07:00
Alex Langford 3516fe0c2f [lldb][NFC] Change how Target stores BreakpointNames (#205419)
This changes 2 things:
1) BreakpointNameList is now called BreakpointNameMap to reflect the
   actual underlying data structure.
2) BreakpointNameMap goes from a `std::map` to a `llvm::StringMap` to
   eliminate the use of ConstString.
2026-06-29 16:59:10 -07:00
Alex Langford 7cb370ddf4 [lldb] Replace ConstString with std::string in BreakpointName (#205910) 2026-06-25 15:50:18 -07:00
Alex Langford 32572205a0 [lldb] Change BreakpointList::FindBreakpointsByName to use StringRef (#205695)
It's not possible to turn a StringRef into a c-string safely without a
potential allocation. I will use this in a follow-up to remove
ConstString from BreakpointName.
2026-06-25 10:22:18 -07:00
Sergei Barannikov 8c7b7dda51 [lldb] Fix format string (#204837)
GetLoadAddress() returns an integer value, not a null-terminated string.
2026-06-19 14:44:11 +00:00
Med Ismail Bennani 691d540948 [lldb] Consolidate Target Hook/StopHook scripted state into ScriptedMetadata (#199088)
This is a follow-up to 1b4a578a9f.

Replace `Target::HookScripted`'s and `Target::StopHookScripted`'s
separate `m_class_name` and `m_extra_args` members with a single
`m_scripted_metadata`, and update `SetScriptCallback to take a `const
ScriptedMetadata &` directly. Drop the now-redundant `args_sp` parameter
from ScriptedHookInterface::CreatePluginObject and
ScriptedStopHookInterface::CreatePluginObject; the Python overrides
construct a StructuredDataImpl from the metadata's args dict for the
dispatched call.

Each hook subclass keeps its own `m_scripted_metadata` member because
the interface's metadata is only set when SetScriptCallback runs the
Python override of CreatePluginObject; the hook needs to hold the
metadata between construction and that callback. Read-side description
printing goes through the new GetScriptClassName() helper which
delegates to m_interface_sp->GetScriptedMetadata(). The two
s.Printf("%s\n", class_name.data()) sites are also converted to
s.Format("{0}\n", class_name).

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-05-21 16:16:45 -07:00
Med Ismail Bennani 1b0e603087 [lldb] Move Policy from Target to Utility (NFC) (#198897)
Move the Policy struct and PolicyStack class from lldb/Target to
lldb/Utility. This is a pure relocation -- no API or behavior changes.

This is needed so that lldbHost (which contains ProcessRunLock) can
depend on Policy without introducing a layering violation, since
lldbHost cannot depend on lldbTarget.

----

The following PRs are related to the Policy feature:
- #195762
- #195771
- #198897
- #195774
- #195775

rdar://176223894

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-05-20 14:07:39 -07:00
Med Ismail Bennani 1b4a578a9f [lldb/Interpreter] Plumb ScriptedMetadata through scripted plugin CreatePluginObject (NFC) (#198425)
Replace the (class_name, args_sp) parameter pair on CreatePluginObject
across the scripted plugin interfaces (ScriptedThread, OperatingSystem,
ScriptedBreakpoint, ScriptedFrameProvider, ScriptedProcess, and the
underlying ScriptedPythonInterface template) with a single `const
ScriptedMetadata &`. Callers (OperatingSystemPython, ScriptedThread,
ScriptedProcess, BreakpointResolverScripted, ScriptedFrameProvider) pass
their existing ScriptedMetadata directly, removing the need to re-bundle
class_name and args at every call site.

ScriptedBreakpoint, ScriptedFrameProvider and ScriptedProcess no longer
carry a redundant `args_sp` parameter; their callers fold those args
into the metadata, and the Python overrides reconstruct a
StructuredDataImpl from the metadata's args dict for the dispatched
call.

ScriptedInterface gains an `m_scripted_metadata` member and a
`GetScriptedMetadata()` accessor; ScriptedPythonInterface populates it
when CreatePluginObject is invoked so subclasses can later report which
script class is in play.

Hook/StopHook/ThreadPlan public interfaces keep their existing `args_sp`
parameter for now; subsequent commits consolidate that.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-05-20 13:07:31 -07:00
Ebuka Ezike 8f6ed9f490 [lldb] Fix possible invalidated iterator. (#198482)
The begin or end interator may be invalidated when a idx_pos in erased
from the vector.

Unblocks sanitised CI.
2026-05-19 16:13:18 +01:00
jimingham 6e7bc01118 Adds GetOptions to CommandObjectBreakpointOverride{List, Delete}. (#197340)
This was causing flaky behavior in TestOverridesResolver.py.

I found this with ASAN, which also didn't like that I was running find
with begin() & end() of an empty std::vector. That surprised me a bit,
but its easy to avoid, so I also changed that here.
2026-05-12 18:16:56 -07:00
jimingham 457380cee1 Add a breakpoint override resolver feature to lldb (#195392)
This is a general mechanism that allows a custom breakpoint resolver to
"override" the resolver lldb would have used. It is implemented by
making a scripted breakpoint resolver class, implementing an extra
"overrides_resolver" method. When lldb has decided what resolver it is
going to use for the breakpoint, if there are any override resolvers
registered, it will pass the serialized form of the resolver to the
`overrides_resolver` method of the registered resolvers. If any of the
override resolvers return true from the overrides_resolver method, that
resolver will be used in place of the one lldb would have used.

The original motivation for this feature is to make the support of
"debugging a scripting language from the implementation side". We added
the notion of "facade breakpoints" so that a location given in the
context of the scripting language can be handled by the emulation code.
But when you are using lldb in some IDE, when "stopped" in the scripting
language, the IDE will show the scripting language source. It is natural
in that case for the user to expect the UI gesture to set a file and
line breakpoint should work the same way.

To implement that, the implementor would make their facade breakpoint
resolver also an override resolver that checks to see if the incoming
resolver was a file and line breakpoint for a source file of the
scripting language type. If it is, it returns true, and lldb will use
that resolver instead. Note, this will also work when breakpoints are
set on the command line, so you can transparently support "scripting
language" breakpoints from the command line as well.
2026-05-11 15:55:34 -07:00
Felipe de Azevedo Piovezan b68f6c0e8b [lldb] Override UpdateBreakpointSites in ProcessGDBRemote to use MultiBreakpoint (#192988)
This concludes the implementation of MultiBreakpoint by actually using
the new packet to batch breakpoint requests.

The following PRs are related to the MultiBreakpoint feature:

* https://github.com/llvm/llvm-project/pull/192910
* https://github.com/llvm/llvm-project/pull/192914
* https://github.com/llvm/llvm-project/pull/192915
* https://github.com/llvm/llvm-project/pull/192919
* https://github.com/llvm/llvm-project/pull/192962
* https://github.com/llvm/llvm-project/pull/192964
* https://github.com/llvm/llvm-project/pull/192971
* https://github.com/llvm/llvm-project/pull/192988
2026-05-07 07:59:37 +01:00
Med Ismail Bennani 504a112781 [lldb] Adopt Policy for private/public view and capability decisions (#195771)
Push Policy::PrivateState() at all sites where the private state thread
needs to see the private reality instead of the public illusion:
- StopInfoBreakpoint::ShouldStopSynchronous (sync callbacks, WasHit)
- StopInfoWatchpoint::ShouldStopSynchronous
- RunThreadPlan (original PST during expression evaluation)
- RunPrivateStateThread (override PSTs)

Consult the policy at all view/capability decision points:
- Process::GetState() -- private vs public state
- Target::GetAPIMutex() -- private vs public mutex
- PrivateStateThread::GetRunLock() -- private vs public run lock
- Thread::GetStackFrameList() -- parent vs provider-augmented frames
- StackFrameList::SelectMostRelevantFrame() -- skip frame recognizers
- StopInfoBreakpoint::PerformAction() -- skip breakpoint actions
- StopInfoWatchpoint::PerformAction() -- skip watchpoint actions

The existing host thread identity checks remain as fallbacks until
Policy is pushed for all PSTs unconditionally.

This commit also add Stream::operator<<(bool) to allow streaming boolean
values as "true"/"false".

rdar://176223894

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-05-07 04:12:34 +00:00
Dave Lee 9f968a8e57 [lldb] Fix misconstructed log/formatv calls (#196129)
Fixes `LLDB_LOG` and `formatv` source errors found using
https://github.com/llvm/llvm-project/pull/195974
2026-05-06 21:33:03 +00:00
Charles Zablit 3a5c7a70c8 [lldb] fix unconsumed llvm::Expected's errors (#193257) 2026-05-05 11:08:50 +01:00
Bar SoloveychikandBar Soloveychik b1c027b3aa [LLDB] Add module hook implementation (#185465)
Introduce a unified target hook command system for LLDB that handles
multiple target lifecycle events (module load, module unload, process
stop) through a single Hook class.

The existing target stop-hook commands remain unchanged for now, meaning
stop-hooks can now be created through either target stop-hook add or
target hook add -S.
A future follow-up can alias target stop-hook to the unified system to
consolidate the two paths.

 New commands:
- target hook add [-o cmd] [-P class] [-u] [-S] - create a hook (fires
on module load by default, optionally on unload/stop)
- target hook add-filter [filter-opts] <hook-id> - attach stop-event
filters (shlib, function, file/line, thread) to an existing hook
- target hook list / delete / enable / disable - manage hooks
- target hook {enable,disable} {module-loaded|module-unloaded|stop-hook}
<id> - per-event toggling

top-event filter options live on a separate add-filter command rather
than on target hook add, keeping the add command clean and making the
system safe for filters on other event types.

Ran the tests + Made sure stop tests are passing as well.

---------

Co-authored-by: Bar Soloveychik <barsolo@fb.com>
2026-04-28 14:07:44 -07:00
Jonas Devlieghere 043e778f85 lldb] Fix two issues causing TestEvents.py flakiness (#194438)
This PR fixes two issues that contribute to `TestEvents.py` being flaky
in CI:

1. `ProcessEventData::DoOnRemoval` runs the full stop-handling logic
(like `ShouldStop` and `RunStopHooks`) every time an event is consumed
from any listener. When the primary listener consumes an event and then
the shadow listener consumes the same event, the logic runs twice. The
second execution can race with subsequent event processing. Fix this by
incrementing `m_update_state` after the first successful run so
secondary listeners skip the full logic.

2. Target::RunStopHooks updates `m_latest_stop_hook_id` (marking a stop
as "handled") before checking whether any threads have stop reasons. If
the check fails and hooks don't run, the stop ID is already consumed,
preventing hooks from ever running for that stop. Fix this by deferring
the update until we're certain we'll actually run hooks.
2026-04-27 15:52:56 -07:00
jimingham 2c7b820bc8 Ensure that the Synthetic children of a ValueObject are managed by their parents ClusterManager (#192561)
A very common pattern in our synthetic child providers was to make the
child ValueObject using ValueObjectConstResult::Create or some form of
the static ValueObject::CreateValueObjectFrom*** methods, and store and
hand that out as the child. Doing that creates a "root" ValueObject
whose lifecycle is not linked to the lifecycle of the ValueObject it is
a child of. And that means it is possible that either the child or the
parent could have gotten destroyed when the other ValueObject gets asked
a question about it.

For the most part this doesn't happen because there are usually enough
other shared pointer references binding the two to keep both sides
alive. But we have gotten a small but steady stream of reports for years
now of crashes where a ValueObject accesses its ClusterManager but that
has already been deleted. I've never been able to find a reproducible
case of this, but one plausible cause is that we are violating the
contract that "all the children of a ValueObject have coterminous
lifespans, enforced by the ClusterManager". So it is unsurprising that
they might sometimes not stay alive as long as they should.

This patch addresses that by providing a way to use these static create
methods but passing in the ClusterManager to be used, and adds or
modifies where extant the CreateChildValueObjectFrom*** methods to pass
in the parent manager.

This patch is not complete. It turns out that routing the ClusterManager
from CreateValueObjectFromExpression all the way to where the expression
result VO is made is quite intrusive, and would have made this already
quite large (though largly mechanical) patch become unweildy. Since I am
mostly concerned about synthetic child providers, and we discourage
using expressions for them, I think that's an acceptable separation.

I also added a test where the ValueObjectSynthetic hands out its
children, checking whether the child being handed out is in fact owned
by the parent handing it out. It is controlled by a setting
(target.check-vo-ownership) which is currently off by default - since I
can't provide a way to do this correctly for expressions yet. But I turn
it on in the testsuite. That's the real testing strategy for this patch,
since its goal is to ensure that all the children we hand out are
managed by their parents. I didn't put an equivalent check in
ValueObjectVariable because that system really doesn't allow a way to do
this incorrectly.

I also fixed some of the tests that were making children using
CreateValueObjectFromExpression to make their children with
CreateValueObjectFromData instead. I could have opted the tests out of
the check, but using the expression parser to do this work is not best
practice, so I didn't want to leave bad examples around. I left one case
that does do it with expressions, however, so we still have a test for
that not-recommended but people do it anyway path.
2026-04-22 15:50:59 -07:00
Michael Buch 8225bcc141 [lldb][PlatformDarwin] Make PlatformDarwin define a safe-path for auto-loading scripting resources (#191454)
This patch adds a new API (`Platform::GetSafeAutoLoadPaths`) which gives
platforms a chance to advertise their safe-paths. We have a
`LLDB_SAFE_AUTO_LOAD_PATHS` CMake variable for this that vendors can
set, but for sensible defaults we wanted to bake them into LLDB for
convenience. We could set the defaults of the CMake variable
per-platform, but for Apple platforms that's trickier because the path
isn't statically known (it's the SDK path derived from the target's
triple).

Depends on:
* https://github.com/llvm/llvm-project/pull/191446
* https://github.com/llvm/llvm-project/pull/192703

Assisted-by: Claude
- Used Claude to write the skeleton of the test before manually cleaning
it up.
2026-04-19 06:03:33 +00:00
Michael Buch 404b75651f [lldb][Target] Move Debugger::GetSafeAutoLoadPaths into Target (#192703)
Required for https://github.com/llvm/llvm-project/pull/191454

We want to make the `Target`/`Platform` define commonly used default
paths (without configuring them in CMake). This is easiest if this logic
lived in `Target` (since then we have access to the associated
`Platform`).
2026-04-19 06:54:45 +01:00
Charles Zablit 28c43a6aa1 [lldb][windows] do not use ConPTY in tests (#192657) 2026-04-18 15:27:19 +02:00
Jonas Devlieghere 029abe6730 [lldb] Store the dummy target in the selected execution context (#190496)
Store the dummy target in the selected execution context. There's no
reason for everybody to have to independently fall back to the dummy
target.
2026-04-17 18:29:08 -07:00
Med Ismail Bennani 8d106eb976 [lldb/Target] Unify frame provider descriptor and chain IDs (#190712)
Replace the two separate ID systems for frame providers — hash-based
descriptor IDs in Target and sequential chain IDs in Thread — with a
single monotonically increasing counter in Target.

Provider IDs are now assigned by
Target::AddScriptedFrameProviderDescriptor
and used directly as the chain ID in Thread, so
RegisterScriptedFrameProvider
returns the same ID used by 'bt --provider'. Also add duplicate
detection to
emit a warning when registering a provider with the same class name and
arguments twice.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-04-08 14:20:25 -07:00
Med Ismail Bennani a030dfb53b [lldb] Add --provider option to thread backtrace (#181071) 2026-04-07 11:55:30 -07:00
Michael BuchandAdrian Prantl e03b73138e [lldb] Add setting to specify (by name) which module's scripting resources can be auto-loaded (#188722)
* Depends on: https://github.com/llvm/llvm-project/pull/189696

This is part of [this
RFC](https://discourse.llvm.org/t/rfc-lldb-moving-libc-data-formatters-out-of-lldb/89591)
which is about turning the libc++ data-formatters into auto-loadable
Python scripts.

Eventually we want the Python data-formatters for `libc++` to be
automatically loaded without requiring user opt-in (since that's how the
builtin formatters have always worked and, in my opinion, we can't
transition to an opt-in model if users have always had the
data-formatters available). To do so we need a way to distinguish which
modules we can *always* auto-load from safe-paths, and which require
`target.load-script-from-symbol-file` to be set to `true`.

This patch adds a setting (`target.auto-load-modules`) that is a
dictionary from module-name to the `LoadScriptFromSymFile` enum,
indicating how the scripts for that module are to be loaded.

Making this a setting also means a user can disable any auto-loading by
clearing it. By default the setting is currently empty. Eventually we'll
want it to contain `libc++.1=true` (and possibly other names which the
`libc++` dylib can commonly have).

**Considerations**:
* I thought about adding an `IsAutoLoadable` API to `FileSpec` and set
it for those that can be auto-loaded. Then we wouldn't have to return
two lists from `LocateExecutableScriptingResources`. I just felt like
`FileSpec` was too high-level of a structure to hold such information so
I opted for the `llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>`.
If people favour one approach over the other, I'm happy to reconsider

**AI Usage**:
* Used Claude to generate the unit-test cases and shell tests. Reviewed
and cleaned them up myself.

---------

Co-authored-by: Adrian Prantl <adrian.prantl@gmail.com>
2026-04-07 13:43:35 +00:00
Michael Buch 116b045b1e [lldb] Make argument to ConstString::AsCString explicit (#190183)
This patch makes the default parameter to ConstString::AsCString
explicit. Currently it defaults to `nullptr`. However, there a bunch of
callsites that do `printf("%s", foo.AsCString())`, which is UB (I have
at least 1 crash on me where this was the root cause).

Alternatively we could change the default to `""` instead of `nullptr`,
but code that did `if (foo.AsCString())` would then change meaning.

Command I ran to generate this patch:
```
rg "\.AsCString\(\)" lldb -l | xargs sed -i '' 's/\.AsCString()/.AsCString(nullptr)/g'
```

There's also a commonly used `Status::AsCString` with a default
parameter. So I added a temporary:
```
const char *AsCString(std::nullptr_t) const = delete;
```
overload to `Status`, and fixed all the compile errors.

In a follow-up PR I intend to change the callsites that do `printf("%s",
foo.AsCString(nullptr)` to pass `""` as the fallback parameter. Another
dangrous pattern is `std::string(error.AsCString(nullptr))`

rdar://171219173
2026-04-07 13:39:48 +00:00
Jonas Devlieghere f866ef202c [lldb] Bring more diagnostics in compliance with our coding standards (#190410)
The LLVM Coding Standards [1] specify that:

> [T]o match error message styles commonly produced by other tools,
> start the first sentence with a lowercase letter, and finish the last
> sentence without a period, if it would end in one otherwise.

Historically, that hasn't been something we've enforced in LLDB, but in
the past year or so I've started to pay more attention to this in code
reviews. This PR brings more error messages in compliance, further
increasing consistency.

I also adopted `createStringErrorV` where it improved the code as a
drive-by for lines I was already touching.

[1] https://llvm.org/docs/CodingStandards.html#error-and-warning-messages

Assisted-by: Claude Code
2026-04-05 10:41:47 -07:00
Jonas Devlieghere 271a08889b [lldb] Load scripts from code signed dSYM bundles (#189444)
LLDB automatically discovers, but doesn't automatically load, scripts in
the dSYM bundle. This is to prevent running untrusted code. Users can
choose to import the script manually or toggle a global setting to
override this policy. This isn't a great user experience: the former
quickly becomes tedious and the latter leads to decreased security.

This PR offers a middle ground that allows LLDB to automatically load
scripts from trusted dSYM bundles. Trusted here means that the bundle
was signed with a certificate trusted by the system. This can be a
locally created certificate (but not an ad-hoc certificate) or a
certificate from a trusted vendor.
2026-04-03 17:04:47 +00:00
Jonas Devlieghere fd68fa98fc [lldb] Remove unnecessary calls to ConstString::AsCString (NFC) (#190298)
Replace calls to `ConstString::AsCString` with
`ConstString::GetString(Ref)` where appropriate.

Assisted-by: Claude Code
2026-04-03 16:11:23 +00:00
Michael Buch f91124a55b [lldb][Module] Only call LoadScriptingResourceInTarget via ModuleList (#190136)
This patch is motivated by
https://github.com/llvm/llvm-project/pull/189943, where we would like to
print the "these module scripts weren't loaded" warning for *all*
modules batched together. I.e., we want to print the warning *after* all
the script loading attempts, not from within each attempt.

To do so we want to hoist the `ReportWarning` calls in
`Module::LoadScriptingResourceInTarget` out into the callsites. But if
we do that, the callers have to remember to print the warnings. To avoid
this, we redirect all callsites to use
`ModuleList::LoadScriptingResourceInTarget`, which will be responsible
for printing the warnings.

To avoid future accidental uses of
`Module::LoadScriptingResourceInTarget` I moved the API into
`ModuleList` and made it `private`.
2026-04-03 07:03:11 +00:00
David Spickett 0f75ecf232 [lldb] Only create RegisterTypeBuilderClang plugin once (#189393)
This plugin creates types based on information from target XML, which is
parsed only once per session. It has internal logic to reuse created
types, but the plugin itself was being remade every time a type was
requested.
2026-03-31 09:33:44 +01:00
Charles Zablit 87085a8705 [lldb-dap][windows] don't use the ConPTY in internalConsole mode (#186472)
In `internalConsole` mode (especially in VSCode), lldb-dap should not
use the ConPTY to read the process' output. This is because the
internalConsole is not a real terminal, there is no reason to use
terminal emulation, which will add arbitrary line returns to the output.

Instead, this patch introduces the `eLaunchFlagUsePipes` flag in
ProcessLaunchInfo which tells ProcessLaunchWindows to use regular pipes
instead of a ConPTY to get the stdin and stdout of the debuggee.

The result is that output which is supposed to be on a single line is
properly rendered.

---

The following example is when debugging a program through lldb-dap on
Windows. The program prints the numbers 0 through 999 on a single line.

# Before
<img width="2214" height="672" alt="Screenshot 2026-03-13 at 17 07 35"
src="https://github.com/user-attachments/assets/26292d11-2288-46ee-a6d2-0b66bfa41288"
/>

The line is split if it's longer than 80 characters (default terminal
size).

# After
<img width="2215" height="689" alt="Screenshot 2026-03-13 at 17 12 39"
src="https://github.com/user-attachments/assets/c9cad9af-b1ce-4c7b-91d5-f684e48e64ca"
/>

The line is correctly printed as a single line.

rdar://172491166
2026-03-30 18:33:45 +01:00
Sergei Barannikov 22cfe6f39d [lldb] Make single-argument Address constructor explicit (NFC) (#189035)
This is to highlight places where we (probably unintentionally)
construct an `Address` object from an already resolved address, making
it unresolved again.
See the changes in `DynamicLoaderDarwin.cpp` for a quick example.

Also, use this constructor instead of `Address(lldb::addr_t file_addr,
const SectionList *section_list)` when `section_list` is `nullptr`.
2026-03-27 20:22:48 +03:00
Med Ismail Bennani e1cd55879b [lldb] Fix circular dependency and deadlock in scripted frame providers (#187411)
When a scripted frame provider calls back into the thread's frame
machinery (e.g. via HandleCommand or EvaluateExpression), two problems
arise:

1. GetStackFrameList() re-enters the SyntheticStackFrameList
 construction, causing infinite recursion.
2. ClearStackFrames() tries to read-lock the StackFrameList's
 shared_mutex that is already write-locked by GetFramesUpTo,
 causing a deadlock.

This patch fixes those issues by tracking when a provider is actively
fetching frames via a per-host-thread map (m_provider_frames_by_thread)
keyed by HostThread. The map is pushed/popped in
SyntheticStackFrameList::FetchFramesUpTo before calling into the
provider. GetStackFrameList() checks it to route re-entrant calls:

- The provider's own host thread gets the parent frame list, preventing
circular dependency when get_frame_at_index calls back into
GetFrameAtIndex.
- The private state thread also gets the parent frame list, preventing
deadlock when a provider calls EvaluateExpression (which needs the
private state thread to process events).
- Other host threads proceed normally and block on the frame list mutex
until the provider finishes, getting the correct synthetic result.

ClearStackFrames() returns early if any provider is active, since the
frame state is shared and tearing it down while a provider is
mid-construction is both unnecessary and unsafe.

rdar://171558394

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-03-25 16:22:25 -07:00
Michael Buch 361987c01a [lldb][Module] Remove feedback_stream parameter from LoadScriptingResources (#186787)
I'm in the process of making `LoadScriptingResources` interactively ask
a user whether to load a script. I'd like to turn the existing warning
into the prompt. The simplest way to achieve this is to not print into a
`feedback_stream` parameter, and instead create a prompt right there.
This patch removes the `feedback_stream` parameter and emits a
`ReportWarning` instead. If we get around to adding the prompt instead
of the warning, those changes will be simpler to review. But even if we
don't end up replacing the warning with a prompt, moving away from
output parameters and towards more structured error reporting is a
nice-to-have (e.g., the `warning` prefix is now colored, IDEs have more
flexibility on how to present the warning, etc.).

For a command-line user nothing should change with this patch (apart
from `warning:` being highlighted).
2026-03-16 15:18:23 +00:00
Dave Lee e10833d845 [lldb] Replace make_error<StringError> with createStringError* (NFC) (#185748)
This makes the constructions of string errors more concise and more
consistent, mainly by removing the `inconvertibleErrorCode()`.
Additional changes replace `createStringError(formatv(...), ...)` with
`createStringErrorV(...)`.

Assisted-by: Claude
2026-03-11 10:46:55 -07:00
Michael Buch 447eba88c8 [lldb][Target] Allow eLanguageTypeAssembly to use ScratchTypeSystemClang (#183771)
After cleaning up some of our `LanguageType`/`SourceLangage`
round-tripping (see `7f51a2a47d2e706d04855b0e41690ebafa2b3238`), a CU
with `DW_LANG_MIPS_Assembler` will get a language type of
`eLanguageTypeAssembly` (as opposed to `eLanguageTypeMipsAssembler`).
Reason being that there is no `DW_LNAME_` (DWARFv6 language code) for
`MIPS Assembler`, only for generic `Assembly`. So it's not possible to
round-trip cleanly between pre-DWARFv6 and DWARFv6 language codes, which
LLDB relies on for storing language types (and will lean into more
heavily in the future). This broke a special provision we have where we
allow `ScratchTypeSystemClang` to be used when evaluating expressions in
assembly CUs (i.e., CUs where the debug-info explicitly sets the
language to assembly).

If we ever want to distinguish MIPS from other Assembly, the proper way
to do so is introduce a `DW_LNAME_Mips_Assembler`. For now, this patch
adds another case for `eLanguageTypeAssembly` in
`GetScratchTypeSystemForLanguage`.

The test is a bit quirky because it checks for error messages in all
cases. For the `TypeSystem`s to exist we would have to initialize the
`TypeSystem` plugins, which I couldn't find a precedent for. But happy
to hear other suggestions for testing

Fixes https://github.com/llvm/llvm-project/issues/183388
2026-03-02 17:06:13 +00:00
Jonas Devlieghere 091296f3e3 [lldb] Revert scripted symbol locator (#181945)
This revert #181334 and its follow-up PRs (including #181488, #181492,
#181493, #181494 and #181498) as well as Ismail's documentation changes
(#181594, #181717). The original commit causes a test failure in CI
(https://github.com/llvm/llvm-project/issues/181938) but the more I look
at the patch, the more I'm convinced it was not ready to land. It will
be easier to iterate on the feedback by re-landing this than by using
post-commit review.
2026-02-17 16:52:21 -08:00
Michael Buch 3f73c86909 [lldb][Target][NFC] Update error messages according to LLVM-coding style (#181795)
The [LLVM coding style
guide](https://llvm.org/docs/CodingStandards.html#error-and-warning-messages)
says:

> start the first sentence with a lowercase letter, and finish the last
sentence
> without a period

This patch updates the erorr messages added in
https://github.com/llvm/llvm-project/pull/179208 accordingly.

(addresses
https://github.com/llvm/llvm-project/pull/179208#issuecomment-3912273053)
2026-02-17 12:14:48 +00:00
rchamalaandRahul Reddy Chamala 945db33963 [lldb] Fix Windows build and remote test failure for ScriptedSymbolLocator (#181488)
## Summary
- Move `GetScriptedSymbolLocatorClassName()` from inline in `Target.h`
to out-of-line in `Target.cpp` to avoid collision with Windows
`winuser.h` `#define GetClassName GetClassNameW` macro.
- Replace `LaunchSimple(None, None, os.getcwd())` with
`lldbutil.run_to_breakpoint_do_run()` in `test_locate_source_file` to
fix test failure on remote platforms where the local working directory
doesn't exist.

Fixes CI failures from #181334.

## Test plan
- [ ] Windows (aarch64-windows) build passes
- [ ] remote-linux-win test passes
- [ ] Existing ScriptedSymbolLocator tests pass on local platforms

Co-authored-by: Rahul Reddy Chamala <rachamal@meta.com>
2026-02-14 17:04:38 +00:00
rchamalaandRahul Reddy Chamala 1ee03d1e09 [lldb] Add ScriptedSymbolLocator plugin for source file resolution (#181334)
## Summary                                                        
                                                                    
Based on discussion from
[RFC](https://discourse.llvm.org/t/rfc-python-callback-for-source-file-resolution/83545),
this PR adds a new `SymbolLocatorScripted` plugin that allows Python
scripts to implement custom symbol and source file resolution logic.
This enables downstream users to build custom symbol servers, source
file remapping, and build artifact resolution entirely in Python.
                                                                    
  ### Changes

- Adds `LocateSourceFile()` to the SymbolLocator plugin interface,
called during source path resolution with a fully loaded `ModuleSP`, so
the plugin has access to the module's UUID, file paths, and symbols.
- Adds `SymbolLocatorScripted` plugin that delegates all four
SymbolLocator methods (`LocateExecutableObjectFile`,
`LocateExecutableSymbolFile`, `DownloadObjectAndSymbolFile`,
`LocateSourceFile`) to a user-provided Python class.
- Adds `ScriptedSymbolLocatorPythonInterface` to bridge C++ calls to
Python, with proper GIL management and error handling.
- Results for `LocateSourceFile` are cached per (module UUID, source
file) pair.
- The Python class is configured via: `settings set
plugin.symbol-locator.scripted.script-class module.ClassName`

  ### Python class interface

  ```python
  class MyLocator:
      def __init__(self, exe_ctx, args): ...
      def locate_source_file(self, module, original_source_file):
  ...
      def locate_executable_object_file(self, module_spec): ...
      def locate_executable_symbol_file(self, module_spec,
  default_search_paths): ...
      def download_object_and_symbol_file(self, module_spec,
  force_lookup, copy_executable): ...
```

  ### Test plan
```
  Added TestScriptedSymbolLocator.py with 3 test cases:
  - test_locate_source_file — verifies the locator resolves source
  files, receives a valid SBModule with UUID, and remaps paths correctly
  - test_locate_source_file_none_fallthrough — verifies returning
None falls through to default LLDB resolution, and that having no script
  class set works normally
  - test_invalid_script_class — verifies graceful handling of
  invalid class names without crashing
```

Co-authored-by: Rahul Reddy Chamala <rachamal@fb.com>
2026-02-14 07:39:00 -08:00
Nerixyz cdbe28887b [LLDB] Set and verify paths of properties from tablegen (#179524)
In #168245, I attempted to dump the available settings to Markdown. That
required a full build of LLDB. However, to build the docs, only the swig
wrappers should need to be compiled. The comment was that we should be
able to use the definitions from the TableGen files.

Currently, the property definitions in don't have information about the
path where they will be available. They only contain a `Definition`
which groups properties, so they can be added to
`OptionValueProperties`.

With this PR, I'm adding the path for each property definition. For
example, `symbols.enable-external-lookup` would have `Name =
enable-external-lookup, Path = symbols`. In LLDB itself, we don't need
this path, we only need it for the documentation. To avoid mismatches
between the actual path and the declared one, I added a debug-only check
when a property group is added to a parent
(`OptionValueProperties::AppendProperty`).

The TableGen emitter for the properties now additionally emits
`g_{definition}_properties_def`, which includes both the array of
properties and the expected path. This constant has to be used to
initialize a `OptionValueProperties`.

I couldn't test this for everything (e.g. IntelPT or ProcessKDP), but
the necessary changes are simple: (1) set the `Path` in the TableGen
file, (2) update `initialize` to use `_def`.
2026-02-10 19:43:29 +01:00
Adrian Vogelsgesang 943782be5a [lldb] Broadcast eBroadcastBitStackChanged when frame providers change (#171482)
We want to reload the call stack whenever the frame providers are
updated. To do so, we now emit a `eBroadcastBitStackChanged` on all
threads whenever any changes to the frame providers take place.

I found this very useful while iterating on a frame provider in
lldb-dap. So far, the new frame provider only took effect after
continuing execution. Now the backtrace in VS-Code gets refreshed
immediately upon running `target frame-provider add`.
2026-02-05 21:00:23 +01:00