Add Multi-Core Debug (MCD) API support
cover Add Multi-Core Debug (MCD) API support
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol. We get around this limitation by following a remote procedure call approach using QMP. The client stub corresponding to this implementation can be found at https://gitlab.com/lauterbach/mcdrefsrv
This series is the successor to:
"[PATCH v5 00/18] first version of mcdstub"
(https://patchew.org/QEMU/[email protected]/)
* Architecture-independent MCD implementation
* QMP instead of custom TCP protocol
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
* Architecture-independent QTest test suite
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-test
* Architecture-specific tests can be found at the client stub
Mario Fleischmann (16):
mcd: Introduce Multi-Core Debug (MCD) API
mcd: Introduce MCD server
mcd: Implement target initialization API
mcd: Implement server connection API
mcd: Implement target system query
mcd: Implement core connection control
mcd: Implement memory space query
gdbstub: Expose GDBRegisterState
mcd: Implement register query
mcd: Implement runstate control
mcd test: Implement core state query
gdbstub: Expose gdb_write_register
mcd: Implement register/memory access
mcd: Implement single stepping
mcd: Implement trigger control
mcd: Implement reset control
MAINTAINERS | 9 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 58 + gdbstub/gdbstub.c | 15 +- include/exec/gdbstub.h | 18 +- mcd/libmcd_qapi.c | 506 +++++ mcd/libmcd_qapi.h | 81 + mcd/mcd_api.h | 3963 +++++++++++++++++++++++++++++++++++++ mcd/mcdserver.c | 2242 +++++++++++++++++++++ mcd/mcdstub_qapi.c | 974 +++++++++ mcd/meson.build | 12 + meson.build | 1 + qapi/mcd.json | 2366 ++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + tests/qtest/libmcd-test.c | 379 ++++ tests/qtest/libmcd-test.h | 68 + tests/qtest/mcd-test.c | 644 ++++++ tests/qtest/meson.build | 2 + 19 files changed, 11331 insertions(+), 10 deletions(-) create mode 100644 docs/interop/mcd.rst create mode 100644 mcd/libmcd_qapi.c create mode 100644 mcd/libmcd_qapi.h create mode 100644 mcd/mcd_api.h create mode 100644 mcd/mcdserver.c create mode 100644 mcd/mcdstub_qapi.c create mode 100644 mcd/meson.build create mode 100644 qapi/mcd.json create mode 100644 tests/qtest/libmcd-test.c create mode 100644 tests/qtest/libmcd-test.h create mode 100644 tests/qtest/mcd-test.c
Signature · 1 line
2.34.1
PATCH 1/16 mcd: Introduce Multi-Core Debug (MCD) API
Formatting changes to mcd_api.h to compily with QEMU's coding style guidelines:
* limit line width to 80
* convert Doxygen to kernel-doc comments
* avoid architecture specific defines
The original MCD API version can be found at:
https://repo.lauterbach.com/sprint_mcd_api_v1_0.zip
--- MAINTAINERS | 6 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 44 + mcd/mcd_api.h | 3963 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 4014 insertions(+) create mode 100644 docs/interop/mcd.rst create mode 100644 mcd/mcd_api.h
MAINTAINERS +6 -0
@@ -3101,6 +3101,12 @@ F: scripts/feature_to_c.py F: scripts/probe-gdb-support.py T: git https://gitlab.com/stsquad/qemu gdbstub/next +MCD +M: Mario Fleischmann <[email protected]> +S: Maintained +F: mcd/* +F: docs/interop/mcd.rst + Memory API M: Paolo Bonzini <[email protected]> M: Peter Xu <[email protected]>
docs/interop/index.rst +1 -0
@@ -14,6 +14,7 @@ are useful for making QEMU interoperate with other software. dbus-vmstate dbus-display live-block-operations + mcd nbd parallels prl-xml
docs/interop/mcd.rst new file +44 -0
44 lines not on this page · raw message
mcd/mcd_api.h new file +3963 -0
2,937 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
PATCH 2/16 mcd: Introduce MCD server
In reply to Mario FleischmannThe MCD implementation follows a remote procedure call approach and uses QMP as the communication protocol:
* mcdserver implements the MCD API
* mcd.json and mcdstub_qapi.c declare and implement the server stub
Our client stub supporting QMP can be found at:
https://gitlab.com/lauterbach/mcdrefsrv
--- MAINTAINERS | 1 + docs/interop/mcd.rst | 14 ++ mcd/mcdserver.c | 431 ++++++++++++++++++++++++++++++++++++++++++ mcd/mcdstub_qapi.c | 13 ++ mcd/meson.build | 12 ++ meson.build | 1 + qapi/mcd.json | 6 + qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 9 files changed, 480 insertions(+) create mode 100644 mcd/mcdserver.c create mode 100644 mcd/mcdstub_qapi.c create mode 100644 mcd/meson.build create mode 100644 qapi/mcd.json
MAINTAINERS +1 -0
@@ -3106,6 +3106,7 @@ M: Mario Fleischmann <[email protected]> S: Maintained F: mcd/* F: docs/interop/mcd.rst +F: qapi/mcd.json Memory API M: Paolo Bonzini <[email protected]>
docs/interop/mcd.rst +14 -0
@@ -38,6 +38,20 @@ The resulting system can be visualized as follows:: | qemu-system-* | | -machine | | -cpu | +----------------+ +----------+ +------+ + +Debugging via QMP +----------------- + +Since the MCD API does not define a communication protocol, the QEMU Machine +Protocol (QMP) is utilized to implement a remote procedure call mechanism. +Each function within the API corresponds to one QMP command, ensuring a +one-to-one mapping between the API's functions and the QMP commands. + +If you are not familiar with QMP, see the :doc:`qmp-spec` for the +protocol, and the :doc:`qemu-qmp-ref` for a full reference of all +commands. + + API Reference -------------
mcd/mcdserver.c new file +431 -0
431 lines not on this page · raw message
mcd/mcdstub_qapi.c new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* MCD server stub using QMP +* +* see qapi/mcd.json for the declarations of the (un)marshalling functions +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "mcd_api.h"
mcd/meson.build new file +12 -0
@@ -0,0 +1,12 @@ +# MCD is only supported in system emulation +mcd_system_ss = ss.source_set() + +mcd_system_ss.add(files('mcdserver.c', 'mcdstub_qapi.c')) +mcd_system_ss = mcd_system_ss.apply({}) + +libmcd_system = static_library('mcd_system', + mcd_system_ss.sources() + genh, + build_by_default: false) + +mcd_system = declare_dependency(objects: libmcd_system.extract_all_objects(recursive: false)) +system_ss.add(mcd_system)
meson.build +1 -0
@@ -3685,6 +3685,7 @@ subdir('authz') subdir('crypto') subdir('ui') subdir('gdbstub') +subdir('mcd') if have_system subdir('hw') else
qapi/mcd.json new file +6 -0
@@ -0,0 +1,6 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# = Multi-Core Debug (MCD) API +##
qapi/meson.build +1 -0
@@ -40,6 +40,7 @@ qapi_all_modules = [ 'machine-common', 'machine', 'machine-target', + 'mcd', 'migration', 'misc', 'misc-target',
qapi/qapi-schema.json +1 -0
@@ -82,3 +82,4 @@ { 'include': 'cryptodev.json' } { 'include': 'cxl.json' } { 'include': 'uefi.json' } +{ 'include': 'mcd.json' }
Signature · 1 line
2.34.1
PATCH 3/16 mcd: Implement target initialization API
In reply to Mario FleischmannThe target initialization API ensures that the requested and provided MCD versions are compatible.
* implement mcd_initialize_f and mcd_qry_error_info_f in mcdserver
* implement QMP stub functionality
* add QTest
Thanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
--- MAINTAINERS | 2 + mcd/libmcd_qapi.c | 66 ++++++++++++++ mcd/libmcd_qapi.h | 26 ++++++ mcd/mcdserver.c | 44 ++++++++- mcd/mcdstub_qapi.c | 35 ++++++++ mcd/meson.build | 2 +- qapi/mcd.json | 183 ++++++++++++++++++++++++++++++++++++++ tests/qtest/libmcd-test.c | 88 ++++++++++++++++++ tests/qtest/libmcd-test.h | 23 +++++ tests/qtest/mcd-test.c | 93 +++++++++++++++++++ tests/qtest/meson.build | 2 + 11 files changed, 562 insertions(+), 2 deletions(-) create mode 100644 mcd/libmcd_qapi.c create mode 100644 mcd/libmcd_qapi.h create mode 100644 tests/qtest/libmcd-test.c create mode 100644 tests/qtest/libmcd-test.h create mode 100644 tests/qtest/mcd-test.c
MAINTAINERS +2 -0
@@ -3107,6 +3107,8 @@ S: Maintained F: mcd/* F: docs/interop/mcd.rst F: qapi/mcd.json +F: tests/qtest/libmcd-test.* +F: tests/qtest/mcd-test.c Memory API M: Paolo Bonzini <[email protected]>
mcd/libmcd_qapi.c new file +66 -0
66 lines not on this page · raw message
mcd/libmcd_qapi.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QAPI marshalling helpers for structures of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef LIBMCD_QAPI_H +#define LIBMCD_QAPI_H + +#include "mcd_api.h" +#include "qapi-types-mcd.h" + +MCDAPIVersion *marshal_mcd_api_version (const mcd_api_version_st *api_version); + +MCDImplVersionInfo *marshal_mcd_impl_version_info ( +const mcd_impl_version_info_st *impl_info); + +MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info); + +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version); + +#endif /* LIBMCD_QAPI_H */
mcd/mcdserver.c +43 -1
73 lines not on this page · raw message
mcd/mcdstub_qapi.c +35 -0
@@ -10,4 +10,39 @@* See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" #include "mcd_api.h" +#include "libmcd_qapi.h" +#include "qapi/qapi-commands-mcd.h" + +MCDInitializeResult *qmp_mcd_initialize (MCDAPIVersion *version_req, +Error **errp) +{ +mcd_impl_version_info_st impl_info; +MCDInitializeResult *result =g_malloc0 (sizeof (*result)); +mcd_api_version_st version_req_unmarshalled = +unmarshal_mcd_api_version (version_req); + + result->return_status =mcd_initialize_f (&version_req_unmarshalled, + &impl_info); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->impl_info =marshal_mcd_impl_version_info (&impl_info); + } + +return result; +} + +void qmp_mcd_exit (Error **errp) +{ +mcd_exit_f (); +} + +MCDErrorInfo *qmp_mcd_qry_error_info (Error **errp) +{ +MCDErrorInfo *result; +mcd_error_info_st error_info; +mcd_qry_error_info_f (NULL , &error_info); + result =marshal_mcd_error_info (&error_info); +return result; +}
mcd/meson.build +1 -1
@@ -1,7 +1,7 @@ # MCD is only supported in system emulation mcd_system_ss = ss.source_set() -mcd_system_ss.add(files('mcdserver.c', 'mcdstub_qapi.c')) +mcd_system_ss.add(files('mcdserver.c', 'mcdstub_qapi.c', 'libmcd_qapi.c')) mcd_system_ss = mcd_system_ss.apply({}) libmcd_system = static_library('mcd_system',
qapi/mcd.json +183 -0
186 lines not on this page · raw message
tests/qtest/libmcd-test.c new file +88 -0
88 lines not on this page · raw message
tests/qtest/libmcd-test.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QTest helpers for functions of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef LIBMCD_TEST_H +#define LIBMCD_TEST_H + +#include "libqtest.h" +#include "mcd/mcd_api.h" +#include "qapi/qapi-visit-mcd.h" + +MCDInitializeResult *qtest_mcd_initialize (QTestState *qts, +q_obj_mcd_initialize_arg *args); + +MCDErrorInfo *qtest_mcd_qry_error_info (QTestState *qts); + +#endif /* LIBMCD_TEST_H */
tests/qtest/mcd-test.c new file +93 -0
93 lines not on this page · raw message
tests/qtest/meson.build +2 -0
@@ -30,6 +30,7 @@ qtests_generic = [ 'qos-test', 'readconfig-test', 'netdev-socket', + 'mcd-test', ] if enable_modules qtests_generic += [ 'modules-test' ]
@@ -383,6 +384,7 @@ qtests = { 'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'), 'aspeed_smc-test': files('aspeed-smc-utils.c', 'aspeed_smc-test.c'), 'ast2700-smc-test': files('aspeed-smc-utils.c', 'ast2700-smc-test.c'), + 'mcd-test': files('mcd-test.c', 'libmcd-test.c', '../../mcd/libmcd_qapi.c'), } if vnc.found()
Signature · 1 line
2.34.1
PATCH 4/16 mcd: Implement server connection API
In reply to Mario FleischmannThis commit implements the necessary operations required to establish a connection with the MCD server:
* query information about the server
* connect to "
* disconnect from "
--- mcd/libmcd_qapi.c | 13 +++ mcd/libmcd_qapi.h | 2 + mcd/mcdserver.c | 110 +++++++++++++++++++- mcd/mcdstub_qapi.c | 98 ++++++++++++++++++ qapi/mcd.json | 205 ++++++++++++++++++++++++++++++++++++++ tests/qtest/libmcd-test.c | 60 +++++++++++ tests/qtest/libmcd-test.h | 9 ++ tests/qtest/mcd-test.c | 96 ++++++++++++++++++ 8 files changed, 588 insertions(+), 5 deletions(-)
mcd/libmcd_qapi.c +13 -0
@@ -64,3 +64,16 @@ MCDErrorInfo *marshal_mcd_error_info(const mcd_error_info_st *error_info)return marshal; } + +MCDServerInfo *marshal_mcd_server_info (const mcd_server_info_st *server_info) +{ +MCDServerInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDServerInfo ) { + .server =g_strdup (server_info->server), + .system_instance =g_strdup (server_info->system_instance), + .acc_hw =g_strdup (server_info->acc_hw), + }; + +return marshal; +}
mcd/libmcd_qapi.h +2 -0
@@ -21,6 +21,8 @@ MCDImplVersionInfo *marshal_mcd_impl_version_info(MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info); +MCDServerInfo *marshal_mcd_server_info (const mcd_server_info_st *server_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);#endif /* LIBMCD_QAPI_H */
mcd/mcdserver.c +105 -5
146 lines not on this page · raw message
mcd/mcdstub_qapi.c +98 -0
110 lines not on this page · raw message
qapi/mcd.json +205 -0
217 lines not on this page · raw message
tests/qtest/libmcd-test.c +60 -0
63 lines not on this page · raw message
tests/qtest/libmcd-test.h +9 -0
@@ -20,4 +20,13 @@ MCDInitializeResult *qtest_mcd_initialize(QTestState *qts,MCDErrorInfo *qtest_mcd_qry_error_info (QTestState *qts); +MCDQryServersResult *qtest_mcd_qry_servers (QTestState *qts, +q_obj_mcd_qry_servers_arg *args); + +MCDOpenServerResult *qtest_mcd_open_server (QTestState *qts, +q_obj_mcd_open_server_arg *args); + +MCDCloseServerResult *qtest_mcd_close_server (QTestState *qts, +q_obj_mcd_close_server_arg *args); +#endif /* LIBMCD_TEST_H */
tests/qtest/mcd-test.c +96 -0
107 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 5/16 mcd: Implement target system query
In reply to Mario FleischmannIn MCD, the target system is divided into system, devices and cores:
[ system ] 1-* [ devices ] 1-* [cores]
This commit implements the necessary functions to query information about the target system.
--- mcd/libmcd_qapi.c | 48 +++++ mcd/libmcd_qapi.h | 4 + mcd/mcdserver.c | 165 +++++++++++++++++- mcd/mcdstub_qapi.c | 116 +++++++++++++ qapi/mcd.json | 356 ++++++++++++++++++++++++++++++++++++++ tests/qtest/libmcd-test.c | 66 +++++++ tests/qtest/libmcd-test.h | 11 ++ tests/qtest/mcd-test.c | 83 +++++++++ 8 files changed, 846 insertions(+), 3 deletions(-)
mcd/libmcd_qapi.c +48 -0
@@ -77,3 +77,51 @@ MCDServerInfo *marshal_mcd_server_info(const mcd_server_info_st *server_info)return marshal; } + +MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info) +{ +MCDCoreConInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDCoreConInfo ) { + .host =g_strdup (con_info->host), + .server_port = con_info->server_port, + .server_key =g_strdup (con_info->server_key), + .system_key =g_strdup (con_info->system_key), + .device_key =g_strdup (con_info->device_key), + .system =g_strdup (con_info->system), + .system_instance =g_strdup (con_info->system_instance), + .acc_hw =g_strdup (con_info->acc_hw), + .device_type = con_info->device_type, + .device =g_strdup (con_info->device), + .device_id = con_info->device_id, + .core =g_strdup (con_info->core), + .core_type = con_info->core_type, + .core_id = con_info->core_id, + }; + +return marshal; +} + +mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info) +{ +mcd_core_con_info_st unmarshal = { + .server_port = con_info->server_port, + .device_type = con_info->device_type, + .device_id = con_info->device_id, + .core_type = con_info->core_type, + .core_id = con_info->core_id, + }; + +strncpy (unmarshal.host, con_info->host,MCD_HOSTNAME_LEN -1 ); +strncpy (unmarshal.server_key, con_info->server_key,MCD_KEY_LEN -1 ); +strncpy (unmarshal.system_key, con_info->system_key,MCD_KEY_LEN -1 ); +strncpy (unmarshal.device_key, con_info->device_key,MCD_KEY_LEN -1 ); +strncpy (unmarshal.system, con_info->system,MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.system_instance, con_info->system_instance, +MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.acc_hw, con_info->acc_hw,MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.device, con_info->device,MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.core, con_info->core,MCD_UNIQUE_NAME_LEN -1 ); + +return unmarshal; +}
mcd/libmcd_qapi.h +4 -0
@@ -23,6 +23,10 @@ MCDErrorInfo *marshal_mcd_error_info(const mcd_error_info_st *error_info);MCDServerInfo *marshal_mcd_server_info (const mcd_server_info_st *server_info); +MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version); +mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info); +#endif /* LIBMCD_QAPI_H */
mcd/mcdserver.c +162 -3
231 lines not on this page · raw message
mcd/mcdstub_qapi.c +116 -0
122 lines not on this page · raw message
qapi/mcd.json +356 -0
368 lines not on this page · raw message
tests/qtest/libmcd-test.c +66 -0
75 lines not on this page · raw message
tests/qtest/libmcd-test.h +11 -0
@@ -20,6 +20,8 @@ MCDInitializeResult *qtest_mcd_initialize(QTestState *qts,MCDErrorInfo *qtest_mcd_qry_error_info (QTestState *qts); +void qtest_mcd_exit (QTestState *qts); +MCDQryServersResult *qtest_mcd_qry_servers (QTestState *qts,q_obj_mcd_qry_servers_arg *args);
@@ -29,4 +31,13 @@ MCDOpenServerResult *qtest_mcd_open_server(QTestState *qts,MCDCloseServerResult *qtest_mcd_close_server (QTestState *qts,q_obj_mcd_close_server_arg *args); +MCDQrySystemsResult *qtest_mcd_qry_systems (QTestState *qts, +q_obj_mcd_qry_systems_arg *args); + +MCDQryDevicesResult *qtest_mcd_qry_devices (QTestState *qts, +q_obj_mcd_qry_devices_arg *args); + +MCDQryCoresResult *qtest_mcd_qry_cores (QTestState *qts, +q_obj_mcd_qry_cores_arg *args); +#endif /* LIBMCD_TEST_H */
tests/qtest/mcd-test.c +83 -0
94 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 6/16 mcd: Implement core connection control
In reply to Mario FleischmannIn MCD, core-specific operations require an open connection to the core. This commit implements the necessary operations to open and close the connection to cores.
--- mcd/mcdserver.c | 176 ++++++++++++++++++++++++++++--- mcd/mcdstub_qapi.c | 116 ++++++++++++++++++++- qapi/mcd.json | 132 +++++++++++++++++++++++- tests/qtest/libmcd-test.c | 52 +++++++++- tests/qtest/libmcd-test.h | 9 +- tests/qtest/mcd-test.c | 212 +++++++++++++++++++++++++++----------- 6 files changed, 613 insertions(+), 84 deletions(-)
mcd/mcdserver.c +162 -14
@@ -34,6 +34,13 @@ static const mcd_error_info_st MCD_ERROR_SERVER_NOT_OPEN = { .error_str = "server is not open", }; +static const mcd_error_info_st MCD_ERROR_UNKNOWN_CORE = { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_PARAM , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="specified core is unknown to server" , +}; +static const mcd_error_info_st MCD_ERROR_NONE = { .return_status =MCD_RET_ACT_NONE , .error_code =MCD_ERR_NONE ,
@@ -44,6 +51,24 @@ static const mcd_error_info_st MCD_ERROR_NONE = {/* reserves memory for custom errors */ static mcd_error_info_st custom_mcd_error; +/** +* struct mcdcore_state - State of a core. +* +* @last_error: Error info of most recent executed function. +* @info: Core connection information. +* @open_core: Open core instance as allocated in mcd_open_core_f(). +* +* MCD is mainly being used on the core level: +* After the initial query functions, a core connection is opened in +* mcd_open_core_f(). The allocated mcd_core_st instance is then the basis +* of subsequent operations. +*/ +typedef struct mcdcore_state { +const mcd_error_info_st *last_error; +mcd_core_con_info_st info; +mcd_core_st *open_core; +}mcdcore_state ; +/** * struct mcdserver_state - State of the MCD server *
@@ -66,6 +91,24 @@ static mcdserver_state g_server_state = { .cores = NULL, }; +static mcdcore_state *find_core (const mcd_core_con_info_st *core_con_info) +{ +uint32_t core_id; +mcdcore_state *core; + +if (!core_con_info || !g_server_state.cores) { +return NULL ; + } + + core_id = core_con_info->core_id; +if (core_id > g_server_state.cores->len) { +return NULL ; + } + + core = &g_array_index (g_server_state.cores, mcdcore_state, core_id); +return core; +} +mcd_return_et mcd_initialize_f (const mcd_api_version_st *version_req,mcd_impl_version_info_st *impl_info) {
@@ -200,16 +243,19 @@ mcd_return_et mcd_open_server_f(const char *system_key, }/* update the internal core information data base */ - g_server_state.cores =g_array_new (false, true, -sizeof (mcd_core_con_info_st)); + g_server_state.cores =g_array_new (false, true,sizeof (mcdcore_state));CPU_FOREACH (cpu) {ObjectClass *oc =object_get_class (OBJECT (cpu));const char *cpu_model =object_class_get_name (oc); -mcd_core_con_info_st info = { - .core_id = g_server_state.cores->len, +mcdcore_state c = { + .info = (mcd_core_con_info_st ) { + .core_id = g_server_state.cores->len, + }, + .last_error = &MCD_ERROR_NONE , + .open_core =NULL , }; -pstrcpy (info.core,MCD_UNIQUE_NAME_LEN , cpu_model); -g_array_append_val (g_server_state.cores, info); +pstrcpy (c.info.core,MCD_UNIQUE_NAME_LEN , cpu_model); +g_array_append_val (g_server_state.cores, c); } g_server_state.last_error = &MCD_ERROR_NONE ;
@@ -240,6 +286,14 @@ mcd_return_et mcd_close_server_f(const mcd_server_st *server)return g_server_state.last_error->return_status; } +for (int i =0 ; i < g_server_state.cores->len; i++) { +mcdcore_state *c = &g_array_index (g_server_state.cores, + mcdcore_state, i); +if (c->open_core) { +mcd_close_core_f (c->open_core); + } + } +g_array_free (g_server_state.cores, true);g_free (g_server_state.open_server); g_server_state.open_server =NULL ;
@@ -396,12 +450,11 @@ mcd_return_et mcd_qry_cores_f(const mcd_core_con_info_st *connection_info, i < *num_cores && start_index + i < g_server_state.cores->len; i++) { -mcd_core_con_info_st *info = &g_array_index (g_server_state.cores, - mcd_core_con_info_st, - start_index + i); +mcdcore_state *c = &g_array_index (g_server_state.cores, mcdcore_state, + start_index + i); core_con_info[i] = *connection_info; - core_con_info[i].core_id = info->core_id; -pstrcpy (core_con_info[i].core,MCD_UNIQUE_NAME_LEN , info->core); + core_con_info[i].core_id = c->info.core_id; +pstrcpy (core_con_info[i].core,MCD_UNIQUE_NAME_LEN , c->info.core); } *num_cores = i;
@@ -421,21 +474,116 @@ mcd_return_et mcd_qry_core_modes_f(const mcd_core_st *core,mcd_return_et mcd_open_core_f (const mcd_core_con_info_st *core_con_info,mcd_core_st **core) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +uint32_t core_id; +mcdcore_state *core_state; +mcd_core_con_info_st *info; + +if (!g_server_state.open_server) { + g_server_state.last_error = &MCD_ERROR_SERVER_NOT_OPEN ; +return g_server_state.last_error->return_status; + } + +if (!core_con_info || !core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_id = core_con_info->core_id; +if (core_id > g_server_state.cores->len) { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_PARAM , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="specified core index exceeds the number of cores" , + }; + g_server_state.last_error = &custom_mcd_error; +return g_server_state.last_error->return_status; + } + + core_state = &g_array_index (g_server_state.cores, mcdcore_state, core_id); +if (core_state->open_core) { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_CONNECTION , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core already open" , + }; + g_server_state.last_error = &custom_mcd_error; +return g_server_state.last_error->return_status; + } + + *core =g_malloc (sizeof (mcd_core_st)); + info =g_malloc (sizeof (mcd_core_con_info_st)); + *info = *core_con_info; + (*core)->core_con_info = info; + (*core)->instance =NULL ; + core_state->open_core = *core; + core_state->last_error = &MCD_ERROR_NONE ; + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }mcd_return_et mcd_close_core_f (const mcd_core_st *core) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +mcdcore_state *core_state; + +if (!core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +if (core_state->open_core != core) { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_CONNECTION , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core not open" , + }; + g_server_state.last_error = &custom_mcd_error; +return g_server_state.last_error->return_status; + } + +g_free ((void *)core->core_con_info); +g_free ((void *)core); + core_state->open_core =NULL ; + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }void mcd_qry_error_info_f (const mcd_core_st *core,mcd_error_info_st *error_info) { -if (error_info) { +mcdcore_state *core_state; + +if (!error_info) { +return ; + } + +if (!core) { *error_info = *g_server_state.last_error; +return ; + } + + core_state =find_core (core->core_con_info); +if (!core_state) { + *error_info =MCD_ERROR_UNKNOWN_CORE ; + }else if (core_state->open_core != core) { + *error_info = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_CONNECTION , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core not open" , + }; + }else { + *error_info = *core_state->last_error; } }
mcd/mcdstub_qapi.c +112 -4
180 lines not on this page · raw message
qapi/mcd.json +131 -1
154 lines not on this page · raw message
tests/qtest/libmcd-test.c +49 -3
73 lines not on this page · raw message
tests/qtest/libmcd-test.h +8 -1
@@ -18,7 +18,8 @@MCDInitializeResult *qtest_mcd_initialize (QTestState *qts,q_obj_mcd_initialize_arg *args); -MCDErrorInfo *qtest_mcd_qry_error_info (QTestState *qts); +MCDErrorInfo *qtest_mcd_qry_error_info (QTestState *qts, +q_obj_mcd_qry_error_info_arg *args);void qtest_mcd_exit (QTestState *qts);
@@ -40,4 +41,10 @@ MCDQryDevicesResult *qtest_mcd_qry_devices(QTestState *qts,MCDQryCoresResult *qtest_mcd_qry_cores (QTestState *qts,q_obj_mcd_qry_cores_arg *args); +MCDOpenCoreResult *qtest_mcd_open_core (QTestState *qts, +q_obj_mcd_open_core_arg *args); + +MCDCloseCoreResult *qtest_mcd_close_core (QTestState *qts, +q_obj_mcd_close_core_arg *args); +#endif /* LIBMCD_TEST_H */
tests/qtest/mcd-test.c +151 -61
259 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 7/16 mcd: Implement memory space query
In reply to Mario FleischmannSupport three main memory space types:
* Physical memory
* Logical memory (MMU)
* GDB Registers
Use custom memory type to mark memory spaces as secure
V=1 QTEST_QEMU_BINARY="./qemu-system-arm -M virt,secure=on -cpu cortex-a15" tests/qtest/mcd-test
--- mcd/libmcd_qapi.c | 22 +++++ mcd/libmcd_qapi.h | 2 + mcd/mcdserver.c | 199 +++++++++++++++++++++++++++++++------- mcd/mcdstub_qapi.c | 44 +++++++++ qapi/mcd.json | 199 ++++++++++++++++++++++++++++++++++++++ tests/qtest/libmcd-test.c | 20 ++++ tests/qtest/libmcd-test.h | 3 + tests/qtest/mcd-test.c | 79 +++++++++++++++ 8 files changed, 534 insertions(+), 34 deletions(-)
mcd/libmcd_qapi.c +22 -0
@@ -125,3 +125,25 @@ mcd_core_con_info_st unmarshal_mcd_core_con_info(MCDCoreConInfo *con_info)return unmarshal; } + +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space) +{ +MCDMemspace *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDMemspace ) { + .mem_space_id = mem_space->mem_space_id, + .mem_space_name =g_strdup (mem_space->mem_space_name), + .mem_type = mem_space->mem_type, + .bits_per_mau = mem_space->bits_per_mau, + .invariance = mem_space->invariance, + .endian = mem_space->endian, + .min_addr = mem_space->min_addr, + .max_addr = mem_space->max_addr, + .num_mem_blocks = mem_space->num_mem_blocks, + .supported_access_options = mem_space->supported_access_options, + .core_mode_mask_read = mem_space->core_mode_mask_read, + .core_mode_mask_write = mem_space->core_mode_mask_write, + }; + +return marshal; +}
mcd/libmcd_qapi.h +2 -0
@@ -25,6 +25,8 @@ MCDServerInfo *marshal_mcd_server_info(const mcd_server_info_st *server_info);MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info); +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcdserver.c +165 -34
374 lines not on this page · raw message
mcd/mcdstub_qapi.c +44 -0
47 lines not on this page · raw message
qapi/mcd.json +199 -0
208 lines not on this page · raw message
tests/qtest/libmcd-test.c +20 -0
@@ -258,3 +258,23 @@ MCDCloseCoreResult *qtest_mcd_close_core(QTestState *qts,return unmarshal; } + +MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces ( +QTestState *qts,q_obj_mcd_qry_mem_spaces_arg *args) +{ +Visitor *v; +QObject *marshal; +QDict *arg, *resp; +QObject *ret; +bool ok; +MCDQryMemSpacesResult *unmarshal; + +MARSHAL_ARGS (q_obj_mcd_qry_mem_spaces_arg); + + resp =qtest_qmp (qts,"{'execute': 'mcd-qry-mem-spaces'," +"'arguments': %p}" , arg); + +UNMARSHAL_RESULT (MCDQryMemSpacesResult); + +return unmarshal; +}
tests/qtest/libmcd-test.h +3 -0
@@ -47,4 +47,7 @@ MCDOpenCoreResult *qtest_mcd_open_core(QTestState *qts,MCDCloseCoreResult *qtest_mcd_close_core (QTestState *qts,q_obj_mcd_close_core_arg *args); +MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces (QTestState *qts, +q_obj_mcd_qry_mem_spaces_arg *args); +#endif /* LIBMCD_TEST_H */
tests/qtest/mcd-test.c +79 -0
90 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 8/16 gdbstub: Expose GDBRegisterState
In reply to Mario Fleischmann--- gdbstub/gdbstub.c | 7 ------- include/exec/gdbstub.h | 8 +++++++- 2 files changed, 7 insertions(+), 8 deletions(-)
gdbstub/gdbstub.c +0 -7
@@ -48,13 +48,6 @@#include "internals.h" -typedef struct GDBRegisterState { -int base_reg; -gdb_get_reg_cb get_reg; -gdb_set_reg_cb set_reg; -const GDBFeature *feature; -}GDBRegisterState ; -GDBState gdbserver_state;void gdb_init_gdbserver_state (void )
include/exec/gdbstub.h +7 -1
@@ -16,11 +16,17 @@ typedef struct GDBFeatureBuilder {int base_reg; } GDBFeatureBuilder; -/* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb )(CPUState *cpu,GByteArray *buf,int reg);typedef int (*gdb_set_reg_cb )(CPUState *cpu,uint8_t *buf,int reg); +typedef struct GDBRegisterState { +int base_reg; +gdb_get_reg_cb get_reg; +gdb_set_reg_cb set_reg; +const GDBFeature *feature; +}GDBRegisterState ; +/** * gdb_init_cpu(): Initialize the CPU for gdbstub. * @cpu: The CPU to be initialized.
Signature · 1 line
2.34.1
PATCH 9/16 mcd: Implement register query
In reply to Mario FleischmannDirectly map MCD register groups to GDB features lists
--- mcd/libmcd_qapi.c | 48 +++++++ mcd/libmcd_qapi.h | 8 ++ mcd/mcdserver.c | 237 ++++++++++++++++++++++++++++-- mcd/mcdstub_qapi.c | 93 ++++++++++++ qapi/mcd.json | 296 ++++++++++++++++++++++++++++++++++++++ tests/qtest/libmcd-test.c | 40 ++++++ tests/qtest/libmcd-test.h | 6 + tests/qtest/mcd-test.c | 85 +++++++++++ 8 files changed, 803 insertions(+), 10 deletions(-)
mcd/libmcd_qapi.c +48 -0
@@ -147,3 +147,51 @@ MCDMemspace *marshal_mcd_memspace(const mcd_memspace_st *mem_space)return marshal; } + +MCDRegisterGroup *marshal_mcd_register_group ( +const mcd_register_group_st *reg_group) +{ +MCDRegisterGroup *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDRegisterGroup ) { + .reg_group_id = reg_group->reg_group_id, + .reg_group_name =g_strdup (reg_group->reg_group_name), + .n_registers = reg_group->n_registers, + }; + +return marshal; +} + +MCDAddr *marshal_mcd_addr (const mcd_addr_st *addr) +{ +MCDAddr *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDAddr ) { + .address = addr->address, + .mem_space_id = addr->mem_space_id, + .addr_space_id = addr->addr_space_id, + .addr_space_type = addr->addr_space_type, + }; + +return marshal; +} + +MCDRegisterInfo *marshal_mcd_register_info (const mcd_register_info_st *reg_info) +{ +MCDRegisterInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDRegisterInfo ) { + .addr =marshal_mcd_addr (®_info->addr), + .reg_group_id = reg_info->reg_group_id, + .regname =g_strdup (reg_info->regname), + .regsize = reg_info->regsize, + .core_mode_mask_read = reg_info->core_mode_mask_read, + .core_mode_mask_write = reg_info->core_mode_mask_write, + .side_effects_read = reg_info->has_side_effects_read, + .side_effects_write = reg_info->has_side_effects_write, + .reg_type = reg_info->reg_type, + .hw_thread_id = reg_info->hw_thread_id, + }; + +return marshal; +}
mcd/libmcd_qapi.h +8 -0
@@ -27,6 +27,14 @@ MCDCoreConInfo *marshal_mcd_core_con_info(const mcd_core_con_info_st *con_info);MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space); +MCDRegisterGroup *marshal_mcd_register_group ( +const mcd_register_group_st *reg_group); + +MCDAddr *marshal_mcd_addr (const mcd_addr_st *addr); + +MCDRegisterInfo *marshal_mcd_register_info ( +const mcd_register_info_st *reg_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcdserver.c +227 -10
297 lines not on this page · raw message
mcd/mcdstub_qapi.c +93 -0
96 lines not on this page · raw message
qapi/mcd.json +296 -0
305 lines not on this page · raw message
tests/qtest/libmcd-test.c +40 -0
@@ -278,3 +278,43 @@ MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces(return unmarshal; } + +MCDQryRegGroupsResult *qtest_mcd_qry_reg_groups ( +QTestState *qts,q_obj_mcd_qry_reg_groups_arg *args) +{ +Visitor *v; +QObject *marshal; +QDict *arg, *resp; +QObject *ret; +bool ok; +MCDQryRegGroupsResult *unmarshal; + +MARSHAL_ARGS (q_obj_mcd_qry_reg_groups_arg); + + resp =qtest_qmp (qts,"{'execute': 'mcd-qry-reg-groups'," +"'arguments': %p}" , arg); + +UNMARSHAL_RESULT (MCDQryRegGroupsResult); + +return unmarshal; +} + +MCDQryRegMapResult *qtest_mcd_qry_reg_map (QTestState *qts, +q_obj_mcd_qry_reg_map_arg *args) +{ +Visitor *v; +QObject *marshal; +QDict *arg, *resp; +QObject *ret; +bool ok; +MCDQryRegMapResult *unmarshal; + +MARSHAL_ARGS (q_obj_mcd_qry_reg_map_arg); + + resp =qtest_qmp (qts,"{'execute': 'mcd-qry-reg-map'," +"'arguments': %p}" , arg); + +UNMARSHAL_RESULT (MCDQryRegMapResult); + +return unmarshal; +}
tests/qtest/libmcd-test.h +6 -0
@@ -50,4 +50,10 @@ MCDCloseCoreResult *qtest_mcd_close_core(QTestState *qts,MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces (QTestState *qts,q_obj_mcd_qry_mem_spaces_arg *args); +MCDQryRegGroupsResult *qtest_mcd_qry_reg_groups (QTestState *qts, +q_obj_mcd_qry_reg_groups_arg *args); + +MCDQryRegMapResult *qtest_mcd_qry_reg_map (QTestState *qts, +q_obj_mcd_qry_reg_map_arg *args); +#endif /* LIBMCD_TEST_H */
tests/qtest/mcd-test.c +85 -0
105 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 10/16 mcd: Implement runstate control
In reply to Mario FleischmannCurrently, only global stop is implemented
--- mcd/mcdserver.c | 74 +++++++++++++++++++++++++++++++-- mcd/mcdstub_qapi.c | 52 +++++++++++++++++++++++ qapi/mcd.json | 100 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+), 4 deletions(-)
mcd/mcdserver.c +70 -4
@@ -14,6 +14,8 @@#include "hw/boards.h" #include "exec/tswap.h" #include "exec/gdbstub.h" +#include "hw/core/cpu.h" +#include "system/runstate.h" /* Custom memory space type */ static const mcd_mem_type_et MCD_MEM_SPACE_IS_SECURE =0x00010000 ;
@@ -1087,13 +1089,53 @@ mcd_return_et mcd_execute_txlist_f(const mcd_core_st *core,mcd_return_et mcd_run_f (const mcd_core_st *core,bool global) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; -return g_server_state.last_error->return_status; +mcdcore_state *core_state; + +if (g_server_state.cores->len >1 && global) { +vm_start (); + g_server_state.last_error = &MCD_ERROR_NONE ; +return g_server_state.last_error->return_status; + } + +if (!core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state || core_state->open_core != core) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +if (!runstate_needs_reset () && !runstate_is_running () && + !vm_prepare_start (false)) { +cpu_resume (core_state->cpu); +qemu_clock_enable (QEMU_CLOCK_VIRTUAL , true); + } + + core_state->last_error = &MCD_ERROR_NONE ; +return core_state->last_error->return_status; }mcd_return_et mcd_stop_f (const mcd_core_st *core,bool global) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +if (g_server_state.cores->len >1 && !global) { + g_server_state.custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_FN_UNIMPLEMENTED , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core-specific stop not implemented" , + }; + g_server_state.last_error = &g_server_state.custom_error; +return g_server_state.last_error->return_status; + } + +if (runstate_is_running ()) { +vm_stop (RUN_STATE_DEBUG ); + } + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }
@@ -1120,7 +1162,31 @@ mcd_return_et mcd_step_f(const mcd_core_st *core, bool global,mcd_return_et mcd_set_global_f (const mcd_core_st *core,bool enable) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +mcdcore_state *core_state; + +if (!core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state || core_state->open_core != core) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +if (!enable) { + core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_GENERAL , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="global stop activities cannot be disabled" , + }; + core_state->last_error = &core_state->custom_error; +return core_state->last_error->return_status; + } + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }
mcd/mcdstub_qapi.c +52 -0
55 lines not on this page · raw message
qapi/mcd.json +100 -0
103 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 11/16 mcd test: Implement core state query
In reply to Mario FleischmannDepending on the VM and CPU state, core states can be queried:
* MCD_CORE_STATE_DEBUG: VM halted or CPU artifically stopped
* MCD_CORE_STATE_RUNNING: VM and CPU running
* MCD_CORE_STATE_HALTED: CPU suspended
--- mcd/libmcd_qapi.c | 16 +++++ mcd/libmcd_qapi.h | 2 + mcd/mcdserver.c | 48 ++++++++++++++- mcd/mcdstub_qapi.c | 21 +++++++ qapi/mcd.json | 55 +++++++++++++++++ tests/qtest/libmcd-test.c | 59 +++++++++++++++++++ tests/qtest/libmcd-test.h | 9 +++ tests/qtest/mcd-test.c | 120 +++++++++++++++++++++++++++++++++++++- 8 files changed, 328 insertions(+), 2 deletions(-)
mcd/libmcd_qapi.c +16 -0
@@ -195,3 +195,19 @@ MCDRegisterInfo *marshal_mcd_register_info(const mcd_register_info_st *reg_info)return marshal; } + +MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state) +{ +MCDCoreState *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDCoreState ) { + .state = state->state, + .event = state->event, + .hw_thread_id = state->hw_thread_id, + .trig_id = state->trig_id, + .stop_str =g_strdup (state->stop_str), + .info_str =g_strdup (state->info_str), + }; + +return marshal; +}
mcd/libmcd_qapi.h +2 -0
@@ -35,6 +35,8 @@ MCDAddr *marshal_mcd_addr(const mcd_addr_st *addr);MCDRegisterInfo *marshal_mcd_register_info (const mcd_register_info_st *reg_info); +MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcdserver.c +47 -1
60 lines not on this page · raw message
mcd/mcdstub_qapi.c +21 -0
@@ -557,3 +557,24 @@ MCDSetGlobalResult *qmp_mcd_set_global(uint32_t core_uid, bool enable, g_stub_state.on_error_ask_server = true;return result; } + +MCDQryStateResult *qmp_mcd_qry_state (uint32_t core_uid,Error **errp) +{ +MCDQryStateResult *result =g_malloc0 (sizeof (*result)); +mcd_core_state_st state; +mcd_core_st *core =NULL ; + + result->return_status =retrieve_open_core (core_uid, &core); +if (result->return_status !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; +return result; + } + + result->return_status =mcd_qry_state_f (core, &state); +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->state =marshal_mcd_core_state (&state); + } + + g_stub_state.on_error_ask_server = true; +return result; +}
qapi/mcd.json +55 -0
64 lines not on this page · raw message
tests/qtest/libmcd-test.c +59 -0
64 lines not on this page · raw message
tests/qtest/libmcd-test.h +9 -0
@@ -56,4 +56,13 @@ MCDQryRegGroupsResult *qtest_mcd_qry_reg_groups(QTestState *qts,MCDQryRegMapResult *qtest_mcd_qry_reg_map (QTestState *qts,q_obj_mcd_qry_reg_map_arg *args); +MCDRunResult *qtest_mcd_run (QTestState *qts, +q_obj_mcd_run_arg *args); + +MCDStopResult *qtest_mcd_stop (QTestState *qts, +q_obj_mcd_stop_arg *args); + +MCDQryStateResult *qtest_mcd_qry_state (QTestState *qts, +q_obj_mcd_qry_state_arg *args); +#endif /* LIBMCD_TEST_H */
tests/qtest/mcd-test.c +119 -1
143 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 12/16 gdbstub: Expose gdb_write_register
In reply to Mario Fleischmann--- gdbstub/gdbstub.c | 2 +- include/exec/gdbstub.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-)
gdbstub/gdbstub.c +1 -1
@@ -527,7 +527,7 @@ int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)return 0 ; } -static int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg) +int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg) {GDBRegisterState *r;
include/exec/gdbstub.h +10 -0
@@ -130,6 +130,16 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname);*/ int gdb_read_register (CPUState *cpu,GByteArray *buf,int reg); +/** +* gdb_write_register() - Write a register associated with a CPU. +* @cpu: The CPU associated with the register. +* @mem_buf: The buffer that the register will be written from. +* @reg: The register's number returned by gdb_find_feature_register(). +* +* Return: The number of written bytes. +*/ +int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg); +/** * typedef GDBRegDesc - a register description from gdbstub */
Signature · 1 line
2.34.1
PATCH 13/16 mcd: Implement register/memory access
In reply to Mario FleischmannIn MCD, all accesses to register or memory are issued over transaction lists. This commit implements three types of transactions:
* register access
* logical memory access (with MMU)
* physical memory access (no MMU)
--- mcd/libmcd_qapi.c | 128 +++++++++++++++++++++++++++++++++ mcd/libmcd_qapi.h | 14 ++++ mcd/mcdserver.c | 176 ++++++++++++++++++++++++++++++++++++++++++++- mcd/mcdstub_qapi.c | 26 +++++++ qapi/mcd.json | 83 +++++++++++++++++++++ 5 files changed, 425 insertions(+), 2 deletions(-)
mcd/libmcd_qapi.c +128 -0
@@ -176,6 +176,18 @@ MCDAddr *marshal_mcd_addr(const mcd_addr_st *addr)return marshal; } +mcd_addr_st unmarshal_mcd_addr (MCDAddr *addr) +{ +mcd_addr_st unmarshal = { + .address = addr->address, + .mem_space_id = addr->mem_space_id, + .addr_space_id = addr->addr_space_id, + .addr_space_type = addr->addr_space_type, + }; + +return unmarshal; +} +MCDRegisterInfo *marshal_mcd_register_info (const mcd_register_info_st *reg_info) {MCDRegisterInfo *marshal =g_malloc0 (sizeof (*marshal));
@@ -211,3 +223,119 @@ MCDCoreState *marshal_mcd_core_state(const mcd_core_state_st *state)return marshal; } + +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx) +{ +MCDTx *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTx ) { + .addr =marshal_mcd_addr (&tx->addr), + .access_type = tx->access_type, + .options = tx->options, + .access_width = tx->access_width, + .core_mode = tx->core_mode, + .num_bytes = tx->num_bytes, + .num_bytes_ok = tx->num_bytes_ok, + }; + +if (tx->num_bytes ==0 ) { +return marshal; + } + +g_assert (tx->data); + +uint8List *head = marshal->data; +for (int i = tx->num_bytes -1 ; i >=0 ; i--) { +QAPI_LIST_PREPEND (head, tx->data[i]); + } + marshal->data = head; +return marshal; +} + +mcd_tx_st unmarshal_mcd_tx (MCDTx *tx) +{ +mcd_tx_st unmarshal = { + .addr =unmarshal_mcd_addr (tx->addr), + .access_type = tx->access_type, + .options = tx->options, + .access_width = tx->access_width, + .core_mode = tx->core_mode, + .data =NULL , + .num_bytes = tx->num_bytes, + .num_bytes_ok = tx->num_bytes_ok, + }; + +if (tx->num_bytes ==0 ) { +return unmarshal; + } + + unmarshal.data =g_malloc (tx->num_bytes); +uint8List *current_data = tx->data; +for (uint32_t i =0 ; i < tx->num_bytes; i++) { +g_assert (current_data); + unmarshal.data[i] = current_data->value; + current_data = current_data->next; + } + +return unmarshal; +} + +void free_mcd_tx (mcd_tx_st *tx) +{ +g_free (tx->data); +} + +MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist) +{ +MCDTxlist *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTxlist ) { + .num_tx = txlist->num_tx, + .num_tx_ok = txlist->num_tx_ok, + }; + +if (txlist->num_tx ==0 ) { +return marshal; + } + +g_assert (txlist->tx); + +MCDTxList **tailp = &(marshal->tx); +for (uint32_t i =0 ; i < txlist->num_tx; i++) { +MCDTx *tx =marshal_mcd_tx (txlist->tx + i); +QAPI_LIST_APPEND (tailp, tx); + } + +return marshal; +} + +mcd_txlist_st unmarshal_mcd_txlist (MCDTxlist *txlist) +{ +mcd_txlist_st unmarshal = { + .tx =g_malloc (txlist->num_tx *sizeof (mcd_tx_st)), + .num_tx = txlist->num_tx, + .num_tx_ok = txlist->num_tx_ok, + }; + +MCDTxList *current_tx = txlist->tx; +for (uint32_t i =0 ; i < txlist->num_tx; i++) { +g_assert (current_tx); + unmarshal.tx[i] =unmarshal_mcd_tx (current_tx->value); + current_tx = current_tx->next; + } + +return unmarshal; +} + +void free_mcd_txlist (mcd_txlist_st *txlist) +{ +if (!txlist->tx) { +return ; + } + +for (uint32_t i =0 ; i < txlist->num_tx; i++) { +free_mcd_tx (txlist->tx + i); + } + +g_free (txlist->tx); +}
mcd/libmcd_qapi.h +14 -0
@@ -37,8 +37,22 @@ MCDRegisterInfo *marshal_mcd_register_info(MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state); +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx); + +MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info); +mcd_addr_st unmarshal_mcd_addr (MCDAddr *addr); + +mcd_tx_st unmarshal_mcd_tx (MCDTx *tx); + +mcd_txlist_st unmarshal_mcd_txlist (MCDTxlist *txlist); + +void free_mcd_tx (mcd_tx_st *tx); + +void free_mcd_txlist (mcd_txlist_st *txlist); +#endif /* LIBMCD_QAPI_H */
mcd/mcdserver.c +174 -2
185 lines not on this page · raw message
mcd/mcdstub_qapi.c +26 -0
@@ -506,6 +506,32 @@ MCDQryRegMapResult *qmp_mcd_qry_reg_map(uint32_t core_uid,return result; } +MCDExecuteTxlistResult *qmp_mcd_execute_txlist (uint32_t core_uid, +MCDTxlist *txlist, +Error **errp) +{ +MCDExecuteTxlistResult *result =g_malloc0 (sizeof (*result)); +mcd_core_st *core =NULL ; + + result->return_status =retrieve_open_core (core_uid, &core); +if (result->return_status !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; +return result; + } + +mcd_txlist_st txlist_unmarshalled =unmarshal_mcd_txlist (txlist); + + result->return_status =mcd_execute_txlist_f (core, &txlist_unmarshalled); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->txlist =marshal_mcd_txlist (&txlist_unmarshalled); + } + +free_mcd_txlist (&txlist_unmarshalled); + g_stub_state.on_error_ask_server = true; +return result; +} +MCDRunResult *qmp_mcd_run (uint32_t core_uid,bool global,Error **errp) {MCDRunResult *result =g_malloc0 (sizeof (*result));
qapi/mcd.json +83 -0
95 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 13/16] mcd: Implement register/memory access
Just found out that in the call stack of address_space_rw, the len argument eventually becomes the access width, if applicable. I wasn't aware of that because GDB's 'm' and 'M' packets don't pose any requirements on the access width ("the stub is free to use byte accesses, or not") and therefore the gdbstub couldn't make advantage of that.
MCD does have the field tx->access_width, so a v2 of this patch will call the memory access functions repeatedly, with
len = tx->access_width (if set)
Quoted 93 lines · Mario Fleischmann
In MCD, all accesses to register or memory are issued over transaction lists. This commit implements three types of transactions:
* register access
* logical memory access (with MMU)
* physical memory access (no MMU)Signed-off-by Mario Fleischmann <[email protected]>--- mcd/libmcd_qapi.c | 128 +++++++++++++++++++++++++++++++++ mcd/libmcd_qapi.h | 14 ++++ mcd/mcdserver.c | 176 ++++++++++++++++++++++++++++++++++++++++++++- mcd/mcdstub_qapi.c | 26 +++++++ qapi/mcd.json | 83 +++++++++++++++++++++ 5 files changed, 425 insertions(+), 2 deletions(-)[...]
mcd/mcdserver.c +67
-0@@ -1081,11 +1081,183 @@ mcd_return_et mcd_qry_trig_set_state_f(const mcd_core_st *core,return g_server_state.last_error->return_status; } +static mcd_return_et execute_memory_tx (mcdcore_state *core_state,mcd_tx_st *tx, +mcd_mem_type_et type) +{ +MemTxResult result; + +/* each address space has one physical and one virtual memory */ +int address_space_id = (tx->addr.mem_space_id -1 ) /2 ; +AddressSpace *as =cpu_get_address_space (core_state->cpu, address_space_id); + +hwaddr addr = tx->addr.address; +hwaddr len = tx->num_bytes; +void *buf = tx->data; +bool is_write; + +if (tx->access_type ==MCD_TX_AT_R ) { + is_write = false; + }else if (tx->access_type ==MCD_TX_AT_W ) { + is_write = true; + }else { + core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_TXLIST_TX , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="tx access type not supported" , + }; + core_state->last_error = &core_state->custom_error; +return core_state->last_error->return_status; + } + +if (type &MCD_MEM_SPACE_IS_PHYSICAL ) { +MemTxAttrs attrs = { + .secure = !!(type &MCD_MEM_SPACE_IS_SECURE ), + .space = address_space_id, + }; + result =address_space_rw (as, addr, attrs, buf, len, is_write); + }else if (type &MCD_MEM_SPACE_IS_LOGICAL ) { +int ret =cpu_memory_rw_debug (core_state->cpu, addr, buf, len, + is_write); + result = (ret ==0 ) ?MEMTX_OK :MEMTX_ERROR ; + }else { + core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_TXLIST_TX , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="unknown mem space type" , + }; + core_state->last_error = &core_state->custom_error; +return core_state->last_error->return_status; + } + +if (result !=MEMTX_OK ) { + core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code = is_write ?MCD_ERR_TXLIST_WRITE :MCD_ERR_TXLIST_READ , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="" , + }; +snprintf (core_state->custom_error.error_str,MCD_INFO_STR_LEN , +"Memory tx failed with error code %d" , result); + core_state->last_error = &core_state->custom_error; +return core_state->last_error->return_status; + } + + tx->num_bytes_ok = tx->num_bytes; + core_state->last_error = &MCD_ERROR_NONE ; +return core_state->last_error->return_status; +}
PATCH 14/16 mcd: Implement single stepping
In reply to Mario Fleischmanngdbstub: abort gdb_set_stop_cpu when step is issued by mcdserver
--- gdbstub/gdbstub.c | 6 ++- mcd/mcdserver.c | 115 +++++++++++++++++++++++++++++++++++++++++---- mcd/mcdstub_qapi.c | 17 +++++++ qapi/mcd.json | 38 ++++++++++++++- 4 files changed, 164 insertions(+), 12 deletions(-)
gdbstub/gdbstub.c +5 -1
@@ -226,6 +226,10 @@ GDBProcess *gdb_get_process(uint32_t pid)static GDBProcess *gdb_get_cpu_process (CPUState *cpu) { +if (!gdbserver_state.processes) { +return NULL ; + } +return gdb_get_process (gdb_get_cpu_pid (cpu)); }
@@ -2272,7 +2276,7 @@ void gdb_set_stop_cpu(CPUState *cpu) {GDBProcess *p =gdb_get_cpu_process (cpu); -if (!p->attached) { +if (!p || !p->attached) {/* * Having a stop CPU corresponding to a process that is not attached * confuses GDB. So we ignore the request.
mcd/mcdserver.c +105 -10
157 lines not on this page · raw message
mcd/mcdstub_qapi.c +17 -0
@@ -566,6 +566,23 @@ MCDStopResult *qmp_mcd_stop(uint32_t core_uid, bool global, Error **errp)return result; } +MCDStepResult *qmp_mcd_step (uint32_t core_uid,bool global,uint32_t step_type, +uint32_t n_steps,Error **errp) +{ +MCDStepResult *result =g_malloc0 (sizeof (*result)); +mcd_core_st *core =NULL ; + + result->return_status =retrieve_open_core (core_uid, &core); +if (result->return_status !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; +return result; + } + result->return_status =mcd_step_f (core, global, step_type, n_steps); + + g_stub_state.on_error_ask_server = true; +return result; +} +MCDSetGlobalResult *qmp_mcd_set_global (uint32_t core_uid,bool enable,Error **errp) {
qapi/mcd.json +37 -1
@@ -1549,6 +1549,43 @@ 'global' : 'bool' }, 'returns': 'MCDStopResult' } + +## +# @MCDStepResult: +# +# Return value of @mcd-step. +# +# @return-status: Return code. +# +# Since: 9.1 +## +{ 'struct': 'MCDStepResult', 'data': { 'return-status': 'uint32' } } + + +## +# @mcd-step: +# +# Function stepping a target core based on the particular step type. +# +# @core-uid: Unique identifier of the open core as returned by @mcd-open-core. +# @global: Set to "TRUE" if all cores of a system shall start +# execution. Otherwise, starting execution of selected core only. +# @step-type: The unit, the stepping of the target core is based on. +# @n-steps: The number of steps, the target core is stepped for. +# +# Returns: @MCDStepResult +# +# Since: 9.1 +## +{ 'command': 'mcd-step', + 'data': { + 'core-uid' : 'uint32', + 'global' : 'bool', + 'step-type': 'uint32', + 'n-steps' : 'uint32' }, + 'returns': 'MCDStepResult' } + + ## # @MCDSetGlobalResult: #
@@ -1580,7 +1617,6 @@ 'enable' : 'bool' }, 'returns': 'MCDSetGlobalResult' } - ## # @MCDQryStateResult: #
Signature · 1 line
2.34.1
PATCH 15/16 mcd: Implement trigger control
In reply to Mario FleischmannMCD's trigger API functions support multiple triggers by expecting a pointer to the trigger instance. Each trigger structure reserves the first four bytes for its size. To get the specific structure, read a uint32_t at passed pointer and compare it to the sizes of known trigger structures.
This approach does not work for serialization. The sizes might vary between host machines and pointers cannot be sent over the network anyway.
Therefore, we define a MCDTrig structure which explicitly lists all supported trigger types as optional fields:
* mcd_trig_simple_core_st: mcd-trig-simple-core
* mcd_trig_complex_core_st: mcd-trig-complex-core
--- mcd/libmcd_qapi.c | 155 +++++++++++- mcd/libmcd_qapi.h | 21 ++ mcd/mcdserver.c | 585 ++++++++++++++++++++++++++++++++++++++++++-- mcd/mcdstub_qapi.c | 290 ++++++++++++++++++++++ qapi/mcd.json | 588 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1619 insertions(+), 20 deletions(-)
mcd/libmcd_qapi.c +154 -1
@@ -188,7 +188,8 @@ mcd_addr_st unmarshal_mcd_addr(MCDAddr *addr)return unmarshal; } -MCDRegisterInfo *marshal_mcd_register_info (const mcd_register_info_st *reg_info) +MCDRegisterInfo *marshal_mcd_register_info ( +const mcd_register_info_st *reg_info) {MCDRegisterInfo *marshal =g_malloc0 (sizeof (*marshal));
@@ -224,6 +225,158 @@ MCDCoreState *marshal_mcd_core_state(const mcd_core_state_st *state)return marshal; } +MCDTrigInfo *marshal_mcd_trig_info (const mcd_trig_info_st *trig_info) +{ +MCDTrigInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigInfo ) { + .type = trig_info->type, + .option = trig_info->option, + .action = trig_info->action, + .trig_number = trig_info->trig_number, + .state_number = trig_info->state_number, + .counter_number = trig_info->counter_number, + .sw_breakpoints = trig_info->sw_breakpoints, + }; + +return marshal; +} + +MCDCtrigInfo *marshal_mcd_ctrig_info (const mcd_ctrig_info_st *trig_info) +{ +MCDCtrigInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDCtrigInfo ) { + .ctrig_id = trig_info->ctrig_id, + .info_str =g_strdup (trig_info->info_str), + }; + +return marshal; +} + +MCDTrigSimpleCore *marshal_mcd_trig_simple_core ( +mcd_trig_simple_core_st const *trig_simple_core) +{ +MCDTrigSimpleCore *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigSimpleCore ) { + .type = trig_simple_core->type, + .option = trig_simple_core->option, + .action = trig_simple_core->action, + .action_param = trig_simple_core->action_param, + .modified = trig_simple_core->modified, + .state_mask = trig_simple_core->state_mask, + .addr_start =marshal_mcd_addr (&trig_simple_core->addr_start), + .addr_range = trig_simple_core->addr_range, + }; + +return marshal; +} + +mcd_trig_simple_core_st unmarshal_mcd_trig_simple_core ( +MCDTrigSimpleCore *trig_simple_core) +{ +mcd_trig_simple_core_st unmarshal = { + .struct_size =sizeof (mcd_trig_simple_core_st), + .type = trig_simple_core->type, + .option = trig_simple_core->option, + .action = trig_simple_core->action, + .action_param = trig_simple_core->action_param, + .modified = trig_simple_core->modified, + .state_mask = trig_simple_core->state_mask, + .addr_start =unmarshal_mcd_addr (trig_simple_core->addr_start), + .addr_range = trig_simple_core->addr_range, + }; + +return unmarshal; +} + +MCDTrigComplexCore *marshal_mcd_trig_complex_core ( +mcd_trig_complex_core_st const *trig_complex_core) +{ +MCDTrigComplexCore *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigComplexCore ) { + .type = trig_complex_core->type, + .option = trig_complex_core->option, + .action = trig_complex_core->action, + .action_param = trig_complex_core->action_param, + .modified = trig_complex_core->modified, + .state_mask = trig_complex_core->state_mask, + .addr_start =marshal_mcd_addr (&trig_complex_core->addr_start), + .addr_range = trig_complex_core->addr_range, + .data_start = trig_complex_core->data_start, + .data_range = trig_complex_core->data_range, + .data_mask = trig_complex_core->data_mask, + .data_size = trig_complex_core->data_size, + .hw_thread_id = trig_complex_core->hw_thread_id, + .sw_thread_id = trig_complex_core->sw_thread_id, + .core_mode_mask = trig_complex_core->core_mode_mask, + }; + +return marshal; +} + +mcd_trig_complex_core_st unmarshal_mcd_trig_complex_core ( +MCDTrigComplexCore *trig_complex_core) +{ +mcd_trig_complex_core_st unmarshal = { + .struct_size =sizeof (mcd_trig_complex_core_st), + .type = trig_complex_core->type, + .option = trig_complex_core->option, + .action = trig_complex_core->action, + .action_param = trig_complex_core->action_param, + .modified = trig_complex_core->modified, + .state_mask = trig_complex_core->state_mask, + .addr_start =unmarshal_mcd_addr (trig_complex_core->addr_start), + .addr_range = trig_complex_core->addr_range, + .data_start = trig_complex_core->data_start, + .data_range = trig_complex_core->data_range, + .data_mask = trig_complex_core->data_mask, + .data_size = trig_complex_core->data_size, + .hw_thread_id = trig_complex_core->hw_thread_id, + .sw_thread_id = trig_complex_core->sw_thread_id, + .core_mode_mask = trig_complex_core->core_mode_mask, + }; + +return unmarshal; +} + +MCDTrigState *marshal_mcd_trig_state (const mcd_trig_state_st *trig_info) +{ +MCDTrigState *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigState ) { + .active = trig_info->active, + .captured = trig_info->captured, + .captured_valid = trig_info->captured_valid, + .count_value = trig_info->count_value, + .count_valid = trig_info->count_valid, + }; + +return marshal; +} + +MCDTrigSetState *marshal_mcd_trig_set_state ( +const mcd_trig_set_state_st *trig_state) +{ +MCDTrigSetState *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigSetState ) { + .active = trig_state->active, + .state = trig_state->state, + .state_valid = trig_state->state_valid, + .trig_bus = trig_state->trig_bus, + .trig_bus_valid = trig_state->trig_bus_valid, + .trace = trig_state->trace, + .trace_valid = trig_state->trace_valid, + .analysis = trig_state->analysis, + .analysis_valid = trig_state->analysis_valid, + }; + +return marshal; +} +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx) {MCDTx *marshal =g_malloc0 (sizeof (*marshal));
mcd/libmcd_qapi.h +21 -0
@@ -37,6 +37,21 @@ MCDRegisterInfo *marshal_mcd_register_info(MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state); +MCDTrigInfo *marshal_mcd_trig_info (const mcd_trig_info_st *trig_info); + +MCDCtrigInfo *marshal_mcd_ctrig_info (const mcd_ctrig_info_st *trig_info); + +MCDTrigSimpleCore *marshal_mcd_trig_simple_core ( +const mcd_trig_simple_core_st *trig_simple_core); + +MCDTrigComplexCore *marshal_mcd_trig_complex_core ( +const mcd_trig_complex_core_st *trig_complex_core); + +MCDTrigState *marshal_mcd_trig_state (const mcd_trig_state_st *trig_info); + +MCDTrigSetState *marshal_mcd_trig_set_state ( +const mcd_trig_set_state_st *trig_state); +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx);MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist);
@@ -47,6 +62,12 @@ mcd_core_con_info_st unmarshal_mcd_core_con_info(MCDCoreConInfo *con_info);mcd_addr_st unmarshal_mcd_addr (MCDAddr *addr); +mcd_trig_simple_core_st unmarshal_mcd_trig_simple_core ( +MCDTrigSimpleCore *trig_simple_core); + +mcd_trig_complex_core_st unmarshal_mcd_trig_complex_core ( +MCDTrigComplexCore *trig_complex_core); +mcd_tx_st unmarshal_mcd_tx (MCDTx *tx);mcd_txlist_st unmarshal_mcd_txlist (MCDTxlist *txlist);
mcd/mcdserver.c +566 -19
704 lines not on this page · raw message
mcd/mcdstub_qapi.c +290 -0
293 lines not on this page · raw message
qapi/mcd.json +588 -0
597 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 16/16 mcd: Implement reset control
In reply to Mario FleischmannProvide a system reset vector and handle it similar to hmp_system_reset
We don't use a QMP related shutdown reason because the mcdserver is implemented independent of the used communication protocol. (In fact, another communication protocol implementation for MCD already exists and can be found at https://gitlab.com/lauterbach/mcdrefsrv)
--- mcd/libmcd_qapi.c | 12 +++++ mcd/libmcd_qapi.h | 2 + mcd/mcdserver.c | 98 ++++++++++++++++++++++++++++++++-- mcd/mcdstub_qapi.c | 61 +++++++++++++++++++++ qapi/mcd.json | 129 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 297 insertions(+), 5 deletions(-)
mcd/libmcd_qapi.c +12 -0
@@ -492,3 +492,15 @@ void free_mcd_txlist(mcd_txlist_st *txlist)g_free (txlist->tx); } + +MCDRstInfo *marshal_mcd_rst_info (const mcd_rst_info_st *rst_info) +{ +MCDRstInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDRstInfo ) { + .class_vector = rst_info->class_vector, + .info_str =g_strdup (rst_info->info_str), + }; + +return marshal; +}
mcd/libmcd_qapi.h +2 -0
@@ -56,6 +56,8 @@ MCDTx *marshal_mcd_tx(const mcd_tx_st *tx);MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist); +MCDRstInfo *marshal_mcd_rst_info (const mcd_rst_info_st *rst_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcdserver.c +93 -5
123 lines not on this page · raw message
mcd/mcdstub_qapi.c +61 -0
67 lines not on this page · raw message
qapi/mcd.json +129 -0
141 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 8 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol. We get around this limitation by following a remote procedure call approach using QMP. The client stub corresponding to this implementation can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 6 lines
This series is the successor to:
"[PATCH v5 00/18] first version of mcdstub"
(https://patchew.org/QEMU/[email protected]/)* Architecture-independent MCD implementation
* QMP instead of custom TCP protocol
Rationale? There must be pros and cons.
How much data would you expect to flow in practical usage? QMP isn't designed for bulk transfer...
Quoted 7 lines
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
* Architecture-independent QTest test suite
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-test
* Architecture-specific tests can be found at the client stub
[...]
Quoted 1 line
qapi/mcd.json | 2366 ++++++++++++++++++++++
This is *massive*. By non-blank, non-comment lines, it's the second largest module in qapi/, almost 9% of the entire schema. It's larger than the entire QEMU guest agent QAPI schema. The QAPI generator generates some 280KiB of C code for it.
[...]
Thanks a lot for the response, I really appreciate your time.
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol. We get around this limitation by following a remote procedure call approach using QMP. The client stub corresponding to this implementation can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 8 lines
Quoted 6 lines
This series is the successor to:
"[PATCH v5 00/18] first version of mcdstub"
(https://patchew.org/QEMU/[email protected]/)* Architecture-independent MCD implementation
* QMP instead of custom TCP protocolRationale? There must be pros and cons.
Assuming you're referring to the protocol of the previous patch series:
The previous TCP protocol only supported a subset of MCD. As the implementation progresses, the protocol eventually needs to be extended, possibly resulting in backwards compatibility problems. Following an RPC approach and keeping the communication layer as close to the MCD API as possible results in a larger protocol at first, but does not need to be changed afterwards. By directly mapping MCD functions onto QMP commands, the complexity in the server and client stubs can be minimized.
Assuming you're referring to the QMP choice:
QMP is being described as the "protocol which allows applications to control a QEMU instance". It provides a RPC framework which automatically (de)serializes methods and their parameters, even inside QTests. The whole interface is automatically documented.
Quoted 2 lines
How much data would you expect to flow in practical usage? QMP isn't designed for bulk transfer...
According to ifstat, the expected data rate in practical usage is around
KB/s in KB/s out
100 100
I fully understand your concern and agree that a JSON-based protocol does not result in the lowest data rate.
If the data rate is the highest priority: *Before* the QMP supported was implemented, the MCD interface was built on a custom RPC framework, generated with the code generator at:
https://gitlab.com/lauterbach/mcdrefsrv/-/tree/main/codegen
The resulting header file was basically a set of functions capable of serializing MCD's function arguments into a byte stream and vice-versa:
The QMP support was added because of the advantages listed above and in order to evade yet another custom communication protocol.
As a user of the MCD interface, I haven't noticed any negative impact of the increased data rate in realistic debugging scenarios, even when trying to drive the data rate up. If that would have been the case, I would have sent this patch request with our custom RPC protocol.
Quoted 8 lines
Quoted 7 lines
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
* Architecture-independent QTest test suite
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-test
* Architecture-specific tests can be found at the client stub
Quoted 8 lines
[...]
Quoted 1 line
qapi/mcd.json | 2366 ++++++++++++++++++++++This is *massive*. By non-blank, non-comment lines, it's the second largest module in qapi/, almost 9% of the entire schema. It's larger than the entire QEMU guest agent QAPI schema. The QAPI generator generates some 280KiB of C code for it.
I understand your point and I think it touches on the point made above regarding MCD's complexity:
Quoted 1 line
mcd/mcd_api.h| 3963 +++++++++++++++++++++++++++++++++++++
I hope that we agree that RPC is generally the right approach to implement MCD. As far as the implementation is concerned, I'm open to any suggestion you have. I've always avoided to introduce any unnecessary external dependencies.
Best regards,
Mario
Quoted 33 lines · Mario Fleischmann
Thanks a lot for the response, I really appreciate your time.
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol. We get around this limitation by following a remote procedure call approach using QMP. The client stub corresponding to this implementation can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 8 lines
Quoted 6 lines
This series is the successor to:
"[PATCH v5 00/18] first version of mcdstub"
(https://patchew.org/QEMU/[email protected]/)* Architecture-independent MCD implementation
* QMP instead of custom TCP protocolRationale? There must be pros and cons.
Assuming you're referring to the protocol of the previous patch series:
The previous TCP protocol only supported a subset of MCD. As the implementation progresses, the protocol eventually needs to be extended, possibly resulting in backwards compatibility problems. Following an RPC approach and keeping the communication layer as close to the MCD API as possible results in a larger protocol at first, but does not need to be changed afterwards.
By directly mapping MCD functions onto QMP commands, the complexity in the server and client stubs can be minimized.
Quoted 6 lines
Assuming you're referring to the QMP choice:
QMP is being described as the "protocol which allows applications to control a QEMU instance".
It provides a RPC framework which automatically (de)serializes methods and their parameters, even inside QTests.
The whole interface is automatically documented.
Let's see whether I understand.
MCD is an established C interface.
Your goal is to provide remote MCD for QEMU, i.e. the client uses the MCD C interface, and the interface's implementation talks to an MCD server integrated into QEMU via some remote transport.
The previous version connects the two with a bespoke protocol via TCP. The client software translates between the C interface and this protocol. QEMU implements the protocol's server side. Designing and maintaining a protocol is expensive.
This versions makes two changes:
1. Instead of layering a protocol on top of MCD, you use MCD directly. This eliminates protocol design and maintenance. Moreover, translation becomes straightforward marshaling / unmarshaling for the transport.
2. You use QMP as a transport. This gets you marshaling / unmarshaling for free. It also provides some useful infrastructure for tests, documentation and such.
Fair?
Quoted 20 lines
Quoted 2 lines
How much data would you expect to flow in practical usage? QMP isn't designed for bulk transfer...
According to ifstat, the expected data rate in practical usage is around
KB/s in KB/s out
100 100I fully understand your concern and agree that a JSON-based protocol does not result in the lowest data rate.
If the data rate is the highest priority: *Before* the QMP supported was implemented, the MCD interface was built on a custom RPC framework, generated with the code generator at:
https://gitlab.com/lauterbach/mcdrefsrv/-/tree/main/codegen
The resulting header file was basically a set of functions capable of serializing MCD's function arguments into a byte stream and vice-versa:
Quoted 8 lines
The QMP support was added because of the advantages listed above and in order to evade yet another custom communication protocol.
As a user of the MCD interface, I haven't noticed any negative impact of the increased data rate in realistic debugging scenarios, even when trying to drive the data rate up. If that would have been the case, I would have sent this patch request with our custom RPC protocol.
I see.
Quoted 12 lines
Quoted 12 lines
Quoted 7 lines
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
* Architecture-independent QTest test suite
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-test
* Architecture-specific tests can be found at the client stub
[...]
Quoted 1 line
qapi/mcd.json | 2366 ++++++++++++++++++++++
Quoted 9 lines
Quoted 4 lines
This is *massive*. By non-blank, non-comment lines, it's the second largest module in qapi/, almost 9% of the entire schema. It's larger than the entire QEMU guest agent QAPI schema. The QAPI generator generates some 280KiB of C code for it.
I understand your point and I think it touches on the point made above regarding MCD's complexity:
Quoted 1 line
mcd/mcd_api.h| 3963 +++++++++++++++++++++++++++++++++++++
Uh, that's a big one.
Out of curiosity, what's the size of the previous version's code to translate between the C interface and TCP?
Quoted 4 lines
I hope that we agree that RPC is generally the right approach to implement MCD. As far as the implementation is concerned, I'm open to any suggestion you have. I've always avoided to introduce any unnecessary external dependencies.
I think you're much better qualified to judge the merits of RPC here than I am. That leaves the question of the RPC transport. You want to use QMP.
On the one hand, I'm tickled to see QAPI/QMP used for things it wasn't designed for.
On the other hand, QMP has grown so big. Keeping it cohesive has become a near-impossible mission.
Hmm.
We already provide another remote debugger interface: the GDB stub. It's optional, i.e. the user has to create it, either with command line option -gdb, or monitor command gdbserver.
We already have two-and-a-half QMPs: qemu-system-FOO's QMP, qemu-storage-daemon's QMP (subset of the previous, so it counts only half), and qemu-ga's QMP-like protocol.
What about providing the MCD interface as a separate QMP-like protocol?
It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.
Thoughts? Alex, Philippe, care to chime in?
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
Quoted 61 lines · Markus Armbruster
Quoted 33 lines · Mario Fleischmann
Thanks a lot for the response, I really appreciate your time.
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol. We get around this limitation by following a remote procedure call approach using QMP. The client stub corresponding to this implementation can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 8 lines
Quoted 6 lines
This series is the successor to:
"[PATCH v5 00/18] first version of mcdstub"
(https://patchew.org/QEMU/[email protected]/)* Architecture-independent MCD implementation
* QMP instead of custom TCP protocolRationale? There must be pros and cons.
Assuming you're referring to the protocol of the previous patch series:
The previous TCP protocol only supported a subset of MCD. As the implementation progresses, the protocol eventually needs to be extended, possibly resulting in backwards compatibility problems. Following an RPC approach and keeping the communication layer as close to the MCD API as possible results in a larger protocol at first, but does not need to be changed afterwards.
By directly mapping MCD functions onto QMP commands, the complexity in the server and client stubs can be minimized.Quoted 6 lines
Assuming you're referring to the QMP choice:
QMP is being described as the "protocol which allows applications to control a QEMU instance".
It provides a RPC framework which automatically (de)serializes methods and their parameters, even inside QTests.
The whole interface is automatically documented.Let's see whether I understand.
MCD is an established C interface.
Your goal is to provide remote MCD for QEMU, i.e. the client uses the MCD C interface, and the interface's implementation talks to an MCD server integrated into QEMU via some remote transport.
The previous version connects the two with a bespoke protocol via TCP. The client software translates between the C interface and this protocol. QEMU implements the protocol's server side. Designing and maintaining a protocol is expensive.
This versions makes two changes:
1. Instead of layering a protocol on top of MCD, you use MCD directly. This eliminates protocol design and maintenance. Moreover, translation becomes straightforward marshaling / unmarshaling for the transport.
Quoted 5 lines
2. You use QMP as a transport. This gets you marshaling / unmarshaling for free. It also provides some useful infrastructure for tests, documentation and such.
Fair?
Couldn't have put it better myself.
Quoted 51 lines
Quoted 20 lines
Quoted 2 lines
How much data would you expect to flow in practical usage? QMP isn't designed for bulk transfer...
According to ifstat, the expected data rate in practical usage is around
KB/s in KB/s out
100 100I fully understand your concern and agree that a JSON-based protocol does not result in the lowest data rate.
If the data rate is the highest priority: *Before* the QMP supported was implemented, the MCD interface was built on a custom RPC framework, generated with the code generator at:
https://gitlab.com/lauterbach/mcdrefsrv/-/tree/main/codegen
The resulting header file was basically a set of functions capable of serializing MCD's function arguments into a byte stream and vice-versa:
Quoted 8 lines
The QMP support was added because of the advantages listed above and in order to evade yet another custom communication protocol.
As a user of the MCD interface, I haven't noticed any negative impact of the increased data rate in realistic debugging scenarios, even when trying to drive the data rate up. If that would have been the case, I would have sent this patch request with our custom RPC protocol.I see.
Quoted 20 lines
Quoted 8 lines
Quoted 7 lines
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
* Architecture-independent QTest test suite
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-test
* Architecture-specific tests can be found at the client stub
Quoted 8 lines
[...]
Quoted 1 line
qapi/mcd.json | 2366 ++++++++++++++++++++++This is *massive*. By non-blank, non-comment lines, it's the second largest module in qapi/, almost 9% of the entire schema. It's larger than the entire QEMU guest agent QAPI schema. The QAPI generator generates some 280KiB of C code for it.
I understand your point and I think it touches on the point made above regarding MCD's complexity:
Quoted 6 lines
Quoted 1 line
Quoted 1 line
mcd/mcd_api.h| 3963 +++++++++++++++++++++++++++++++++++++Uh, that's a big one.
Out of curiosity, what's the size of the previous version's code to translate between the C interface and TCP?
The previous version's protocol was very similar to GDB's remote serial protocol which is why the size of its implementation is comparable to that of gdbstub.c
Quoted 1 line
debug/mcdstub/mcdstub.c| 2481 ++++++++++++++++++++++
Note that this file contains both the transport layer as well as the implementation and does not implement mcd_api.h which makes the two patch sets difficult to compare.
Quoted 8 lines
Quoted 4 lines
I hope that we agree that RPC is generally the right approach to implement MCD. As far as the implementation is concerned, I'm open to any suggestion you have. I've always avoided to introduce any unnecessary external dependencies.
I think you're much better qualified to judge the merits of RPC here than I am. That leaves the question of the RPC transport. You want to use QMP.
I think that QMP is the more mature protocol than my RPC proof-of-concept and would improve interoperability. However, our open-source client stub supports both transport layers, so we're fine with both.
Quoted 2 lines
On the one hand, I'm tickled to see QAPI/QMP used for things it wasn't designed for.
Might be a language issue but I can't tell whether that's meant positively or negatively.
Quoted 8 lines
On the other hand, QMP has grown so big. Keeping it cohesive has become a near-impossible mission.
Hmm.
We already provide another remote debugger interface: the GDB stub. It's optional, i.e. the user has to create it, either with command line option -gdb, or monitor command gdbserver.
We had that option in our previous patch set:
Quoted 1 line
$ qemu-system-arm -M virt -cpu cortex-a15 -mcd tcp::1235
If you'd like, we can of course add such an option again. The QMP choice made that redundant for me because I wasn't aware of a way to only provide a subset of QMP.
Quoted 11 lines
We already have two-and-a-half QMPs: qemu-system-FOO's QMP, qemu-storage-daemon's QMP (subset of the previous, so it counts only half), and qemu-ga's QMP-like protocol.
What about providing the MCD interface as a separate QMP-like protocol? It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.Thoughts? Alex, Philippe, care to chime in?
Sound reasonable to me. Keeping in mind the size of generated QAPI code, an option to ./configure [...] --enable-mcd is definitely advisable.
Quoted 134 lines · Mario Fleischmann
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
Quoted 61 lines · Markus Armbruster
Quoted 33 lines · Mario Fleischmann
Thanks a lot for the response, I really appreciate your time.
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol. We get around this limitation by following a remote procedure call approach using QMP. The client stub corresponding to this implementation can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 8 lines
Quoted 6 lines
This series is the successor to:
"[PATCH v5 00/18] first version of mcdstub"
(https://patchew.org/QEMU/[email protected]/)* Architecture-independent MCD implementation
* QMP instead of custom TCP protocolRationale? There must be pros and cons.
Assuming you're referring to the protocol of the previous patch series:
The previous TCP protocol only supported a subset of MCD. As the implementation progresses, the protocol eventually needs to be extended, possibly resulting in backwards compatibility problems. Following an RPC approach and keeping the communication layer as close to the MCD API as possible results in a larger protocol at first, but does not need to be changed afterwards.
By directly mapping MCD functions onto QMP commands, the complexity in the server and client stubs can be minimized.Quoted 6 lines
Assuming you're referring to the QMP choice:
QMP is being described as the "protocol which allows applications to control a QEMU instance".
It provides a RPC framework which automatically (de)serializes methods and their parameters, even inside QTests.
The whole interface is automatically documented.Let's see whether I understand.
MCD is an established C interface.
Your goal is to provide remote MCD for QEMU, i.e. the client uses the MCD C interface, and the interface's implementation talks to an MCD server integrated into QEMU via some remote transport.
The previous version connects the two with a bespoke protocol via TCP. The client software translates between the C interface and this protocol. QEMU implements the protocol's server side. Designing and maintaining a protocol is expensive.
This versions makes two changes:
1. Instead of layering a protocol on top of MCD, you use MCD directly. This eliminates protocol design and maintenance. Moreover, translation becomes straightforward marshaling / unmarshaling for the transport.
Quoted 5 lines
2. You use QMP as a transport. This gets you marshaling / unmarshaling for free. It also provides some useful infrastructure for tests, documentation and such.
Fair?
Couldn't have put it better myself.
Quoted 51 lines
Quoted 20 lines
Quoted 2 lines
How much data would you expect to flow in practical usage? QMP isn't designed for bulk transfer...
According to ifstat, the expected data rate in practical usage is around
KB/s in KB/s out
100 100I fully understand your concern and agree that a JSON-based protocol does not result in the lowest data rate.
If the data rate is the highest priority: *Before* the QMP supported was implemented, the MCD interface was built on a custom RPC framework, generated with the code generator at:
https://gitlab.com/lauterbach/mcdrefsrv/-/tree/main/codegen
The resulting header file was basically a set of functions capable of serializing MCD's function arguments into a byte stream and vice-versa:
Quoted 8 lines
The QMP support was added because of the advantages listed above and in order to evade yet another custom communication protocol.
As a user of the MCD interface, I haven't noticed any negative impact of the increased data rate in realistic debugging scenarios, even when trying to drive the data rate up. If that would have been the case, I would have sent this patch request with our custom RPC protocol.I see.
Quoted 20 lines
Quoted 8 lines
Quoted 7 lines
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
* Architecture-independent QTest test suite
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-test
* Architecture-specific tests can be found at the client stub
Quoted 8 lines
[...]
Quoted 1 line
qapi/mcd.json | 2366 ++++++++++++++++++++++This is *massive*. By non-blank, non-comment lines, it's the second largest module in qapi/, almost 9% of the entire schema. It's larger than the entire QEMU guest agent QAPI schema. The QAPI generator generates some 280KiB of C code for it.
I understand your point and I think it touches on the point made above regarding MCD's complexity:
Quoted 6 lines
Quoted 1 line
Quoted 1 line
mcd/mcd_api.h| 3963 +++++++++++++++++++++++++++++++++++++Uh, that's a big one.
Out of curiosity, what's the size of the previous version's code to translate between the C interface and TCP?
The previous version's protocol was very similar to GDB's remote serial protocol which is why the size of its implementation is comparable to that of
gdbstub.c
Quoted 5 lines
Quoted 1 line
debug/mcdstub/mcdstub.c| 2481 ++++++++++++++++++++++Note that this file contains both the transport layer as well as the implementation and does not implement
mcd_api.hwhich makes the two patch sets difficult to compare.
Understood.
Quoted 14 lines
Quoted 8 lines
Quoted 4 lines
I hope that we agree that RPC is generally the right approach to implement MCD. As far as the implementation is concerned, I'm open to any suggestion you have. I've always avoided to introduce any unnecessary external dependencies.
I think you're much better qualified to judge the merits of RPC here than I am. That leaves the question of the RPC transport. You want to use QMP.
I think that QMP is the more mature protocol than my RPC proof-of-concept and would improve interoperability. However, our open-source client stub supports both transport layers, so we're fine with both.
Quoted 5 lines
Quoted 2 lines
On the one hand, I'm tickled to see QAPI/QMP used for things it wasn't designed for.
Might be a language issue but I can't tell whether that's meant positively or negatively.
Positively!
Quoted 9 lines
Quoted 8 lines
On the other hand, QMP has grown so big. Keeping it cohesive has become a near-impossible mission.
Hmm.
We already provide another remote debugger interface: the GDB stub. It's optional, i.e. the user has to create it, either with command line option -gdb, or monitor command gdbserver.
Quoted 7 lines
We had that option in our previous patch set:
Quoted 1 line
$ qemu-system-arm -M virt -cpu cortex-a15 -mcd tcp::1235If you'd like, we can of course add such an option again. The QMP choice made that redundant for me because I wasn't aware of a way to only provide a subset of QMP.
Or rather several QMPs.
Quoted 3 lines
Quoted 3 lines
We already have two-and-a-half QMPs: qemu-system-FOO's QMP, qemu-storage-daemon's QMP (subset of the previous, so it counts only half), and qemu-ga's QMP-like protocol.
qemu-ga's protocol differs in certain details for historical reasons. A new one should not.
QMP supports introspection via query-qmp-schema. This enables clients to deal with a wide range of server versions. You don't need this if your interface never changes (a rather bold assertion), or your client always targets one specific version. If you need it, I'm happy to advise on how to use it.
Quoted 11 lines
Quoted 8 lines
What about providing the MCD interface as a separate QMP-like protocol? It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.
Thoughts? Alex, Philippe, care to chime in?
Sound reasonable to me. Keeping in mind the size of generated QAPI code, an option to
./configure [...] --enable-mcdis definitely advisable.
Alex, Philippe?
Quoted 74 lines · Markus Armbruster
Quoted 72 lines · Mario Fleischmann
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
Quoted 61 lines · Markus Armbruster
Quoted 33 lines · Mario Fleischmann
Thanks a lot for the response, I really appreciate your time.
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol. We get around this limitation by following a remote procedure call approach using QMP. The client stub corresponding to this implementation can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 8 lines
Quoted 6 lines
This series is the successor to:
"[PATCH v5 00/18] first version of mcdstub"
(https://patchew.org/QEMU/[email protected]/)* Architecture-independent MCD implementation
* QMP instead of custom TCP protocolRationale? There must be pros and cons.
Assuming you're referring to the protocol of the previous patch series:
The previous TCP protocol only supported a subset of MCD. As the implementation progresses, the protocol eventually needs to be extended, possibly resulting in backwards compatibility problems. Following an RPC approach and keeping the communication layer as close to the MCD API as possible results in a larger protocol at first, but does not need to be changed afterwards.
By directly mapping MCD functions onto QMP commands, the complexity in the server and client stubs can be minimized.Quoted 6 lines
Assuming you're referring to the QMP choice:
QMP is being described as the "protocol which allows applications to control a QEMU instance".
It provides a RPC framework which automatically (de)serializes methods and their parameters, even inside QTests.
The whole interface is automatically documented.Let's see whether I understand.
MCD is an established C interface.
Your goal is to provide remote MCD for QEMU, i.e. the client uses the MCD C interface, and the interface's implementation talks to an MCD server integrated into QEMU via some remote transport.
The previous version connects the two with a bespoke protocol via TCP. The client software translates between the C interface and this protocol. QEMU implements the protocol's server side. Designing and maintaining a protocol is expensive.
This versions makes two changes:
1. Instead of layering a protocol on top of MCD, you use MCD directly. This eliminates protocol design and maintenance. Moreover, translation becomes straightforward marshaling / unmarshaling for the transport.
Quoted 5 lines
2. You use QMP as a transport. This gets you marshaling / unmarshaling for free. It also provides some useful infrastructure for tests, documentation and such.
Fair?
Couldn't have put it better myself.
<snip>
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
What about providing the MCD interface as a separate QMP-like protocol? It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thoughts? Alex, Philippe, care to chime in?
Sound reasonable to me. Keeping in mind the size of generated QAPI code, an option to
./configure [...] --enable-mcdis definitely advisable.Alex, Philippe?
When I spoke to Mario at DVCon last year I liked the idea of re-using QMP instead of inventing yet another RPC interface for QEMU. QMP certainly has nicer properties than the gdbstub which has a very "organic" and "serial" feel to it.
Are you suggesting we re-use the machinery but use an entirely separate socket with just the MCD namespace in it? I don't see that being a problem as long as we can test it properly in the CI.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 7 lines · Alex Bennée
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Mario Fleischmann
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
On 08.04.2025 09:00, Markus Armbruster wrote:
[...]
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
What about providing the MCD interface as a separate QMP-like protocol? It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thoughts? Alex, Philippe, care to chime in?
Sound reasonable to me. Keeping in mind the size of generated QAPI code, an option to
./configure [...] --enable-mcdis definitely advisable.Alex, Philippe?
Quoted 8 lines
When I spoke to Mario at DVCon last year I liked the idea of re-using QMP instead of inventing yet another RPC interface for QEMU. QMP certainly has nicer properties than the gdbstub which has a very "organic" and "serial" feel to it.
Are you suggesting we re-use the machinery but use an entirely separate socket with just the MCD namespace in it? I don't see that being a problem as long as we can test it properly in the CI.
Yes.
"Keep them separate" is only a gut feeling, though. While I pay attention to my gut feelings, I know they can be wrong. I am soliciting opinions.
Quoted 35 lines · Markus Armbruster
Quoted 7 lines · Alex Bennée
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Mario Fleischmann
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
On 08.04.2025 09:00, Markus Armbruster wrote:
[...]
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
What about providing the MCD interface as a separate QMP-like protocol? It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thoughts? Alex, Philippe, care to chime in?
Sound reasonable to me. Keeping in mind the size of generated QAPI code, an option to
./configure [...] --enable-mcdis definitely advisable.Alex, Philippe?
Quoted 8 lines
When I spoke to Mario at DVCon last year I liked the idea of re-using QMP instead of inventing yet another RPC interface for QEMU. QMP certainly has nicer properties than the gdbstub which has a very "organic" and "serial" feel to it.
Are you suggesting we re-use the machinery but use an entirely separate socket with just the MCD namespace in it? I don't see that being a problem as long as we can test it properly in the CI.
Quoted 5 lines
Yes.
"Keep them separate" is only a gut feeling, though. While I pay attention to my gut feelings, I know they can be wrong. I am soliciting opinions.
I forgot to add isn't the flexibility of the QMP API something we need to handle for single binary anyway?
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 37 lines · Alex Bennée
Quoted 35 lines · Markus Armbruster
Quoted 7 lines · Alex Bennée
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Mario Fleischmann
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
On 08.04.2025 09:00, Markus Armbruster wrote:
[...]
Quoted 22 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
What about providing the MCD interface as a separate QMP-like protocol? It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thoughts? Alex, Philippe, care to chime in?
Sound reasonable to me. Keeping in mind the size of generated QAPI code, an option to
./configure [...] --enable-mcdis definitely advisable.Alex, Philippe?
When I spoke to Mario at DVCon last year I liked the idea of re-using QMP instead of inventing yet another RPC interface for QEMU. QMP certainly has nicer properties than the gdbstub which has a very "organic" and "serial" feel to it.
Are you suggesting we re-use the machinery but use an entirely separate socket with just the MCD namespace in it? I don't see that being a problem as long as we can test it properly in the CI.
Quoted 8 lines
Quoted 5 lines
Yes.
"Keep them separate" is only a gut feeling, though. While I pay attention to my gut feelings, I know they can be wrong. I am soliciting opinions.
I forgot to add isn't the flexibility of the QMP API something we need to handle for single binary anyway?
I have no idea :)
Evolving a target-dependent interface into a target-independent interface without breaking compatibility is always a bother.
It's likely more of a bother when the interface is binary. Textual interfaces tend to have less target-dependence.
Designing a target-independent interface is probably easier than evolving it compatibly from a target-dependent one.
QMP is textual, and it's designed for certain kinds of compatible evolution. Using QAPI/QMP for a debugging interface may be a perfectly sensible idea. I don't know enough about debugging interfaces to judge.
Use of QAPI/QMP does not imply use of the QMP monitor. We can keep the monitor and the debugging interface separate even though both are based on QAPI/QMP.
The monitor code is gnarly, I'm afraid. It supports multiple monitors, but they are not fully independent for historical reasons, chiefly implied mutual exclusion for commands. Adding a QAPI/QMP-based debugging interface without undue coupling to monitors may pose a few technical problems. One way to find out.
Quoted 41 lines · Markus Armbruster
Quoted 39 lines · Alex Bennée
Quoted 37 lines · Markus Armbruster
Quoted 7 lines · Alex Bennée
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Mario Fleischmann
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
On 08.04.2025 09:00, Markus Armbruster wrote:
[...]
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
What about providing the MCD interface as a separate QMP-like protocol? It gets its own QAPI schema, just like for qemu-ga. Simplifies compiling it out when not needed.
It gets its own socket, just like the GDB stub. Might reduce interference between debugging and QMP.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thoughts? Alex, Philippe, care to chime in?
Sound reasonable to me. Keeping in mind the size of generated QAPI code, an option to
./configure [...] --enable-mcdis definitely advisable.Alex, Philippe?
Quoted 8 lines
When I spoke to Mario at DVCon last year I liked the idea of re-using QMP instead of inventing yet another RPC interface for QEMU. QMP certainly has nicer properties than the gdbstub which has a very "organic" and "serial" feel to it.
Are you suggesting we re-use the machinery but use an entirely separate socket with just the MCD namespace in it? I don't see that being a problem as long as we can test it properly in the CI.
Yes.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
"Keep them separate" is only a gut feeling, though. While I pay attention to my gut feelings, I know they can be wrong. I am soliciting opinions.
I forgot to add isn't the flexibility of the QMP API something we need to handle for single binary anyway?
I have no idea :)
Alex, thanks for chiming in! By "single binary", I assume you mean user space emulation? In that case, could you elaborate whether and how it's a concern related to MCD? Maybe I'm missing something here. MCD is specifically designed for debugging multi-core SoCs and therefore currently only supported in system emulation. For user-space debugging, I don't see any reason why not to use GDB's remote serial protocol.
Quoted 8 lines
Evolving a target-dependent interface into a target-independent interface without breaking compatibility is always a bother.
It's likely more of a bother when the interface is binary. Textual interfaces tend to have less target-dependence.
Designing a target-independent interface is probably easier than evolving it compatibly from a target-dependent one.
Like the gdbstub, the MCD implementation does not have any target-specific dependencies. This is also a change compared to the last patch set and something I wanted to point out with
Quoted 1 line
Architecture-independent MCD implementation
But, again, maybe I'm missing something.
Quoted 3 lines
QMP is textual, and it's designed for certain kinds of compatible evolution. Using QAPI/QMP for a debugging interface may be a perfectly sensible idea. I don't know enough about debugging interfaces to judge.
Even though MCD is a very stable API (developed in 2008, functions haven't changed since then), as you've already pointed out, it's bold to assume that it will never change in the future. For that reason, MCD provides the mcd_initialize_f function which can be used to communicate the requested and implemented API versions. As long as that function stays serializable over the RPC layer, evolution should be possible.
Quoted 9 lines
Use of QAPI/QMP does not imply use of the QMP monitor. We can keep the monitor and the debugging interface separate even though both are based on QAPI/QMP.
The monitor code is gnarly, I'm afraid. It supports multiple monitors, but they are not fully independent for historical reasons, chiefly implied mutual exclusion for commands. Adding a QAPI/QMP-based debugging interface without undue coupling to monitors may pose a few technical problems. One way to find out.
If I understand you correctly, when QAPI-MCD runs on a separate socket without using a monitor, it's still coupled to the monitor code internally? Does this have an influence on the either the usage of a monitor or the MCD interface or is it rather an implementation detail?
Quoted 15 lines · Mario Fleischmann
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Alex Bennée
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Alex Bennée
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Mario Fleischmann
Apologies for the line wrapping in yesterday's answer. Should be fixed now.
On 08.04.2025 09:00, Markus Armbruster wrote:
<snip>
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
"Keep them separate" is only a gut feeling, though. While I pay attention to my gut feelings, I know they can be wrong. I am soliciting opinions.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I forgot to add isn't the flexibility of the QMP API something we need to handle for single binary anyway?
I have no idea :)
Alex, thanks for chiming in! By "single binary", I assume you mean user space emulation? In that case, could you elaborate whether and how it's a concern related to MCD? Maybe I'm missing something here.
Not directly, it was aimed at Markus. As we work towards a single binary build we have to consider how the QMP API is going to be presented when the binary could run a number of different targets. Markus and Philippe have discussed it before but I forget the details.
Quoted 3 lines
MCD is
specifically designed for debugging multi-core SoCs and therefore currently only supported in system emulation.
Eventually we hope to get to the position QEMU can emulation a heterogeneous SoC so having multiple architectures under one binary will present potential issues for debugging.
Quoted 41 lines
For user-space debugging,
I don't see any reason why not to use GDB's remote serial protocol.Quoted 8 lines
Evolving a target-dependent interface into a target-independent interface without breaking compatibility is always a bother.
It's likely more of a bother when the interface is binary. Textual interfaces tend to have less target-dependence.
Designing a target-independent interface is probably easier than evolving it compatibly from a target-dependent one.
Like the gdbstub, the MCD implementation does not have any target-specific dependencies. This is also a change compared to the last patch set and something I wanted to point out with
Quoted 1 line
Architecture-independent MCD implementation
But, again, maybe I'm missing something.
Quoted 3 lines
QMP is textual, and it's designed for certain kinds of compatible evolution. Using QAPI/QMP for a debugging interface may be a perfectly sensible idea. I don't know enough about debugging interfaces to judge.
Even though MCD is a very stable API (developed in 2008, functions haven't changed since then), as you've already pointed out, it's bold to assume that it will never change in the future. For that reason, MCD provides the
mcd_initialize_ffunction which can be used to communicate the requested and implemented API versions. As long as that function stays serializable over the RPC layer, evolution should be possible.Quoted 9 lines
Use of QAPI/QMP does not imply use of the QMP monitor. We can keep the monitor and the debugging interface separate even though both are based on QAPI/QMP.
The monitor code is gnarly, I'm afraid. It supports multiple monitors, but they are not fully independent for historical reasons, chiefly implied mutual exclusion for commands. Adding a QAPI/QMP-based debugging interface without undue coupling to monitors may pose a few technical problems. One way to find out.
Quoted 4 lines
If I understand you correctly, when QAPI-MCD runs on a separate socket without using a monitor, it's still coupled to the monitor code internally? Does this have an influence on the either the usage of a monitor or the MCD interface or is it rather an implementation detail?
An implementation detail - we should try and avoid needless coupling if we can though.
AFAIK not all monitor commands map to QMP equivalents but I'm not sure if that's true the other way around - can you do everything you can over QMP under HMP? If you don't have to then that implies we can over a separate schema on a debug socket that doesn't need monitor bits tied in.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 3 lines · Alex Bennée
Quoted 1 line · Mario Fleischmann
On 08.04.2025 16:37, Markus Armbruster wrote:
[...]
Quoted 15 lines
Quoted 10 lines
Quoted 9 lines
Use of QAPI/QMP does not imply use of the QMP monitor. We can keep the monitor and the debugging interface separate even though both are based on QAPI/QMP.
The monitor code is gnarly, I'm afraid. It supports multiple monitors, but they are not fully independent for historical reasons, chiefly implied mutual exclusion for commands. Adding a QAPI/QMP-based debugging interface without undue coupling to monitors may pose a few technical problems. One way to find out.
Quoted 4 lines
If I understand you correctly, when QAPI-MCD runs on a separate socket without using a monitor, it's still coupled to the monitor code internally? Does this have an influence on the either the usage of a monitor or the MCD interface or is it rather an implementation detail?
Quoted 8 lines
An implementation detail - we should try and avoid needless coupling if we can though.
AFAIK not all monitor commands map to QMP equivalents but I'm not sure if that's true the other way around - can you do everything you can over QMP under HMP? If you don't have to then that implies we can over a separate schema on a debug socket that doesn't need monitor bits tied in.
Ideally, HMP commands are human-friendly wrappers around QMP commands. Such commands can't do anything that could be done with QMP.
Not all the functionality of QMP needs to be exposed in HMP. Some functionality might only exist in QMP. How much to expose is a pragmatic "is it worth the bother?" decision.
Certain HMP commands make no sense in QMP. Examples:
* HMP cpu sets the default CPU. The concept doesn't exist in QMP.
* Ad hoc debugging commands that are used only by humans, such as sync-profile.
* The desk calculator[*]
My abstract mental model of MCD has it completely separate from monitors (HMP and QMP). Just like gdbstub.
We're considering to use QAPI/QMP as interface definition and transport infrastructure.
Mario's patches do that in a simple way: by "embedding" MCD in the QMP monitor. This creates a coupling that doesn't exist in my abstract mental model.
We could have a separate QAPI schema for interface definition, and a separate socket for transport. This avoids coupling.
Obviously, we'd still want to reuse existing QMP infrastructure as much as practical. Some of that that code is gnarly. If we're not careful, we get some subtle coupling deep under the hood.
Here's one possible complication. While we can have any number of QMP monitors, we still funnel most[**] commands to the main loop thread, where they run one after the other. If we reuse all that machinery for MCD, we end up forcing MCD commands through the same funnel to the main loop thread. This coupling could be undesirable.
Before we contemplate how to press the existing QMP infrastructure into service for MCD, we should first figure out how we'd want MCD to operate if we started on a green field. Can we have more than one MCD connection? Which thread should execure MCD commands? Any locking requirements? Any need for asynchronous commands?
[*] Which arguably makes no sense in HMP either.
[**] Not out-of-band commands. You probably don't want to know more.
Quoted 65 lines · Markus Armbruster
Quoted 3 lines · Alex Bennée
Quoted 1 line · Mario Fleischmann
On 08.04.2025 16:37, Markus Armbruster wrote:
[...]
Quoted 15 lines
Quoted 10 lines
Quoted 9 lines
Use of QAPI/QMP does not imply use of the QMP monitor. We can keep the monitor and the debugging interface separate even though both are based on QAPI/QMP.
The monitor code is gnarly, I'm afraid. It supports multiple monitors, but they are not fully independent for historical reasons, chiefly implied mutual exclusion for commands. Adding a QAPI/QMP-based debugging interface without undue coupling to monitors may pose a few technical problems. One way to find out.
Quoted 4 lines
If I understand you correctly, when QAPI-MCD runs on a separate socket without using a monitor, it's still coupled to the monitor code internally? Does this have an influence on the either the usage of a monitor or the MCD interface or is it rather an implementation detail?
Quoted 8 lines
An implementation detail - we should try and avoid needless coupling if we can though.
AFAIK not all monitor commands map to QMP equivalents but I'm not sure if that's true the other way around - can you do everything you can over QMP under HMP? If you don't have to then that implies we can over a separate schema on a debug socket that doesn't need monitor bits tied in.
Ideally, HMP commands are human-friendly wrappers around QMP commands. Such commands can't do anything that could be done with QMP.
Not all the functionality of QMP needs to be exposed in HMP. Some functionality might only exist in QMP. How much to expose is a pragmatic "is it worth the bother?" decision.
Certain HMP commands make no sense in QMP. Examples:
* HMP cpu sets the default CPU. The concept doesn't exist in QMP.
* Ad hoc debugging commands that are used only by humans, such as sync-profile.
* The desk calculator[*]
My abstract mental model of MCD has it completely separate from monitors (HMP and QMP). Just like gdbstub.
We're considering to use QAPI/QMP as interface definition and transport infrastructure.
Mario's patches do that in a simple way: by "embedding" MCD in the QMP monitor. This creates a coupling that doesn't exist in my abstract mental model.
We could have a separate QAPI schema for interface definition, and a separate socket for transport. This avoids coupling.
Obviously, we'd still want to reuse existing QMP infrastructure as much as practical. Some of that that code is gnarly. If we're not careful, we get some subtle coupling deep under the hood.
Quoted 5 lines
Here's one possible complication. While we can have any number of QMP monitors, we still funnel most[**] commands to the main loop thread, where they run one after the other. If we reuse all that machinery for MCD, we end up forcing MCD commands through the same funnel to the main loop thread. This coupling could be undesirable.
I think now we understand each other. Let me try to rephrase: We're trying to add a QEMU "debug" monitor which is used to debug the emulated system. The debug monitor is built on the MCD API as the debug protocol and QMP as the transport protocol and runs in parallel to the QEMU monitor which is used to control the emulator. Since the QEMU monitor is also built on QMP, we can reuse as much as possible from its QMP code but have to be careful not to add any coupling that goes beyond the transport layer.
If I understood you correctly, I would feel prepared to go to work and try it out. If problems come up, I would get back to you.
Quoted 4 lines
Before we contemplate how to press the existing QMP infrastructure into service for MCD, we should first figure out how we'd want MCD to operate if we started on a green field. Can we have more than one MCD connection?
There are two types of connections in MCD. mcd_open_server_f opens the connection to the MCD implementation, i.e. mcdserver, and initializes mcdserver's core database. The actual debugging is performed over core connections opened by mcd_open_core_f. Each core connection will be identified by a pointer to a mcd_core_st object in the MCD API and by an uint32_t holding a unique identifier over the RPC protocol.
In homogeneous multi-core systems, we can get away with one server connection and multiple core connections. In heterogeneous systems, we need multiple server connections since most likely multiple debuggers have to be connected to QEMU simultaneously.
While there are use-cases to opening multiple connections to the same core at once, I would propose to keep this is as a future option but not to include this in the initial commits since it considerably complicates things.
Quoted 1 line
Which thread should execute MCD commands?
Since both gdbserver and QMP monitor run in the main thread, I don't see a reason why not to run the mcdserver in there as well.
Quoted 1 line
Any locking requirements?
As there are no explicit locks in gdbstub.c, I assume they are enforced by QEMU's infrastructure.
Quoted 1 line
Any need for asynchronous commands?
No, none that I'm aware of.
Quoted 3 lines
[*] Which arguably makes no sense in HMP either.
[**] Not out-of-band commands. You probably don't want to know more.