0

I'm trying to dump memory from a process on my Linux machine using GDB, but I'm trying to automate this using a script.

So far I've been using the following commands (example):

$ gdb --pid [pid]
(gdb) dump memory dump_file 0x00621000 0x00622000

Is there a way to do this using only one command that I can implement in a shell script? Or is there a way to perform gdb commands using shell scripts?

Any help would be greatly appreciated :)

1 Answers1

1

Create a file in /usr/local/bin and make it executable afterwards:

#!/bin/sh
if [ $# -eq 3 ]; then
  tf=$(tempfile)
  echo -e "dump memory dump_file ${2} ${3}" > $tf
  gdb -p $1 -x $tf
else
    echo "Pass me a PID MEM_START MEM_END"
fi

If you name it memory-dump-gdb or mdg for short then you make it executable like so:

chmod 750 /usr/local/bin/mdg

Then you can run "mdg 1234 0x00621000 0x00622000"

flowtron
  • 215
  • 2
  • 5