【GDB】.gdbinit file

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 mainthese.

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 .gdbinitthis 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/.gdbinitwrite code in , so you want to add it in the current directory .gdbinitto facilitate debugging.

At this time, if you /home/tyustli/code/c_project/.gdbinitadd it directly .gdbinitand 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 .gdbinitand 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/.gdbinitthe directory (that is, the directory you want to debug), also add a .gdbinit
4. Edit it .gdbinitand add some instructions you need, for example:

layout asm
b 5

reference

https://blog.csdn.net/shenjin_s/article/details/103196892

Guess you like

Origin blog.csdn.net/tyustli/article/details/133363847