1 //===-- CommandObjectQuit.cpp -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "CommandObjectQuit.h"
16 // Other libraries and framework includes
18 #include "lldb/Interpreter/CommandInterpreter.h"
19 #include "lldb/Interpreter/CommandReturnObject.h"
22 using namespace lldb_private;
24 //-------------------------------------------------------------------------
26 //-------------------------------------------------------------------------
28 CommandObjectQuit::CommandObjectQuit (CommandInterpreter &interpreter) :
29 CommandObjectParsed (interpreter, "quit", "Quit out of the LLDB debugger.", "quit")
33 CommandObjectQuit::~CommandObjectQuit ()
37 // returns true if there is at least one alive process
38 // is_a_detach will be true if all alive processes will be detached when you quit
39 // and false if at least one process will be killed instead
41 CommandObjectQuit::ShouldAskForConfirmation (bool& is_a_detach)
43 if (m_interpreter.GetPromptOnQuit() == false)
45 bool should_prompt = false;
47 for (uint32_t debugger_idx = 0;
48 debugger_idx < Debugger::GetNumDebuggers();
51 DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx));
54 const TargetList& target_list(debugger_sp->GetTargetList());
55 for (uint32_t target_idx = 0;
56 target_idx < target_list.GetNumTargets();
59 TargetSP target_sp(target_list.GetTargetAtIndex(target_idx));
62 ProcessSP process_sp(target_sp->GetProcessSP());
64 && process_sp->IsValid()
65 && process_sp->IsAlive()
66 && process_sp->WarnBeforeDetach())
69 if (process_sp->GetShouldDetach() == false)
71 // if we need to kill at least one process, just say so and return
82 CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result)
84 bool is_a_detach = true;
85 if (ShouldAskForConfirmation (is_a_detach))
88 message.Printf("Quitting LLDB will %s one or more processes. Do you really want to proceed", (is_a_detach ? "detach from" : "kill"));
89 if (!m_interpreter.Confirm(message.GetData(), true))
91 result.SetStatus(eReturnStatusFailed);
95 m_interpreter.BroadcastEvent (CommandInterpreter::eBroadcastBitQuitCommandReceived);
96 result.SetStatus (eReturnStatusQuit);