Programs and Scripts

This page links to some programs, scripts, and little code snippets I've written (or, in the case of some of the snippets, gathered).

As of 7/26/2011 I'm putting this page together from the various scripts I've written over the years, so bear with me while I get things into the right place, and not everything is available quite yet.

Quick reference

AutoCC: platform-independent compiler flags

Hosted at github.

This is a Python module I wrote, intended for use with SCons, my build system of choice. SCons provides some a number of platform independent abstractions. For instance, you can instruct its C/C++ builders to add my-project/include to CPPPATH, and it will add a -I prefix when compiling with a GCC-like compiler and /I when compiling with MSVC. It will also choose prefixes and suffixes for libraries, turning blah into libblah.a on POSIX and into blah.lib with MSVC (or .so and .dll).

However, SCons does not provide abstractions for other common compiler settings, such as optimization level, debugging information, or warning settings. AutoCC aims to change that.

Right now it contains a (very) small catalog of compiler-independent settings and their translation into flags for GCC, MSVC's cl, and Intel's icc.

It should be considered pre-release at the moment, but some time I get a couple spare days I'll get back to it. I may also rename it to AutoFlags...

libjitdbg: JIT debugging on *nix

Hosted at github.

Windows has a neat feature informally called JIT Debugging. Basically you run a program like normal (outside of a debugger), and if it crashes or something then it will allow you to break into it with a debugger from that location.

This project is my attempt to bring this ability to Linux. It comes as a LD_PRELOAD library which pulls the following hacky (read: awesome) tricks. It registers some signal handlers (for such things as SIGSEGV and SIGTRAP) which fire in "crashy" situations; it also overrides the abort() and __assert_fail functions from libc. If any of those signals fire, or either of those functions are called, your process will fork(), start GDB from the child process, and attach that GDB instance to the parent (which is in the process of sort-of crashing).

The benefit of JIT debugging over using core files postmortem is that you can continue to execute code. To a small extent you could see this as being able to continue execution if you fix the problem, but the real win comes from the fact that you can execute GDB print statements and not have it tell you that "You can't do that without a process to debug."

Of course given the content of a couple paragraphs ago, there are lots of caveats. In particular, don't just set LD_PRELOAD in your shell's .rc file; that would be bad.

Rewrite: read from and write to the same file

Hosted at github.

I got annoyed at not being able to do munge foo.txt > foo.txt from the shell, so I wrote this script. You can run it as rewrite foo.txt munge @, and it will "do the right thing".

Demux: multi-output grep

Hosted at github.

This is like a really fancy grep (at least along one axis). You provide n regular expressions and n+1 output files. It reads some input line-by-line: for each line, if regular expression #k matches, then that line is written to the kth output file. (If none match, it's written to the k+1th file.)

This really needs commented... after that, I may move it to github.

Program Committee: fake a PC

Coming at some point (this is lower priority)

This is a script or two useful if you are faking a program committee (say, within a research group) and need to divide up the papers according to preferences and tally results.