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) |
| 28 | : CommandObjectParsed(interpreter, "quit", "Quit the LLDB debugger.", "quit") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
| 32 | CommandObjectQuit::~CommandObjectQuit () |
| 33 | { |
| 34 | } |
| 35 | |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 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 |
| 39 | bool |
| 40 | CommandObjectQuit::ShouldAskForConfirmation (bool& is_a_detach) |
| 41 | { |
| 42 | if (m_interpreter.GetPromptOnQuit() == false) |
| 43 | return false; |
| 44 | bool should_prompt = false; |
| 45 | is_a_detach = true; |
| 46 | for (uint32_t debugger_idx = 0; |
| 47 | debugger_idx < Debugger::GetNumDebuggers(); |
| 48 | debugger_idx++) |
| 49 | { |
| 50 | DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx)); |
| 51 | if (!debugger_sp) |
| 52 | continue; |
| 53 | const TargetList& target_list(debugger_sp->GetTargetList()); |
| 54 | for (uint32_t target_idx = 0; |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 55 | target_idx < static_cast<uint32_t>(target_list.GetNumTargets()); |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 56 | target_idx++) |
| 57 | { |
| 58 | TargetSP target_sp(target_list.GetTargetAtIndex(target_idx)); |
| 59 | if (!target_sp) |
| 60 | continue; |
| 61 | ProcessSP process_sp(target_sp->GetProcessSP()); |
Jason Molenda | 408fa33 | 2013-05-11 00:52:25 +0000 | [diff] [blame] | 62 | if (process_sp |
| 63 | && process_sp->IsValid() |
| 64 | && process_sp->IsAlive() |
| 65 | && process_sp->WarnBeforeDetach()) |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 66 | { |
| 67 | should_prompt = true; |
| 68 | if (process_sp->GetShouldDetach() == false) |
| 69 | { |
| 70 | // if we need to kill at least one process, just say so and return |
| 71 | is_a_detach = false; |
| 72 | return should_prompt; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | return should_prompt; |
| 78 | } |
| 79 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 81 | CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | { |
Enrico Granata | bcba2b2 | 2013-01-17 21:36:19 +0000 | [diff] [blame] | 83 | bool is_a_detach = true; |
| 84 | if (ShouldAskForConfirmation (is_a_detach)) |
| 85 | { |
| 86 | StreamString message; |
| 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)) |
| 89 | { |
| 90 | result.SetStatus(eReturnStatusFailed); |
| 91 | return false; |
| 92 | } |
| 93 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 94 | const uint32_t event_type = CommandInterpreter::eBroadcastBitQuitCommandReceived; |
| 95 | m_interpreter.BroadcastEvent (event_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | result.SetStatus (eReturnStatusQuit); |
| 97 | return true; |
| 98 | } |
| 99 | |