【问题标题】:How can I debug Windows in one VM from another VM using VirtualBox?如何使用 VirtualBox 从另一个 VM 调试一个 VM 中的 Windows?
【发布时间】:2012-09-19 02:53:56
【问题描述】:

我正在为 Windows 7 编写一些启动(登录前)代码,并希望能够对其进行调试(如果只是为了看看它是如何工作的,因为 Microsoft 的文档很糟糕)。

我的环境是 Linux 主机上的 VirtualBox,有三个 Windows 虚拟机(一个 Windows 2008 域控制器、一个 Windows 7 开发机器和一个 Windows 7 测试机器),我希望能够调试启动过程使用虚拟串行连接两个虚拟机,从 dev 机器远程测试机器。

[在另一种生活中,我曾在 Windows 主机上使用 VMware 工作站从另一个 Linux VM 中调试 Linux 内核驱动程序,因此我知道这种事情可能是可行的。]

我见过有人使用 windbg 从主机调试 VirtualBox 虚拟机中的 Windows,但我需要从第二个来宾执行此操作(因为我的主机不是 Windows)。有人知道怎么做吗?

编辑: 在发布之前,我已经尝试过明显的方法。我在每个虚拟机配置中创建了一个虚拟串行端口,并将它们都连接到同一个主机管道,由开发虚拟机(调试器)创建并由测试虚拟机(被调试者)使用。然后我跑了

bcdedit /dbgsettings serial debugport:1 baudrate:115200
bcdedit /debug {current} on

在测试虚拟机中并关闭它。在 dev VM 中运行 windbg 选择内核调试(在正确的串行端口上)并重新启动测试 VM。出现了一些关于没有可用符号并且测试 VM 挂起的消息。

我后来找到了这篇文章:http://www.benjaminhumphrey.co.uk/remote-kernel-debugging-windbg-virtualbox/(虽然那个人使用的是 Windows 主机)似乎准确地描述了我尝试过的方法,但他的测试 VM 没有挂起。我在 wndbg 窗口中得到的输出与他的相同,但在“Windows XP Kernel ...”行之前停止

我现在不太确定这个问题是否与 VirtualBox 有关,更不确定我是否正确使用了 windbg。任何帮助将不胜感激。

另一个编辑 我尝试将测试 VM 的虚拟串行端口附加到主机文件,并在文件中得到一些调试输出。我尝试将两个 VM 的虚拟串口设置为指向主机管道并在 Dev VM 中运行终端(而不是 WinDbg),并在终端中获取调试信息。

我想我现在已经确定这肯定是 WinDbg 而不是 VirtualBox 的问题(我将删除 virtualbox 标签并用 windbg 替换它)但我不确定 WinDbg 为什么不说话。

更多信息: 我刚刚升级到 VirtualBox 4.2.4(不确定版本是否重要)并再次查看。

我重建了测试虚拟机,更加耐心了!

现在看来,测试虚拟机正在运行 - 我最终在 windbg 窗口中得到了一些输出 - 但调试对象操作系统启动大约需要 15 分钟!这显然对日常内核调试没有用处。我不知道为什么这会这么慢......如果我在开发虚拟机而不是 windbg 中运行一个简单的终端,则不会出现明显的减速(当然,调试信息大多是垃圾)。

有什么想法吗?

