From ffde5274dea2aad65b383d2d34923ab12a5620ff Mon Sep 17 00:00:00 2001 From: Andrew David Wong Date: Tue, 12 Dec 2023 06:18:59 -0800 Subject: [PATCH] Revert "Merge branch 'pr-1331'" This reverts commit f5a7d8138f78a978057e32ff032b79bb813befbd, reversing changes made to 647da03e05bc1757099e9a69e1747755a215fcd2. Reason: QubesOS/qubes-doc#1331 contains a change that prevents GitHub Pages from building the site: "The tag `block` on line 12 in `_doc/developer/debugging/windows-debugging.md` is not a recognized Liquid tag." https://github.com/QubesOS/qubesos.github.io/runs/19558577224 --- developer/debugging/windows-debugging.md | 287 ++++++++++++++++++----- 1 file changed, 234 insertions(+), 53 deletions(-) diff --git a/developer/debugging/windows-debugging.md b/developer/debugging/windows-debugging.md index ee692847..852d1c67 100644 --- a/developer/debugging/windows-debugging.md +++ b/developer/debugging/windows-debugging.md @@ -10,72 +10,253 @@ ref: 50 title: Windows debugging --- -Debugging Windows code can be tricky in a virtualized environment. The guide below assumes Qubes 4.1 and Windows 7 or later VMs. +Debugging Windows code can be tricky in a virtualized environment. The guide below assumes Xen hypervisor and Windows 7 VMs. User-mode debugging is usually straightforward if it can be done on one machine. Just duplicate your normal debugging environment in the VM. -Things get complicated if you need to perform kernel debugging or troubleshoot problems that only manifest on system boot, user logoff or similar. For that you need two Windows VMs: the *host* and the *target*. The *host* will contain the debugger, your source code and private symbols. The *target* will run the code being debugged. We will use kernel debugging over network which is supported from Windows 7 onwards. The main caveat is that Windows kernel supports only specific network adapters for this, and the default one in Qubes won't work. +Things get complicated if you need to perform kernel debugging or troubleshoot problems that only manifest on system boot, user logoff or similar. For that you need two Windows VMs: the *host* and the *target*. The *host* will contain [WinDbg](https://msdn.microsoft.com/en-us/library/windows/hardware/ff551063(v=vs.85).aspx) installation, your source code and private symbols. The *target* will run the code being debugged. Both will be linked by virtual serial ports. -## Modifying the NIC of the target VM +- First, you need to prepare separate copies of both *target* and *host* VM configuration files with some changes. Copy the files from **/var/lib/qubes/appvms/vmname/vmname.conf** to some convenient location, let's call them **host.conf** and **target.conf**. +- In both copied files add the following line at the end: `serial = 'pty'`. This will make Xen connect VM's serial ports to dom0's ptys. +- From now on you need to start both VMs like this: `qvm-start --custom-config=/your/edited/host.conf host` +- To connect both VM serial ports together you will either need [socat](http://www.dest-unreach.org/socat/) or a custom utility described later. +- To determine which dom0 pty corresponds to VM's serial port you need to read xenstore, example script below: -You will need to create a custom libvirt config for the target VM. See [the documentation](https://dev.qubes-os.org/projects/core-admin/en/latest/libvirt.html) for overview of how libvirt templates work in Qubes. The following assumes the target VM is named `target-vm`. +```bash +#!/bin/sh -- Edit `/usr/share/qubes/templates/libvirt/xen.xml` to prepare our custom config to override just the NIC part of the global template: - - add `{% block network %}` before `{% if vm.netvm %}` - - add `{% endblock %}` after the matching `{% endif %}` -- Copy `/usr/share/qubes/templates/libvirt/devices/net.xml` to `/etc/qubes/templates/libvirt/xen/by-name/target-vm.xml`. -- Add `` to the `` section. -- Enclose everything within `{% block network %}` + `{% endblock %}`. -- Add `{% extends 'libvirt/xen.xml' %}` at the start. -- The final `target-vm.xml` should look something like this: +id1=$(xl domid "$1-dm") +tty1=$(xenstore-read /local/domain/${id1}/device/console/3/tty) +echo $tty1 +``` -~~~ -{% extends 'libvirt/xen.xml' %} -{% block network %} - - - - -