This is an archive of the discontinued LLVM Phabricator instance.

Update the current execution context at the beginning of tab completions
ClosedPublic

Authored by MrHate on Mar 4 2020, 12:10 AM.

Details

Summary

Fix a bug that tab completions won't synchronous the current execution context. ( Thanks for Jim's explanation! )

Diff Detail

Event Timeline

MrHate created this revision.Mar 4 2020, 12:10 AM
labath added a comment.Mar 4 2020, 2:24 AM

Based on Jim's explanation (thanks!) this sounds like the right thing to do. Does this also fix the "frame var" bug that Jim mentioned on the other thread? Could you also add a test case like that?

lldb/source/Interpreter/CommandObject.cpp
271

If we do this, should we also call Cleanup() at the end of the function?

MrHate added a comment.Mar 4 2020, 5:22 AM

Thanks labath, for noting me about my missing test and Cleanup()!
For the test, my idea is to modify the original test for frame variable to make it not run frame variable before completion.
For the Cleanup(), I've checked the related code. It seems that Cleanup() is used to clear m_exe_ctx ( by calling its member function Clear() ) and release m_api_locker. From the comment at the beginning of CheckRequirements(), it says "Every command should call CommandObject::Cleanup() after it has completed." and we can find that Cleanup() appears only at the end of Execute(). But from CommandInterpreter::GetExecutionContext, ExecutionContextRef::Lock and ExecutionContext::ExecutionContext(const ExecutionContextRef*, bool) we can know that, this process is just assignments on smart pointers. So I think using m_exe_ctx.Clear() here might be better.

MrHate updated this revision to Diff 248154.Mar 4 2020, 5:29 AM

Modified the test for frame variable so that it will not execute frame variable before completion test.
Added m_exe_ctx.Clear() at the end of CommandObject::HandleCompletion to ensure that nothing will be stored in m_exe_ctx between running commands.

MrHate edited the summary of this revision. (Show Details)Mar 4 2020, 5:42 AM
labath added a comment.Mar 4 2020, 5:44 AM

Thanks labath, for noting me about my missing test and Cleanup()!
For the test, my idea is to modify the original test for frame variable to make it not run frame variable before completion.
For the Cleanup(), I've checked the related code. It seems that Cleanup() is used to clear m_exe_ctx ( by calling its member function Clear() ) and release m_api_locker. From the comment at the beginning of CheckRequirements(), it says "Every command should call CommandObject::Cleanup() after it has completed." and we can find that Cleanup() appears only at the end of Execute(). But from CommandInterpreter::GetExecutionContext, ExecutionContextRef::Lock and ExecutionContext::ExecutionContext(const ExecutionContextRef*, bool) we can know that, this process is just assignments on smart pointers. So I think using m_exe_ctx.Clear() here might be better.

Yes, that sounds reasonable.

lldb/test/API/functionalities/completion/TestCompletion.py
46–47

Please also remove this FIXME. Instead, you could add a comment that we're explicitly testing the scenario where "frame var" is completed without any preceding commands.

MrHate updated this revision to Diff 248168.Mar 4 2020, 6:26 AM
MrHate marked an inline comment as done.

Added comments about the new version test for command frame variable.

jingham accepted this revision.Mar 4 2020, 10:13 AM

LGTM, thanks for fixing this.

This revision is now accepted and ready to land.Mar 4 2020, 10:13 AM

I'll land this for @MrHate (he's my GSoC student)

This revision was automatically updated to reflect the committed changes.