Fix target-attach MI command attaching to dummy target #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The implementation of the
target-attach
command (CMICmdCmdTargetAttach::Execute
) tries to search for a selected target to work with, before creating a new one. However, this is not implemented correctly.The
CMICmnLLDBDebugSessionInfo::GetTarget
function will return the selected target if there is one, and the dummy target otherwise. Effectively, this means that the!target.IsValid()
check always evaluates tofalse
.Consider a scenario where a user starts an lldb-mi session and issues
-target-attach
as the first command, in which case there is no target yet. lldb-mi will then select the dummy target and attach a process to it, which causes all kinds of odd behavior. For instance, because the dummy target is not 'real' and not included in the target list, all commands operating on actual targets do not work.We can observe this in practice like so:
Note how the process has been attached, but there is no matching target, leaving the debugger in something of a broken state. The process can be controlled with MI commands:
... but not inspected with LLDB-specific commands:
This PR resolves this issue by ensuring that
target-attach
will never attempt to bind a process to the dummy target; it should only look for a selected target, and if there is none, create one.