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 "CommandObjectQuit.h"
14 // Other libraries and framework includes
16 #include "lldb/Interpreter/CommandInterpreter.h"
17 #include "lldb/Interpreter/CommandReturnObject.h"
18 #include "lldb/Target/Process.h"
21 using namespace lldb_private;
23 //-------------------------------------------------------------------------
25 //-------------------------------------------------------------------------
27 CommandObjectQuit::CommandObjectQuit (CommandInterpreter &interpreter) :
28 CommandObjectParsed (interpreter, "quit", "Quit out of the LLDB debugger.", "quit")
32 CommandObjectQuit::~CommandObjectQuit ()
36 // returns true if there is at least one alive process
37 // is_a_detach will be true if all alive processes will be detached when you quit
38 // and false if at least one process will be killed instead
40 CommandObjectQuit::ShouldAskForConfirmation (bool& is_a_detach)
42 if (m_interpreter.GetPromptOnQuit() == false)
44 bool should_prompt = false;
46 for (uint32_t debugger_idx = 0;
47 debugger_idx < Debugger::GetNumDebuggers();
50 DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx));
53 const TargetList& target_list(debugger_sp->GetTargetList());
54 for (uint32_t target_idx = 0;
55 target_idx < static_cast<uint32_t>(target_list.GetNumTargets());
58 TargetSP target_sp(target_list.GetTargetAtIndex(target_idx));
61 ProcessSP process_sp(target_sp->GetProcessSP());
63 && process_sp->IsValid()
64 && process_sp->IsAlive()
65 && process_sp->WarnBeforeDetach())
68 if (process_sp->GetShouldDetach() == false)
70 // if we need to kill at least one process, just say so and return
81 CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result)
83 bool is_a_detach = true;
84 if (ShouldAskForConfirmation (is_a_detach))
87 message.Printf("Quitting LLDB will %s one or more processes. Do you really want to proceed", (is_a_detach ? "detach from" : "kill"));
88 if (!m_interpreter.Confirm(message.GetData(), true))
90 result.SetStatus(eReturnStatusFailed);
94 const uint32_t event_type = CommandInterpreter::eBroadcastBitQuitCommandReceived;
95 m_interpreter.BroadcastEvent (event_type);
96 result.SetStatus (eReturnStatusQuit);