Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 "CommandObjectQuit.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Eli Friedman | 59817b1 | 2010-06-09 07:57:51 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 17 | #include "lldb/Interpreter/CommandReturnObject.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 18 | #include "lldb/Target/Process.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | //------------------------------------------------------------------------- |
| 24 | // CommandObjectQuit |
| 25 | //------------------------------------------------------------------------- |
| 26 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 27 | CommandObjectQuit::CommandObjectQuit(CommandInterpreter &interpreter) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | : CommandObjectParsed(interpreter, "quit", "Quit the LLDB debugger.", |
| 29 | "quit") {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | CommandObjectQuit::~CommandObjectQuit() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 33 | // returns true if there is at least one alive process |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | // is_a_detach will be true if all alive processes will be detached when you |
| 35 | // quit |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 36 | // and false if at least one process will be killed instead |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | bool CommandObjectQuit::ShouldAskForConfirmation(bool &is_a_detach) { |
| 38 | if (m_interpreter.GetPromptOnQuit() == false) |
| 39 | return false; |
| 40 | bool should_prompt = false; |
| 41 | is_a_detach = true; |
| 42 | for (uint32_t debugger_idx = 0; debugger_idx < Debugger::GetNumDebuggers(); |
| 43 | debugger_idx++) { |
| 44 | DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx)); |
| 45 | if (!debugger_sp) |
| 46 | continue; |
| 47 | const TargetList &target_list(debugger_sp->GetTargetList()); |
| 48 | for (uint32_t target_idx = 0; |
| 49 | target_idx < static_cast<uint32_t>(target_list.GetNumTargets()); |
| 50 | target_idx++) { |
| 51 | TargetSP target_sp(target_list.GetTargetAtIndex(target_idx)); |
| 52 | if (!target_sp) |
| 53 | continue; |
| 54 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 55 | if (process_sp && process_sp->IsValid() && process_sp->IsAlive() && |
| 56 | process_sp->WarnBeforeDetach()) { |
| 57 | should_prompt = true; |
| 58 | if (process_sp->GetShouldDetach() == false) { |
| 59 | // if we need to kill at least one process, just say so and return |
| 60 | is_a_detach = false; |
| 61 | return should_prompt; |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 62 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | } |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 64 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | } |
| 66 | return should_prompt; |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | bool CommandObjectQuit::DoExecute(Args &command, CommandReturnObject &result) { |
| 70 | bool is_a_detach = true; |
| 71 | if (ShouldAskForConfirmation(is_a_detach)) { |
| 72 | StreamString message; |
| 73 | message.Printf("Quitting LLDB will %s one or more processes. Do you really " |
| 74 | "want to proceed", |
| 75 | (is_a_detach ? "detach from" : "kill")); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 76 | if (!m_interpreter.Confirm(message.GetString(), true)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | result.SetStatus(eReturnStatusFailed); |
| 78 | return false; |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 79 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | } |
| 81 | const uint32_t event_type = |
| 82 | CommandInterpreter::eBroadcastBitQuitCommandReceived; |
| 83 | m_interpreter.BroadcastEvent(event_type); |
| 84 | result.SetStatus(eReturnStatusQuit); |
| 85 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | } |