[ Content | Sidebar ]

Archives for 2012

New TrainGame release

September 8th, 2012

It’s been ages since I did much work on my unimaginatively-titled train driving game. Surprisingly some people have actually been trying to build the last release and it turns out anything using Boost bit-rots at an alarming pace. So I’ve bundled up the latest working version as TrainGame-0.2.2.tar.gz.

It’s not all build fixes though. Looking through the log for the past few years I’ve done plenty of optimisation and prettied up the grass as I explained previously.

To build and run after extracting the archive you’ll need to:

cmake .
make
./bin/TrainGame play figure8

You’ll need a recent-ish GCC or Clang and Boost.

Fluffy

September 2nd, 2012

Out wandering high up in the Chilterns near Russel’s Water I came across these pretty fluffy things. No idea what they are as usual. Perhaps some sort of dandelion? Blodgett would know.

Daily factoid: perusing the previously linked Wikipedia article, I discovered that these plants are adjacent to a pond featured in Chitty Chitty Bang Bang. Fascinating, eh?

Mascot

September 2nd, 2012

The protagonist was thrilled to finally meet his long-standing hero, cyclopean freak “Mandeville”, at the Paralympic rowing this weekend.

Airshow

August 19th, 2012

I went to the Eastbourne Airshow with my mum while I was at home last weekend. Borrowed my Dad’s SLR avec telephoto lens to take some snaps. I think they came out rather well after some judicious cropping.

Filed in photos - Comments closed

More Castle

August 12th, 2012

I spent last weekend visiting some northern acquaintances in Yorkshire. On Saturday we went on an adventure to Richmond Castle via Darlington. And a very pleasant castle it is too! It’s got a nicely preserved keep which you can climb to the top of for some excellent views of the quaint market town and surrounding countryside. By happy coincidence there was some medieval event on featuring people hitting each other with swords and such like. We managed to dodge the storm clouds for the whole day which was a bonus.

Rochester Castle

July 29th, 2012

I had some surprisingly well-timed holiday booked this week so I decided to visit a nearby(ish) castle at Rochester. The last time I came here I was a small child and all I remember is being terrified by how tall and massive it was. Some shrinkage has occurred over the last twenty years. Still it’s a very pleasant castle and nicely preserved too. Worth visiting, although there’s not a whole lot else to do in Rochester.

Some photos I took (not my best):

Come back for more castle next week!

Accessorising

July 15th, 2012

Got this really cute hemp chalk bag. Climbing is all about the fashion.

Filed in musings - Comments closed

Automagic Debugging

July 8th, 2012

It’s kind of annoying to have to go back and run GDB after your program crashes. Here’s a signal handler I’ve been using which drops you into GDB straight away:

static void gdb_sighandler(int sig, siginfo_t *info)
{
   char exe[256];
   if (readlink("/proc/self/exe", exe, sizeof(exe)) < 0) {
      perror("readlink");
      exit(EXIT_FAILURE);
   }
 
   char pid[16];
   snprintf(pid, sizeof(pid), "%d", getpid());
 
   pid_t p = fork();
   if (p == 0) {
      execl("/usr/bin/gdb", "gdb", "-ex", "cont", 
            exe, pid, NULL);
      perror("execl");
      exit(EXIT_FAILURE);
   }
   else if (p < 0) {
      perror("fork");
      exit(EXIT_FAILURE);
   }
   else {
      // Allow a little time for GDB to start before 
      // dropping into the default signal handler
      sleep(1);
      signal(sig, SIG_DFL);
   }
}

This probably breaks all sorts of rules on what you shouldn’t do in a signal handler but hey, it was going to crash anyway. Resetting the handler to SIG_DFL at the end is important or you’ll end up stuck in a loop when you try to quit GDB. Install it for all the unpleasant signals like this:

struct sigaction sa;
sa.sa_sigaction = (void*)gdb_sighandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
 
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGFPE, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
sigaction(SIGABRT, &sa, NULL);

It’s probably worth checking whether GDB is already running before you do this. On Linux you can check this by trying to ptrace yourself: if it succeeds then a debugger isn’t attached.

static int is_debugger_running(void)
{
   pid_t pid = fork();
   if (pid == -1) {
      perror("fork");
      exit(EXIT_FAILURE);
   }
   else if (pid == 0) {
      int ppid = getppid();
      if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) {
         waitpid(ppid, NULL, 0);
         ptrace(PTRACE_CONT, NULL, NULL);
         ptrace(PTRACE_DETACH, getppid(), NULL, NULL);
         exit(0);
      }
      else
         exit(1);
   }
   else {
      int status;
      waitpid(pid, &status, 0);
      return WEXITSTATUS(status);
   }
}

Red Flowers, Big Stone

July 7th, 2012

Title says it all: some red flowers in a field last weekend:

I don’t know what sort they are :-(. Also a big stone in a place appropriately called Ibstone:

Wikipedia thinks the stone is marking the Bucks/Oxfordshire border, which is a bit mundane.

Also I’ve decided that driving is among the most stressful and miserable experiences known to mankind. I have no idea how people can do this all day and actually enjoy it…

UPDATE: a reader informs me that the flowers are poppies.