Home > Blogs > VMware Workstation Zealot


Getting smart cards to work with replay debugging

After moving from working on Workstation to working on the Windows View Client, I try to use Workstation’s Visual Studio plugin as much as I can when debugging the View Client.  Being able to use the remote debugging integration to debug in my VMs is really helpful, but replay debugging takes the cake as the single most helpful feature that Workstation offers me.  I seriously cannot say enough about its power in changing a bug from nearly impossible to fixable in the course of an hour or two.

The most recent example was in the upcoming smart card removal policy feature for the Windows View Client.  Due to the nature of this feature, if a smart card removal policy was also configured on the Windows machine, we were both triggering at exactly the same time.  Most of the time this would be fine; Windows would lock and the View Client would disconnect from the View Connection Server and show the Connect dialog.  But occasionally (anywhere from 10-30% of the time) I would see weird behavior where the dialog was arbitrarily moved to the upper-left corner of the screen and resized to be 100 pixels taller!

As I figured out quickly, debugging using the traditional methods was not an option.  Either I would not see the issue or if I spent too much time in breakpoints I would lose my connection to the View Connection Server.  I could feel replay debugging calling me because it fit so perfectly; I could run the program in the VM and make sure I would reproduce the issue, then attach a debugger and spend however much time I needed to figure it out.  Features like Reverse Run to Cursor and Reverse Continue would make debugging faster as well.

I was all ready to start up on it when I remembered that VMware’s record/replay technology doesn’t support USB devices.  Whether you connect your smart card exclusively to the virtual machine or connect it in shared mode, it is still exposed to the virtual machine as a USB device.  If you start a recording in Workstation, this USB device is immediately disconnected.

The workaround that I figured out was simply to start a recording in a VM then RDP into the VM and use RDP’s built-in smart card redirection to connect the smart card to the VM while recording.  Then in the RDP session, I would run the View Client and reproduce the bug, close the View Client, then stop the recording.  This works because RDP doesn’t actually connect the smart card to the virtual machine as a USB device (seriously, check Device Manager!).  Instead it performs API redirection from the server (in this case the VM) to the client (in this case the host machine) and this certainly still works when recording execution in Workstation.

The only downside of this approach is that when you are replaying execution, you won’t be able to see the contents of the console, as seen below.  So this approach is best for uncomplicated debugging sessions where you generally remember the procession of commands executed in the application.  The reason why you can’t see the console is that when you RDP into a machine, the console session is locked and RDP creates a new session to protect your privacy.  When you replay this recording, there is no actual network traffic (it is just simulated) so there is no way to reattach an RDP client to it.  You are only left viewing the locked console session, but the program still is executing in the virtual machine.

Locked
This is the only view you get into the VM when replaying, but the app is running and the smart card activity really is being replayed!

Once I figured out how to get smart cards working with replay debugging, isolating and fixing the bug was extremely easy.  As a parting shot, I want to commend the improvements made in replay debugging for Workstation 7.0.  As an internal dogfooder, I am often one of VMware’s harshest critics.  But when testing replay debugging this time, I was taken aback at the speed improvements and optimizations when doing normal replay sessions and especially when doing reverse operations.  These folks have worked so hard on the product and it really shows.

As a summary, here are the steps to create a recording of your app with smart cards:

  1. Start your VM and find the IP address.
  2. Start recording execution in Workstation by selecting VM > Replay > Record.
  3. RDP into your VM, making sure to enable smart card redirection in the Local Resources tab by clicking More…
  4. Run your app in the RDP session, reproducing your bug.
  5. Close your app, disconnect your RDP session, and stop your recording.