Archive for the 'tech' Category

Debugging reference counting in GNOME C++ bindings with GDB

Overview

For the last couple days I’ve been tracking down some reference counting problems in cluttermm. In the course of this I’ve been working on figuring out how GDB can help me do this. Here is what I’ve come up with. If you have improvements please let me know.

Watching the reference count variable

The first small obstacle is that pretty much all objects are wrapped in a RefPtr, glibmm‘s reference-counting shared smartpointers. This is a good thing and gdb makes accessing the underlying C++ object pretty painless. The following command demonstrates this.

p alpha.pCppObject_

For this example I’m using the alpha variable of type Glib::RefPtr<Clutter::Alpha>. In this command we used the fact that gdb gives you access to any member of a class, whether public or private. You should have gotten output similar to the following.

$1 = (Clutter::Alpha *) 0x9cfe40

Now the interesting part. We want to detect any changes in the ref_count variable. To do this we need to watch the ref_count field. The following command does this.

watch alpha.pCppObject_->gobject_->ref_count

To make this a bit more convenient, I’ve used the gdb define command to create a shortcut. Here is an example session.

(gdb) define watchRefCnt
Type commands for definition of "watchRefCnt".
End with a line saying just "end".
>watch ($arg0).pCppObject_->gobject_->ref_count
>end

Now you just need to use the shortcut like this.

watchRefCnt alpha

Which should give you a confirmation similar to the following.

Hardware watchpoint 2: (alpha).pCppObject_->gobject_->ref_count

The obvious thing to do next is to place this command in a .gdbinit file so that it can be pulled in automatically.

Breaking on last unreference

One of things I was most interested in catching was when the g_object_unref function was called with the condition that the _object pointer was equal to a certian pointer and the ref_count variable == 1. This would indicate that the object is ready to be disposed. To do this we first need to get the address of the underlying GObject like this.

(gdb) p alpha.pCppObject_->gobject_
$3 = (GObject *) 0x9c91e0

You now have a convenience variable, $3, which you can use in the conditions. You then need to set a breakpoint on g_object_unref and set the conditions like this.

b g_object_unref
cond 4 _object==$3&&((GObject*)$3)->ref_count==1

This, of course, would also be nice as a custom command. I’ll leave that as an exercise for the reader. ;)

Future explorations

I forsee future blog entries along these lines so stay tuned. There are quite a few things that interest me in gdb right now.

The Archer project is quickly improving C++ support in gdb. I’ve been using gdb 7.2 for my debugging as I wanted to have a stable debugging platform with all the new C++ enhancements. They have a git repository for those who want the bleeding edge.

Python scripting has been available in gdb since 7.0. I plan on looking into this as a way of streamlining debugging tasks and honing my Python skills which are pretty rusty.

Please let me know if you see any areas for improvement.

New Flat and the Internet Gap

We slept in the new flat for the first time last night. As usual, at least in Germany, it’s going to take a few weeks to get DSL connected. In our case, DSL gets connected on the 30th. This used to be the time when I’d fall into a deep depression due to withdrawal issues. However, this time is different.

For the time being I’m using the awesome new feature in Android 2.2 for sharing a mobile internet connection. Impressed with how easy it is to set up. It’s as easy as turning the feature on and setting the access point name and passphrase. Once that’s done up to 8 computers can connect as they would to any wireless access point.

Unfortunately, my mobile data plan only allows up to 200MB at 3G speed after which it gets throttled down to GPRS speeds. But it’s better than nothing and once DSL is finally connected we’ll be rewarded with 50Mbits down and 10Mbits up. That’s about 8-9 faster than what we had in San Diego for only a little more money.

Introducing GMemory v0.1

For the last few weeks I’ve been working on a small concentration game called GMemory. This was done as a part of the Openismus trainee program.

Update: See below.

For those not familiar with the game Concentration, or Memory as I grew up knowing it, the basic idea is that one has a number of matching card pairs turned face down. The player(s) then attempt(s) to match these pairs by turning over two cards. If the cards match those two cards remain face up. Otherwise, the cards are returned to the face down position. This is repeated until all cards are face up. Here’s a screencast of GMemory being played.

As you can hopefully see, GMemory is currently in a playable state and it actual quite enjoyable if you’re into these types of games. However, there is a lot more to do to reach what I’d consider a 1.0 release. Besides some code reworking and some known bugs, I’d like to see a score tracker, multi-player mode, card animation and selectable themes.

The game is written in C using GTK+, GObject, Clutter and Cairo. In the course of writing GMemory I ran into a few bugs in clutter-gtk. The first bug was that no events were being received when using the embedded clutter gtk widget. You can find the bug report here. The second major bug I ran into was that once I got a version combination that gave me events, I always received double the events that I expected. This is a known bug and I’ve got a work around in the code for that.

