How to pass parameters to GDB script?

Viewed 1499

I have a GDB script which I pass to GDB:

gdb -x my_script.gdb

Inside my_script.gdb I have a variable, say foo, which I use as a parameter. Right now, I manually change foo inside the script whenever I want to try a different value for foo.

What I would like to do, is pass a command-line parameter when launching GDB with the command above, so that foo takes the value of that parameter. Is this possible?

1 Answers

You can emulate this behavior with User-defined Commands. You can define some function in my_script.gdb script and call it with arguments from command line:

$ cat my_script.gdb
define func
   print $arg0
end
$ gdb -q -x my_script.gdb -ex "func 123"
$1 = 123
(gdb) 
Related