tatyana-krasnukha created this revision.
tatyana-krasnukha added reviewers: JDevlieghere, jingham.
tatyana-krasnukha added a project: LLDB.
Herald added a subscriber: lldb-commits.
Usually, SIGTARP, SIGINT and SIGSTOP don't imply a crash. Rely on process
signals' ShouldSuppress to filter such kind of signals out.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D67776
Files:
include/lldb/Interpreter/CommandInterpreter.h
include/lldb/Interpreter/CommandReturnObject.h
source/Commands/CommandObjectProcess.cpp
source/Interpreter/CommandInterpreter.cpp
source/Interpreter/CommandReturnObject.cpp
Index: source/Interpreter/CommandReturnObject.cpp
===================================================================
--- source/Interpreter/CommandReturnObject.cpp
+++ source/Interpreter/CommandReturnObject.cpp
@@ -33,8 +33,7 @@
CommandReturnObject::CommandReturnObject()
: m_out_stream(), m_err_stream(), m_status(eReturnStatusStarted),
- m_did_change_process_state(false), m_interactive(true),
- m_abnormal_stop_was_expected(false) {}
+ m_did_change_process_state(false), m_interactive(true) {}
CommandReturnObject::~CommandReturnObject() {}
Index: source/Interpreter/CommandInterpreter.cpp
===================================================================
--- source/Interpreter/CommandInterpreter.cpp
+++ source/Interpreter/CommandInterpreter.cpp
@@ -63,8 +63,10 @@
#include "lldb/Utility/Args.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/StopInfo.h"
#include "lldb/Target/TargetList.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Target/UnixSignals.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
@@ -2141,6 +2143,39 @@
return platform_sp;
}
+bool CommandInterpreter::DidProcessStopAbnormally() const {
+ TargetSP target_sp = m_debugger.GetTargetList().GetSelectedTarget();
+ if (!target_sp)
+ return false;
+
+ ProcessSP process_sp(target_sp->GetProcessSP());
+ if (!process_sp)
+ return false;
+
+ if (eStateStopped != process_sp->GetState())
+ return false;
+
+ for (const auto &thread_sp : process_sp->GetThreadList().Threads()) {
+ StopInfoSP stop_info = thread_sp->GetStopInfo();
+ if (!stop_info)
+ return false;
+
+ StopReason reason = stop_info->GetStopReason();
+ if (eStopReasonException == reason || eStopReasonInstrumentation == reason)
+ return true;
+
+ if (eStopReasonSignal == reason) {
+ const auto stop_signal = static_cast<int32_t>(stop_info->GetValue());
+ UnixSignalsSP signals = process_sp->GetUnixSignals();
+ if (!signals || !signals->GetShouldSuppress(stop_signal))
+ // The signal is not of known suppressable signals, so it is abnormal.
+ return true;
+ }
+ }
+
+ return false;
+}
+
void CommandInterpreter::HandleCommands(const StringList &commands,
ExecutionContext *override_context,
CommandInterpreterRunOptions &options,
@@ -2251,38 +2286,22 @@
}
// Also check for "stop on crash here:
- bool should_stop = false;
- if (tmp_result.GetDidChangeProcessState() && options.GetStopOnCrash()) {
- TargetSP target_sp(m_debugger.GetTargetList().GetSelectedTarget());
- if (target_sp) {
- ProcessSP process_sp(target_sp->GetProcessSP());
- if (process_sp) {
- for (ThreadSP thread_sp : process_sp->GetThreadList().Threads()) {
- StopReason reason = thread_sp->GetStopReason();
- if (reason == eStopReasonSignal || reason == eStopReasonException ||
- reason == eStopReasonInstrumentation) {
- should_stop = true;
- break;
- }
- }
- }
- }
- if (should_stop) {
- if (idx != num_lines - 1)
- result.AppendErrorWithFormat(
- "Aborting reading of commands after command #%" PRIu64
- ": '%s' stopped with a signal or exception.\n",
- (uint64_t)idx + 1, cmd);
- else
- result.AppendMessageWithFormat(
- "Command #%" PRIu64 " '%s' stopped with a signal or exception.\n",
- (uint64_t)idx + 1, cmd);
+ if (tmp_result.GetDidChangeProcessState() && options.GetStopOnCrash() &&
+ DidProcessStopAbnormally()) {
+ if (idx != num_lines - 1)
+ result.AppendErrorWithFormat(
+ "Aborting reading of commands after command #%" PRIu64
+ ": '%s' stopped with a signal or exception.\n",
+ (uint64_t)idx + 1, cmd);
+ else
+ result.AppendMessageWithFormat(
+ "Command #%" PRIu64 " '%s' stopped with a signal or exception.\n",
+ (uint64_t)idx + 1, cmd);
- result.SetStatus(tmp_result.GetStatus());
- m_debugger.SetAsyncExecution(old_async_execution);
+ result.SetStatus(tmp_result.GetStatus());
+ m_debugger.SetAsyncExecution(old_async_execution);
- return;
- }
+ return;
}
}
@@ -2770,27 +2789,10 @@
// Finally, if we're going to stop on crash, check that here:
if (!m_quit_requested && result.GetDidChangeProcessState() &&
- io_handler.GetFlags().Test(eHandleCommandFlagStopOnCrash)) {
- bool should_stop = false;
- TargetSP target_sp(m_debugger.GetTargetList().GetSelectedTarget());
- if (target_sp) {
- ProcessSP process_sp(target_sp->GetProcessSP());
- if (process_sp) {
- for (ThreadSP thread_sp : process_sp->GetThreadList().Threads()) {
- StopReason reason = thread_sp->GetStopReason();
- if ((reason == eStopReasonSignal || reason == eStopReasonException ||
- reason == eStopReasonInstrumentation) &&
- !result.GetAbnormalStopWasExpected()) {
- should_stop = true;
- break;
- }
- }
- }
- }
- if (should_stop) {
- io_handler.SetIsDone(true);
- m_stopped_for_crash = true;
- }
+ io_handler.GetFlags().Test(eHandleCommandFlagStopOnCrash) &&
+ DidProcessStopAbnormally()) {
+ io_handler.SetIsDone(true);
+ m_stopped_for_crash = true;
}
}
Index: source/Commands/CommandObjectProcess.cpp
===================================================================
--- source/Commands/CommandObjectProcess.cpp
+++ source/Commands/CommandObjectProcess.cpp
@@ -429,7 +429,6 @@
result.AppendMessage(stream.GetString());
result.SetStatus(eReturnStatusSuccessFinishNoResult);
result.SetDidChangeProcessState(true);
- result.SetAbnormalStopWasExpected(true);
} else {
result.AppendError(
"no error returned from Target::Attach, and target has no process");
Index: include/lldb/Interpreter/CommandReturnObject.h
===================================================================
--- include/lldb/Interpreter/CommandReturnObject.h
+++ include/lldb/Interpreter/CommandReturnObject.h
@@ -144,14 +144,6 @@
void SetInteractive(bool b);
- bool GetAbnormalStopWasExpected() const {
- return m_abnormal_stop_was_expected;
- }
-
- void SetAbnormalStopWasExpected(bool signal_was_expected) {
- m_abnormal_stop_was_expected = signal_was_expected;
- }
-
private:
enum { eStreamStringIndex = 0, eImmediateStreamIndex = 1 };
@@ -162,14 +154,6 @@
bool m_did_change_process_state;
bool m_interactive; // If true, then the input handle from the debugger will
// be hooked up
- bool m_abnormal_stop_was_expected; // This is to support
- // eHandleCommandFlagStopOnCrash vrs.
- // attach.
- // The attach command often ends up with the process stopped due to a signal.
- // Normally that would mean stop on crash should halt batch execution, but we
- // obviously don't want that for attach. Using this flag, the attach command
- // (and anything else for which this is relevant) can say that the signal is
- // expected, and batch command execution can continue.
};
} // namespace lldb_private
Index: include/lldb/Interpreter/CommandInterpreter.h
===================================================================
--- include/lldb/Interpreter/CommandInterpreter.h
+++ include/lldb/Interpreter/CommandInterpreter.h
@@ -502,6 +502,8 @@
void GetProcessOutput();
+ bool DidProcessStopAbnormally() const;
+
void SetSynchronous(bool value);
lldb::CommandObjectSP GetCommandSP(llvm::StringRef cmd,
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits