xref: /llvm-project/lldb/test/API/api/command-return-object/main.cpp (revision 99451b4453688a94c6014cac233d371ab4cc342d)
1 #include "lldb/API/SBCommandInterpreter.h"
2 #include "lldb/API/SBCommandReturnObject.h"
3 #include "lldb/API/SBDebugger.h"
4 
5 using namespace lldb;
6 
subcommand(SBDebugger & dbg,const char * cmd)7 static SBCommandReturnObject subcommand(SBDebugger &dbg, const char *cmd) {
8   SBCommandReturnObject Result;
9   dbg.GetCommandInterpreter().HandleCommand(cmd, Result);
10   return Result;
11 }
12 
13 class CommandCrasher : public SBCommandPluginInterface {
14 public:
DoExecute(SBDebugger dbg,char ** command,SBCommandReturnObject & result)15   bool DoExecute(SBDebugger dbg, char **command,
16                  SBCommandReturnObject &result) {
17     // Test assignment from a different SBCommandReturnObject instance.
18     result = subcommand(dbg, "help");
19     // Test also whether self-assignment is handled correctly.
20     result = result;
21     return result.Succeeded();
22   }
23 };
24 
main()25 int main() {
26   SBDebugger::Initialize();
27   SBDebugger dbg = SBDebugger::Create(false /*source_init_files*/);
28   SBCommandInterpreter interp = dbg.GetCommandInterpreter();
29   static CommandCrasher crasher;
30   interp.AddCommand("crasher", &crasher, nullptr /*help*/);
31   SBCommandReturnObject Result;
32   dbg.GetCommandInterpreter().HandleCommand("crasher", Result);
33 }
34