gdb python api: 如何自动导入脚本文件
gdb python api: how to automatically import a script file
如何添加一个 python 文件,它会在我启动 gdb
时加载?例如,作为测试我添加了:
# /home/ubuntu/lib/python3.6/site-packages/objfile-gdb.py
print ("Hello")
但是,当我尝试加载它时,它似乎不起作用:
(gdb) set auto-load scripts-directory /home/ubuntu/lib/python3.6/site-packages
(gdb) info auto-load python
No auto-load scripts.
你应该如何正确加载它?我正在使用这个 as a reference
.
如果您只想为每个 gdb 会话添加辅助函数,则在 the gdb user initialization file 中使用 source
加载 python 脚本会容易得多,通常 ~/.gdbinit
:
source /home/ubuntu/lib/python3.6/site-packages/objfile-gdb.py
如果你还想使用“objfile-gdb.ext”样式自动加载,你必须遵循the script naming convention:
script-name is formed by ensuring that the file name of objfile is absolute, following all symlinks, and resolving . and .. components, and appending the -gdb.ext suffix. If this file exists and is readable, GDB will evaluate it as a script in the specified extension language.
例如,如果你想为gdb /usr/bin/tree
这样的会话加载脚本,脚本应该放在/home/ubuntu/lib/python3.6/site-packages/usr/bin/tree-gdb.py
,此外,你可能需要调整auto-load safe-path
config。
如何添加一个 python 文件,它会在我启动 gdb
时加载?例如,作为测试我添加了:
# /home/ubuntu/lib/python3.6/site-packages/objfile-gdb.py
print ("Hello")
但是,当我尝试加载它时,它似乎不起作用:
(gdb) set auto-load scripts-directory /home/ubuntu/lib/python3.6/site-packages
(gdb) info auto-load python
No auto-load scripts.
你应该如何正确加载它?我正在使用这个 as a reference
.
如果您只想为每个 gdb 会话添加辅助函数,则在 the gdb user initialization file 中使用 source
加载 python 脚本会容易得多,通常 ~/.gdbinit
:
source /home/ubuntu/lib/python3.6/site-packages/objfile-gdb.py
如果你还想使用“objfile-gdb.ext”样式自动加载,你必须遵循the script naming convention:
script-name is formed by ensuring that the file name of objfile is absolute, following all symlinks, and resolving . and .. components, and appending the -gdb.ext suffix. If this file exists and is readable, GDB will evaluate it as a script in the specified extension language.
例如,如果你想为gdb /usr/bin/tree
这样的会话加载脚本,脚本应该放在/home/ubuntu/lib/python3.6/site-packages/usr/bin/tree-gdb.py
,此外,你可能需要调整auto-load safe-path
config。