Language that does not complain -> confusing bugs

Today I had to debug a clients site.

You see, the slider was broken.

Why?

The slider javascript wasn’t being loaded.

Why?

The entire lower portion of the html is non-existent.

Even the caching plugin’s status information is missing.

The html’s last words were “<!– mfunc”, a harmless comment. Let’s pay attention to where the comment was.

It was where the sidebar should have been.

Let’s look in the sidebar template file.

That’s odd, the template uses a special php function that stops php from sending the html to the browser until you call a second special function.

Maybe a bug is stopping this second function from being called.

Let’s add other random comments to see if they show up.

They do. Thus it cannot be the special function.

So what is it? Lets see what the supposedly harmless comment is.

It’s magic.

Or that is to say, it is way for a plugin to run code indirectly if the site is being cached.

All added with a wordpress hook, a way for a plugin to indirectly run code during html generation.

Yes! A plugin is indirectly-indirectly running code, and this code is crashing.

And that is the real bug.

I just wish finding it was quicker.

Pulling options from the sql db is done.

Thought I’d give an update to my Christmas plans. I ended up taking longer than just the Christmas break. I used the extra time to do some refactoring and cut the size of DB.pm by a thousand lines or so.

Filters will slowly be pulled from DB.pm and moved into a logical hierarchy within the new ‘filter’ directory. As it is now DB.pm is simply too large to wrap your head around. When I started this summer DB.pm was almost 10k lines. Since then it has slowly shrunk to 8k. Due to the size some dead code has built up.

An excellent example of this is get_javascript2() which the old openprinting website used. The funny part is that there is not get_javascript1() or get_javascript().

Oh and then there is comment_filter() which filters user input on a web page with regex. It actually works! Which is quite a feat considering the many got-ya’s with user input

My strategy right now is to remove the proper functionality into modules. My hope is that the dead code will then become more obvious.

The hardest bug I have ever encountered

This semester I’m taking a RISC assembly class. I like it.

Programming in assembly is relaxing because of its simplicity. Or at least  until it stops being simple. Such as today.

For a CRC calculating program I needed to be able to set a mask with the high bits set. This is tricky since the move instruction can only set the lower 13 bits. In my first attempt I used move and shift instructions to assemble the mask. This was of course messy which is why I was thankful when my friend showed me the set instruction which could set all 32 bits at once.

We puzzled at how this might be possible since that would leave no room for the opcode. The entire instruction has to be translated to 32 bits which includes the arguments to the instruction. So 32 bits of instructions should be impossible.

I decided to ignore the underlining mechanise.

Turns out ignoring what the computer is doing when you are programming in assembly is a bad idea. The set instruction does in-fact map to multiple instructions when the input is greater than 13 bits.

It just so happens that I would find this out the hard way. You see one of those high bit masks I needed was assigned in the delay slot of a branching instruction. For the laymen; a delay slot is a way to slip in an extra instruction when otherwise the cpu would do nothing. This meant that of the two instructions that set was translated too, only one of them was ran.

Thus one key portion of my bit mask was left unset.

When the mask should have been 0x80000810 it turned into only 0x80000800

Notice that the 5th bit is a zero instead of a one and so my CRC had one less xor gate than it should have.

This easily took an hour to debug. And unlike most bugs this one didn’t have an ah-ha! moment. Even when GDB clearly showed that the mask was incorrect I had to experiment to assure myself of what I was seeing.

Assembly is not very relaxing when you do not know what the computer doing.