aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Interpreter/CommandObject.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2024-07-31 09:57:10 -0700
committerGitHub <noreply@github.com>2024-07-31 09:57:10 -0700
commit8398ad9cb21736dc57ee4dd766bd0859ef9bd000 (patch)
tree928489616eb403b4328eb66656664c83ff9f1241 /lldb/source/Interpreter/CommandObject.cpp
parentfaf3333510e0c2c3f319af40456e10c471e11ce8 (diff)
downloadllvm-8398ad9cb21736dc57ee4dd766bd0859ef9bd000.zip
llvm-8398ad9cb21736dc57ee4dd766bd0859ef9bd000.tar.gz
llvm-8398ad9cb21736dc57ee4dd766bd0859ef9bd000.tar.bz2
[lldb] Unify the way we get the Target in CommandObject (#101208)
Currently, CommandObjects are obtaining a target in a variety of ways. Often the command incorrectly operates on the selected target. As an example, when a breakpoint command is running, the current target is passed into the command but the target that hit the breakpoint is not the selected target. In other places we use the CommandObject's execution context, which is frozen during the execution of the command, and comes with its own limitations. Finally, we often want to fall back to the dummy target if no real target is available. Instead of having to guess how to get the target, this patch introduces one helper function in CommandObject to get the most relevant target. In order of priority, that's the target from the command object's execution context, from the interpreter's execution context, the selected target or the dummy target. rdar://110846511
Diffstat (limited to 'lldb/source/Interpreter/CommandObject.cpp')
-rw-r--r--lldb/source/Interpreter/CommandObject.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index 4634b75..c819024 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -758,17 +758,23 @@ Target &CommandObject::GetDummyTarget() {
return m_interpreter.GetDebugger().GetDummyTarget();
}
-Target &CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) {
- return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);
-}
-
-Target &CommandObject::GetSelectedTarget() {
- assert(m_flags.AnySet(eCommandRequiresTarget | eCommandProcessMustBePaused |
- eCommandProcessMustBeLaunched | eCommandRequiresFrame |
- eCommandRequiresThread | eCommandRequiresProcess |
- eCommandRequiresRegContext) &&
- "GetSelectedTarget called from object that may have no target");
- return *m_interpreter.GetDebugger().GetSelectedTarget();
+Target &CommandObject::GetTarget() {
+ // Prefer the frozen execution context in the command object.
+ if (Target *target = m_exe_ctx.GetTargetPtr())
+ return *target;
+
+ // Fallback to the command interpreter's execution context in case we get
+ // called after DoExecute has finished. For example, when doing multi-line
+ // expression that uses an input reader or breakpoint callbacks.
+ if (Target *target = m_interpreter.GetExecutionContext().GetTargetPtr())
+ return *target;
+
+ // Finally, if we have no other target, get the selected target.
+ if (TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget())
+ return *target_sp;
+
+ // We only have the dummy target.
+ return GetDummyTarget();
}
Thread *CommandObject::GetDefaultThread() {