Skip to content

Commit 21030b9

Browse files
committed
[lldb][Docs] Add section on using QEMU without bridge networking
Bridge network means that you can get to any port on the VM, from the host, which is great. However it is quite involved to setup in some cases, and I've certainly messed it up in the past. An alternative is forwarding a block of ports and using some hidden options to lldb-server to limit what it uses. This commit documents that and the pitfall that the port list isn't shared. The theory also works for Arm's FVP (which inspired me to write this up) but since QEMU is the preferred option upstream, it goes in that document. Along the way I fixed a link to the QEMU page that used the URL not a relative link to the document.
1 parent 529ad40 commit 21030b9

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lldb/docs/resources/test.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ Running tests in QEMU System Emulation Environment
589589
``````````````````````````````````````````````````
590590

591591
QEMU can be used to test LLDB in an emulation environment in the absence of
592-
actual hardware. `QEMU based testing <https://lldb.llvm.org/use/qemu-testing.html>`_
593-
page describes how to setup an emulation environment using QEMU helper scripts
594-
found under llvm-project/lldb/scripts/lldb-test-qemu. These scripts currently
592+
actual hardware. :doc:`/use/qemu-testing` describes how to setup an
593+
emulation environment using QEMU helper scripts found in
594+
``llvm-project/lldb/scripts/lldb-test-qemu``. These scripts currently
595595
work with Arm or AArch64, but support for other architectures can be added easily.
596596

597597
Debugging Test Failures

lldb/docs/use/qemu-testing.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ run-qemu.sh has following dependencies:
113113
Steps for running lldb-server in QEMU system emulation environment
114114
------------------------------------------------------------------
115115

116+
Using Bridge Networking
117+
***********************
118+
116119
* Make sure bridge networking is enabled between host machine and QEMU VM
117120

118121
* Find out ip address assigned to eth0 in emulation environment
@@ -136,3 +139,39 @@ Steps for running lldb-server in QEMU system emulation environment
136139
* Run lldb-server inside QEMU VM
137140

138141
* Try connecting to lldb-server running inside QEMU VM with selected ip:port
142+
143+
Without Bridge Networking
144+
*************************
145+
146+
Without bridge networking you will have to forward individual ports from the VM
147+
to the host (refer to QEMU's manuals for the specific options).
148+
149+
* At least one to connect to the intial ``lldb-server``.
150+
* One more if you want to use ``lldb-server`` in ``platform mode``, and have it
151+
start a ``gdbserver`` instance for you.
152+
* A bunch more if you want to run tests against the ``lldb-server`` platform.
153+
154+
If you are doing either of the latter 2 you should also restrict what ports
155+
``lldb-server tries`` to use, otherwise it will randomly pick one that is almost
156+
certainly not forwarded. An example of this is shown below.
157+
158+
::
159+
160+
$ lldb-server plaform --server --listen 0.0.0.0:54321 \
161+
--min-gdbserver-port 49140 --max-gdbserver-port 49150
162+
163+
The result of this is that:
164+
165+
* ``lldb-server`` platform mode listens externally on port ``54321``.
166+
167+
* When it is asked to start a new gdbserver mode instance, it will use a port
168+
in the range ``49140`` to ``49150``.
169+
170+
Your VM configuration should have ports ``54321``, and ``49140`` to ``49150``
171+
forwarded for this to work.
172+
173+
.. note::
174+
These options are used to create a "port map" within ``lldb-server``.
175+
Unfortunately this map is not shared across all the processes it may create,
176+
and across a few uses you may run out of valid ports. To work around this,
177+
restart the platform every so often, especially after running a set of tests.

0 commit comments

Comments
 (0)