bashgdbcoredump

Gdb scripting using bash


I am trying to write a script to analyze core dumps. So far I have come up with this script.

#!/bin/bash

#
# A script to extract core-file informations
#

#Binary image
binimg=$1

# Today and yesterdays cores
core=$2

gdblogfile="$core-gdb.log"
rm -f $gdblogfile

gdb -batch \
    -ex "set logging file $gdblogfile" \
    -ex "set logging on" \
    -ex "set pagination off" \
    -ex "file $binimg" \
    -ex "core-file $core" \
    -ex "bt" \
    -ex "quit"

when I try to execute it, I get this error: File 'quit' does not exist or is not a regular file.

Can you please let me know what I am doing wrong?


Solution

  • Might be something wrong with your version of gdb (which version are you using)? I can reproduce your error with gdb 6.3, but not with 7.6. Anyhow, it seems gdb, even though you have started it in batch mode, still thinks the last argument "quit" is the filename of the image (and its trying to load it, and complaining it can't be found). So, to play along with what gdb expects, just pass in the image and core file as you normally would (and also remove the "ex file" and "ex core-file" arguments). See if something like this works for you:

    gdb -batch \
        -ex "set logging file $gdblogfile" \
        -ex "set logging on" \
        -ex "set pagination off" \
        -ex bt \
        -ex quit \
        "$binimg" \
        "$core"