[ Content | Sidebar ]

Making Emacs GUD Usable

June 9th, 2019

Emacs provides a wrapper for various debuggers including GDB called the Grand Unified Debugger (GUD). I’ve tried it in the past but always run into lots of minor annoyances with the UI so I just use command line GDB instead. But recently I’ve being trying to adopt a more “Emacs native” workflow, including using EShell instead of a separate terminal window for Bash, Magit instead of command line git, ERC for IRC, etc. So let’s see if we can fix these GUD problems…

Basic configuration

(setq gdb-many-windows t
      gdb-use-separate-io-buffer t)

The default mode of GUD just creates a single window with the the normal GDB terminal. This doesn’t seem to offer much over running GDB directly. The “many windows” mode splits the screen into six separate windows showing the current source file, locals/registers, output, etc.

Source file opens in the wrong window

By default if you jump to a source file from e.g. the stack trace window it will open on top of the command input window (labeled “2” below) rather than the source file window “1”.

This seems to be “normal” behaviour, and there are loads of threads on Stack Overflow complaining about it but with no conclusive solution. E.g. see here or here.

The problem here is that GUD makes all the popup windows “dedicated” except for the command window. When you jump to a file it opens in the first non-dedicated window, which sort-of makes sense. The function that sets up the windows is called gdb-setup-windows so we can use Emacs’ “advice” system to hook this function and run some extra code afterwards to make the command window dedicated:

(advice-add 'gdb-setup-windows :after
            (lambda () (set-window-dedicated-p (selected-window) t)))

This works because gdb-setup-windows always leaves the command window selected when it finishes.

Quitting messes up the window configuration

How do you quit anyway? I think the correct way is just to run quit in the command window. But no matter how you quit GUD always messes up whatever window configuration you had before you opened it.

We can fix that by saving the window layout when we run M-x gdb by storing the layout into a register in gud-mode-hook. The gud-sentinal function runs when some event occurs on the inferior gdb process. We can hook that to restore the window state when the process exits.

(defconst gud-window-register 123456)
 
(defun gud-quit ()
  (interactive)
  (gud-basic-call "quit"))
 
