[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 24/24] contrib/plugins: Add cc plugin
From: |
Akihiko Odaki |
Subject: |
[PATCH v2 24/24] contrib/plugins: Add cc plugin |
Date: |
Wed, 2 Aug 2023 17:46:12 +0900 |
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
diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst
index c9f8b27590..0a11f8036c 100644
--- a/docs/devel/tcg-plugins.rst
+++ b/docs/devel/tcg-plugins.rst
@@ -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
---
diff --git a/configure b/configure
index 26ec5e4f54..0065b0dfe0 100755
--- a/configure
+++ b/configure
@@ -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
diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
index b2b9db9f51..93d86b3d07 100644
--- a/contrib/plugins/Makefile
+++ b/contrib/plugins/Makefile
@@ -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
diff --git a/contrib/plugins/cc.cc b/contrib/plugins/cc.cc
new file mode 100644
index 0000000000..83a5528db0
--- /dev/null
+++ b/contrib/plugins/cc.cc
@@ -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;
+}
+
+};
diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target
index 462289f47c..3d7837d3b8 100644
--- a/tests/tcg/Makefile.target
+++ b/tests/tcg/Makefile.target
@@ -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
--
2.41.0
- [PATCH v2 14/24] gdbstub: Add members to identify registers to GDBFeature, (continued)
- [PATCH v2 14/24] gdbstub: Add members to identify registers to GDBFeature, Akihiko Odaki, 2023/08/02
- [PATCH v2 15/24] target/arm: Fill new members of GDBFeature, Akihiko Odaki, 2023/08/02
- [PATCH v2 16/24] target/ppc: Fill new members of GDBFeature, Akihiko Odaki, 2023/08/02
- [PATCH v2 17/24] target/riscv: Fill new members of GDBFeature, Akihiko Odaki, 2023/08/02
- [PATCH v2 18/24] hw/core/cpu: Add a parameter to gdb_read_register/gdb_write_register, Akihiko Odaki, 2023/08/02
- [PATCH v2 19/24] gdbstub: Hide gdb_has_xml, Akihiko Odaki, 2023/08/02
- [PATCH v2 20/24] gdbstub: Expose functions to read registers, Akihiko Odaki, 2023/08/02
- [PATCH v2 21/24] plugins: Allow to read registers, Akihiko Odaki, 2023/08/02
- [PATCH v2 22/24] contrib/plugins: Allow to log registers, Akihiko Odaki, 2023/08/02
- [PATCH v2 23/24] plugins: Support C++, Akihiko Odaki, 2023/08/02
- [PATCH v2 24/24] contrib/plugins: Add cc plugin,
Akihiko Odaki <=