Skip to content

Commit b3c2c5e

Browse files
author
jeffreytan81
committed
Address review comments with mixin class
1 parent ad6a787 commit b3c2c5e

File tree

9 files changed

+76
-40
lines changed

9 files changed

+76
-40
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,11 +1316,11 @@ class Process : public std::enable_shared_from_this<Process>,
13161316

13171317
/// Send an async interrupt request.
13181318
///
1319-
/// If \a thread is specified the async interrupt stop will be attributed the
1320-
/// specified thread.
1319+
/// If \a thread is specified the async interrupt stop will be attributed to
1320+
/// the specified thread.
13211321
///
13221322
/// \param[in] thread
1323-
/// The thread from which to attribute the async interrupt stop to.
1323+
/// The thread the async interrupt will be attributed to.
13241324
void SendAsyncInterrupt(Thread *thread = nullptr);
13251325

13261326
// Notify this process class that modules got loaded.
@@ -2844,6 +2844,14 @@ void PruneThreadPlans();
28442844
return std::nullopt;
28452845
}
28462846

2847+
/// Handle thread specific async interrupt and return the original thread
2848+
/// that requested the async interrupt. It can be null if original thread
2849+
/// has exited.
2850+
virtual lldb::ThreadSP
2851+
HandleThreadAsyncInterrupt(uint8_t signo, const std::string &description) {
2852+
return lldb::ThreadSP();
2853+
}
2854+
28472855
lldb::StateType GetPrivateState();
28482856

28492857
/// The "private" side of resuming a process. This doesn't alter the state

