简体   繁体   中英

BASH Reading prompt from GDB

My intentions are the following. I am debugging an object file compiled with gcc from a .c script. Lets call this compiled script "foo". When I run the command from my terminal on mac:

gdb -q ./foo

I get the an output of:

Reading symbols from ./foo...Reading symbols from /Users/john/Documents....done.
done.

And immediately I get a prompt from the shell looking like so:

(gdb) "Shell waiting for my input command here from keyboard"

At this point I want to automate the input of certain commands like: break, list, x/x "symbol in .c file", x/s "symbol in .c file" and many more. For this automation I want to use a little bash script, and so far I have the following:

#!/bin/bash

SCRIPT=$1
gstdbuf -oL gdb -q $SCRIPT |
        while read -r LINE
        do
            echo "$LINE"
        done

At the point of executing this bash script, I see the following output on my terminal's shell:

Reading symbols from ./foo...Reading symbols from /Users/john/Documents....done.
done.

But I do not see the:

(gdb) "Shell waiting for my input command here from keyboard"

How can I detect this prompt from the gdb process in my shell script in order to be able to automate the commands I want instead of inputting them manually?

Many Thanks!

You can create a file .gdbinit and put the initial commands there. gdb will execute them on startup if you added the following line to $HOME/.gdbinit :

add-auto-load-safe-path /path/to/project/.gdbinit

Now you can place commands into /path/to/project/.gdbinit , like this:

break main
run --foo=bar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM