Score:0

Automating GDB memory dumps

eg flag

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 :)

Score:1
cn flag

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"

us flag
How does your script do the memory dump?
flowtron avatar
cn flag
Oh. Oups .. must've been distracted and thought I was doing a shell-script 101 .. heh .. the new solution should do what was asked.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.