Use gdb custom commands for .gdbinit files
background
When gdb is started, you usually want to add your own commands, for example layout asm
, b main
these.
Method 1 - shell script
Create a new shell script
gdb-multiarch --tui a.out \
--eval-command="target remote localhost:1234" \
--eval-command="b main"
Method 2 - .gdbinit file
When gdb starts, it will search for .gdbinit
this file in your current working directory and interpret its contents as a gdb command, so if I name the script .gdbinit
, it will process some of your commonly used commands when it starts. .
In actual use, there will be a problem. For example, you need to /home/tyustli/code/c_project/.gdbinit
write code in , so you want to add it in the current directory .gdbinit
to facilitate debugging.
At this time, if you /home/tyustli/code/c_project/.gdbinit
add it directly .gdbinit
and then call GDB,
the following error will be reported:
auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
The solution is as follows:
1. Add one under /home/tyustli .gdbinit
. This file will be called by default when GDB is initialized.
2. Edit this .gdbinit
and addset auto-load safe-path /home/tyustli/code/c_project/.gdbinit
set auto-load safe-path /home/tyustli/code/c_project/.gdbinit
3. In /home/tyustli/code/c_project/.gdbinit
the directory (that is, the directory you want to debug), also add a .gdbinit
4. Edit it .gdbinit
and add some instructions you need, for example:
layout asm
b 5
reference
https://blog.csdn.net/shenjin_s/article/details/103196892