Received: from eggs.gnu.org ([208.118.235.92]:34291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US6vH-00075y-8v for qemu-devel@nongnu.org; Tue, 16 Apr 2013 10:31:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1US6dD-00017T-4A for qemu-devel@nongnu.org; Tue, 16 Apr 2013 10:13:15 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:44895) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US6I1-0003av-1L for qemu-devel@nongnu.org; Tue, 16 Apr 2013 09:51:17 -0400 Received: from gw.ac.upc.edu (gw.ac.upc.es [147.83.30.3]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id r3GDpGs4030908 for ; Tue, 16 Apr 2013 15:51:16 +0200 Received: from localhost (unknown [84.88.51.85]) by gw.ac.upc.edu (Postfix) with ESMTP id 064406B01C9 for ; Tue, 16 Apr 2013 15:51:16 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova Date: Tue, 16 Apr 2013 15:51:15 +0200 Message-Id: <20130416135115.21588.60152.stgit@fimbulvetr.bsc.es> In-Reply-To: <20130416134949.21588.80064.stgit@fimbulvetr.bsc.es> References: <20130416134949.21588.80064.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 15/23] instrument: [qmp, qapi] Add control interface List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Add QMP commands to control (un)loading of dynamic instrumentation librar= y. Signed-off-by: Llu=C3=ADs Vilanova --- include/qapi/qmp/qerror.h | 9 +++++ instrument/Makefile.objs | 1 + instrument/qapi-schema.json | 33 ++++++++++++++++++++ instrument/qmp.c | 70 +++++++++++++++++++++++++++++++++++++= +++++ qapi-schema.json | 2 + qmp-commands.hx | 71 +++++++++++++++++++++++++++++++++++++= ++++++ qmp.c | 4 ++ 7 files changed, 190 insertions(+) create mode 100644 instrument/qapi-schema.json create mode 100644 instrument/qmp.c diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h index 6c0a18d..67b4528 100644 --- a/include/qapi/qmp/qerror.h +++ b/include/qapi/qmp/qerror.h @@ -129,6 +129,15 @@ void assert_no_error(Error *err); #define QERR_FEATURE_DISABLED \ ERROR_CLASS_GENERIC_ERROR, "The feature '%s' is not enabled" =20 +#define QERR_INSTR_LOAD_DL \ + ERROR_CLASS_GENERIC_ERROR, "Error loading dynamic library: %s" + +#define QERR_INSTR_LOAD_LOADED \ + ERROR_CLASS_GENERIC_ERROR, "Already loaded" + +#define QERR_INSTR_LOAD_UNLOADED \ + ERROR_CLASS_GENERIC_ERROR, "Already unloaded" + #define QERR_INVALID_BLOCK_FORMAT \ ERROR_CLASS_GENERIC_ERROR, "Invalid block format '%s'" =20 diff --git a/instrument/Makefile.objs b/instrument/Makefile.objs index 02cc5b7..e3d4e9b 100644 --- a/instrument/Makefile.objs +++ b/instrument/Makefile.objs @@ -68,3 +68,4 @@ endif target-obj-y +=3D control.o =20 common-obj-$(CONFIG_SOFTMMU) +=3D hmp.o +common-obj-$(CONFIG_SOFTMMU) +=3D qmp.o diff --git a/instrument/qapi-schema.json b/instrument/qapi-schema.json new file mode 100644 index 0000000..0ecf31f --- /dev/null +++ b/instrument/qapi-schema.json @@ -0,0 +1,33 @@ +# *-*- Mode: Python -*-* + +## +# @instr-dynamic: +# +# Whether dynamic trace instrumentation is available. +# +# Since: 1.5 +## +{ 'command': 'instr-dynamic', + 'returns': 'bool' } + +## +# @instr-load: +# +# Load a dynamic instrumentation library. +# +# @path: path to the dynamic instrumentation library +# @iargs: arguments to the dynamic instrumentation library +# +# Since: 1.5 +## +{ 'command': 'instr-load', + 'data': { 'path': 'str', 'iargs': ['String'] } } + +## +# @instr-unload: +# +# Unload the current dynamic instrumentation library. +# +# Since: 1.5 +## +{ 'command': 'instr-unload' } diff --git a/instrument/qmp.c b/instrument/qmp.c new file mode 100644 index 0000000..f744250 --- /dev/null +++ b/instrument/qmp.c @@ -0,0 +1,70 @@ +/* + * QMP interface for dynamic trace instrumentation control commands. + * + * Copyright (C) 2012-2013 Llu=C3=ADs Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. + * See the COPYING file in the top-level directory. + */ + +#include "qemu-common.h" +#include "qapi/qmp/qerror.h" +#include "qmp-commands.h" + +#include + +#include "instrument/control.h" + + + +bool qmp_instr_dynamic(Error **errp) +{ + return instr_dynamic(); +} + +void qmp_instr_load(const char * path, StringList * iargs, Error **errp) +{ + int argc =3D 0; + const char **argv =3D NULL; + + StringList *entry; + while (entry !=3D NULL) { + argv =3D realloc(argv, sizeof(*argv) * (argc + 1)); + argv[argc] =3D entry->value->str; + argc++; + entry =3D entry->next; + } + + InstrLoadError err =3D instr_load(path, argc, argv); + switch (err) { + case INSTR_LOAD_OK: + break; + case INSTR_LOAD_UNAVAILABLE: + error_set(errp, QERR_UNSUPPORTED); + break; + case INSTR_LOAD_LOADED: + error_set(errp, QERR_INSTR_LOAD_LOADED); + break; + case INSTR_LOAD_DL: + error_set(errp, QERR_INSTR_LOAD_DL, dlerror()); + break; + } +} + +void qmp_instr_unload(Error **errp) +{ + InstrLoadError err =3D instr_unload(); + switch (err) { + case INSTR_UNLOAD_OK: + break; + case INSTR_UNLOAD_UNAVAILABLE: + error_set(errp, QERR_UNSUPPORTED); + break; + case INSTR_UNLOAD_UNLOADED: + error_set(errp, QERR_INSTR_LOAD_UNLOADED); + break; + case INSTR_UNLOAD_DL: + error_set(errp, QERR_INSTR_LOAD_DL, dlerror()); + break; + } +} diff --git a/qapi-schema.json b/qapi-schema.json index db542f6..bc5fe06 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3513,3 +3513,5 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +input("instrument/qapi-schema.json") diff --git a/qmp-commands.hx b/qmp-commands.hx index 1e0e11e..1ea6c38 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1510,6 +1510,77 @@ Notes: o Commands that prompt the user for data (eg. 'cont' when the block device is encrypted) don't currently work =20 +instr-dynamic +------------- + +Whether dynamic trace instrumentation is available. + +Arguments: None. + +Example: + +-> { "execute": "instr-dyanmic" } +<- { "return": true } + +EQMP + + { + .name =3D "instr-dynamic", + .args_type =3D "", + .mhandler.cmd_new =3D qmp_marshal_input_instr_dynamic, + }, + + +SQMP + +instr-load +---------- + +Load a dynamic instrumentation library. + +Arguments: + +- path: path to the dynamic instrumentation library +- args: arguments to the dynamic instrumentation library + +Example: + +-> { "execute": "instr-load", "arguments": { "path": "/tmp/libtrace-inst= rument.so" } } +<- { "return": {} } + +EQMP + + { + .name =3D "instr-load", + .args_type =3D "", + .mhandler.cmd_new =3D qmp_marshal_input_instr_load, + }, + + +SQMP + +instr-unload +------------ + +Unload the current dynamic instrumentation library. + +Arguments: None. + +Example: + +-> { "execute": "instr-unload" } +<- { "return": {} } + +EQMP + + { + .name =3D "instr-unload", + .args_type =3D "", + .mhandler.cmd_new =3D qmp_marshal_input_instr_unload, + }, + + +SQMP 3. Query Commands =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/qmp.c b/qmp.c index 55b056b..72abe03 100644 --- a/qmp.c +++ b/qmp.c @@ -24,6 +24,10 @@ #include "hw/qdev.h" #include "sysemu/blockdev.h" #include "qom/qom-qobject.h" +#if defined(TRACE_INSTRUMENT_DYNAMIC) +#include "instrument/qi-qmp-commands.h" +#endif + =20 NameInfo *qmp_query_name(Error **errp) {