@@ -584,6 +584,14 @@ The plugin has a number of arguments, all of them are optional:
configuration arguments implies ``l2=on``.
(default: N = 2097152 (2MB), B = 64, A = 16)
+- contrib/plugins/cc.cc
+
+cc plugin demonstrates how to write a plugin in C++. It simply outputs
+"hello, world" to the plugin log::
+
+ $ qemu-system-arm $(QEMU_ARGS) \
+ -plugin ./contrib/plugins/libcc.so -d plugin
+
API
---
@@ -293,10 +293,18 @@ else
cc="${CC-${cross_prefix}gcc}"
fi
-if test -z "${CXX}${cross_prefix}"; then
- cxx="c++"
+if test -n "${CXX+x}"; then
+ cxx="$CXX"
else
- cxx="${CXX-${cross_prefix}g++}"
+ if test -n "${cross_prefix}"; then
+ cxx="${cross_prefix}g++"
+ else
+ cxx="c++"
+ fi
+
+ if ! has "$cxx"; then
+ cxx=
+ fi
fi
# Preferred ObjC compiler:
@@ -1702,6 +1710,7 @@ echo "MESON=$meson" >> $config_host_mak
echo "NINJA=$ninja" >> $config_host_mak
echo "PKG_CONFIG=${pkg_config}" >> $config_host_mak
echo "CC=$cc" >> $config_host_mak
+echo "CXX=$cxx" >> $config_host_mak
echo "EXESUF=$EXESUF" >> $config_host_mak
# use included Linux headers
@@ -21,6 +21,9 @@ NAMES += lockstep
NAMES += hwprofile
NAMES += cache
NAMES += drcov
+ifneq ($(CXX),)
+NAMES += cc
+endif
SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
@@ -31,6 +34,8 @@ CFLAGS += -fPIC -Wall
CFLAGS += $(if $(CONFIG_DEBUG_TCG), -ggdb -O0)
CFLAGS += -I$(SRC_PATH)/include/qemu
+CXXFLAGS := $(CFLAGS)
+
all: $(SONAMES)
%.o: %.c
new file mode 100644
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <qemu-plugin.h>
+
+extern "C" {
+
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+ const qemu_info_t *info, int argc,
+ char **argv)
+{
+ qemu_plugin_outs("hello, world\n");
+ return 0;
+}
+
+};
@@ -149,6 +149,9 @@ PLUGIN_SRC=$(SRC_PATH)/tests/plugin
PLUGIN_LIB=../../plugin
VPATH+=$(PLUGIN_LIB)
PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
+ifneq ($(CXX),)
+PLUGINS+=$(patsubst %.cc, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.cc)))
+endif
# We need to ensure expand the run-plugin-TEST-with-PLUGIN
# pre-requistes manually here as we can't use stems to handle it. We
This demonstrates how to write a plugin in C++. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> --- docs/devel/tcg-plugins.rst | 8 ++++++++ configure | 15 ++++++++++++--- contrib/plugins/Makefile | 5 +++++ contrib/plugins/cc.cc | 17 +++++++++++++++++ tests/tcg/Makefile.target | 3 +++ 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 contrib/plugins/cc.cc