qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	qemu-devel@nongnu.org, "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PULL 09/11] docs/system/gdb.rst: Document how to debug multicore machines
Date: Tue,  6 Apr 2021 16:00:39 +0100	[thread overview]
Message-ID: <20210406150041.28753-10-alex.bennee@linaro.org> (raw)
In-Reply-To: <20210406150041.28753-1-alex.bennee@linaro.org>

From: Peter Maydell <peter.maydell@linaro.org>

Document how multicore machines appear to GDB when debugged
via the debug stub. This is particularly non-intuitive for
the "multiple heterogenous clusters" case, but unfortunately
as far as I know there is no way with the remote protocol
for the stub to tell gdb "I have 2 inferiors, please connect
to both", so the user must set it all up manually.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20210325175023.13838-3-peter.maydell@linaro.org>
Message-Id: <20210401102530.12030-10-alex.bennee@linaro.org>

diff --git a/docs/system/gdb.rst b/docs/system/gdb.rst
index 0bb1bedf1b..144d083df3 100644
--- a/docs/system/gdb.rst
+++ b/docs/system/gdb.rst
@@ -45,6 +45,61 @@ Here are some useful tips in order to use gdb on system code:
 3. Use ``set architecture i8086`` to dump 16 bit code. Then use
    ``x/10i $cs*16+$eip`` to dump the code at the PC position.
+Debugging multicore machines
+GDB's abstraction for debugging targets with multiple possible
+parallel flows of execution is a two layer one: it supports multiple
+"inferiors", each of which can have multiple "threads". When the QEMU
+machine has more than one CPU, QEMU exposes each CPU cluster as a
+separate "inferior", where each CPU within the cluster is a separate
+"thread". Most QEMU machine types have identical CPUs, so there is a
+single cluster which has all the CPUs in it.  A few machine types are
+heterogenous and have multiple clusters: for example the ``sifive_u``
+machine has a cluster with one E51 core and a second cluster with four
+U54 cores. Here the E51 is the only thread in the first inferior, and
+the U54 cores are all threads in the second inferior.
+When you connect gdb to the gdbstub, it will automatically
+connect to the first inferior; you can display the CPUs in this
+cluster using the gdb ``info thread`` command, and switch between
+them using gdb's usual thread-management commands.
+For multi-cluster machines, unfortunately gdb does not by default
+handle multiple inferiors, and so you have to explicitly connect
+to them. First, you must connect with the ``extended-remote``
+protocol, not ``remote``::
+    (gdb) target extended-remote localhost:1234
+Once connected, gdb will have a single inferior, for the
+first cluster. You need to create inferiors for the other
+clusters and attach to them, like this::
+  (gdb) add-inferior
+  Added inferior 2
+  (gdb) inferior 2
+  [Switching to inferior 2 [<null>] (<noexec>)]
+  (gdb) attach 2
+  Attaching to process 2
+  warning: No executable has been specified and target does not support
+  determining executable automatically.  Try using the "file" command.
+  0x00000000 in ?? ()
+Once you've done this, ``info threads`` will show CPUs in
+all the clusters you have attached to::
+  (gdb) info threads
+    Id   Target Id         Frame
+    1.1  Thread 1.1 (cortex-m33-arm-cpu cpu [running]) 0x00000000 in ?? ()
+  * 2.1  Thread 2.2 (cortex-m33-arm-cpu cpu [halted ]) 0x00000000 in ?? ()
+You probably also want to set gdb to ``schedule-multiple`` mode,
+so that when you tell gdb to ``continue`` it resumes all CPUs,
+not just those in the cluster you are currently working on::
+  (gdb) set schedule-multiple on
 Advanced debugging options

  parent reply	other threads:[~2021-04-06 15:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 15:00 [PULL 00/11] rc2 fixes (check-tcg, gitlab, gdbstub) Alex Bennée
2021-04-06 15:00 ` [PULL 01/11] tests/tcg: update the defaults for x86 compilers Alex Bennée
2021-04-06 15:00 ` [PULL 02/11] tests/docker: don't set DOCKER_REGISTRY on non-x86_64 Alex Bennée
2021-04-06 15:00 ` [PULL 03/11] tests/tcg: add concept of container_hosts Alex Bennée
2021-04-06 15:00 ` [PULL 04/11] tests/tcg/configure.sh: make sure we pick up x86_64 cross compilers Alex Bennée
2021-04-06 15:00 ` [PULL 05/11] tests/tcg/i386: expand .data sections for system tests Alex Bennée
2021-04-06 15:00 ` [PULL 06/11] tests/tcg/i386: force -fno-pie for test-i386 Alex Bennée
2021-04-06 15:00 ` [PULL 07/11] tests/tcg: relax the next step precision of the gdb sha1 test Alex Bennée
2021-04-06 15:00 ` [PULL 08/11] docs/system/gdb.rst: Add some more heading structure Alex Bennée
2021-04-06 15:00 ` Alex Bennée [this message]
2021-04-06 15:00 ` [PULL 10/11] gitlab-ci.yml: Fix the filtering for the git submodules Alex Bennée
2021-04-06 15:00 ` [PULL 11/11] gitlab-ci.yml: Test the dtrace backend in one of the jobs Alex Bennée
2021-04-06 17:37 ` [PULL 00/11] rc2 fixes (check-tcg, gitlab, gdbstub) Peter Maydell
2021-04-07 17:25   ` Alex Bennée
2021-04-07 18:27     ` Peter Maydell
2021-04-07 18:41       ` Alex Bennée
2021-04-08 13:00         ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210406150041.28753-10-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=f4bug@amsat.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --subject='Re: [PULL 09/11] docs/system/gdb.rst: Document how to debug multicore machines' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).