Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

shell - Invoke gdb to automatically pass arguments to the program being debugged

I'd like to write a script that (under certain conditions) will execute gdb and automatically run some program X with some set of arguments Y. Once the program has finished executing the user should remain at gdb's prompt until s/he explicitly exits it.

One way to do this would be to have the script output the run command plus arguments Y to some file F and then have the script invoke gdb like this:

gdb X < F

But is there a way to do this without introducing a temporary file?

Thanks.

question from:https://stackoverflow.com/questions/322110/invoke-gdb-to-automatically-pass-arguments-to-the-program-being-debugged

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to run some commands through GDB and then have it exit or run to completion, just do

echo commands | gdb X

If you want to leave it at the command prompt after running those commands, you can do

(echo commands; cat) | gdb X

This results in echoing the commands to GDB, and then you type into the cat process, which copies its stdin to stdout, which is piped into GDB.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...