I am looking to set up the path for the source code when debugging with gdb. I chose to do that with a .gdbinit file.
我想在使用gdb进行调试时设置源代码的路径。我选择使用.gdbinit文件。
Basically, it contains a command:
基本上,它包含一个命令:
directory="/path/to/src".
However, I would like to be able to specify that command as:
但是,我希望能够将该命令指定为:
directory="$SOURCESROOT/src"
where SOURCESROOT
is an environment variable. And, if possible, being able to do that inside gdb debuuging session too, by entering directory=$SOURCESROOT/folder
.
其中SOURCESROOT是一个环境变量。并且,如果可能的话,也可以通过输入directory = $ SOURCESROOT / folder在gdb debuuging会话中执行此操作。
Basically, I am looking to access inside gdb (or inside .gdbinit) the environment variables.
基本上,我希望访问内部gdb(或.gdbinit内部)的环境变量。
But not the environment of the debugee (set env and so on), but the environment of the gdb itself (ie. of the bash prompt where I type in the first place "gdb program").
但不是debugee的环境(设置env等),而是gdb本身的环境(即我首先输入的bash提示符“gdb program”)。
While typing shell $SOURCESROOT
inside gdb session shows the content of the environment variable, this is quite useless, as I cannot enter: directory=shell $SOURCESROOT
.
虽然在gdb会话中键入shell $ SOURCESROOT会显示环境变量的内容,但这是无用的,因为我无法输入:directory = shell $ SOURCESROOT。
PS: Anybody found an ideal setup for Linux (Debian) to download the sources with "apt-get source", to update those with some kind of "apt-get update" utopic command and to install them so that gdb will automatically find these sources?
PS:任何人都找到了一个理想的设置Linux(Debian)下载带有“apt-get source”的源代码,用某种“apt-get update”utopic命令更新那些并安装它们以便gdb自动找到这些来源?
3 个解决方案
#1
17
Nevermind, I found how to do it by using Python scripting.
没关系,我发现如何使用Python脚本来做到这一点。
My .gdbinit
file is now:
我的.gdbinit文件现在是:
python
import os
gdb.execute('directory' + os.environ['SOURCES'] + '/package_name/src')
end
show directories
#2
1
If you don't want to involve python, then this could work?
如果你不想涉及python,那么这可行吗?
"show environment [varname] Print the value of environment variable varname to be given to your program when it starts. If you do not supply varname, print the names and values of all environment variables to be given to your program. You can abbreviate environment as env."
“show environment [varname]打印环境变量varname的值,它在程序启动时给你的程序。如果你不提供varname,打印要给你的程序的所有环境变量的名称和值。你可以缩写环境作为环境。“
ftp://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_19.html
ftp://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_19.html
Maybe they could be used for conditions as well:
也许他们也可以用于条件:
https://www.adacore.com/gems/gem-119-gdb-scripting-part-1
https://www.adacore.com/gems/gem-119-gdb-scripting-part-1
#3
1
(6 year late!)
(已晚6年!)
Don't use .gdbinit
for this purpose. It does not expand env vars. Instead, use this commandline to launch gdb:
不要为此目的使用.gdbinit。它不会扩展env vars。相反,使用此命令行启动gdb:
gdb --init-eval-command="set dir $SOURCESROOT/src"
(gdb) show dir
/path/to/src
FYI this technique can be used to set other critical variables, e.g
仅供参考,这项技术可用于设定其他关键变量,例如
gdb --eval-command="set sysroot $SYSROOTDIR"
Which sets sysroot
and solib-absolute-prefix
in gdb
在gdb中设置sysroot和solib-absolute-prefix
#1
17
Nevermind, I found how to do it by using Python scripting.
没关系,我发现如何使用Python脚本来做到这一点。
My .gdbinit
file is now:
我的.gdbinit文件现在是:
python
import os
gdb.execute('directory' + os.environ['SOURCES'] + '/package_name/src')
end
show directories
#2
1
If you don't want to involve python, then this could work?
如果你不想涉及python,那么这可行吗?
"show environment [varname] Print the value of environment variable varname to be given to your program when it starts. If you do not supply varname, print the names and values of all environment variables to be given to your program. You can abbreviate environment as env."
“show environment [varname]打印环境变量varname的值,它在程序启动时给你的程序。如果你不提供varname,打印要给你的程序的所有环境变量的名称和值。你可以缩写环境作为环境。“
ftp://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_19.html
ftp://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_19.html
Maybe they could be used for conditions as well:
也许他们也可以用于条件:
https://www.adacore.com/gems/gem-119-gdb-scripting-part-1
https://www.adacore.com/gems/gem-119-gdb-scripting-part-1
#3
1
(6 year late!)
(已晚6年!)
Don't use .gdbinit
for this purpose. It does not expand env vars. Instead, use this commandline to launch gdb:
不要为此目的使用.gdbinit。它不会扩展env vars。相反,使用此命令行启动gdb:
gdb --init-eval-command="set dir $SOURCESROOT/src"
(gdb) show dir
/path/to/src
FYI this technique can be used to set other critical variables, e.g
仅供参考,这项技术可用于设定其他关键变量,例如
gdb --eval-command="set sysroot $SYSROOTDIR"
Which sets sysroot
and solib-absolute-prefix
in gdb
在gdb中设置sysroot和solib-absolute-prefix