summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectQuit.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2013-01-17 21:36:19 +0000
committerEnrico Granata <egranata@apple.com>2013-01-17 21:36:19 +0000
commitbcba2b2b7507d997742eaf1aa108b91d28b84fce (patch)
treed5c22cdce1e4937f666546edddeff32fa092e681 /lldb/source/Commands/CommandObjectQuit.cpp
parentda29e005781274c390029abe0e596d51478342ab (diff)
downloadbcm5719-llvm-bcba2b2b7507d997742eaf1aa108b91d28b84fce.tar.gz
bcm5719-llvm-bcba2b2b7507d997742eaf1aa108b91d28b84fce.zip
<rdar://problem/12786725>
If there is any alive process being debugged, the user is asked for confirmation before quitting LLDB This should prevent situations where the user mistakenly types "q" and LLDB slaughters their process without any mercy whatsoever Since it can quickly get tedious, there is a new setting on the command interpreter to disable this and replicate the previous behavior llvm-svn: 172757
Diffstat (limited to 'lldb/source/Commands/CommandObjectQuit.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectQuit.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectQuit.cpp b/lldb/source/Commands/CommandObjectQuit.cpp
index bdccec4899f..c4c09e87b9b 100644
--- a/lldb/source/Commands/CommandObjectQuit.cpp
+++ b/lldb/source/Commands/CommandObjectQuit.cpp
@@ -34,9 +34,63 @@ CommandObjectQuit::~CommandObjectQuit ()
{
}
+// returns true if there is at least one alive process
+// is_a_detach will be true if all alive processes will be detached when you quit
+// and false if at least one process will be killed instead
+bool
+CommandObjectQuit::ShouldAskForConfirmation (bool& is_a_detach)
+{
+ if (m_interpreter.GetPromptOnQuit() == false)
+ return false;
+ bool should_prompt = false;
+ is_a_detach = true;
+ for (uint32_t debugger_idx = 0;
+ debugger_idx < Debugger::GetNumDebuggers();
+ debugger_idx++)
+ {
+ DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx));
+ if (!debugger_sp)
+ continue;
+ const TargetList& target_list(debugger_sp->GetTargetList());
+ for (uint32_t target_idx = 0;
+ target_idx < target_list.GetNumTargets();
+ target_idx++)
+ {
+ TargetSP target_sp(target_list.GetTargetAtIndex(target_idx));
+ if (!target_sp)
+ continue;
+ ProcessSP process_sp(target_sp->GetProcessSP());
+ if (process_sp &&
+ process_sp->IsValid() &&
+ process_sp->IsAlive())
+ {
+ should_prompt = true;
+ if (process_sp->GetShouldDetach() == false)
+ {
+ // if we need to kill at least one process, just say so and return
+ is_a_detach = false;
+ return should_prompt;
+ }
+ }
+ }
+ }
+ return should_prompt;
+}
+
bool
CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result)
{
+ bool is_a_detach = true;
+ if (ShouldAskForConfirmation (is_a_detach))
+ {
+ StreamString message;
+ message.Printf("Quitting LLDB will %s one or more processes. Do you really want to proceed", (is_a_detach ? "detach from" : "kill"));
+ if (!m_interpreter.Confirm(message.GetData(), true))
+ {
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
m_interpreter.BroadcastEvent (CommandInterpreter::eBroadcastBitQuitCommandReceived);
result.SetStatus (eReturnStatusQuit);
return true;
OpenPOWER on IntegriCloud