Stefan’s Weblog

Repository for my thoughts

Visual Studio Debugging Tip: Tracepoints

Posted by Stefan on November 15, 2009

If you are the kind of developer that writes bug-free code, then you have no reason to waste your time reading this. Better go and write some more of your perfect code. This article is for the rest of us who have to spend some time in the debugger, trying to figure out what’s wrong with the code.

Still reading? Good… Visual Studio comes with one of the best debuggers out there. It supports both native and managed code and you can even extend it to support custom languages. For example the IronPython team added support for python scripts.

This is the first of a series of posts where I’ll try to discuss some of the Visual Studio’s debugger features. John Cunningham said that “Some of the best debugger features are always hidden behind the right click.” One of this features is tracepoints.

A tracepoint is a breakpoint that performs an action on your code. To insert a new tracepoint, right click on the line of code where you want to insert it and select Breakpoint –> Insert Tracepoint. This will open a window that will allow you to configure the tracepoint.

Configure Tracepoint

This window will allow you to specify the action to be performed when the tracepoint is hit. Most often a tracepoint will be used to print some information. You can print variable values but also a variety of program state types: program locations, thread info, etc. For more advanced actions you can specify a predefined macro to be executed.

For example let’s consider the following code snippet

The tracepoint is set to print "--> Iteration {i}: {number}" and continue execution. When the program is executed, the output window will show something like this

tracepoint-output

You can see how easy is to trace the evolution of a variable during program execution. This becomes even much more interesting when you do the same with stack traces or thread information.

One can argue that the same thing can be achieved with a logging system. The advantage of tracepoints over log messages is that you can easily set and then modify them during the same debugging session. No need to stop the debugging session, insert log messages and then recompile and restart the application.

If you want to fond more about tracepoints check out the MSDN documentation about Breakpoints and Tracepoints.

Posted in Programming, Visual Studio | Tagged: , , | Leave a Comment »

Shorten URL Plugin for Pidgin

Posted by Stefan on June 24, 2009

Pidgin is a great chat client. It allows the user to connect to multiple chat networks simultaneously through an easy to use and very intuitive interface. I use it all the time to stay in touch with my friends / family / coworkers and I’m very happy I don’t have to install a different client for each chat network I want to connect to.

But since I started using Twitter this has changed. Now I had to install another client just to receive and post tweets and it was very annoying. As Miguel de Icaza likes to say “Twitter is IRC for young people” so it seems natural to be accessed from the chat client like all other networks.

After a quick search on the Net I found tweet.IM, a free service offered by ProcessOne which enables you to use a micro-blogging platform with a chat client. It basically adds a bot to your contacts list that forwards periodically new updates from your Twitter feed to your messaging account. It also allows you to post updates by forwarding messages to the bot. Using this service made Pidgin a nice Twitter client but it had two problems: it lacked character counting and URL shortening.

For the first issue I found Dossy’s excelent character counting plugin, but I couldn’t find anything for URL shortening so… I made one :)

Shorten URL is a very simple Pidgin plugin. It adds a new button on the conversation window’s toolbar that pops up a dialog which allows you to shrink an URL using a specialized web service.

shorten-url

By default it uses is.gd because it creates very small URL’s. Initially I wanted to support many services but I could not find an easy way to add a combo box to the dialog. I still plan to add this in the future, when I find some time to dig more in the Pidgin’s API. Right now the only way to modify the service is to change the source and recompile the code.

You can download the plugin as a precompiled Windows DLL that can be copied in you Pidgin’s plugins folder, or you can take the source code and compile it for any platform that Pidgin runs on.

Enjoy!

Posted in Pidgin, Plugins, Programming | Tagged: , , , | 3 Comments »

Global Hotkeys for iTunes

Posted by Stefan on May 28, 2009

I always had a love/hate relationship with iTunes. I started using it a couple of years ago when I received an iPod Nano as a present for my birthday. I was immediately hooked by the library and podcast management features.

But iTunes can be very annoying sometimes. With each new version the application speed seems to decrease, startup times are bigger and program features seem to randomly disappear and reappear. For example the update from version 7 to 8 removed among others all the podcast management options and the ability to import songs as mp3 files. The latter magically appeared back in version 8.1. Also there is no way to control the player while other programs have focus using some system-wide key combination and there are no notifications when songs change.

In spite all this I still use it is my default music player because it’s the best way to manage my iPod and it’s one of the best podcast managers out there. And a few other cool features like iTunes U and Audible.com support.

Although the extensibility model for iTunes is not great, I found a plug-in that “displays a popup notifier window with track information (art cover, song name, artist, album)” each time a new track is played and a few applications that add global hotkeys support. I used for a while Jacob Hickman’s application but this is an external application, not an iTunes plug-in so every time you want to use it you have to remember to open it. What I really wanted was something similar with the iTunes toaster plug-in that added global hotkeys to the player.

And so iTunes Global Hotkeys Plug-in for Windows (ighp) was born. Ighp enables the user to trigger different actions using predefined shortcuts even if the player is minimized or hidden, just like the external apps do. The advantage is that it is automatically started and stopped with the player. You do not have to worry about anything else.

To achieve this, ighp uses a technique similar with the one used by the toaster plug-in. iTunes supports only visual plug-ins so ighp uses iTunes Visual Plug-ins SDK to make the player think it is a visual plug-in.

Global Hotkeys Plugin Visualizer

After the plug-in is loaded, it uses the iTunes COM for Windows SDK to control the player, just like the external applications do. The following actions are supported:

Action Description
PlayPause toggle play/pause
NextTrack advance to the next track in playlist
PreviousTrack go back to previous track in playlist
ToggleRandom toggle random on/off
ToggleRepeat toggle repeat on/off
SongRatingClear clear rating for the selected song
SongRating1 set rating to one star
SongRating2 set rating to two stars
SongRating3 set rating to three stars
SongRating4 set rating to four stars
SongRating5 set rating to five stars
ShowHide minimize/restore player window
VolumeUp increase volume level
VolumeDown decrease volume level
ToggleMute toggle mute/unmute
OpenSettingsFile Open settings file in notepad
ReloadHotkeys Read the configuration file and reload the hotkey bindings

By default, only two actions are configured: OpenSettingsFile (Ctrl+Shift+P) and ReloadHotkeys (Ctrl+Shift+R). You can configure more actions using the instructions on the project’s page and then you can reload the configuration to activate the hotkeys. Here is an example of a typical settings file:

<hotkeys>
  <hotkey action="OpenSettingsFile" key="P" control="true" shift="true" />
  <hotkey action="ReloadHotkeys" key="R" control="true" shift="true" />
  <hotkey action="PlayPause" key="Spacebar" alt="true"/>
  <hotkey action="NextTrack" key="." alt="true"/>
  <hotkey action="PreviousTrack" key="," alt="true"/>
  <hotkey action="ShowHide" key="q" alt="true"/>
  <hotkey action="VolumeUp" key="a" alt="true"/>
  <hotkey action="VolumeDown" key="z" alt="true"/>
</hotkeys>

The latest release of the plugin can be found here. iTunes Global Hotkeys Plugin is released under the MIT/X Consortium License. Feel free to download the source code and if you fix a bug, or add a new feature, just send me a patch.

Posted in iTunes, Plugins | Tagged: , | Leave a Comment »

Hello blogging

Posted by Stefan on March 27, 2009

I tried microblogging a few months back and it seems to work. Now I want to start a blog where I will post when I have something to say in more than 140 characters. Real content coming soon…

Posted in Uncategorized | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.