diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp')
-rw-r--r-- | gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp b/gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp new file mode 100644 index 00000000000..e65fa164f04 --- /dev/null +++ b/gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp @@ -0,0 +1,46 @@ +//===-- fooplugin.cpp -------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +/* +An example plugin for LLDB that provides a new foo command with a child +subcommand +Compile this into a dylib foo.dylib and load by placing in appropriate locations +on disk or +by typing plugin load foo.dylib at the LLDB command line +*/ + +#include <LLDB/SBCommandInterpreter.h> +#include <LLDB/SBCommandReturnObject.h> +#include <LLDB/SBDebugger.h> + +namespace lldb { +bool PluginInitialize(lldb::SBDebugger debugger); +} + +class ChildCommand : public lldb::SBCommandPluginInterface { +public: + virtual bool DoExecute(lldb::SBDebugger debugger, char **command, + lldb::SBCommandReturnObject &result) { + if (command) { + const char *arg = *command; + while (arg) { + result.Printf("%s\n", arg); + arg = *(++command); + } + return true; + } + return false; + } +}; + +bool lldb::PluginInitialize(lldb::SBDebugger debugger) { + lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); + lldb::SBCommand foo = interpreter.AddMultiwordCommand("foo", NULL); + foo.AddCommand("child", new ChildCommand(), "a child of foo"); + return true; +} |