-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to pass thread ID to thread select command #73596
Changes from 5 commits
97a6e23
34045b9
3ef88cd
e30a155
e109a2e
2db54f6
e1f1f0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -83,6 +83,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks( | |||
CommandCompletions::RemoteDiskDirectories}, | ||||
{lldb::eTypeCategoryNameCompletion, | ||||
CommandCompletions::TypeCategoryNames}, | ||||
{lldb::eThreadIDCompletion, CommandCompletions::ThreadIDs}, | ||||
{lldb::CompletionType::eNoCompletion, | ||||
nullptr} // This one has to be last in the list. | ||||
}; | ||||
|
@@ -807,6 +808,23 @@ void CommandCompletions::TypeCategoryNames(CommandInterpreter &interpreter, | |||
}); | ||||
} | ||||
|
||||
void CommandCompletions::ThreadIDs(CommandInterpreter &interpreter, | ||||
CompletionRequest &request, | ||||
SearchFilter *searcher) { | ||||
const ExecutionContext &exe_ctx = interpreter.GetExecutionContext(); | ||||
if (!exe_ctx.HasProcessScope()) | ||||
return; | ||||
|
||||
ThreadList &threads = exe_ctx.GetProcessPtr()->GetThreadList(); | ||||
lldb::ThreadSP thread_sp; | ||||
for (uint32_t idx = 0; (thread_sp = threads.GetThreadAtIndex(idx)); ++idx) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit, don't block the review on this, but why do you have ()s here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's to avoid this warning:
It's also consistent to how it was done in the ThreadIndex completer code:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow, I had not noticed what we were doing here, we usually see that pattern in So that means that if one of the thread pointers in the middle of the list is null, we stop processing other threads? This seems counter intuitive, I would have expected the code to be:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (please don't resolve conversations until the author has had a chance to look at the answer) |
||||
StreamString strm; | ||||
thread_sp->GetStatus(strm, 0, 1, 1, true); | ||||
request.TryCompleteCurrentArg(std::to_string(thread_sp->GetID()), | ||||
strm.GetString()); | ||||
} | ||||
} | ||||
|
||||
void CommandCompletions::CompleteModifiableCmdPathArgs( | ||||
CommandInterpreter &interpreter, CompletionRequest &request, | ||||
OptionElementVector &opt_element_vector) { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public enums are part of our public API, we can't add new values in the middle, we must always add them to the end. If someone compiled against an older LLDB, they would have 25 meaning
eCustomCompletion
, but if the re-link allowing the above change it would now meaneThreadIDCompletion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clayborg Is there anything special about
eCustomCompletion
being last? The comment in 1300-1302 seems to allude to this, but I don't see anything in the code base requiring this nor any other custom completions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a problem. If there ever is a magic bit it should be something like:
But this is public API now which causes a problem for reasons I mentioned before. @jimingham any ideas on if we care about adding the thread ID before the
eCustomCompletion
from an API standpoint? lldb-rpc-server is the main thing I worry about here since it sends enums as integers, not as strings which are then converted back into integers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimingham What are your thoughts on putting eThreadIDCompletion before eCustomCompletion? (See @clayborg 's comments above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Independent of the API standpoint, Greg is right. This is ABI-breaking, something we try hard to avoid in LLDB. Even though programs linked against older versions of LLDB will still be able to run against newer versions of LLDB, the semantics of these values have changed and the program may do the wrong thing. Even though I don't think it's likely that this will affect many folks, you can never be too sure.
https://lldb.llvm.org/resources/sbapi.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this was a public enum, there was never anything you could do with it from the SB API's. The only place you could set completions at all from the outside was in
command script add
and that didn't use the enum values, it used string equivalents.So I think at this point we can change it as we need.
We also don't add completions that extend this table anywhere in lldb that I can see, we use custom completion functions that we use by hand in the HandleCompletion's instead. And anyway, all that is internal to lldb_private, that's not exposed.
So I think none of this is really designed or used at this point, and we should think of what we want to do with this.
I think eCustomCompletion should mean "this object implements a custom completion, use that instead of any of the built-in ones." So overloading it to be the enum terminator is wrong, since its value cannot float, it has to have a definite meaning.
The terminator is useful for input validation. The "parsed command" patch I'm working on WILL allow users to specify a completion for the arguments, and it would be useful to be able to say "that enum value you just passed me was out of the range of valid completions." But I think that's all it's needed for.
So I'd suggest leaving eCustomCompletion where it is, adding the Thread ID one after and then adding a terminator for input validation.