Skip to content

Commit 1098360

Browse files
committed
[lldb] Add Process::SupportsReverseDirection() method and use it
This allows `SBProcess::ContinueInDirection()` to error out early if the target does not support any kind of reverse execution.
1 parent 1d587f1 commit 1098360

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,13 @@ class Process : public std::enable_shared_from_this<Process>,
10891089
/// Returns an error object.
10901090
virtual Status WillResume() { return Status(); }
10911091

1092+
/// Reports whether this process supports reverse execution.
1093+
///
1094+
/// \return
1095+
/// Returns true if the process supports reverse execution (at least
1096+
/// under some circumstances).
1097+
virtual bool SupportsReverseDirection() { return false; }
1098+
10921099
/// Resumes all of a process's threads as configured using the Thread run
10931100
/// control functions.
10941101
///

lldb/source/API/SBProcess.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,14 @@ SBError SBProcess::Continue() {
584584
}
585585

586586
SBError SBProcess::ContinueInDirection(RunDirection direction) {
587-
if (ProcessSP process_sp = GetSP())
587+
if (ProcessSP process_sp = GetSP()) {
588+
if (direction == RunDirection::eRunReverse &&
589+
!process_sp->SupportsReverseDirection())
590+
return Status::FromErrorStringWithFormatv(
591+
"error: {0} does not support reverse execution of processes",
592+
GetPluginName());
588593
process_sp->SetBaseDirection(direction);
594+
}
589595
return Continue();
590596
}
591597

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,11 @@ Status ProcessGDBRemote::WillResume() {
11821182
return Status();
11831183
}
11841184
1185+
bool ProcessGDBRemote::SupportsReverseDirection() {
1186+
return m_gdb_comm.GetReverseStepSupported() ||
1187+
m_gdb_comm.GetReverseContinueSupported();
1188+
}
1189+
11851190
Status ProcessGDBRemote::DoResume(RunDirection direction) {
11861191
Status error;
11871192
Log *log = GetLog(GDBRLog::Process);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class ProcessGDBRemote : public Process,
111111
// Process Control
112112
Status WillResume() override;
113113

114+
bool SupportsReverseDirection() override;
115+
114116
Status DoResume(lldb::RunDirection direction) override;
115117

116118
Status DoHalt(bool &caused_stop) override;

lldb/test/API/functionalities/reverse-execution/TestReverseContinueNotSupported.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def test_reverse_continue_not_supported(self):
2222

2323
# This will fail gracefully.
2424
status = process.ContinueInDirection(lldb.eRunReverse)
25-
self.assertFailure(status, "target does not support reverse-continue")
25+
self.assertFailure(
26+
status, "error: gdb-remote does not support reverse execution of processes"
27+
)
2628

2729
status = process.ContinueInDirection(lldb.eRunForward)
2830
self.assertSuccess(status)

0 commit comments

Comments
 (0)