summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
committerpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
commit061da546b983eb767bad15e67af1174fb0bcf31c (patch)
tree83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/examples/plugins/commands/fooplugin.cpp
parentImport LLVM 10.0.0 release including clang, lld and lldb. (diff)
downloadwireguard-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.cpp46
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;
+}