[lldb] Fix dummy target filtering regression in CommandInterpreter (#198949)
In #198429 (reland), CommandObject::GetTarget() was tightened to return
nullptr instead of the dummy target when no real target exists, unless
the command explicitly opts in via eCommandAllowsDummyTarget or standard
target requirements
However in CommandInterpreter::GetExecutionContext(bool
adopt_dummy_target) :
```
ExecutionContext
CommandInterpreter::GetExecutionContext(bool adopt_dummy_target) const {
return !m_overriden_exe_contexts.empty()
? m_overriden_exe_contexts.top()
: m_debugger.GetSelectedExecutionContext(adopt_dummy_target);
}
```
If m_overriden_exe_contexts is not empty, the method returned the top
context immediately—completely ignoring the adopt_dummy_target argument
requested by the command object.
Because of this:
1. During sourced script runs, process attach received the dummy target
as its execution target (since adopt_dummy_target = false was ignored).
2. It bypassed the target == nullptr check and proceeded to attach
directly to the dummy target.
3. As the dummy target was never registered in m_target_list , the main
target list remained empty ( No targets. ), causing all subsequent
commands (e.g., setting breakpoints or continuing) to fail with invalid
target errors.
### The Fix:
lldb/source/Interpreter/CommandInterpreter.cpp :
Respect adopt_dummy_target = false in GetExecutionContext when a dummy
target is present in the overridden execution context stackm so that if
adopt_dummy_target is false and the overridden context on the stack
contains the dummy target, we clear the context before returning it.
This forces GetTarget() to return nullptr as originally intended.
### Test:
• lldb/test/Shell/Commands/process-attach-dummy.test :
Add a new standalone Lit shell test to replicate this scenario. The test
sources a command sequence executing process attach when no target
exists, and verifies that target list successfully registers the newly
created real
target ( target #0: <none> ) instead of leaving the list empty.