views:

712

answers:

4

The title says it all. 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?

A: 

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

David Spillett
But why would I choose this compared to vmware?
Robert S. Barnes
"As it runs the kernel as a userland process under the host kernel it is easier to attach common debugging tools to" (possibly including tools that wouldn't normally be able to hook into a running kernel)
David Spillett
+1  A: 

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.

TokenMacGuy
+1 ... was thinking the same thing
Aiden Bell
You think using a vm would be a problem with developing a driver for a USB device?
Robert S. Barnes
No one mentioned USB. Unless all devices are USB?
Aiden Bell
Wouldn't I be able to use Kdump http://lse.sourceforge.net/kdump/ under VMware? If I can then I have eliminated the need for a second machine and I can just debug my USB beer temperature monitor on my laptop at the beach :-)
Robert S. Barnes
A: 

I recently started building GNU Mach/HURD and found the combination of QEmu/KVM to work really quite well.. for the following reasons:

  1. QEmu presents quite a clean environment
  2. Networking has alot of options
  3. 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.

Aiden Bell
A: 

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 :)

MarkR
I would have thought that debugging something like a USB device would be possible as they are accessible though the vm and I assumed that the USB traffic / data would just get passed through to the USB controller on the vm.
Robert S. Barnes
I suspect you're right - there is a method of "passing through" USB traffic to allow the guest OS to see a device directly. I have seen this option but never used it.
MarkR