1#include "lldb/API/SBCommandInterpreter.h"
2#include "lldb/API/SBCommandReturnObject.h"
3#include "lldb/API/SBDebugger.h"
4
5using namespace lldb;
6
7static SBCommandReturnObject subcommand(SBDebugger &dbg, const char *cmd) {
8 SBCommandReturnObject Result;
9 dbg.GetCommandInterpreter().HandleCommand(cmd, Result);
10 return Result;
11}
12
13class CommandCrasher : public SBCommandPluginInterface {
14public:
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
25int 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

source code of lldb/test/API/api/command-return-object/main.cpp