This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][GUI] Expand selected thread tree item by default
ClosedPublic

Authored by OmarEmaraDev on Apr 10 2021, 4:00 AM.

Details

Summary

This patch expands the tree item that corresponds to the selected thread
by default in the Threads window. Additionally, the tree root item is
always expanded, which is the process in the Threads window.

Diff Detail

Event Timeline

OmarEmaraDev requested review of this revision.Apr 10 2021, 4:00 AM
OmarEmaraDev created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2021, 4:00 AM

I have been meaning to get to this for a while, thanks for taking this on! It would be great if we can actually select the selected stack frame as well when this the process view is initialized. Same kind of code as with the selected thread. See inline comments.

lldb/source/Core/IOHandlerCursesGUI.cpp
3382–3384

Remove parens for single statement if due to LLVM coding guidelines.

3971–3973

Remove parens for single statement if due to LLVM coding guidelines.

Including the inlined comments for showing and selecting the selected frame.

lldb/source/Core/IOHandlerCursesGUI.cpp
3971–3973

It would be great if we can also select the currently selected stack frame here. Something like:

if (selected_thread && selected_thread->GetID() == thread->GetID()) {
  item[i].Expand();
  StackFrameSP selected_frame = thread->GetSelectedFrame();
  if (selected_frame) {
    // Add all frames and select the right one...
  }
}
  • Follow LLVM coding guidelines
OmarEmaraDev marked 2 inline comments as done.Apr 20 2021, 6:43 AM
OmarEmaraDev added inline comments.
lldb/source/Core/IOHandlerCursesGUI.cpp
3971–3973

@clayborg I didn't implement selection in this patch because my implementation didn't look great and I thought selection could be refactored to to make handling easier.

I haven't looked at this in more details yet, but I was thinking that maybe instead of having linear selection, we would have it hierarchical.
Each tree item declares which of its children is selected, so the process item will declare which thread item is selected and the selected thread item will declare which frame item is selected and so on.
It could be more conceptually correct because when selecting a frame, you are also selecting its parent thread. And selection can be checked by traversing parents and highlighting can be done by checking for leaf items. Something like that.

clayborg added inline comments.Apr 21 2021, 11:21 AM
lldb/source/Core/IOHandlerCursesGUI.cpp
3973

yeah, we need one frame item to be selected at all times so it indicates the current thread/frame that is selected within LLDB.

So a great solution would be to expand the selected thread and show all frames within the selected thread. Add code to select the current frame after as we can re-use this code as we step along in our program. If we add a command line window that allows LLDB commands, if the user types "frame select 12", the view should update to indicate which frame is selected. Also if the user types "thread select 5", the view should update accordingly.

wallace added inline comments.
lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
39

create a method self.exit_gui to dedup some code, as you'll end up doing a lot of them as you write your tests

def exit_gui(self):
  self.child.send(chr(27).encode())
  self.expect_prompt()

you can also create a method start_gui

def start_gui(self):
  self.child.sendline("gui")
  self.child.send(chr(27).encode())

you could also later create a base class lldbgui_testcase similar to lldbvscode_testcase, where you can put all needed common code

  • Merge branch 'main' into lldb-gui-expand-threads-tree
  • Implement default selection
OmarEmaraDev added inline comments.Jun 10 2021, 2:25 PM
lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
39

Okay. I will do for all tests in a separate patch.

clayborg requested changes to this revision.Jun 11 2021, 12:02 PM

Many minor things, but looking good! I look forward to seeing this get checked in

lldb/source/Core/IOHandlerCursesGUI.cpp
3364–3365

Don't make this pure virtual unless all subclasses must implement this. I see a few implementations below that do nothing, so just make a default implementation so classes that don't need this don't have to implement it. Also renamed to TreeDelegateUpdateSelection to stay consistent with the other delegate methods.

3382–3383

We might want to opt into this? We don't want all variables in a variable view to be expanded by default. But we do want the process tree to always expand, so we need to be able to opt in in the tree delegates.

3612–3613

I assume we want this method to update both m_selected_row_idx and m_selected_item right? If so, make sure we switch to references on line 1611 above so both do get updated.

3797–3801

Remove and make a default implementation in the base class and don't make it pure virtual

3883–3887

Remove and make a default implementation in the base class and don't make it pure virtual

3942–3943

See comment below where you used to set m_need_to_set_default_selection to false.

4000

This just sets the local variable "selected_item" to a value. Make sure we switch to using references on 1611 as mentioned before.

4002

You can remove this and just always set this in the TreeDelegateGenerateChildren

4015

Maybe renamed to m_update_selection so this variable is a bit shorter?

This revision now requires changes to proceed.Jun 11 2021, 12:02 PM
  • Handle review
clayborg accepted this revision.Jun 11 2021, 2:08 PM

Looks good!

This revision is now accepted and ready to land.Jun 11 2021, 2:08 PM
This revision was landed with ongoing or failed builds.Jul 26 2021, 2:21 PM
This revision was automatically updated to reflect the committed changes.

This change has caused various GUI related tests to fail randomly.
https://lab.llvm.org/buildbot/#/builders/96/builds/10100

This also causes random failures of one of the most resource sufficient buildbot here:
https://lab.llvm.org/buildbot/#/builders/68/builds/16275
https://lab.llvm.org/buildbot/#/builders/68/builds/16300

@teemperor
Referring to your comment on skipping TestGuiBasicDebug.py this may have caused it.

I suspect this change as culprit behind failure of various GUI tests randomly on various LLDB buildbots. I have reverted this change to see if its the real culprit.