From a427b63cb5c7f8d5c55242133a57dd219cfa3fd2 Mon Sep 17 00:00:00 2001 From: Nikolai Nosov Date: Wed, 22 Jan 2020 20:04:39 +0400 Subject: [PATCH] run trace under GDB in batch mode and print SP in every frame --- gdb-batch.sh | 4 ++++ script.gdb | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 gdb-batch.sh create mode 100644 script.gdb diff --git a/gdb-batch.sh b/gdb-batch.sh new file mode 100755 index 0000000..6c84587 --- /dev/null +++ b/gdb-batch.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +make +gdb --batch --command=script.gdb ./build/trace \ No newline at end of file diff --git a/script.gdb b/script.gdb new file mode 100644 index 0000000..d56a003 --- /dev/null +++ b/script.gdb @@ -0,0 +1,58 @@ +# http://sourceware.org/gdb/wiki/FAQ: to disable the +# "---Type to continue, or q to quit---" +# in batch mode: +set width 0 +set height 0 +set verbose off +# enable breakpoint pending on future shared library load in batch +set breakpoint pending on +dashboard -enabled off +handle SIGSEGV nostop noprint + +b _start +commands 1 + p $rsp + continue +end + +# at __libc_start_main point - print RSP +b __libc_start_main +commands 2 + p $rsp + continue +end + +# at entry point - print RSP +b main +commands 3 + p $rsp + continue +end + +# at Fun1 point - print RSP +b Fun1 +commands 4 + p $rsp + continue +end + +# at Fun2 point - print RSP +b Fun2 +commands 5 + p $rsp + printf "\n" + continue +end + +# show arguments for program +#show args +#printf "Note, however: in batch mode, arguments will be ignored!\n" + +# note: even if arguments are shown; +# must specify cmdline arg for "run" +# when running in batch mode! (then they are ignored) +# below, we specify command line argument "2": +run # run + +#start # alternative to run: runs to main, and stops +#continue