Last night, I was debugging a general protection fault on Viengoos. The problem was immediately obvious once I looked at the actual instruction that caused the fault (and not the line of code that it corresponded to).

Normally I use gdb to disassemble a binary (list *addr). This was not an easy option last night: whereas the Viengoos binary I was examining was compiled for x86-64, my current development machine is an x86 system, and Debian doesn't have x86-64 support built into their gdb package for that architecture. As such, I turned to objdump. I was surprised how nice its output is. For instance, -S interleaves the source with the assembly. I cooked up the following bash function to make my life easier. It's not bullet proof, however, it works for me.

function asmat()
{
    addr=$(echo "$2" | sed 's/^0x//' | tr 'a-f' 'A-F')
    start=$(echo "16 o 16 i $addr 10 - p" | dc)
    end=$(echo "16 o 16 i $addr 30 + p" | dc)
    t=$(tempfile)
    objdump --start-address=0x$start --stop-address=0x$end -S "$1" >"$t"
    if ! grep -i -C 999999 "$addr" "$t"
    then
      cat "$t"
    fi
    rm -f "$t"
}