[PATCH v3 00/20] first version of mcdstub

Nicolas Eder posted 20 patches 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231107130323.4126-1-nicolas.eder@lauterbach.com
Maintainers: Nicolas Eder <nicolas.eder@lauterbach.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, Peter Maydell <peter.maydell@linaro.org>
There is a newer version of this series
MAINTAINERS                          |   11 +
debug/debug-common.c                 |   42 +
debug/debug-gdb.c                    |   24 +
debug/debug-mcd.c                    |   25 +
gdbstub/gdbstub.c                    |    9 +-
gdbstub/internals.h                  |   26 -
gdbstub/meson.build                  |    4 +-
gdbstub/system.c                     |    4 +
gdbstub/user.c                       |    2 +
include/cutils.h                     |   30 +
include/exec/cpu-common.h            |    2 +
include/exec/gdbstub.h               |   14 +-
include/exec/memory.h                |    9 +
include/hw/boards.h                  |    1 +
include/mcdstub/arm_mcdstub.h        |  107 ++
include/mcdstub/mcd_shared_defines.h |  108 ++
include/mcdstub/mcdstub.h            |  893 ++++++++++++
include/mcdstub/mcdstub_common.h     |   59 +
include/qemu/debug.h                 |   19 +
include/qemu/typedefs.h              |    2 +
mcdstub/mcdstub.c                    | 1998 ++++++++++++++++++++++++++
mcdstub/meson.build                  |   15 +
meson.build                          |    1 +
qemu-options.hx                      |   18 +
system/cpus.c                        |    9 +-
system/memory.c                      |   11 +
system/physmem.c                     |   26 +
system/vl.c                          |   13 +
target/arm/mcdstub.c                 |  304 ++++
target/arm/meson.build               |    1 +
30 files changed, 3749 insertions(+), 38 deletions(-)
create mode 100644 debug/debug-common.c
create mode 100644 debug/debug-gdb.c
create mode 100644 debug/debug-mcd.c
create mode 100644 include/cutils.h
create mode 100644 include/mcdstub/arm_mcdstub.h
create mode 100644 include/mcdstub/mcd_shared_defines.h
create mode 100644 include/mcdstub/mcdstub.h
create mode 100644 include/mcdstub/mcdstub_common.h
create mode 100644 include/qemu/debug.h
create mode 100644 mcdstub/mcdstub.c
create mode 100644 mcdstub/meson.build
create mode 100644 target/arm/mcdstub.c
[PATCH v3 00/20] first version of mcdstub
Posted by Nicolas Eder 1 year ago
SUMMARY
=======

This patch-set introduces the first version of the mcdstub.
The mcdstub is a debug interface, which enables debugging QEMU
using the MCD (Multi-Core Debug) API.
The mcdstub uses TCP to communicate with the host debug software. However,
because MCD is merely an API, the TCP communication is not part of
the MCD spec but specific to this project.

To translate between the MCD API and the TCP data stream coming from the mcdstub,
the host has to use a shared library (.dll/.so).
Such a shared library will be available soon Lauterbach's open source site
and will be linked to from inside this project in a future patch.
The MCD API itself can be downloaded here: https://repo.lauterbach.com/sprint_mcd_api_v1_0.zip

QUICK START
===========

Attention: MCD is currently only supported for qemu-system-arm !

Three components are required to Debug QEMU via MCD:

1. qemu-system-arm (built with this patch series applied).
2. MCD shared library (translates between the MCD API and TCP data).
3. Host debugging software with support for the MCD API (e.g. Lauterbach TRACE32).

To activate the mcdstub, just use the "mcd" launch option in combination with
a TCP port.

With the default TCP port 1235:

$ qemu-system-arm -M virt -cpu cortex-a15 -mcd default

With a custom TCP port:

$ qemu-system-arm -M virt -cpu cortex-a15 -mcd tcp::1235

QEMU will listen for an MCD host to connect to the specified port.

IMPORTANT CHANGES
=================

1. DebugClass:

This patch-set introduces the DebugClass to the QOM, which is used to abstract
GDB/MCD specific debugger details.
It is declared in include/qemu/debug.h, defined in debug/debug-common.c
and configured in debug/debug-gdb.c and debug/debug-mcd.c respectively.
It currently only offers one function: set_stop_cpu, which gets called
in cpu_handle_guest_debug in softmmu/cpus.c.
In the future, other functions could be moved from the mcd/gdbstub
to the DebugClass.

2. mcd launch option:

This patch-set introduces the mcd launch option to QEMU. The quick start
section describes how to use it.

3. MCD debugging features:

* Go, break, step
* Read/write memory (user space only)
* Read/write registers (GPR and CP)
* Set breakpoints and watchpoints.

=================

Signed-off-by: Nicolas Eder <nicolas.eder@lauterbach.com>

