969 Commits
Author SHA1 Message Date
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
Sergei Druzhkov 0c38875e1a [lldb] Revert stop-on-fork and stop-on-vfork (#207663)
This was causing failures on green dragon
2026-07-06 09:14:59 +01:00
Sergei Druzhkov 38ecfd2c0d [lldb] Add stop-on-fork and stop-on-vfork settings (#188710)
Added support for new `target.process.stop-on-fork` and
`target.process.stop-on-vfork` settings. GDB already has ability to set
[catchpoints](https://www.sourceware.org/gdb/current/onlinedocs/gdb.html/Set-Catchpoints.html)
on `fork` and `vfork`, so having this feature in LLDB might be useful
(e.g. use it to get pid of new process and attach to the new process
from different console).
2026-07-04 13:49:50 +03:00
Med Ismail Bennani 6b3e7235ed [lldb] Harden PolicyStack against cross-thread Guard misuse (#195774)
Two related correctness/clarity improvements to the `Policy`
infrastructure introduced by 504a112:

`PolicyStack::Guard` now stores the std::thread::id of the thread that
created it. Destruction and move operations call
`llvm::report_fatal_error` when they happen on a different thread, since
the `PolicyStack` is `thread_local`: popping from the wrong thread would
silently corrupt that thread's stack.

`Push`/`Pop` on `PolicyStack` are now private. Callers go through named
factories (`PushPrivateState`, `PushPublicStateRunningExpression`) that
return RAII Guards. The transition factories on Policy
(`CreatePrivateState`, `CreatePublicStateRunningExpression`) inherit
from `PolicyStack::Get().Current()` and apply their named change on top,
so pushed policies preserve existing stack state rather than resetting
unrelated fields. `CreatePublicState` remains the baseline reference
value (returns a default `Policy{}`); the stack returns to public state
by popping the private guards, not by pushing a "public" policy on top.

----

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-01 16:44:20 -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
Jason MolendaandJonas Devlieghere 31340a9222 [lldb] Add memory region info cache to Process (#206208)
Every time a memory region is queried in the inferior with a
ProcessGDBRemote connection, lldb needs to send a packet requesting the
information. When we are querying multiple addresses within the same
region, this can result in many redundant packets - e.g. to test for
whether an address is in stack memory during a backtrace.

This adds a MemoryRegionInfoCache wrapper around RangeDataVector to save
the memory regions that we query, and supply them to future queries. The
cache is flushed on any process resume in the same way that the memory
cache is; the valid pages may change as a program executes.

This PR started as a combination of this cache plus extensions to gdb
remote serial protocol packets so the debug stub can provide memory
region infos when we have a public stop (e.g. the info about each
thread's stack memory region) - including changes to both debugserver
and ProcessGDBRemote to implement that (
https://github.com/llvm/llvm-project/pull/202509 ). I'm separating out
the two pieces into separate patchsets. The test in this PR retains the
full code in the .c file that I will need to test the expedited memory
region infos still, even though it doesn't do antyhing but launch the
inferior process in the current tests.

rdar://179067896

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2026-06-30 18:51:33 +00:00
Greg Clayton 45afced2e7 Fix ProcessElfCore::FindModuleUUID() so it work with symlinks. (#206601)
Resumbitting https://github.com/llvm/llvm-project/pull/205235 with
disabled parallel module loading to fix buildbot deadlock.

ProcessElfCore was reading the NT_FILE list and using that to help
FindModuleUUID to provide UUID information when loading core files. The
NT_FILE list contains resolved paths only, while the
DynamicLoaderPOSIXDYLD plug-in was using paths found in the r_debug
structure which contains a linked list of all of the shared libraries in
a process. The issue was these paths could be symlinks which would cause
ProcessELFCore::FindModuleUUID(...) to fail because the paths wouldn't
match up. This led to the ProcessELFCore often not being able to provide
UUIDs for shared libraries and cause the incorrect binaries to be loaded
from the current machine even when the shared library UUIDs don't match.

The solution was to add the ability for a ModuleSpec to contain a load
address for the shared library. This allows ProcessELFCore to uniquely
identify a library regardless of the name used in NT_FILE. We can now
correctly supply the UUID from the .gnu-build-id to any binaries which
use symlinks when linking, but have differing resolved paths to the
libraries.

The process virtual function for finding a UUID was changed from:

virtual lldb_private::UUID FindModuleUUID(const llvm::StringRef path);
to:

    virtual bool FindModuleUUID(ModuleSpec &spec);
to allow Process::FindModuleUUID to rely on other data in the ModuleSpec
since the path isn't enough.

We will be able to use the ModuleSpec's load address for creating a
module from a ModuleSpec, but that isn't in this PR.
2026-06-30 10:44:00 -07:00
David Spickett c124b0e7f6 Revert "Fix ProcessElfCore::FindModuleUUID() so it work with symlinks." (#206062)
Reverts llvm/llvm-project#205235

Due to timeouts reported in GitHub CI and reproduced locally by me. 
See https://github.com/llvm/llvm-project/issues/205879 for details.
2026-06-26 13:58:13 +00:00
Greg Clayton a218ee3ef4 Fix ProcessElfCore::FindModuleUUID() so it work with symlinks. (#205235)
ProcessElfCore was reading the NT_FILE list and using that to help
FindModuleUUID to provide UUID information when loading core files. The
NT_FILE list contains resolved paths only, while the
DynamicLoaderPOSIXDYLD plug-in was using paths found in the r_debug
structure which contains a linked list of all of the shared libraries in
a process. The issue was these paths could be symlinks which would cause
ProcessELFCore::FindModuleUUID(...) to fail because the paths wouldn't
match up. This led to the ProcessELFCore often not being able to provide
UUIDs for shared libraries and cause the incorrect binaries to be loaded
from the current machine even when the shared library UUIDs don't match.

The solution was to add the ability for a ModuleSpec to contain a load
address for the shared library. This allows ProcessELFCore to uniquely
identify a library regardless of the name used in NT_FILE. We can now
correctly supply the UUID from the .gnu-build-id to any binaries which
use symlinks when linking, but have differing resolved paths to the
libraries.

The process virtual function for finding a UUID was changed from:

virtual lldb_private::UUID FindModuleUUID(const llvm::StringRef path);

to:

        virtual bool FindModuleUUID(ModuleSpec &spec);

to allow Process::FindModuleUUID to rely on other data in the ModuleSpec
since the path isn't enough.

We will be able to use the ModuleSpec's load address for creating a
module from a ModuleSpec, but that isn't in this PR.
2026-06-24 20:27:50 -07:00
Charles Zablit 1ef2f3b98b [NFC][lldb][Windows] Move ProcessIOHandler in Target (#202353)
This patch merges `IOHandlerProcessSTDIO` and
`IOHandlerProcessSTDIOWindows` in one file: `ProcessIOHandler.h`.

This is an NFC change which reduces the size of `Process.cpp` and allows
to reuse `IOHandlerProcessSTDIOWindows` in GDBRemote, ahead of
https://github.com/llvm/llvm-project/pull/201638.
2026-06-08 16:58:58 +01:00
Felipe de Azevedo Piovezan 96c0f5ad27 [lldb] Use MemoryCache in Process::ReadRangesFromMemory (#201166)
There are scenarios (especially in the ObjectiveC metadata reading) in
which multiple strings are read over and over again, but through
different code paths. In order to make that part of the code use
MultiMemRead effectively, the memory cache must be integrated into
ReadRangesFromMemory before we can migrate the string reading to
vectorized version.
2026-06-04 08:17:14 +01:00
Felipe de Azevedo Piovezan fb8cb1b3d0 [lldb] Strip pointer metadata in ReadMemoryRanges (#200398)
The Process base class is generally responsible for fixing pointer
metadata before delegating memory reads to concrete Process
specializations. However, ReadMemoryRanges was a direct path into the
derived classes, which made it so that pointer metadata was never
stripped.

This commit creates a non-virtual ReadMemoryRanges in Process, which
clears pointer metadata, before delegating to the new virtual method
DoReadMemoryRanges. This also allows, in the future, to plug into the
memory cache system.
2026-06-01 08:21:59 +00:00
Felipe de Azevedo Piovezan 18ddec75ba [lldb] Use private stop for breakpoint-delaying decision (#199639) 2026-05-27 07:21:28 +02: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
Felipe de Azevedo Piovezan cbd69a684a [lldb] Fix delayed breakpoints on running processes (#198747)
Breakpoints should never be delayed on a running process, as they can
immediately affect program execution.
2026-05-20 17:30:09 +00:00
Felipe de Azevedo Piovezan a2134b8b75 [lldb][NFC] Sink eager breakpoint logic into ExecuteBreakpointSiteAction (#198741)
A future patch will want to control whether all breakpoints are eager or
not based on whether the process is running. Sinking the logic allows
for a smaller diff.
2026-05-20 18:04:31 +01:00
Jonas Devlieghere 7380aebcf9 [lldb] Fix data race on Process::FindPlugin's unique-id counter (#197807)
g_process_unique_id is a function-local static used to hand out unique
IDs to each Process. It was a plain uint32_t, so concurrent
SBTarget::LoadCore / Target::CreateProcess calls raced on the increment.

Make it std::atomic<uint32_t>. Prefix operator++ on std::atomic is
already an atomic fetch_add that returns the new value, so the call
sites are unchanged.

Found by ThreadSanitizer as part of #197792.
2026-05-14 21:32:34 +00:00
Jasmine Tang 774e82b179 [LLDB] Extract process arguments from core dump for Linux (#185338)
This PR adds the ability for lldb to print out how to reproduce the
crash by printing out the arguments used with the process on Linux.

This is implemented by extracting arguments from the field `pr_psargs`
of the struct `ELFLinuxPrPsInfo`, a note entries of an ELF coredump
file.

A limitation of this approach is that the `pr_psargs` char array is only
80 character long, so the command arguments that triggers a core dump
might not be fully captured. To alleviate this, if the arguments
extracted matches the maximal length, we emit `(command may be
truncated)` message when printing the arguments to the user.

Calling `process status -v` also prints out said arguments for users, as
suggested by #156427.

Not implemented for BSD-based OSs.

Assisted with Claude.
2026-05-13 15:32:45 +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
Felipe de Azevedo Piovezan 11d15c38c1 [lldb] Flush delayed breakpoints before eagerly changing one (#195815)
See the discussion in https://github.com/llvm/llvm-project/pull/192971

When LLDB makes the decision to eagerly send a breakpoint packet, it
should first ensure the delayed breakpoints are flushed, as they may
interfere with the eager breakpoint that is about to be changed.

Implementation note: we could have included the eager breakpoint in the
    batch that is about to be flushed. However, it's important to get
    information about the error status of this eager breakpoint, and the
current APIs dont make it easy to distinguish which breakpoint caused an
    error.
2026-05-05 12:33:40 +00:00
Felipe de Azevedo Piovezan f5eb7a9ef4 [lldb] Disable delayed breakpoints on Windows (#195241)
Tests started failing on a mysterious way there, potentially related to:
https://github.com/llvm/llvm-project/issues/191222
2026-05-01 09:33:02 +00:00
Felipe de Azevedo Piovezan 776ee6f0dd [lldb] Implement delayed breakpoints (#192971)
This patch changes the Process class so that it delays *physically*
enabling/disabling breakpoints until the process is about to
resume/detach/be destroyed, potentially reducing the packets transmitted
by batching all breakpoints together.

Most classes only need to know whether a breakpoint is "logically"
enabled, as opposed to "physically" enabled (i.e. the remote server has
actually enabled the breakpoint). However, lower level classes like
derived Process classes, or StopInfo may actually need to know whether
the breakpoint was physically enabled. As such, this commit also adds a
"IsPhysicallyEnabled" API.

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-01 07:52:46 +01:00
Felipe de Azevedo Piovezan 3e8fbb278e [lldb][NFC] Move BreakpointSite::IsEnabled/SetEnabled into Process (#192964)
The Process class is the one responsible for managing the state of a
BreakpointSite inside the process. As such, it should be the one
answering questions about the state of the site.

Future patches will make this even more important by introducing a
"logical" is enabled, by delaying the moment in which breakpoints are
actually updated in the process.


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-04-30 07:43:54 +01: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
Philip DePetro 7b336dcfce [lldb] Allow forks to occur in expression evaluation (#184815)
@jimingham You had suggested to @clayborg that we should call DidFork(),
DidVFork() and DidVForkDone() after a corresponding stop in expression
evaluation. Those functions require parameters that are private to the
specific child StopInfo class. I went with reusing the existing
StopInfo::PerformAction() virtual function, rather than create a new one
just for this purpose.
2026-04-24 11:48:17 -07:00
Sergei Barannikov 9a63d04447 [lldb] Fix inappropriate uses of LLDB_INVALID_IMAGE_TOKEN (#193365)
It may not be obvious from its name, but `Process::m_image_tokens`
contains loaded image addresses, not "tokens". The tokens are actually
indices into that array.
2026-04-22 18:53:38 +03:00
Jonas Devlieghere 9332051a2e [lldb] Add target.process.always-run-thread-names setting (#192870)
Add a process setting that keeps named threads running during
single-stepping operations. Some programs install in-process Mach
exception handler threads that must continue running to forward
exceptions. When lldb single-steps and suspends all other threads, these
handler threads stall, potentially causing a deadlock if the stepped
instruction raises an exception.

The new `target.process.always-run-thread-names` setting accepts a list
of thread name strings. In `ThreadList::WillResume`, threads whose names
match an entry in this list are resumed with `eStateRunning` instead of
`eStateSuspended`, ensuring they appear in vCont packets even during
single-thread stepping.

rdar://175038920
2026-04-20 13:14:56 -07:00
GeorgeHuyuboandGeorge Hu 02fdc8f8de [lldb] Fix stale Symbol pointer crash in statusline after 'target symbols add' (#188377)
Context: 
lldb might crash when running to a debuggee crashing state and do a
target symbols add command.
Backtrace: 
```
 #0 0x000055ca6790dc65 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/hyubo/osmeta/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:848:11
 #1 0x000055ca6790e434 PrintStackTraceSignalHandler(void*) /home/hyubo/osmeta/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:931:1
 #2 0x000055ca6790b839 llvm::sys::RunSignalHandlers() /home/hyubo/osmeta/external/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x000055ca6790ff6b SignalHandler(int, siginfo_t*, void*) /home/hyubo/osmeta/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:430:38
 #4 0x00007fe9e5e44560 __restore_rt /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/signal/../sysdeps/unix/sysv/linux/libc_sigaction.c:13:0
 #5 0x00007fe9e5f25649 syscall /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/misc/../sysdeps/unix/sysv/linux/x86_64/syscall.S:38:0
 #6 0x00007fe9ec649170 SignalHandler(int, siginfo_t*, void*) /home/hyubo/osmeta/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:429:7
 #7 0x00007fe9e5e44560 __restore_rt /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/signal/../sysdeps/unix/sysv/linux/libc_sigaction.c:13:0
 #8 0x00007fe9ebb77bf0 lldb_private::operator<(lldb_private::StackID const&, lldb_private::StackID const&) /home/hyubo/osmeta/external/llvm-project/lldb/source/Target/StackID.cpp:99:16
 #9 0x00007fe9ebb6863d CompareStackID(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&) /home/hyubo/osmeta/external/llvm-project/lldb/source/Target/StackFrameList.cpp:683:3
#10 0x00007fe9ebb6d049 bool __gnu_cxx::__ops::_Iter_comp_val<bool (*)(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&)>::operator()<__gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, lldb_private::StackID const>(__gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, lldb_private::StackID const&) /mnt/gvfs/third-party2/libgcc/d1129753c8361ac8e9453c0f4291337a4507ebe6/11.x/platform010/5684a5a/include/c++/11.x/bits/predefined_ops.h:196:4
#11 0x00007fe9ebb6cefe __gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>> std::__lower_bound<__gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, lldb_private::StackID, __gnu_cxx::__ops::_Iter_comp_val<bool (*)(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&)>>(__gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, __gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, lldb_private::StackID const&, __gnu_cxx::__ops::_Iter_comp_val<bool (*)(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&)>) /mnt/gvfs/third-party2/libgcc/d1129753c8361ac8e9453c0f4291337a4507ebe6/11.x/platform010/5684a5a/include/c++/11.x/bits/stl_algobase.h:1464:8
#12 0x00007fe9ebb6cdfc __gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>> std::lower_bound<__gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, lldb_private::StackID, bool (*)(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&)>(__gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, __gnu_cxx::__normal_iterator<std::shared_ptr<lldb_private::StackFrame>*, std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>>, lldb_private::StackID const&, bool (*)(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&)) /mnt/gvfs/third-party2/libgcc/d1129753c8361ac8e9453c0f4291337a4507ebe6/11.x/platform010/5684a5a/include/c++/11.x/bits/stl_algo.h:2062:14
#13 0x00007fe9ebb685fa auto llvm::lower_bound<std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>&, lldb_private::StackID const&, bool (*)(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&)>(std::vector<std::shared_ptr<lldb_private::StackFrame>, std::allocator<std::shared_ptr<lldb_private::StackFrame>>>&, lldb_private::StackID const&, bool (*)(std::shared_ptr<lldb_private::StackFrame> const&, lldb_private::StackID const&)) /home/hyubo/osmeta/external/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2001:10
#14 0x00007fe9ebb68441 lldb_private::StackFrameList::GetFrameWithStackID(lldb_private::StackID const&) /home/hyubo/osmeta/external/llvm-project/lldb/source/Target/StackFrameList.cpp:697:11
#15 0x00007fe9ebbee395 lldb_private::Thread::GetFrameWithStackID(lldb_private::StackID const&) /home/hyubo/osmeta/external/llvm-project/lldb/include/lldb/Target/Thread.h:459:7
#16 0x00007fe9ebac7cf7 lldb_private::ExecutionContextRef::GetFrameSP() const /home/hyubo/osmeta/external/llvm-project/lldb/source/Target/ExecutionContext.cpp:643:25
#17 0x00007fe9ebac80e1 lldb_private::GetStoppedExecutionContext(lldb_private::ExecutionContextRef const*) /home/hyubo/osmeta/external/llvm-project/lldb/source/Target/ExecutionContext.cpp:164:34
#18 0x00007fe9eb8903fa lldb_private::Statusline::Redraw(std::optional<lldb_private::ExecutionContextRef>) /home/hyubo/osmeta/external/llvm-project/lldb/source/Core/Statusline.cpp:139:7
#19 0x00007fe9eb7ac8be lldb_private::Debugger::RedrawStatusline(std::optional<lldb_private::ExecutionContextRef>) /home/hyubo/osmeta/external/llvm-project/lldb/source/Core/Debugger.cpp:1233:3
#20 0x00007fe9eb804d1e lldb_private::IOHandlerEditline::RedrawCallback() /home/hyubo/osmeta/external/llvm-project/lldb/source/Core/IOHandler.cpp:446:3
#21 0x00007fe9eb80aa81 lldb_private::IOHandlerEditline::IOHandlerEditline(lldb_private::Debugger&, lldb_private::IOHandler::Type, std::shared_ptr<lldb_private::File> const&, std::shared_ptr<lldb_private::LockableStreamFile> const&, std::shared_ptr<lldb_private::LockableStreamFile> const&, unsigned int, char const*, llvm::StringRef, llvm::StringRef, bool, bool, unsigned int, lldb_private::IOHandlerDelegate&)::$_2::operator()() const /home/hyubo/osmeta/external/llvm-project/lldb/source/Core/IOHandler.cpp:262:73
#22 0x00007fe9eb80aa5d void llvm::detail::UniqueFunctionBase<void>::CallImpl<lldb_private::IOHandlerEditline::IOHandlerEditline(lldb_private::Debugger&, lldb_private::IOHandler::Type, std::shared_ptr<lldb_private::File> const&, std::shared_ptr<lldb_private::LockableStreamFile> const&, std::shared_ptr<lldb_private::LockableStreamFile> const&, unsigned int, char const*, llvm::StringRef, llvm::StringRef, bool, bool, unsigned int, lldb_private::IOHandlerDelegate&)::$_2>(void*) /home/hyubo/osmeta/external/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:213:5
#23 0x00007fe9eb93bfbf llvm::unique_function<void ()>::operator()() /home/hyubo/osmeta/external/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:365:5
#24 0x00007fe9eb93bb80 lldb_private::Editline::GetCharacter(wchar_t*) /home/hyubo/osmeta/external/llvm-project/lldb/source/Host/common/Editline.cpp:0:5
#25 0x00007fe9eb941a18 lldb_private::Editline::ConfigureEditor(bool)::$_0::operator()(editline*, wchar_t*) const /home/hyubo/osmeta/external/llvm-project/lldb/source/Host/common/Editline.cpp:1287:5
#26 0x00007fe9eb9419e2 lldb_private::Editline::ConfigureEditor(bool)::$_0::__invoke(editline*, wchar_t*) /home/hyubo/osmeta/external/llvm-project/lldb/source/Host/common/Editline.cpp:1286:27
#27 0x00007fe9f3384e26 el_getc /home/engshare/third-party2/libedit/3.1/src/libedit/src/read.c:439:14
#28 0x00007fe9f3384e26 el_getc /home/engshare/third-party2/libedit/3.1/src/libedit/src/read.c:400:1
#29 0x00007fe9f3384f90 read_getcmd /home/engshare/third-party2/libedit/3.1/src/libedit/src/read.c:247:14
#30 0x00007fe9f3384f90 el_gets /home/engshare/third-party2/libedit/3.1/src/libedit/src/read.c:586:14
#31 0x00007fe9eb9409f3 lldb_private::Editline::GetLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, bool&) /home/hyubo/osmeta/external/llvm-project/lldb/source/Host/common/Editline.cpp:1636:16
#32 0x00007fe9eb8044d7 lldb_private::IOHandlerEditline::GetLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, bool&) /home/hyubo/osmeta/external/llvm-project/lldb/source/Core/IOHandler.cpp:339:5
#33 0x00007fe9eb805609 lldb_private::IOHandlerEditline::Run() /home/hyubo/osmeta/external/llvm-project/lldb/source/Core/IOHandler.cpp:600:11
#34 0x00007fe9eb7b214c lldb_private::Debugger::RunIOHandlers() /home/hyubo/osmeta/external/llvm-project/lldb/source/Core/Debugger.cpp:1280:16
#35 0x00007fe9eb98f00f lldb_private::CommandInterpreter::RunCommandInterpreter(lldb_private::CommandInterpreterRunOptions&) /home/hyubo/osmeta/external/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:3620:16
#36 0x00007fe9eb4f0e09 lldb::SBDebugger::RunCommandInterpreter(bool, bool) /home/hyubo/osmeta/external/llvm-project/lldb/source/API/SBDebugger.cpp:1234:42
#37 0x000055ca6788d6b0 Driver::MainLoop() /home/hyubo/osmeta/external/llvm-project/lldb/tools/driver/Driver.cpp:677:3
#38 0x000055ca6788e226 main /home/hyubo/osmeta/external/llvm-project/lldb/tools/driver/Driver.cpp:887:17
#39 0x00007fe9e5e2c657 __libc_start_call_main /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#40 0x00007fe9e5e2c718 call_init /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../csu/libc-start.c:128:20
#41 0x00007fe9e5e2c718 __libc_start_main@GLIBC_2.2.5 /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../csu/libc-start.c:379:5
#42 0x000055ca67889a11 _start /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../sysdeps/x86_64/start.S:118:0
Segmentation fault (core dumped)
```

When `target symbols add` is run, `Symtab::AddSymbol()` can reallocate
the underlying `std::vector<Symbol>` and resize it, invalidating all
existing Symbol* pointers. While `Process::Flush()` clears stale stack
frames, the statusline caches its own `ExecutionContextRef` containing a
`StackID` with a `SymbolContextScope*` (which can be a `Symbol*`). This
cached reference is not cleared by `Process::Flush()`, so the next
statusline redraw accesses a dangling pointer and crashes.

Fix this by adding `Statusline::Flush()` which clears the cached frame,
`Debugger::Flush()` which forwards to it under the statusline mutex, and
calling `Debugger::Flush()` from `Process::Flush()` so that all flush
paths (symbol add, exec, module load) also invalidate the statusline's
stale state.

After this fix, lldb is not crashing anymore, new symbols from a symbol
file are correctly loaded

---------

Co-authored-by: George Hu <georgehuyubo@gmail.com>
2026-04-15 11:43:07 -07:00
Med Ismail Bennani 348061d58d [lldb] Fix deadlock when scripted frame providers load on private state thread (#191913)
Frame providers are an overlay on top of the parent reality (the
unwinder stack). The private state thread (PST) manages the stop of that
parent reality, so the correct view for PST logic IS the parent --
providers should only be applied once the process has settled and
clients query the stopped state.

When a scripted breakpoint's `was_hit` callback calls
`EvaluateExpression` on the PST, `RunThreadPlan` spawns an override PST
(Thread B) and reassigns `m_current_private_state_thread_sp` to it. Two
threads then need to see parent frames:

- Thread B (override PST): processes stop events via
`HandlePrivateEvent` -> `ShouldStop` -> `GetStackFrameList`. If it loads
a provider, the provider's Python code can acquire locks held by Thread
A, causing a deadlock.

- Thread A (original PST): processes events inline via
`FindNextEventInternal` -> `DoOnRemoval` -> `GetStackFrameList`. After
the override is created, `CurrentThreadIsPrivateStateThread` no longer
recognizes Thread A (it checks against
`m_current_private_state_thread_sp`, which now points to Thread B).

The existing re-entrancy guard in `GetStackFrameList` (e1cd558) only
triggers when a provider is already active. In the deadlock scenario,
provider loading is being initiated for the first time, so the guard
does not trigger.

This patch introduces `PrivateStateThreadGuard`, an RAII guard that sets
a `thread_local` flag checked by `GetStackFrameList` to return parent
frames instead of loading providers. The guard is activated in two
places:

- `RunPrivateStateThread`: for override PSTs only (identified via a new
`is_override` flag on `PrivateStateThread`). The original PST does not
set the guard here, so normal stepping still sees provider-augmented
frames.

- `RunThreadPlan`: for the original PST, scoped to the event processing
window when an override has been spawned.

rdar://174679105

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-04-14 17:33:57 -07:00
Jonas Devlieghere de0cb1cd04 [lldb] Upstream and adopt ReadUnsignedIntegersFromMemory in AppleObjCRuntimeV2 (#190564)
This PR upstreams ReadUnsignedIntegersFromMemory, which uses the
MultiMemRead packet to speed up reading unsigned numbers from memory.
Felipe landed this on Github because we didn't have a use-case for it
upstream, until now, which uses it to batch up reading ObjC runtime
symbols.
2026-04-08 14:15:35 +01:00
Felipe de Azevedo Piovezan 30a99ce6b4 [lldb][NFC] Add helper to compute breakpoint's constituent load address (#190762)
This allows the callsite to be simplified.
This also exposes a bug where the variable `ShouldShowError` is guarding
more than the error printing.
2026-04-08 10:27:51 +01: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
Felipe de Azevedo Piovezan 27a762c1a3 [lldb][NFC] Add helper function for computing whether to show Process error (#190189) 2026-04-04 18:39:41 +01:00
David Spickett 2e51fdaa77 [lldb] Replace OptionalBool with LazyBool (#189652)
The only difference between them is that OptionalBool's third state
is "unknown" and LazyBool's is "calculate". We don't need to tell
the difference in a single context, so I've made a new eLazyBoolDontKnow
which is an alias of eLazyBoolCalculate.
2026-04-01 09:26:02 +01:00
Anshul Nigham b95b902bb7 [LLDB] Use shared_ptr for m_current_private_state_thread (#188542)
Avoids manual memory management.

Uses `shared_ptr` instead of `unique_ptr` because we store references to
the current thread in a backup variable.

Simplifies the private thread `is_secondary` semantics by providing a
backup storage for the current thread instead of a boolean value with a
contract to manage the backup separately.
2026-03-25 18:42:30 -07:00
Jason Molenda fb36a54ef6 [lldb] Rename formatv verbose log call, misc log cleanups [NFC] (#186951)
lldb had three preprocessor defines for logging,

LLDB_LOG  - formatv style argument
LLDB_LOGF - printf style argument
LLDB_LOGV - formatv style argument, only when verbose enabled

If you weren't looking at Log.h and the definition of these three, and
wanted to log something with formatv, it was easy to use LLDB_LOGV by
accident. We just had a situation where an important log statement
wasn't logging and it turned out to be this. This is fragile if you
aren't looking at the header directly, so I'd like to make this more
explicit. My proposal:

LLDB_LOG  - formatv style argument
LLDB_LOG_VERBOSE - formatv style argument, only when verbose enabled 
LLDB_LOGF - printf style argument
LLDB_LOGF_VERBOSE - printf style argument, only when verbose enabled

The new fouth one is to remove several places where we do `if (log &&
log->GetVerbose()) LLDB_LOGF (...)` in the sources today, and make both
styles consistent.

This PR implements that change, mechanically changing all LLDB_LOGV's to
LLDB_LOG_VERBOSE.

It also updates many of the `if (log && log->GetVerbose()) LLDB_LOGF`'s.
Some uses of this conditional expression do extra calculations in
addition to logging, and so those were left as-is so we're not doing
throwaway work when running without verbose logging.

There were many instances throughout lldb where callers are still doing
`if (log) LLDB_LOG*(...)`, a remnant of when all calls were to the `Log`
object's `Printf()` method, and you had to check if your local Log*
pointer was non-nullptr before calling the method. I removed those,
again keeping ones where work for logging is done in the block of code.

The code changes are all mechanical and uninteresting, but the question
of whether this naming change is widely agreed on is maybe worth
discussing.
2026-03-18 16:31:33 -07:00
Jonas Devlieghere 81a537e708 [lldb] Use range-based for loops over plugins (#184837)
This PR replaces the Get*CallbackAtIndex pattern in the PluginManager
with returning a snapshot of callbacks that the caller can iterate over
using a range-based for loop. This is a continuation of #184452 which
added thread safety by using snapshots. However, that introduced a bunch
of unnecessary copies which are largely eliminated again by getting the
snapshot once when gather all the callbacks, rather than doing that on
each iteration when querying a plugin for a given index. It also
eliminates the possibility of the snapshot changing underneath you when
iterating over the plugins.

This change was largely mechanical and I used Claude to do the menial
work of updating the signatures and call sites.
2026-03-06 22:48:33 +00:00
Jim Ingham ecd6f8c22b Revert "Add the ability to "allow another thread to see the private state" mode. (#184272)"
This reverts commit 97572c1860.

This patch seems to cause TestWatchpointCommandPython.py to time out
on the ubuntu buildbots (but nowhere else that I can find so far.)  The
timeout is weird too, the TEST FILE is timing out but the individual
tests aren't being shown and there's no other output.  Grrr...
Anyway I'll revert this and then see if I can do some guessing about
how this change might cause the test to fail.
2026-03-05 12:09:07 -08:00
jimingham 97572c1860 Add the ability to "allow another thread to see the private state" mode. (#184272)
When lldb stops to run a breakpoint condition or other callback that has
to happen between the private stop and returning control to the user, it
will run in the state where the public state is still "running". But if
the callback needs to run lldb commands or python code, it needs to see
the correct "stop" state.

We used to handle that by switching the public state to stopped before
running the callbacks. However, that opened a window where we are still
handling the stop event and another thread would be allowed to continue
the target or do other actions that can interfere with that orderly
process.

This patch adds the ability to designate a particular thread as "seeing
the private state" while all other threads see the "public state". Then
when we run a breakpoint callback, no threads but the one that is
actually running the callback will see the state change until the event
has been delivered to the primary state listener.

It also adds a test that while a long-running breakpoint callback runs,
another thread continues to see the state as running.
2026-03-05 08:17:16 -08:00
Jonas Devlieghere 28638f5197 [lldb] Remove Debugger::{FindTargetWithProcessID, FindTargetWithProcess} (#184446)
In #184259, Jim noticed that Debugger::FindTargetWithProcess and
Debugger::FindTargetWithProcessID are rather poorly designed APIs as
tehy allow code running in one Debugger to mess with Targets from
another Debugger. The only use is Process::SetProcessExitStatus which
isn't actually used.
2026-03-03 14:29:15 -08:00
Vy Nguyen d518d49531 [LLDB]Move clean up to dtor (#181010)
I attempted to cleanup the raw ptr in pr/180996. But the cleanup should
have been done in the dtor, not `StopPrivateStateThread` so moving it
there.
2026-02-11 15:41:53 -05:00
Vy Nguyen e6b99fa5b4 [LLDB]Fix asan error from pr/179799 (#180996)
Fix asan error mentioned in [this
comment](https://github.com/llvm/llvm-project/pull/179799#issuecomment-3882710678)
This is breaking our internal builds.

Details: The field needs to be cleaned up or we'll have a leak. We could
also make it a smart pointer if you'd like. But as-is, this is the
quickest way to resolve the issue.
2026-02-11 14:24:42 -05: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
jimingham 6bdb7b0f00 Cleanup the use of m_is_secondary_thread from PR #179799. (#180255)
This ivar was passed to the thread function for the private state thread
- mostly because the equivalent variable was passed in in the original
version of the code. But it was never used, so I didn't notice that the
ivar equivalent wasn't being initialized. I'm going to keep the ivar
because it will be useful when debugging to easily see whether you are
on the main or secondary private state thread.

So in this change, I set m_is_secondary_thread properly in the
constructor, but remove passing it to the thread function since it
wasn't needed there.
2026-02-06 10:51:57 -08:00
jimingham 124c8b4054 Fix the modal private state thread we use for running expressions on the private state thread (#179799)
We have a problem when some code on the private state thread needs to
run an expression. The private state thread is the one that fetches
"raw" events from the Process Plugin and decides how to handle them. But
if the private state thread needs to fetch the processed events to drive
running an expression, it can't also be the thread processing the raw
events.

We solve this by swapping in a modal private state thread just to handle
the events from the expression evaluation. That worked until you could
cause the expression evaluation to happen from Python, because then it
wasn't just the fetching of events that matter, but also the state of
the process and the state of the runlocks. The modal private state
thread is really a modal version of the thread and its associated state.

This patch gathers all the relevant control parameters into a structure
which we can swap in and out when needed.

It also adds a test using the new "was_hit" breakpoint resolver
affordance, which, since it acts as an asynchronous breakpoint callback,
gets run on the private state thread, showing that with the change we
can call expressions in the `was_hit` callback without problems.
2026-02-05 15:03:52 -08:00
Alex Langford 9ebdeb2e8c [lldb] Return Expected<ModuleSP> from Process::ReadModuleFromMemory (#179583)
I noticed that Module::GetMemoryObjectFile populates a Status object
upon error but it's effectively dropped on the floor. Instead, the
clients can report the error as desired.

At the moment, all clients are either (1) consuming the error because
it's only trying to find a module, or (2) log the error and bail out
early. I tried to preserve existing behavior as faithfully as possible.
2026-02-05 11:49:17 -08:00
Alex Langford 9ca02a13a4 [lldb][NFC] Mark Symbol pointers as const where easily possible (#177472)
These are the places that required no modifications to surrounding code.
2026-01-27 15:23:49 -08:00
Victor Chernyakin c438773432 [LLVM][ADT] Migrate users of make_scope_exit to CTAD (#174030)
This is a followup to #173131, which introduced the CTAD functionality.
2026-01-02 20:42:56 -08:00
Felipe de Azevedo Piovezan e47b10917f [lldb] Add ReadCStrings API to Process (#172026)
This commit uses Process::ReadMemoryRanges to create an efficient method
for reading multiple strings at once. This method works like the
single-string version, reading 256 bytes at a time, but instead doing it
for _every_ string requested at the same time.
2025-12-22 09:59:14 -03:00