xref: /freebsd-src/contrib/llvm-project/lldb/source/Commands/CommandObjectGUI.cpp (revision 9dba64be9536c28e4800e06512b7f29b43ade345)
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     File &output = debugger.GetOutputFile();
33     if (input.GetStream() && output.GetStream() && input.GetIsRealTerminal() &&
34         input.GetIsInteractive()) {
35       IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
36       if (io_handler_sp)
37         debugger.PushIOHandler(io_handler_sp);
38       result.SetStatus(eReturnStatusSuccessFinishResult);
39     } else {
40       result.AppendError("the gui command requires an interactive terminal.");
41       result.SetStatus(eReturnStatusFailed);
42     }
43   } else {
44     result.AppendError("the gui command takes no arguments.");
45     result.SetStatus(eReturnStatusFailed);
46   }
47   return true;
48 #else
49   result.AppendError("lldb was not build with gui support");
50   return false;
51 #endif
52 }
53