There are also a number of known bugs. As you may have noticed from the screencast, the last card of the last successful match does not get shown before the statistics dialog box pops up. It seems the dialog blocks the drawing even thought the function to draw the card is called before the call to show the dialog box. Another bug is that once the game is over the playing area does not resize when the window is resized. I’ll tackle this once I’ve reworked the code some.

You can find GMemory’s git repository at Gitorious and the tarball can be had here.

Unfortunately, right now I’m building against the master branches of clutter and clutter-gtk. Expect breakage.

Btw, I'm attending GUADEC right now.

Update: After trying this on Ubuntu Lucid, I experienced none of the event-related problems with clutter-gtk. This seems to be Fedora 13 specific. Thus, I’ve removed the workaround for the double event issue and changed the configure.ac file to rely on the clutter and clutter-gtk versions shipped with Ubuntu Lucid. The new tarball is here.

Openismus

As I mentioned in an earlier post, I’ll be moving back to Berlin at the end of May. Making the move has become even more exciting after learning that I’ve been chosen as one of the new trainees for Openismus. Since Murray has made the announcement, I thought I’d introduce myself to the community.

First of all, I should state that I’m American despite what the umlaut in my last name would suggest. My last name was Wilson before taking my wife’s last name just before our daughter, Vada, was born a couple years ago. I met my wife in Berlin and am very familiar with the city, having lived there from October ’99 until late 2005. I love Berlin and am excited to be moving back.

In a few weeks I’ll be graduating with a BS in Computer Engineering from San Diego State University. While in school I interned at a small company programming mostly in C++. I learned a lot from my work there but feel like I’ve got lots more to learn.

I’ve been a long time GNOME user after being converted from KDE at about the 2.4 release. Before starting school I’d occasionally submit bugs for Ubuntu and GNOME. I even attended GUADEC in Stuttgart where I met lots of interesting folks and got really inspired. But, alas, school started and free time vanished. We then sprouted a family which is a timesink, but such a wonderful one. Having a chance to learn and contribute on the job is a chance I couldn’t pass up.

I’m very much looking forward to the opportunity that I’m getting at Openismus to learn about and contribute to the projects I’ve been following so closely for so long.

Thanks Murray and Openismus.

Senior Design Project

In order to graduate from the Engineering program at San Diego State University, each student needs to complete a senior design project with a team of between 6 to 10 students. The group that I’m apart of is working on building a system to localize nodes in a wireless sensor network (WSN). We do this by using signal strength and, when nodes are in line of sight of each other, ultrasonic transducers to measure the time difference of the received ultrasonic signal and the radio signal. This is a problem that has been tackled many times and I’m pretty sure we won’t be able to come up with anything novel in the short time we have, but the task of building the working system is what is important.

Partially populated node rototype board

Partially populated prototype board

I’m in charge of building the GUI and integrating the software side of the system. For the GUI I’m using Qt. I’ve used this before and found it pleasant enough although I still run into issues that cause me to waste more time than I’d like. The most important thing for me was that Qt is cross-platform and has great documentation. Having some high-profile applications such as Google Earth and Skype using it makes it easier to “sell” to the other team members as well.

For the WSN we chose Atmel Zigbit modules. These have a ZigBee wireless chip and an ATMEGA128 microcontroller embedded within. This module was chosen because much of the difficult circuitry was taken care of, previous good experiences with AVRs, and the low-cost of the hardware and development tools. Thus far we’ve created custom PCB’s to hold the Zigbit modules, a pair of ultrasonic transducers, and the accompanying circuitry. We are currently testing those so that we can get about 20 boards professionally made.

We’ve got less than a month to finish up and are working feverishly to get everything brought together and integrated. With luck we’ll have a working system in a couple of weeks.

Setting background color of SWT buttons in Windows not supported

Just wasted a while to figure this out only to find out that it’s not supported because it’s not supported in the Windows native widget.

xorg.conf for Ubuntu Gutsy tribe 5 on IBM Thinkpad t43 2668-75U

This is the xorg.conf file as generated from the Live CD.

# xorg.conf (xorg X Window System server configuration file)
#
# This file was generated by dexconf, the Debian X Configuration tool, using
# values from the debconf database.
#
# Edit this file with caution, and see the xorg.conf manual page.
# (Type "man xorg.conf" at the shell prompt.)
#
# This file is automatically updated on xserver-xorg package upgrades *only*
# if it has not been modified since the last upgrade of the xserver-xorg
# package.
#
# If you have edited this file but would like it to be automatically updated
# again, run the following command:
# sudo dpkg-reconfigure -phigh xserver-xorg

Section "Files"
EndSection

Section "InputDevice"
Identifier "Generic Keyboard"
Driver "kbd"
Option "CoreKeyboard"
Option "XkbRules" "xorg"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
EndSection

Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ImPS/2"
Option "ZAxisMapping" "4 5"
Option "Emulate3Buttons" "true"
EndSection

