xref: /llvm-project/lldb/source/Commands/CommandObjectGUI.cpp (revision 7ca15ba73f67f1d3b6652cb19bbf78731e3b128d)
1 //===-- CommandObjectGUI.cpp ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "CommandObjectGUI.h"
10 
11 #include "lldb/Interpreter/CommandInterpreter.h"
12 #include "lldb/Interpreter/CommandReturnObject.h"
13 #include "lldb/lldb-private.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 // CommandObjectGUI
19 
20 CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter)
21     : CommandObjectParsed(interpreter, "gui",
22                           "Switch into the curses based GUI mode.", "gui") {}
23 
24 CommandObjectGUI::~CommandObjectGUI() {}
25 
26 bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
27 #ifndef LLDB_DISABLE_CURSES
28   if (args.GetArgumentCount() == 0) {
29     Debugger &debugger = GetDebugger();
30 
31     File &input = debugger.GetInputFile();
32     if (input.GetIsRealTerminal() && input.GetIsInteractive()) {
33       IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
34       if (io_handler_sp)
35         debugger.PushIOHandler(io_handler_sp);
36       result.SetStatus(eReturnStatusSuccessFinishResult);
37     } else {
38       result.AppendError("the gui command requires an interactive terminal.");
39       result.SetStatus(eReturnStatusFailed);
40     }
41   } else {
42     result.AppendError("the gui command takes no arguments.");
43     result.SetStatus(eReturnStatusFailed);
44   }
45   return true;
46 #else
47   result.AppendError("lldb was not build with gui support");
48   return false;
49 #endif
50 }
51