Skip to content

Commit a94fbb2

Browse files
committed
Revert "Revert "[LLDB][GUI] Expand selected thread tree item by default""
This reverts commit fd18f0e. I reverted this change to see its effect on failing GUI tests on LLDB Arm/AArch64 Linux buildbots. I could not find any evidence against this particular change so reverting it back. Differential Revision: https://reviews.llvm.org/D100243
1 parent 8f30db8 commit a94fbb2

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,8 +3768,13 @@ class TreeDelegate {
37683768

37693769
virtual void TreeDelegateDrawTreeItem(TreeItem &item, Window &window) = 0;
37703770
virtual void TreeDelegateGenerateChildren(TreeItem &item) = 0;
3771+
virtual void TreeDelegateUpdateSelection(TreeItem &root, int &selection_index,
3772+
TreeItem *&selected_item) {
3773+
return;
3774+
}
37713775
virtual bool TreeDelegateItemSelected(
37723776
TreeItem &item) = 0; // Return true if we need to update views
3777+
virtual bool TreeDelegateExpandRootByDefault() { return false; }
37733778
};
37743779

37753780
typedef std::shared_ptr<TreeDelegate> TreeDelegateSP;
@@ -3779,7 +3784,10 @@ class TreeItem {
37793784
TreeItem(TreeItem *parent, TreeDelegate &delegate, bool might_have_children)
37803785
: m_parent(parent), m_delegate(delegate), m_user_data(nullptr),
37813786
m_identifier(0), m_row_idx(-1), m_children(),
3782-
m_might_have_children(might_have_children), m_is_expanded(false) {}
3787+
m_might_have_children(might_have_children), m_is_expanded(false) {
3788+
if (m_parent == nullptr)
3789+
m_is_expanded = m_delegate.TreeDelegateExpandRootByDefault();
3790+
}
37833791

37843792
TreeItem &operator=(const TreeItem &rhs) {
37853793
if (this != &rhs) {
@@ -4008,6 +4016,8 @@ class TreeWindowDelegate : public WindowDelegate {
40084016
const int num_visible_rows = NumVisibleRows();
40094017
m_num_rows = 0;
40104018
m_root.CalculateRowIndexes(m_num_rows);
4019+
m_delegate_sp->TreeDelegateUpdateSelection(m_root, m_selected_row_idx,
4020+
m_selected_item);
40114021

40124022
// If we unexpanded while having something selected our total number of
40134023
// rows is less than the num visible rows, then make sure we show all the
@@ -4309,7 +4319,7 @@ class ThreadsTreeDelegate : public TreeDelegate {
43094319
public:
43104320
ThreadsTreeDelegate(Debugger &debugger)
43114321
: TreeDelegate(), m_thread_delegate_sp(), m_debugger(debugger),
4312-
m_stop_id(UINT32_MAX) {
4322+
m_stop_id(UINT32_MAX), m_update_selection(false) {
43134323
FormatEntity::Parse("process ${process.id}{, name = ${process.name}}",
43144324
m_format);
43154325
}
@@ -4337,6 +4347,7 @@ class ThreadsTreeDelegate : public TreeDelegate {
43374347

43384348
void TreeDelegateGenerateChildren(TreeItem &item) override {
43394349
ProcessSP process_sp = GetProcess();
4350+
m_update_selection = false;
43404351
if (process_sp && process_sp->IsAlive()) {
43414352
StateType state = process_sp->GetState();
43424353
if (StateIsStoppedState(state, true)) {
@@ -4345,6 +4356,7 @@ class ThreadsTreeDelegate : public TreeDelegate {
43454356
return; // Children are already up to date
43464357

43474358
m_stop_id = stop_id;
4359+
m_update_selection = true;
43484360

43494361
if (!m_thread_delegate_sp) {
43504362
// Always expand the thread item the first time we show it
@@ -4356,24 +4368,58 @@ class ThreadsTreeDelegate : public TreeDelegate {
43564368
TreeItem t(&item, *m_thread_delegate_sp, false);
43574369
ThreadList &threads = process_sp->GetThreadList();
43584370
std::lock_guard<std::recursive_mutex> guard(threads.GetMutex());
4371+
ThreadSP selected_thread = threads.GetSelectedThread();
43594372
size_t num_threads = threads.GetSize();
43604373
item.Resize(num_threads, t);
43614374
for (size_t i = 0; i < num_threads; ++i) {
4362-
item[i].SetIdentifier(threads.GetThreadAtIndex(i)->GetID());
4375+
ThreadSP thread = threads.GetThreadAtIndex(i);
4376+
item[i].SetIdentifier(thread->GetID());
43634377
item[i].SetMightHaveChildren(true);
4378+
if (selected_thread->GetID() == thread->GetID())
4379+
item[i].Expand();
43644380
}
43654381
return;
43664382
}
43674383
}
43684384
item.ClearChildren();
43694385
}
43704386

4387+
void TreeDelegateUpdateSelection(TreeItem &root, int &selection_index,
4388+
TreeItem *&selected_item) override {
4389+
if (!m_update_selection)
4390+
return;
4391+
4392+
ProcessSP process_sp = GetProcess();
4393+
if (!(process_sp && process_sp->IsAlive()))
4394+
return;
4395+
4396+
StateType state = process_sp->GetState();
4397+
if (!StateIsStoppedState(state, true))
4398+
return;
4399+
4400+
ThreadList &threads = process_sp->GetThreadList();
4401+
std::lock_guard<std::recursive_mutex> guard(threads.GetMutex());
4402+
ThreadSP selected_thread = threads.GetSelectedThread();
4403+
size_t num_threads = threads.GetSize();
4404+
for (size_t i = 0; i < num_threads; ++i) {
4405+
ThreadSP thread = threads.GetThreadAtIndex(i);
4406+
if (selected_thread->GetID() == thread->GetID()) {
4407+
selected_item = &root[i][thread->GetSelectedFrameIndex()];
4408+
selection_index = selected_item->GetRowIndex();
4409+
return;
4410+
}
4411+
}
4412+
}
4413+
43714414
bool TreeDelegateItemSelected(TreeItem &item) override { return false; }
43724415

4416+
bool TreeDelegateExpandRootByDefault() override { return true; }
4417+
43734418
protected:
43744419
std::shared_ptr<ThreadTreeDelegate> m_thread_delegate_sp;
43754420
Debugger &m_debugger;
43764421
uint32_t m_stop_id;
4422+
bool m_update_selection;
43774423
FormatEntity::Entry m_format;
43784424
};
43794425

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
ENABLE_THREADS := YES
3+
include Makefile.rules
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Test the 'gui' default thread tree expansion.
3+
The root process tree item and the tree item corresponding to the selected
4+
thread should be expanded by default.
5+
"""
6+
7+
import lldb
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
from lldbsuite.test.lldbpexpect import PExpectTest
11+
12+
class TestGuiExpandThreadsTree(PExpectTest):
13+
14+
mydir = TestBase.compute_mydir(__file__)
15+
16+
# PExpect uses many timeouts internally and doesn't play well
17+
# under ASAN on a loaded machine..
18+
@skipIfAsan
19+
@skipIfCursesSupportMissing
20+
def test_gui(self):
21+
self.build()
22+
23+
self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,500))
24+
self.expect("breakpoint set -r thread_start_routine", substrs=["Breakpoint 1", "address ="])
25+
self.expect("run", substrs=["stop reason ="])
26+
27+
escape_key = chr(27).encode()
28+
29+
# Start the GUI and close the welcome window.
30+
self.child.sendline("gui")
31+
self.child.send(escape_key)
32+
self.child.expect_exact("Threads")
33+
34+
# The thread running thread_start_routine should be expanded.
35+
self.child.expect_exact("frame #0: thread_start_routine")
36+
37+
# Exit GUI.
38+
self.child.send(escape_key)
39+
self.expect_prompt()
40+
41+
# Select the main thread.
42+
self.child.sendline("thread select 1")
43+
44+
# Start the GUI.
45+
self.child.sendline("gui")
46+
self.child.expect_exact("Threads")
47+
48+
# The main thread should be expanded.
49+
self.child.expect("frame #\d+: main")
50+
51+
# Quit the GUI
52+
self.child.send(escape_key)
53+
54+
self.expect_prompt()
55+
self.quit()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <pthread.h>
2+
3+
void *thread_start_routine(void *arg) { return NULL; }
4+
5+
int main() {
6+
pthread_t thread;
7+
pthread_create(&thread, NULL, thread_start_routine, NULL);
8+
pthread_join(thread, NULL);
9+
return 0;
10+
}

0 commit comments

Comments
 (0)