lldb/include/lldb/Target/ThreadPlanSingleThreadTimeout.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ class ThreadPlanSingleThreadTimeout : public ThreadPlan {
4646

4747
~ThreadPlanSingleThreadTimeout() override;
4848

49-
// Create a new instance from fresh new state.
50-
static void CreateNew(Thread &thread, TimeoutInfo &info);
51-
// Reset and create a new instance from the previous state.
52-
static void ResetFromPrevState(Thread &thread, TimeoutInfo &info);
49+
// If input \param thread is running in single thread mode, push a
50+
// new ThreadPlanSingleThreadTimeout based on timeout setting from fresh new
51+
// state. The reference of \param info is passed in so that when
52+
// ThreadPlanSingleThreadTimeout got popped out its last state can be stored
53+
// in it for future resume.
54+
static void PushNewWithTimeout(Thread &thread, TimeoutInfo &info);
55+
56+
// Push a new ThreadPlanSingleThreadTimeout by restoring state from
57+
// input \param info and resume execution.
58+
static void ResumeFromPrevState(Thread &thread, TimeoutInfo &info);
5359

5460
void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
5561
bool ValidatePlan(Stream *error) override { return true; }

lldb/include/lldb/Target/ThreadPlanStepOverRange.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
#include "lldb/Core/AddressRange.h"
1313
#include "lldb/Target/StackID.h"
1414
#include "lldb/Target/Thread.h"
15-
#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
1615
#include "lldb/Target/ThreadPlanStepRange.h"
16+
#include "lldb/Target/TimeoutResumeAll.h"
1717

1818
namespace lldb_private {
1919

2020
class ThreadPlanStepOverRange : public ThreadPlanStepRange,
21-
ThreadPlanShouldStopHere {
21+
ThreadPlanShouldStopHere,
22+
TimeoutResumeAll {
2223
public:
2324
ThreadPlanStepOverRange(Thread &thread, const AddressRange &range,
2425
const SymbolContext &addr_context,
@@ -45,13 +46,9 @@ class ThreadPlanStepOverRange : public ThreadPlanStepRange,
4546

4647
void SetupAvoidNoDebug(LazyBool step_out_avoids_code_without_debug_info);
4748
bool IsEquivalentContext(const SymbolContext &context);
48-
// Clear and create a new ThreadPlanSingleThreadTimeout to detect if program
49-
// is moving forward.
50-
void ResetSingleThreadTimeout();
5149

5250
bool m_first_resume;
5351
lldb::RunMode m_run_mode;
54-
ThreadPlanSingleThreadTimeout::TimeoutInfo m_timeout_info;
5552

5653
ThreadPlanStepOverRange(const ThreadPlanStepOverRange &) = delete;
5754
const ThreadPlanStepOverRange &
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- TimeoutResumeAll.h -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_TARGET_TIMEOUTRESUMEALL_H
10+
#define LLDB_TARGET_TIMEOUTRESUMEALL_H
11+
12+
#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
13+
14+
namespace lldb_private {
15+
16+
// Mixin class that provides capability for ThreadPlan that supports single
17+
// thread execution to resume all threads after a timeout.
18+
// Opt-in thread plan should call PushNewTimeout() in its DidPush() and
19+
// ResumeWithTimeout() during DoWillResume().
20+
class TimeoutResumeAll {
21+
public:
22+
TimeoutResumeAll(Thread &thread) : m_thread(thread) {}
23+
24+
void PushNewTimeout() {
25+
ThreadPlanSingleThreadTimeout::PushNewWithTimeout(m_thread, m_timeout_info);
26+
}
27+
28+
void ResumeWithTimeout() {
29+
ThreadPlanSingleThreadTimeout::ResumeFromPrevState(m_thread,
30+
m_timeout_info);
31+
}
32+
33+
private:
34+
Thread &m_thread;
35+
ThreadPlanSingleThreadTimeout::TimeoutInfo m_timeout_info;
36+
};
37+
38+
} // namespace lldb_private
39+
40+
#endif // LLDB_TARGET_TIMEOUTRESUMEALL_H

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,9 @@ class ProcessGDBRemote : public Process,
440440
void HandleStopReply() override;
441441
void HandleAsyncStructuredDataPacket(llvm::StringRef data) override;
442442

443-
// Handle thread specific async interrupt and return the original thread
444-
// that requested the async interrupt. It can be null if original thread
445-
// has exited.
446-
lldb::ThreadSP HandleThreadAsyncInterrupt(uint8_t signo,
447-
const std::string &description);
443+
lldb::ThreadSP
444+
HandleThreadAsyncInterrupt(uint8_t signo,
445+
const std::string &description) override;
448446

449447
void SetThreadPc(const lldb::ThreadSP &thread_sp, uint64_t index);
450448
using ModuleCacheKey = std::pair<std::string, std::string>;

lldb/source/Target/Process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3965,7 +3965,7 @@ thread_result_t Process::RunPrivateStateThread(bool is_secondary_thread) {
39653965

39663966
if (interrupt_requested) {
39673967
if (StateIsStoppedState(internal_state, true)) {
3968-
// Oly mark interrupt event if it is not thread specific async
3968+
// Only mark interrupt event if it is not thread specific async
39693969
// interrupt.
39703970
if (m_interrupt_tid == LLDB_INVALID_THREAD_ID) {
39713971
// We requested the interrupt, so mark this as such in the stop

lldb/source/Target/StopInfo.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,15 +1140,6 @@ class StopInfoInterrupt : public StopInfo {
11401140
return lldb::eStopReasonInterrupt;
11411141
}
11421142

1143-
bool ShouldStopSynchronous(Event *event_ptr) override { return true; }
1144-
1145-
bool ShouldStop(Event *event_ptr) override {
1146-
ThreadSP thread_sp(m_thread_wp.lock());
1147-
if (thread_sp)
1148-
return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
1149-
return false;
1150-
}
1151-
11521143
const char *GetDescription() override {
11531144
if (m_description.empty()) {
11541145
m_description = "async interrupt";

lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,12 @@ std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
5656
}
5757
}
5858

59-
void ThreadPlanSingleThreadTimeout::CreateNew(Thread &thread,
60-
TimeoutInfo &info) {
59+
void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
60+
TimeoutInfo &info) {
6161
uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
6262
if (timeout_in_ms == 0)
6363
return;
6464

65-
if (info.m_instance != nullptr)
66-
return;
67-
6865
// Do not create timeout if we are not stopping other threads.
6966
if (!thread.GetCurrentPlan()->StopOthers())
7067
return;
@@ -77,8 +74,8 @@ void ThreadPlanSingleThreadTimeout::CreateNew(Thread &thread,
7774
LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");
7875
}
7976

80-
void ThreadPlanSingleThreadTimeout::ResetFromPrevState(Thread &thread,
81-
TimeoutInfo &info) {
77+
void ThreadPlanSingleThreadTimeout::ResumeFromPrevState(Thread &thread,
78+
TimeoutInfo &info) {
8279
uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
8380
if (timeout_in_ms == 0)
8481
return;

lldb/source/Target/ThreadPlanStepOverRange.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ ThreadPlanStepOverRange::ThreadPlanStepOverRange(
3737
: ThreadPlanStepRange(ThreadPlan::eKindStepOverRange,
3838
"Step range stepping over", thread, range,
3939
addr_context, stop_others),
40-
ThreadPlanShouldStopHere(this), m_first_resume(true),
41-
m_run_mode(stop_others) {
40+
ThreadPlanShouldStopHere(this), TimeoutResumeAll(thread),
41+
m_first_resume(true), m_run_mode(stop_others) {
4242
SetFlagsToDefault();
4343
SetupAvoidNoDebug(step_out_avoids_code_without_debug_info);
4444
}
@@ -346,7 +346,7 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) {
346346

347347
void ThreadPlanStepOverRange::DidPush() {
348348
if (m_run_mode == lldb::eOnlyThisThread && IsControllingPlan())
349-
ThreadPlanSingleThreadTimeout::CreateNew(GetThread(), m_timeout_info);
349+
PushNewTimeout();
350350
}
351351

352352
bool ThreadPlanStepOverRange::DoPlanExplainsStop(Event *event_ptr) {
@@ -427,7 +427,6 @@ bool ThreadPlanStepOverRange::DoWillResume(lldb::StateType resume_state,
427427
}
428428
}
429429
if (m_run_mode == lldb::eOnlyThisThread && IsControllingPlan())
430-
ThreadPlanSingleThreadTimeout::ResetFromPrevState(GetThread(),
431-
m_timeout_info);
430+
ResumeWithTimeout();
432431
return true;
433432
}

0 commit comments

Comments
 (0)