如何访问.gdbinit和gdb内部的环境变量? [英] How to access environment variables inside .gdbinit and inside gdb itself?

查看:174
本文介绍了如何访问.gdbinit和gdb内部的环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用gdb调试时设置源代码的路径。我选择使用.gdbinit文件来做到这一点。



基本上,它包含一个命令:

 目录= /路径/到/ SRC。 

但是,我希望能够将该命令指定为:

  directory =$ SOURCESROOT / src

其中 SOURCESROOT 是一个环境变量。并且,如果可能的话,可以在gdb的debuuging会话中输入 directory = $ SOURCESROOT / folder

基本上,我正在寻找访问gdb(或内部.gdbinit)的环境变量。



但是不是恶魔的环境(set env等等),但是gdb本身的环境(即我输入第一个地方的bash提示gdb程序)。

在输入 shell $ SOURCESROOT 里面的gdb会显示环境变量的内容,这是非常没用的,因为我不能输入: directory = shell $ SOURCESROOT



PS:任何人都可以找到Linux(Debian)下载源代码为apt-get source的理想设置,以便用某种apt 更新utopic命令并安装它们以便gdb自动查找这些源代码?

解决方案

Nevermind,我发现如何通过使用Python脚本来完成它。

我的 .gdbinit 文件现在是:

  python 
import os
gdb.execute('directory'+ os.environ ['SOURCES'] +'/ package_name / src')
结束

显示目录


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.

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.

Basically, I am looking to access inside gdb (or inside .gdbinit) the environment variables.

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").

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.

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?

解决方案

Nevermind, I found how to do it by using Python scripting.

My .gdbinit file is now:

python
import os
gdb.execute('directory' + os.environ['SOURCES'] + '/package_name/src')
end

show directories

这篇关于如何访问.gdbinit和gdb内部的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