【问题讨论】:

  • 您是否尝试重新启动被调试机器?这是不久前的事了,但我记得上次使用 VirtualBox 时,我必须在 WinDbg 在调试器中运行时重新启动调试器才能建立连接。内核连接配置对话框中有一个“重新连接”选项,可以让 WinDbg 在被调试对象重新启动时保持活动状态。
  • 是的。如果我在测试 VM 启动并运行时在 Dev VM 上启动 windbg,则不会发生任何事情(两个 VM 继续运行,没有调试输出)。只有当我重新启动测试 VM(调试对象)时,我才会在 windbg 窗口中获得一些输出并且测试 VM 挂起。它可能只是在断点处等待,但我尝试在 windbg 窗口中输入 g(可能次数不够?)
  • 精确 重复:stackoverflow.com/questions/12696825/…。听起来与您所描述的相似,但如果您完全按照说明进行操作,您可能会发现最初出了什么问题。我想强调两点:调试器应该创建管道(而被调试者不应该);湾。在“内核调试”下,必须取消选中“COM”、“管道”。祝你好运。
  • 是的,那个问题(你的问题!)几乎和我的一样。你似乎也做了和我一样的事情。我一直在研究其他东西,但需要重新审视这个,我会检查我是否错过了任何东西。谢谢你的“两点”......我这样做是正确的(从我使用终端而不是windbg时我确实看到调试输出这一事实可以看出)......问题是windbg没有似乎看到客户端启动并永远等待建立连接(并且“管道”未选中)。这似乎是一个 windbg 问题,而不是 VirtualBox 问题。

标签: windbg remote-debugging


【解决方案1】:

我知道这是一个死灵,但是......

您是否尝试过为内核模式网络调试设置被调试者?我认为放缓在很大程度上是因为连续剧是如此 g.d.慢。

http://msdn.microsoft.com/en-us/library/windows/hardware/hh439346%28v=vs.85%29.aspx

如果/当 M$ 决定删除该链接时,您需要执行以上文章的这些部分来进行设置:

设置目标计算机

要设置目标计算机,请按以下步骤操作:

Verify that the target computer has a supported network adapter.

Connect the supported adapter to a network hub or switch using standard CAT5 or better network cable. Do not use a crossover cable, and do not use a crossover port in your hub or switch.

In an elevated Command Prompt window, enter the following commands, where w.x.y.z is the IP address of the host computer, and n is a port number of your choice:

    bcdedit /debug on
    bcdedit /dbgsettings net hostip:w.x.y.z port:n

bcdedit will display an automatically generated key. Copy the key and store it on a removable storage device like a USB flash drive. You will need the key when you start a debugging session on the host computer.

Note  We strongly recommend that you use an automatically generated key. However, you can create your own key as described later in the Creating Your Own Key section.

If there is more than one network adapter in the target computer, use Device Manager to determine the PCI bus, device, and function numbers for the adapter you want to use for debugging. Then in an elevated Command Prompt window, enter the following command, where b, d, and f are the bus number, device number, and function number of the adapter:
bcdedit /set "{dbgsettings}" busparams b.d.f
Reboot the target computer.

要连接到它,请使用以下步骤:

Using WinDbg

On the host computer, open WinDbg. On the File menu, choose Kernel Debug. In the Kernel Debugging dialog box, open the Net tab. Enter your port number and key. Click OK.

You can also start a session with WinDbg by opening a Command Prompt window and entering the following command, where n is your port number and Key is the key that was automatically generated by bcdedit when you set up the target computer:

windbg -k net:port=n,key=Key

If you are prompted about allowing WinDbg to access the port through the firewall, allow WinDbg to access the port for all the different network types.

Using KD

On the host computer, open a Command Prompt window. Enter the following command, where n is your port number and Key is the key that was automatically generated by bcdedit when you set up the target computer:

kd -k net:port=n,key=Key

If you are prompted about allowing KD to access the port through the firewall, allow KD to access the port for all the different network types.

【讨论】:

  • 是的,这个问题有点像死神,因为我现在正在做完全不同的事情(与 Windows 无关,感谢 $DEITY!)。不过,我不确定串行通信的速度是否应归咎于启动缓慢,因为当连接到简单终端或将其输出转储到文件时,调试器启动得足够快。调试器运行时可能会发生更多通信……但是您可以在 15 分钟内以 115k2 发送大量数据。这是一个谜,但我不再关心(直到下一次)。不过,感谢您的意见。它可能对其他人有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-12
  • 1970-01-01
  • 2021-02-05
  • 1970-01-01
  • 1970-01-01
  • 2011-01-05
相关资源
最近更新 更多