1 //===-- CommandObjectQuit.cpp -----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/lldb-python.h" 11 12 #include "CommandObjectQuit.h" 13 14 // C Includes 15 // C++ Includes 16 // Other libraries and framework includes 17 // Project includes 18 #include "lldb/Interpreter/CommandInterpreter.h" 19 #include "lldb/Interpreter/CommandReturnObject.h" 20 #include "lldb/Target/Process.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 //------------------------------------------------------------------------- 26 // CommandObjectQuit 27 //------------------------------------------------------------------------- 28 29 CommandObjectQuit::CommandObjectQuit (CommandInterpreter &interpreter) : 30 CommandObjectParsed (interpreter, "quit", "Quit out of the LLDB debugger.", "quit") 31 { 32 } 33 34 CommandObjectQuit::~CommandObjectQuit () 35 { 36 } 37 38 // returns true if there is at least one alive process 39 // is_a_detach will be true if all alive processes will be detached when you quit 40 // and false if at least one process will be killed instead 41 bool 42 CommandObjectQuit::ShouldAskForConfirmation (bool& is_a_detach) 43 { 44 if (m_interpreter.GetPromptOnQuit() == false) 45 return false; 46 bool should_prompt = false; 47 is_a_detach = true; 48 for (uint32_t debugger_idx = 0; 49 debugger_idx < Debugger::GetNumDebuggers(); 50 debugger_idx++) 51 { 52 DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx)); 53 if (!debugger_sp) 54 continue; 55 const TargetList& target_list(debugger_sp->GetTargetList()); 56 for (uint32_t target_idx = 0; 57 target_idx < static_cast<uint32_t>(target_list.GetNumTargets()); 58 target_idx++) 59 { 60 TargetSP target_sp(target_list.GetTargetAtIndex(target_idx)); 61 if (!target_sp) 62 continue; 63 ProcessSP process_sp(target_sp->GetProcessSP()); 64 if (process_sp 65 && process_sp->IsValid() 66 && process_sp->IsAlive() 67 && process_sp->WarnBeforeDetach()) 68 { 69 should_prompt = true; 70 if (process_sp->GetShouldDetach() == false) 71 { 72 // if we need to kill at least one process, just say so and return 73 is_a_detach = false; 74 return should_prompt; 75 } 76 } 77 } 78 } 79 return should_prompt; 80 } 81 82 bool 83 CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result) 84 { 85 bool is_a_detach = true; 86 if (ShouldAskForConfirmation (is_a_detach)) 87 { 88 StreamString message; 89 message.Printf("Quitting LLDB will %s one or more processes. Do you really want to proceed", (is_a_detach ? "detach from" : "kill")); 90 if (!m_interpreter.Confirm(message.GetData(), true)) 91 { 92 result.SetStatus(eReturnStatusFailed); 93 return false; 94 } 95 } 96 const uint32_t event_type = CommandInterpreter::eBroadcastBitQuitCommandReceived; 97 m_interpreter.BroadcastEvent (event_type); 98 result.SetStatus (eReturnStatusQuit); 99 return true; 100 } 101 102