Skip to content

Instantly share code, notes, and snippets.

@hiboma
Created April 15, 2014 13:50
Show Gist options
  • Select an option

  • Save hiboma/10734390 to your computer and use it in GitHub Desktop.

Select an option

Save hiboma/10734390 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# here is an original code:
# http://serverfault.com/questions/173999/dump-a-linux-processs-memory-to-file
#
function extract_memory_region()
{
pid=$1
grep rw-p /proc/${pid}/maps | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p'
}
function gdb_dump_memory()
{
pid=$1
start=$2
end=$3
gdb --batch --pid ${pid} -ex "dump memory ${pid}-$start-$stop.dump 0x$start 0x$stop"
}
pid=$1
if [ "$pid" = "" ]; then
echo "[usage] $0 <pid>"
exit 1
fi
extract_memory_region $pid | while read start stop
do
gdb_dump_memory $pid $start $end
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment