Is there any way to debug bootloaders/BIOS of a virtual machine on Hyper-V (as can be done on QEMU with GDB)? - debugging

QEMU has a -gdb option that enables the use of GDB (or any debugger that understands GDB's remote protocol) to step through bootloaders and even the BIOS/UEFI firmware of a virtual machine. Does Hyper-V (or any related MS product) have an equivalent to this? Is there any way whatsoever that a bootloader in a Hyper-V VM could be stepped through with a debugger (like WinDbg/KD)?
If not, are there any technical reasons for this limitation, or is it simply not a feature that Microsoft chose to implement?

Related

Driver debugging on a local machine

Why there is no GUI kernel debugger like SoftICE, which allows to debug kernel driver on a local machine nowadays? Why remote machine is obligatory for driver debugging in Windows 7 and higher?
An in-system kernel-mode debugger is an extremely complicated software because it must take care of many low-level kernel resources and operations. If kernel internals are changed in the next OS version, the debugger must be updated accordingly. Debugger developers must work together with kernel developers and have access to kernel source code. All that makes in-system debugger development complex and expensive.
And any kernel-mode debugging on the development system is a dangerous and inconvenient process. Even if no FS damages and/or other data losses occur due to a BSOD, booting a development system, starting all required applications to re-create convenient development environment is much longer process than rebooting a dumb target machine (hardware or virtual).
When hardware computers were expensive, there was no efficient remote debugging interface and there were no efficient virtual machine solutions, SoftICE was an acceptable tool. But in the last 15 years, remote kernel debugging in Windows had been greatly improved, so using WinDbg is much more convenient that using SoftICE, even though WinDbg has many flaws and bugs.

True-Time debugger / hiwave.exe: run multiple instances?

I have a couple Freescale 68HCS08 MCUs connected in an I2C network, running different programs. When I click "debug," Codewarrior checks for a running instance of hiwave.exe to load and debug the program. I'd like to debug both simultaneously, which means having two instances running.
What is the best way to do this? Do I need two PC's? Is it better to try and manually reload the MCU's, using the Build command instead of Debug in Codewarrior?
I can run two instances of hiwave.exe manually, and then use the "File"->"Load Application" menu item to select the .abs file. It seems to run both instances fine, including code display and breakpoints, although I'm using full-chip simulation rather than a hardware debugger at the moment. I would guess that's where most of the fun is, in making sure that each instance uses the correct debugger, especially if you're using two of the same USB devices.
"That's too easy", I can hear you saying. Fine, take option 2:
I do all my CodeWarrior / Hiwave stuff in "Windows XP Mode", a Virtual PC running under Windows 7, mostly because CodeWarrior's installer doesn't run on 64-bit architectures (or it didn't a few months ago, for which I yelled at them in their forums).
I'm not entirely sure of the licensing technicalities (if you have Windows 7 pro, you should get at least one free license to use the Windows XP mode), but perhaps you could do something similar - e.g. run a Virtual PC environment with one of your debuggers passed through to the virtual system (Windows Virtual PC and other virtualization environments let you pass USB devices through), and have your other debugger still attached to the 'host' system. You could then have CodeWarrior/Hiwave installed on both the virtual and host systems, with one controlling system A and the other controlling system B. USB fun-time still applies, as you'd have to make sure the 'correct' USB debugger was passed through to the virtual system.
The debugger, HIWAVE.EXE will not work in either Windows XP mode, nor VMs such as VMWARE WORKSTATION, nor any of the VMs available in Linux. This is to do with the way the driver for the USB MULTILINK has been architecured.
Making Codewarrior v6.x work in Windows 7 is easy, by patching the installer.
We were not able to get the debugging pod to work to debug live hardware, because of the fact that the USB driver is implemented with Jungo Windriver, and, as per other articles, neither of the virtual machines can push that across into the virtual environment.
I have wasted months trying to solve this, in the end we resurrected old XP licenses and installed XP. However safe to say that, this, combined with Freescale's lack of vision to allow people running Linux to develop for the silicon, forced me into a decision that I will no longer use their products.
However, running multiple instances of the debugger is possible. The maximum seems to be around 20

Low level qemu based debugging

I've to test some low level code on an ARM architecture. Typically experimentation is quite complicated on the real board, so I was thinking about QEMU.
What I'd like to get is some kind of debugging information like printfs or gdb. I know that this is simple with linux since it implements both the device driver for the QEMU Integrator and the gdb feature, but I'm not working with Linux. Also I suspect that extracting this kind of functionality from the Linux kernel source code would be complicated.
I'm searching from some simple operating system that already implements one of those features. Do you have some advice?
You don't need a target OS to debug code that's running inside QEMU -- QEMU already does that for you.
Specifically, QEMU supports remote debugging from GDB -- you can run QEMU with the appropriate command-line options and it will export an interface that a copy of GDB (running on the host machine) can connect to. At that point, you can debug the program in GDB pretty much just as if you were running it on the host machine.
http://wiki.osdev.org/GDB appears to have a bit more basic information; possibly not enough to completely get you started, but at least give you the basic idea and some terms to look for in the QEMU and GDB documentation. Skip over the bit about "Implementing GDB Stubs", which doesn't apply here since QEMU has one already, and start at the section on "Using Emulator Stubs". The short form is simply that you start QEMU with the -s option (export a GDB connection on localhost:1234) and the -S option (wait for a GDB "continue" command before starting execution), and then in GDB on your host you say target remote :1234 instead of run. Also, of course, you need to be using an ARM version of GDB rather than a native-x86 one.
(In addition, if you're willing to pay for a commercial solution, CodeSourcery's ARM toolchain has the IDE integration to set all of this up automatically, including support for "printf" to print into the debugger console. That works on a physical board, too, if you've got a hardware debugger. Usual disclaimer about me being a CodeSourcery employee applies -- but I do find it very easy to use.)
Update, 2012: CodeSourcery's toolchain is now called Mentor Graphics Sourcery CodeBench, but all the above still applies.
I realise that I am addressing your original problem here rather than your proposed solution (perhaps that's better?), but to use GDB (or Insight/GDB) directly on the target, use a low-cost JTAG tool and OpenOCD. An example of such a set-up and how to implement it can be found here.
If you have a larger budget, a more fully featured JTAG debugger may be useful, such as the Abatron BDI3000 with bdiGDB firmware which allows remote debugging and device programming over Ethernet with GDB and no special drivers or target debug agent.
Maybe a microkernel like OKL4 would suit your needs?

debugging code run in a virtual machine using the host

Is there a debugger which works from a virtual machine's host?
That is, instead of using interrupts inside the machine, I expect this debugger to recognize the virtual machine's OS routines, memory locations etc, and to recognize when the OS is launching a certian EXE. Then I want to be able to set hardware-like breakpoints per process through the host computer. I'll clarify. The virtualized computer and OS would never know that the breakpoint was set or occurred. All debug handling would be done by the host computer which emulates a virtual computer.
This would enable much stronger breakpoint mechanism, for example "break when a certain data is read from the CDROM drive", or "break when a certain file on the disk contains the following byte sequence".
This approach will also, for example, eliminate anti-debugger techniques which are suppose to alter the executable's behavior when running under a debugger. (OTOH it opens up a new area of anti-virtualization techniques which relies upon slight differences between emulated computer and real hardware).
Is there such a product? Does it look like a good idea?
VMware has offered VM debugging plugins for Visual Studio and Eclipse for some time now. It is even possible to record a VM run (which logs input from all devices, allowing to replay the execution of the VM precisely as when it was recorded), then step through the recording with a debugger.
Recent versions of IDA Pro include a debugger interface which, among other setups, can inspect a BOCHS virtual machine.

kvm vs. vmware for kernel debugging / USB driver development

I'm currently setting up vmware Server 2.0 for kernel debugging with gdb ( see this setup guide ) and someone asked me why not use kvm?
So I ask: kvm vs. vmware for kernel debugging / USB driver development
what are the pros and cons of each?
Driver development? are you working on a driver for a particular piece of hardware? if so, then you probably won't be able to use virtualization, because the virtualized instance won't have access to the new hardware.
For this you will need two machines, one running a remote debugger on the other.
*Edit: * Apparently you're developing a driver for a USB Device? this is one area in particular that a VM actually Can help. These days most VM's have the ability to delegate specific USB devices to a guest OS.
That said, this situation doesn't really offer any benefits over the remote debugger option, because you still need a way to inspect the state of the running or crashed OS, and VM's offer very little assistance in this regard. You might be able to replay saved states from just before a crash.
You might be able to get a bit of traction using UML, which would allow you to do local debugging as on a regular user process, which is a little bit less trouble.
Instead of answering the direct question I'll add another option... Depending on if the kernel in question is a Linux kernel, and what part(s) of it you are working on, you might find that UserModeLinux (included in the 2.6.x source, and available as patch sets for 2.4 and 2.2) may trump both of those options.
As it runs the kernel as a userland process under the host kernel it is easier to attach common debugging tools to. I believe it is very commonly used in the early stages of updates/additions to file-system related code. If you are developing/debugging modules that interact directly with hardware it may be much less use to you though.
Reference links: home,
other
I recently started building GNU Mach/HURD and found the combination of QEmu/KVM to work really quite well.. for the following reasons:
QEmu presents quite a clean environment
Networking has alot of options
I can easily mount the filesystem using a raw device file / loopback
Bottom line is, for kernel work I just want the minimum of functionality to boot and see the result. VMWare is much more for usable virtualization rather than down-and-dirty.
There is however no comparison to booting on a real machine with real hardware. The VM environment can seem like a safety blanket somtimes ... because even my toaster would know what a Realtek RTL8139C was.
If it is a "real hardware" device, of course, vmware will not emulate it, so you won't be able to debug the driver under it (nor will any other virtualisation software, unless you extend one to do so).
Device driver debugging can be done to some extent with a real hardware machine with a normal kernel - although there are obviously things you can't do - like set breakpoints.
It is still possible to attach a debugger to the kernel and inspect stuff. Moreover, traditional printf() debugging is quite possible (printk, anyone), and there are various features in the kernel which make debugging easier. It's possible to build the kernel with various debug options to try to detect pointer problems, memory leaks etc.
By default, the kernel even gives a nice-ish stack trace on the log when it encounters an OOPS or BUG condition (obviously this does not necessarily get written anywhere if the system hangs or crashes). Of course a pointer-out-of-range condition happening inside an interrupt is a recipe for disaster, but you could still get a stack trace on the screen immediately before the panic :)

Resources