简体   繁体   English

来自GDB的BASH阅读提示

[英]BASH Reading prompt from GDB

My intentions are the following. 我的意图如下。 I am debugging an object file compiled with gcc from a .c script. 我正在调试从.c脚本使用gcc编译的目标文件。 Lets call this compiled script "foo". 让我们将此编译脚本称为“ foo”。 When I run the command from my terminal on mac: 在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: 并立即从shell收到如下提示:

(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. 在这一点上,我想自动化某些命令的输入,例如:break,list,x / x“ .c文件中的符号”,x / s“ .c文件中的符号”等等。 For this automation I want to use a little bash script, and so far I have the following: 对于这种自动化,我想使用一些bash脚本,到目前为止,我具有以下内容:

#!/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: 在执行此bash脚本时,我在终端的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? 我如何从我的Shell脚本中的gdb进程中检测到此提示,以便能够自动化所需的命令,而不是手动输入命令?

Many Thanks! 非常感谢!

You can create a file .gdbinit and put the initial commands there. 您可以创建文件.gdbinit并将初始命令放在此处。 gdb will execute them on startup if you added the following line to $HOME/.gdbinit : 如果将以下行添加到$HOME/.gdbinit gdb将在启动时执行它们:

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

Now you can place commands into /path/to/project/.gdbinit , like this: 现在,您可以将命令放入/path/to/project/.gdbinit ,如下所示:

break main
run --foo=bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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