This is an archive of the discontinued LLVM Phabricator instance.

"target create" shouldn't save target if the command failed
ClosedPublic

Authored by tatyana-krasnukha on Dec 10 2020, 9:42 AM.

Details

Summary

TargetList::CreateTarget automatically adds created target to the list, however, CommandObjectTargetCreate does some additional preparation after creating a target and which can fail.
The command should remove the created target if it failed. Since the function has many ways to return, scope guard does this safer.

Changes to the TargetList make target adding and selection more transparent by splitting CreateTarget into two parts: creation and adding to the list.

Other changes remove unnecessary SetSelectedTarget calls after CreateTarget.

Diff Detail

Event Timeline

tatyana-krasnukha requested review of this revision.Dec 10 2020, 9:42 AM

It's a little awkward that you have the "do_select" parameter with a default argument of "true" but then you explicitly pass "true" every time you use it...

It seems reasonable that the Debugger might want to create targets w/o selecting them. For instance, suppose we had some mechanism to say "attach to everything that the currently being debugged process launches", and you were stepping over the routine in the main target that creates a new process, we will make a new target for the child process, but you really wouldn't want to make the new process' target the default target, it hasn't done anything interesting yet... So having the parameter there seems right. But either use the default value or don't have it. I'm in favor of the latter, it's good for people to see that the selected target is going to get switched by this call.

Other than that, this seems fine to me.

Removed do_select's default value.

jingham accepted this revision.Dec 11 2020, 10:33 AM

LGTM, thanks for the cleanup.

This revision is now accepted and ready to land.Dec 11 2020, 10:33 AM