Nicolas Eder (20):
  mcdstub: initial file structure for new mcdstub created. -mcd QEMU
    startup option added. Functions for initializing the mcdstub added.
    Basic helper functions for processes/cpus in the mcdstub added
  mcdstub gdbstub: new DebugClass and DebugState introduced. They are
    used to abstract the debugger details behind a QOM. This is
    currently used in the cpu_handle_guest_debug function
  gdbstub: moving code so that it can be easier accessed from outside
    the gdbstub: fromhex and tohex functions moved to a cutils header.
    GDBRegisterState moved to gdbstub.h
  mcdstub: added header with defines specific to the mcd tcp packet
    communication
  mcdstub: tcp packet processing added
  mcdstub: open/close server functions and trigger/reset data added.
    User for initial connection with an mcd client
  mcdstub: quitting QEMU via mcd command added
  mcdstub: query packet processing added and core/system querie added
  mcdstub: open/close core added. This includes core specific data
    preparation: memory spaces, register groups and registers. This data
    preparation is done in the arm mcdstub
  mcdstub: state query added: this query collects information about the
    state of a specific core. This commit also includes
    mcd_vm_state_change, which is called when the cpu state changes
    because it collects data for the query
  mcdstub: reset and trigger queries added
  mcdstub: missing parse_reg_xml function for parsing gdb register xml
    files added
  mcdstub: added queries for memory spaces, register groups and
    registers
  mcdstub: missing handle_query_state function added
  mcdstub: added go, break and step functionality and all corresponding
    functions
  mcdstub: function construct for resets added
  mcdstub: reading/writing registers added
  mcdstub: read/write to memory added: This also includes various helper
    functions in the QEMU memory code
  mcdstub: break/watchpoints added
  mcdstub: updated MAINTAINERS file and fully activated the mcdstub in
    the meson build system

 MAINTAINERS                          |   11 +
 debug/debug-common.c                 |   42 +
 debug/debug-gdb.c                    |   24 +
 debug/debug-mcd.c                    |   25 +
 gdbstub/gdbstub.c                    |    9 +-
 gdbstub/internals.h                  |   26 -
 gdbstub/meson.build                  |    4 +-
 gdbstub/system.c                     |    4 +
 gdbstub/user.c                       |    2 +
 include/cutils.h                     |   30 +
 include/exec/cpu-common.h            |    2 +
 include/exec/gdbstub.h               |   14 +-
 include/exec/memory.h                |    9 +
 include/hw/boards.h                  |    1 +
 include/mcdstub/arm_mcdstub.h        |  107 ++
 include/mcdstub/mcd_shared_defines.h |  108 ++
 include/mcdstub/mcdstub.h            |  893 ++++++++++++
 include/mcdstub/mcdstub_common.h     |   59 +
 include/qemu/debug.h                 |   19 +
 include/qemu/typedefs.h              |    2 +
 mcdstub/mcdstub.c                    | 1998 ++++++++++++++++++++++++++
 mcdstub/meson.build                  |   15 +
 meson.build                          |    1 +
 qemu-options.hx                      |   18 +
 system/cpus.c                        |    9 +-
 system/memory.c                      |   11 +
 system/physmem.c                     |   26 +
 system/vl.c                          |   13 +
 target/arm/mcdstub.c                 |  304 ++++
 target/arm/meson.build               |    1 +
 30 files changed, 3749 insertions(+), 38 deletions(-)
 create mode 100644 debug/debug-common.c
 create mode 100644 debug/debug-gdb.c
 create mode 100644 debug/debug-mcd.c
 create mode 100644 include/cutils.h
 create mode 100644 include/mcdstub/arm_mcdstub.h
 create mode 100644 include/mcdstub/mcd_shared_defines.h
 create mode 100644 include/mcdstub/mcdstub.h
 create mode 100644 include/mcdstub/mcdstub_common.h
 create mode 100644 include/qemu/debug.h
 create mode 100644 mcdstub/mcdstub.c
 create mode 100644 mcdstub/meson.build
 create mode 100644 target/arm/mcdstub.c

-- 
2.34.1
Re: [PATCH v3 00/20] first version of mcdstub
Posted by Alex Bennée 12 months ago
Nicolas Eder <nicolas.eder@lauterbach.com> writes:

> SUMMARY
> =======
>
> This patch-set introduces the first version of the mcdstub.
> The mcdstub is a debug interface, which enables debugging QEMU
> using the MCD (Multi-Core Debug) API.
> The mcdstub uses TCP to communicate with the host debug software. However,
> because MCD is merely an API, the TCP communication is not part of
> the MCD spec but specific to this project.
>
> To translate between the MCD API and the TCP data stream coming from the mcdstub,
> the host has to use a shared library (.dll/.so).
> Such a shared library will be available soon Lauterbach's open source site
> and will be linked to from inside this project in a future patch.

Do you have a timeline for this? Its impossible to test without some
sort of open implementation of the library.

> The MCD API itself can be downloaded here: https://repo.lauterbach.com/sprint_mcd_api_v1_0.zip
>
> QUICK START
> ===========
>
> Attention: MCD is currently only supported for qemu-system-arm !
>
> Three components are required to Debug QEMU via MCD:
>
> 1. qemu-system-arm (built with this patch series applied).
> 2. MCD shared library (translates between the MCD API and TCP data).
> 3. Host debugging software with support for the MCD API (e.g.
> Lauterbach TRACE32).

