Linux

Debugging Vala programs in an IDE

Geany

Geany is an IDE the supports a number of languages including Vala. This tutorial will show you how to get the debugger plugin for Geany working with Vala code. At the time of this writing the plugin in the Ubuntu repositories happens to be broken. We’ll install it from source and configure it for Vala. If you don’t use Ubuntu or a derivative like Elementary OS this article should still be applicable. You just might need to change a few things.

Installation

You can install Geany with:
sudo apt-get install geany

There is a package called geany-plugin-debugger. You can try installing it. At the time of this writing its broken. It installs to the wrong location. If you copy the files to the right location it causes a segmentation fault as soon as you enable it. This was reported half a year ago: https://bugs.launchpad.net/ubuntu/+source/geany-plugins/+bug/1354747

Instead you can get all the plugins for Geany off Github. At the current time the version of Geany in the Ubuntu repos is 1.24. All we care about is the debugger but the other ones are nice to have. I removed the ones from the build script that won’t compile on 1.24 and forked it. You can get it using this command:
git clone https://github.com/agronick/geany-plugins.git

If you have Geany 1.25 grab the offical one:
git clone https://github.com/geany/geany-plugins.git

You need autotools to compile it. Just do sudo apt-get autotools 

Now to install it just do:
./autogen.sh
make -j PROCESSORS #Replace PROCESSORS with the number of processor cores your computer has or the number of jobs you want to spawn to compile
sudo make install

Hopefully this worked. If you get an dependency error install whatever dependency is missing.

Now open up Geany. If you go to Tools > Plugin Manager you should be able to enable the debugger. It wont work just yet though. There are a few more things you need to set up.

Configuration

At this point you’ll want to create a new project. Now you’ll need to set the build parameters. Go to Build > Set Build Commands.

Set this under Vala Commands:

Label Command
Compile valac -c "%f"
Build valac -g --save-temps --pkg gtk+-3.0 "%f"

You can remove the –pkg gtk+-3.0 part if you don’t want to build GTK apps.

Now you will need to do the following:

  1. Insert a breakpoint in your Vala program
  2. Click the build icon
  3. Open the debugging view
  4. Browse for the executable it created
  5. Run your Vala program

Steps for debugging
 There you go. You now have a working Vala debugger. You can step through the code and look up variables at runtime right in your IDE. I hope this helps and is useful. I know I was looking for it for a few months. Its nice to finally have.

I also made this video on how to debug segmentation faults in a command line:

Advertisements

6 thoughts on “Debugging Vala programs in an IDE

    1. I wish they both had better autocomplete. The UI builder in Anjuta is nice but its just Glade so you can install that as a stand alone as use it with Geany. This is the first debugger I’ve found that is build into an IDE so that certainly makes it more useful. Neither of these are perfect. I hope somewhere down the line we get an Vala IDE that feels a lot more complete. Something that can do autocompletion and understands how all the Vala classes are tied together.

      1. I might give this a try then. I’m a C# developer so I’m spoiled by the amazing debugging ability afforded by both Visual Studio and MonoDevelop. I’ve been meaning to give Vala a try because the syntax is so similar to C# but I’ve found the tools to be lackluster.

      2. Vala would be a great language if the could wrap a decent IDE and debugger around it. It compiles to the speed of C and has a lot of features of an interpreted language.

  1. I’m having trouble on yosemite – gdb sends a signal then geany aborts. I codesigned gdb – tested it manually on my executable – it works. I followed your instructions – was able to set a breakpoint and got the debug window to come up. However – no icons for the buttons on the debug window – and when I click where the debug/run button is – it aborts. I tried building from sources using https://github.com/geany/geany-osx – but jhbuild fails (bad zip file on gtk sources). Any suggestions ?

  2. update – gtk did build after many retries and a few changes. Getting to: jhbuild build meta-gtk-osx-core however – build fails – and it looks like it expects 64bit mono which is not installed (and I think mono 64bit on OSX has issues). Is there somewhere that I have to specify a 32bit build ?

    CCLD libcairo.la
    ld: warning: ignoring file /Library/Frameworks/Mono.framework/Versions/4.0.5/lib/libfreetype.dylib, file was built for i386 which is not the architecture being linked (x86_64): /Library/Frameworks/Mono.framework/Versions/4.0.5/lib/libfreetype.dylib
    Undefined symbols for architecture x86_64:
    “_FT_Bitmap_Convert”, referenced from:
    __get_bitmap_surface in cairo-ft-font.o

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s