I want to do the same repetitive job in gdb across a bunch of different files. Namely,
bash$ gdb ./file1
... gdb starts up ...
gdb$ b *0xdeadbeef
gdb$ r < file2
... some output prints ...
gdb$ x/3a $esp
... some addresses print ...
Is there some way I can script this? Starting up gdb via a script is easy, but passing commands to gdb and getting their output isn't obvious to me. Would I use redirection?
You can just use a shell trick to pass multiple gdb
commands in sequence, new-line separated to standard input of gdb
, for it to consume. For e.g. for a single file just do
printf '%s\n' 'b *0xdeadbeef' 'r < file2' 'x/3a $esp' | gdb ./file1
For multiple input files, and feeding one file to gdb
at a time, starting with name file*
. Use an appropriate glob expression based on your actual filename
for file in file*; do
printf '%s\n' 'b *0xdeadbeef' 'r < file2' 'x/3a $esp' | gdb "$file"
done
User contributions licensed under CC BY-SA 3.0