We will need some sort of basic implementation to exercise the API as I
assume TRACE32 is a paid for binary.

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH v3 00/20] first version of mcdstub
Posted by nicolas.eder@lauterbach.com 12 months ago
On 29/11/2023 15:44, Alex Bennée wrote:
> Nicolas Eder<nicolas.eder@lauterbach.com>  writes:
>
>> SUMMARY
>> =======
>>
>> This patch-set introduces the first version of the mcdstub.
>> The mcdstub is a debug interface, which enables debugging QEMU
>> using the MCD (Multi-Core Debug) API.
>> The mcdstub uses TCP to communicate with the host debug software. However,
>> because MCD is merely an API, the TCP communication is not part of
>> the MCD spec but specific to this project.
>>
>> To translate between the MCD API and the TCP data stream coming from the mcdstub,
>> the host has to use a shared library (.dll/.so).
>> Such a shared library will be available soon Lauterbach's open source site
>> and will be linked to from inside this project in a future patch.
> Do you have a timeline for this? Its impossible to test without some
> sort of open implementation of the library.

You can find the library source code here:

https://gitlab.com/lauterbach/mcdrefsrv

It can be built using CMake.

>
>> The MCD API itself can be downloaded here:https://repo.lauterbach.com/sprint_mcd_api_v1_0.zip
>>
>> QUICK START
>> ===========
>>
>> Attention: MCD is currently only supported for qemu-system-arm !
>>
>> Three components are required to Debug QEMU via MCD:
>>
>> 1. qemu-system-arm (built with this patch series applied).
>> 2. MCD shared library (translates between the MCD API and TCP data).
>> 3. Host debugging software with support for the MCD API (e.g.
>> Lauterbach TRACE32).
> We will need some sort of basic implementation to exercise the API as I
> assume TRACE32 is a paid for binary.

I am working on a python script, which directly calls the API functions. 
Upon completion it will be added to the mcdrefsrv gitlab.
Re: [PATCH v3 00/20] first version of mcdstub
Posted by Philippe Mathieu-Daudé 1 year ago
Hi Nicolas,

On 7/11/23 14:03, Nicolas Eder wrote:
> SUMMARY
> =======
> 
> This patch-set introduces the first version of the mcdstub.


>   30 files changed, 3749 insertions(+), 38 deletions(-)
>   create mode 100644 debug/debug-common.c
>   create mode 100644 debug/debug-gdb.c
>   create mode 100644 debug/debug-mcd.c
>   create mode 100644 include/cutils.h
>   create mode 100644 include/mcdstub/arm_mcdstub.h
>   create mode 100644 include/mcdstub/mcd_shared_defines.h
>   create mode 100644 include/mcdstub/mcdstub.h
>   create mode 100644 include/mcdstub/mcdstub_common.h
>   create mode 100644 include/qemu/debug.h
>   create mode 100644 mcdstub/mcdstub.c
>   create mode 100644 mcdstub/meson.build
>   create mode 100644 target/arm/mcdstub.c

These files are missing a license. Adding:
/* SPDX-License-Identifier: GPL-2.0-or-later */
on the first line is usually enough.

No need to respin a v4 yet, let's wait for technical
comments on your patches.

Regards,

Phil.
Re: [PATCH v3 00/20] first version of mcdstub
Posted by nicolas.eder@lauterbach.com 1 year ago
Hi Phil,

okay thanks! I'll add the license.

Regards,
Nicolas
On 08/11/2023 15:27, Philippe Mathieu-Daudé wrote:
> Hi Nicolas,
>
> On 7/11/23 14:03, Nicolas Eder wrote:
>> SUMMARY
>> =======
>>
>> This patch-set introduces the first version of the mcdstub.
>
>
>>   30 files changed, 3749 insertions(+), 38 deletions(-)
>>   create mode 100644 debug/debug-common.c
>>   create mode 100644 debug/debug-gdb.c
>>   create mode 100644 debug/debug-mcd.c
>>   create mode 100644 include/cutils.h
>>   create mode 100644 include/mcdstub/arm_mcdstub.h
>>   create mode 100644 include/mcdstub/mcd_shared_defines.h
>>   create mode 100644 include/mcdstub/mcdstub.h
>>   create mode 100644 include/mcdstub/mcdstub_common.h
>>   create mode 100644 include/qemu/debug.h
>>   create mode 100644 mcdstub/mcdstub.c
>>   create mode 100644 mcdstub/meson.build
>>   create mode 100644 target/arm/mcdstub.c
>
> These files are missing a license. Adding:
> /* SPDX-License-Identifier: GPL-2.0-or-later */
> on the first line is usually enough.
>
> No need to respin a v4 yet, let's wait for technical
> comments on your patches.
>
> Regards,
>
> Phil.