I do not see native GDB commands can do this: check if a gdb script file exists, if so, source the file.
Maybe I need to resort to python, but still want to ask here.
The use case is, I am working on several different computing environments, each one has some different GDB setup. I like to add the above to ~/.gdbinit so that even in each environment I have a different GDB script, it is automatically sourced in my ~/.gdbinit.
There's no built-in way to do this. It can be done via scripting in a couple of different ways.
The classic way is to use shell
to test the file existence and have it write out a file that then decides what to do. Something like:
(gdb) shell if test -f blah; then echo source blah; fi > /tmp/F
(gdb) source /tmp/F
This is pretty ugly, but it would work.
Alternatively you can write a Python command to do this quite easily. Or you can dig up the Python ignore-errors
command, and just use ignore-errors source whatever
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With