Section "InputDevice"
Identifier "Synaptics Touchpad"
Driver "synaptics"
Option "SendCoreEvents" "true"
Option "Device" "/dev/psaux"
Option "Protocol" "auto-dev"
Option "HorizScrollDelta" "0"
EndSection

Section "InputDevice"
Driver "wacom"
Identifier "stylus"
Option "Device" "/dev/input/wacom"
Option "Type" "stylus"
Option "ForceDevice" "ISDV4" # Tablet PC ONLY
EndSection

Section "InputDevice"
Driver "wacom"
Identifier "eraser"
Option "Device" "/dev/input/wacom"
Option "Type" "eraser"
Option "ForceDevice" "ISDV4" # Tablet PC ONLY
EndSection

Section "InputDevice"
Driver "wacom"
Identifier "cursor"
Option "Device" "/dev/input/wacom"
Option "Type" "cursor"
Option "ForceDevice" "ISDV4" # Tablet PC ONLY
EndSection

Section "Device"
Identifier "ATI Technologies Inc M22 [Mobility Radeon X300]"
Driver "ati"
BusID "PCI:1:0:0"
EndSection

Section "Monitor"
Identifier "Generic Monitor"
Option "DPMS"
EndSection

Section "Screen"
Identifier "Default Screen"
Device "ATI Technologies Inc M22 [Mobility Radeon X300]"
Monitor "Generic Monitor"
DefaultDepth 24
SubSection "Display"
Modes "1400x1050"
EndSubSection
EndSection

Section "ServerLayout"
Identifier "Default Layout"
Screen "Default Screen"
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
InputDevice "stylus" "SendCoreEvents"
InputDevice "cursor" "SendCoreEvents"
InputDevice "eraser" "SendCoreEvents"
InputDevice "Synaptics Touchpad"
EndSection

Students, Sponsors: Beware of Pacific Nautilus

This is rant. You’ve been warned. This will hopefully be the last time I ever mention Pacific Nautilus on this blog. Also this is my personal opinion and may or may not be representative of the San Diego City College Robotics Engineering Club and its members. For background read my last post.

It looks like Pacific Nautilus is trying to assemble another team. Actually, when I say Pacific Nautilus it should be clarified that I mean Chris Carter. There is no one, to my knowledge that is still apart of his pseudo-organization. For a second year in a row, an entire team has left Chris. So when Chris writes “we” he is being optimistic. Let me detail why this year’s team left him.

During the first day of the competition Chris and I were the only ones actually at the facility from our team. The first two days are set aside for testing and is also when you have to actually qualify for a spot in the competition. Like many schools, we were having some problems. During this time, there were various people coming around to see what teams were doing and asking questions. While I was trying to trouble shoot the problems and eventually fix them he took every opportunity to tell each and every person that passed how “they”, meaning the team, “wouldn’t listen” to him and hadn’t “kept it simple.” After hearing this 5 times, I was extremely irritated. After 20+ times I was infuriated. Still, I said nothing. I wanted to keep everything as professional as possible. Basically, I was there for 12 hours trying and eventually getting the sub to work all while Chris stood around and talked shit about the work that the rest of the team and myself had put hours upon hours into.

The next day the sub was working and with a few quirks we made it straight through the gate to qualify. At this point Chris starts to change his tone. Instead of “they” he starts to include himself in the teams work by using “we.”

Now lets talk about sponsors. I had identified a source on the Internet for possible sponsorship of hydrophones. I gave Chris the information and he contacted the organization and eventually the guy in charge. This turned out to be a gold mind. The guy made us a set of 4 custom-made, matching hydrophones. he also sent us an adjustable pinger made to match what was used in the competition. Now, however, our team has no hydrophones nor a pinger. These are all in Chris’ possession and, although I’m sure the sponsor was donating them to “the team,” we have no access to these because instead of donating them to the Club they (we believe) were donated to Pacific Nautilus. The same thing happened to a $2500 camera that was donated to the team.

The main difference between Chris and the other team members is that he wanted to have ownership of everything. He wanted to have City College pay for as many things as possible (shirts, entry fee, etc) but he wanted Pacific Nautilus to own the Sub. I and many others wanted to be apart of a project that the next generation of students could work on. Chris hated the idea that what he started could later be controlled by someone else. I had the feeling the entire time that Chris would not be apart of a project of which he was not the leader. We had and have an extremely good team but Chris was never interested in being a team player and I therefore don’t consider him to ever have been apart of “the team”. He was interested only in being the leader.

