September 22, 2004

Re: Gdb Macro Recursion?

A few days ago, I asked why my recursive RB-Tree GDB macro was "hanging". I found the problems:

1) I forgot the "end" terminator for the if clauses. So when the recursion ended there was no termination and the macro "hung". Note to self: GDB is not as lax as C!

2) GDB variables are not scoped, so their contents are not preserved on the stack during a recurisve call. So when a leaf node was reached, and we started back up the call stack the previous value of the variable holding the node address was not restored and things went south. However, macro arguments are locally scoped (and hence preserved), so the fix is not to copy the argument into a variable.

Fixing both of these problems allows me to print all nodes in an RB-Tree with a simple recursive macro.

define sc_prb
printf "%d\n" $arg0->r_key

if ($arg0->r_left)
sc_prb $arg0->r_left
end
if ($arg0->r_right)
sc_prb $arg0->r_right
end
end

P.S. The recursion limit in GDB is 1024 (which can be changed with "set max-user-call-depth"). This is not a problem at all, as a ~60,000 node tree will only have 18 levels of recursion (the number of nodes between the root and a leaf).

Posted by brian at 11:34 AM | Comments (0) | TrackBack

September 20, 2004

Choice is more than a binary option

Slashdot | Libertarian Presidential Candidate Michael Badnarik Answers

Badnarik's answers about our freedoms and rights (get rid of the PATRIOT Act, DMCA, and veto INDUCE) have cemented him as my choice. Read this article and know that there is a choice other than 1 or 0.

I absolutely love the following quote, it sums up my feelings about government perfectly.

"With the support of my party, I'm offering Americans a chance to peacefully transition back to policies that served America well for more than a century -- free trade, a non-interventionist foreign policy, minimal government, minimal taxes, maximum freedom -- rationalized into the paradigm of the 21st century." -- Michael Badernilk

Posted by brian at 03:07 PM | Comments (0) | TrackBack

September 15, 2004

GDB macro recursion?

So I've been working on a lookup cache that uses a Red-Black Tree. Everything is going well, but for debugging purposes, I want to print out the whole tree in gdb. I thought this would be pretty easy using a recursive macro, but the macro hangs when it reaches the first leaf node (nil). So it doesn't look like macro recursion is possible.

Here's the macro:

define sc_prb
set $scrb = (struct rbnode*)$arg0

printf "%d\n" $scrb->r_key

if ($scrb->r_left)
sc_prb $scrb->r_left
if ($scrb->r_right)
sc_prb $scrb->r_right
end

Anyone out there have experience with gdb recursive macros? Am I missing something?

Posted by brian at 06:24 PM | Comments (0) | TrackBack

September 09, 2004

Defending Open Waters from The Scourge of the Sea

Unsanity has a post about a developer who took drastic measures against the pirates who cracked his software within one day of release. His revenge was to move their home folder to the system temporary directory. This is pretty bad, but if the pirate was unlucky enough to reboot (which would be a common reaction to your home folder disappearing) the system would happily delete their home folder and all data within!

I understand the developer's frustation with pirates, but this kind of action could end up with an FBI agent on his front stoop. He removed the "piracy prevention code" within a day, but the backlash is already huge. Slashdot will probably pick this story up soon, and that's when the bit-shit will really hit the fan.

BTW, the Unsanity post fails to mention the developer's name or his product, but this information is easily found elsewhere.

Posted by brian at 11:05 AM | Comments (1) | TrackBack