在运行程序时将命令传递给gdb

时间:2021-12-26 07:05:36

I am using gdb to debug a program, and I want to have the output of the command

我正在使用gdb来调试程序,我希望得到命令的输出

$(perl -e 'print "A"x20') 

as my argument. How can I do that? This way the argument would be very flexible.

作为我的论点。我怎样才能做到这一点?这样,论证就会非常灵活。

3 个解决方案

#1


You can use the run command and pass it any parameters afterwards which will be arguments.

您可以使用run命令并在之后将任何参数传递给参数。

If you want the above, try:

如果你想要上述内容,请尝试:

run `$(perl -e 'print "A"x20')`

as a command once you start gdb.

一旦你启动gdb作为命令。

#2


The above is slightly off and wouldn't work for me either. If you use the set args command, the following will work (at least on my system):

上面稍微偏了,对我来说也不行。如果使用set args命令,则以下内容将起作用(至少在我的系统上):

set args "`perl -e 'print "A"x20;'`"

As usual, simply type 'run' after to start debugging, and the proper argument should be passed.

像往常一样,只需在开始调试后输入'run',就应该传递正确的参数。

#3


It looks like you didn't start your program with gdb properly. Supposing your program is "a.out", in bash:

看起来你没有正确地使用gdb启动你的程序。假设您的程序是“a.out”,在bash中:

$gdb a.out
(gdb)run `$(perl -e 'print "A"x20')`

Hope this helps you.

希望这对你有所帮助。

#1


You can use the run command and pass it any parameters afterwards which will be arguments.

您可以使用run命令并在之后将任何参数传递给参数。

If you want the above, try:

如果你想要上述内容,请尝试:

run `$(perl -e 'print "A"x20')`

as a command once you start gdb.

一旦你启动gdb作为命令。

#2


The above is slightly off and wouldn't work for me either. If you use the set args command, the following will work (at least on my system):

上面稍微偏了,对我来说也不行。如果使用set args命令,则以下内容将起作用(至少在我的系统上):

set args "`perl -e 'print "A"x20;'`"

As usual, simply type 'run' after to start debugging, and the proper argument should be passed.

像往常一样,只需在开始调试后输入'run',就应该传递正确的参数。

#3


It looks like you didn't start your program with gdb properly. Supposing your program is "a.out", in bash:

看起来你没有正确地使用gdb启动你的程序。假设您的程序是“a.out”,在bash中:

$gdb a.out
(gdb)run `$(perl -e 'print "A"x20')`

Hope this helps you.

希望这对你有所帮助。