| 1 | #include "lldb/API/SBCommandInterpreter.h" |
| 2 | #include "lldb/API/SBCommandReturnObject.h" |
| 3 | #include "lldb/API/SBDebugger.h" |
| 4 | |
| 5 | using namespace lldb; |
| 6 | |
| 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: |
| 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 | |
| 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 | |