(add-hook 'gud-mode-hook
          (lambda ()
            (gud-tooltip-mode)
            (window-configuration-to-register gud-window-register)
            (local-set-key (kbd "C-q") 'gud-quit)))
 
(advice-add 'gud-sentinel :after
            (lambda (proc msg)
              (when (memq (process-status proc) '(signal exit))
                (jump-to-register gud-window-register)
                (bury-buffer))))

I’ve bound C-q to gud-quit which send the quit command to GDB to save typing.

Zhouzhuang

May 14th, 2019

I went to Zhouzhuang ancient town a few weeks for a day trip. It takes just an hour or so by bus from Shanghai, and because of that it’s extremely crowded on the weekend and also very commercialised. There’s also not many indoor attractions and museums to visit, just a lot of shops. The town is just 10km from Tongli which I thought was much more picturesque and authentic so you might as well just go there, although I haven’t been back since it got connected to the Suzhou metro. I want to go back to Anhui for a weekend sometime, as I really enjoyed visiting the old towns there a few years ago.

Big Wheel

May 2nd, 2019

On a clear day I can see in the distance a very tall tower-like thing from my apartment. On closer inspection it’s a giant Ferris wheel! It’s about 45 minutes walk away, near Shanghai south railway station. As it’s 108 metres tall and Shanghai is totally flat, from the top you ought to be able to see everything, but unfortunately the day I went was a bit hazy / polluted.

Bottom of the wheel…

At the top! I can see my apartment from here!

The wheel is attached to a fairground

It was almost sunset the first time round. Here’s a bonus night photo!

Guilin Park

April 14th, 2019

There’s a really nice garden a few metro stops away from where I live (the station is also called “Guilin Park”). It only costs 1元 to go in! It’s not as impressive as some of the gardens I visited in Suzhou but it’s quite pleasant for a few hours on a Sunday afternoon. Especially with the cherry blossoms in spring…

Pandas

February 28th, 2019

I forgot to post anything from my work trip to Chengdu last year. A bit late, but I saw pandas for the first time ever!

Panda, eating some leaves

In a sort of semi-wild panda sanctuary. The best bit was when one of them climbed up a tree, looked around, and then climbed/fell down again. Otherwise they lived up to their reputation and didn’t do very much.

Panda, in a tree

Two pandas, playing?

Qibao Old Town

December 28th, 2018

Here’s another of these traditional water towns. It would be quite unremarkable if it wasn’t in the Shanghai suburbs, which makes it very easy to get to (it’s actually just a few km from where I live). But this also means it’s full of tourists and very over commercialised. It’s definitely worth an hour or two walking around though. Getting there is really easy: just take subway line 9 to “Qibao” and the follow the signs to the old town.

Weird Sunset and a Relocation

October 13th, 2018

So I decided to take a job doing open source-y things for a certain well-known CPU vendor. More on that in the future, maybe. But as part of that I relocated to Shanghai. Now I live up here in the sky:

Some apartment blocks and things

Last weekend there was mini-typhoon. It rained a lot and then there was this really strange sunset.

I didn’t notice the construction site when I viewed the apartment

Virgin Upper Class Review

September 30th, 2018

All those years travelling around for Cisco finally paid off when I used 67000 air miles plus £365 tax to buy a one-way “upper class” (Virgin Atlantic’s first class) ticket London Heathrow to Shanghai. Is first class better than economy? OMG yes. Is it worth the £5300 list price? Probably not.

My life of luxury started in the special check in area for special people (3x 32kg baggage allowance!) and a private elevator to the fast-track security channel. No need to shout “out of the way plebs!” as there was a screen to hide the regular passengers.

Virgin Atlantic lounge

I’ve spent a lot of time waiting in Heathrow Terminal 3 but this time I deliberately arrived over four hours early and went straight to the exclusive Virgin lounge upstairs. OMG it was good. The seats were so comfy and the decoration was very classy and all the food was FREE. I had this salad and fish for lunch. Felt like a right doofus for paying £10 for breakfast in the hotel before I came to the airport.

Totally free lunch

The toilets were so luxurious! They had proper hand towels and everything. Not like the regular airport toilets on the floor below.

Nice toilet

Eventually I boarded the plane via the special people channel and went right to my window seat at the front of the plane.

My seat

I say “window” seat. It’s actually rather difficult to look out they window as you need to crane your neck awkwardly to the side: the seat actually points diagonally into the cabin. I found this most strange when the plane took off as the acceleration pushes you in a weird direction. But the side panels mean you can’t see any other passengers, which I rather liked.

In-flight meal

The food was excellent (why am I eating fish again?!) and served on proper plates with proper cutlery. This was actually my favourite part, makes such a big difference to eating out of a miserable plastic tray in economy. And if you want tea they bring it to you an a proper mug, and after you finish and ask for a refill they’ll be like “do you want a biscuit with that??!”. OMG yes please. Service.

Fully flat bed

After dinner it’s time for bed! The seat folds into a fully flat bed and there’s a duvet and sheets hidden behind. They even give you pyjamas if you want. I don’t think I slept that well, and it didn’t help that the flight landed at 3am UK time, but I’ve flown on VS250 soo many times in economy and I always arrived exhausted and nauseous, but after 12 hours in upper class, I just felt a bit tired.

And the breakfast was fantastic too

Ignoring the price, I’d give the whole experience 10/10. I think maybe I’d be prepared to pay 2-3x the economy fare, but at close to 10x it’s a little outside my regular budget. 🙁

Mysterious Key

August 30th, 2018

I’ve been carrying this key around with me for at least 10 years, since I lived in York. I’m pretty sure I’ve not used it in that time, and have completely forgotten what it’s for. It’s possible it opened the padlock on the storage room we used when moving student houses, or perhaps I misappropriated it from one of those houses. Surely one of the great mysteries of our time.

Do YOU recognise this key??

Winchelsea

August 24th, 2018

I was at home visiting my parents last weekend and decided to go out for a walk eastwards through the marshes towards Rye. But I didn’t make it that far and ended up in the ancient village of Winchelsea.

The Church is worth a visit as it’s very picturesque, and Spike Milligan is buried in the graveyard. The day was just a bit too gloomy to be enjoyable though, and the bleak marshland landscape didn’t help.

Winchelsea church

While I was out I met a lunatic. He announced “this is the year!” and then proceeded to tell me all about how Qanon is right about everything and something I didn’t quite follow about feminists. I think he was from 4chan.

Near where I met Qanon’s representative