So now let’s talk about the Pacific Nautilus website. There, Chris lauds the achievement of 2007 team for placing 11th out of 27th. I’d like to correct him. We actually placed 9th as the there was a error in tallying the final score. This will be officially corrected soon. He also lists a fictitious UCSD team which he has been talking about for a year. Chris uses area schools to make Pacific Nautilus sound more reputable. He falsely represents Pacific Nautilus as being somehow in cooperation with San Diego academic institutions. In reality, Pacific Nautilus acted as a barrier in the case of our team. City College was extremely wary of this outside organization that would offer no written agreements. The Club tried on several occasions to get Pacific Nautilus’ relationship with the Club formalized in writing. Chris never wanted this and it never happened. Having formal agreements didn’t allow Chris the flexibility to take his ball and go home. Now that we have completely broke with Pacific Nautilus (and I’m sure because of our success), the school is more willing to offer support.

After a certain point we, the team, all kinda decided that we would put off the politics in order to put together a working sub for the competition. We knew it wasn’t going to be pretty once we expressed to Chris that we no longer desired to have him in charge. We actually never got around to telling him that due to the somewhat dramatic conclusion to the competition.

Wow, this is getting long. Even though I have more to say, I think I’ll cut it short here.

In closing, if you’d like to join or sponsor one of the Autonomous Underwater Vehicle teams in San Diego, you’ve got 2 legitimate teams to choose from: The first team that broke from Pacific Nautilus – San Diego iBotics or the second team that broke with Pacific Nautilus (my team) – San Diego City College Robotics Engineering Club.

2007 Autonomous Underwater Vehicle Competition

Update: We actually placed 9th out of 27 teams. There was an error in the tabulation of the final scores stating we placed 11th. This will soon be changed on the competition website.

This year I and some friends from San Diego City College Robotics Engineering Club took part in the AUV Competition here in San Diego. For the uninitiated, this is an international event that has some of the top engineering schools in the country, and a few abroad, competing against each other. The goal is to build an autonomous vehicle that can navigate an underwater course and carry out specified tasks.

This year our entry, The Seahorse, did extremely well. While the final results have not yet been posted we heard from a good course that we were 11th out of 28. This is exceptional considering that the entries that placed around us had about $20,000 invested in their subs while we spent about $3,000. Additionally, we won the award for Most Improved entry. This year we easily passed through the gate almost every single time and came within inches of surfacing in the octagon several times. We are currently planning for next years event and are confident that we can place even higher.

Our team has also severed ties with Pacific Nautilus. After the close of the event, Chris Carter, who IS Pacific Nautilus, tried to usurp control of the sub although City College and our various team members have receipts for almost every part. After a slight altercation, the sub was taken by the event coordinators. Our Dean of Engineering contacted the event coordinators and the sub is, or very soon will be back in the hands of the school. Thus, it will be available to us for next year’s event. The one or two parts that may belong to Pacific Nautilus will be returned once ownership is clear.

Unfortunately, the products that our sponsors donated – the custom-made hydrophones and titanium underwater camera – are currently in the possession of Chris Carter/Pacific Nautilus. We will soon be in contact with said sponsors in order to let them know what has happened to the products that they intended for the team.

This is the second year in a row that Chris Carter has lost an entire team. The other team reformed as San Diego iBotics and competed in this years event as well. Although it is tempting to join forces, it is obvious that our teams have differing design philosophies. We do wish to cooperate with them in the future, however.

Top 30 Django Tutorials and Articles

As a response to the Top 30 Ruby on Rails Tutorials, I’ve compiled a list of the top 30 Django tutorials and articles. These links are in addition to the great documentation on the Django project site.

For those who don’t know, Django is a Python web development framework that makes development super fast.

The list in no particular order…

  1. Are you generic?
  2. Sending E-Mails via Templates
  3. Django admin for your PHP app?
  4. Hacking FreeComment
  5. the difference between ‘blank’ and ‘null’
  6. Using Django’s TemplateTags
  7. A Django website that took (a lot) more than 20 minutes
  8. Forms With Multiple Inline Objects
  9. Extending Generic Views
  10. Template context processors
  11. Custom SQL In Django
  12. How Django processes a request
  13. Write better template tags
  14. Extending the User model
  15. Django’s Undocumented contenttype app
  16. Django, gzip and WSGI
  17. Django for non-programmers
  18. Django Templates: The Power of Inheritance
  19. Django Templates: An Introduction
  20. Setting up Django on Dreamhost
  21. Django on Windows HOWTO
  22. Django Admin Hack – Fields varying with user permissions
  23. Some django gotchas
  24. Django Templates are not limited
  25. Develop for the Web with Django and Python
  26. An AJAX ComboBox Widget for Django
  27. Using Django’s Free Comments
  28. MochiKit and Django
  29. RSS made stupidly simple
  30. Installing Django on OSX

Note: keep an eye out at Django’s community page for new tutorials and articles.

Related Links

If you have an additional tutorial, put it in the comments.

digg story