如何使用shell命令在GDB中设置环境变量? [英] How to set environment variable within GDB using shell command?

查看:367
本文介绍了如何使用shell命令在GDB中设置环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其环境中仅使用单个变量MyVar来运行gdb.

I want to run gdb with only a single variable MyVar in its environment.

但是,变量的内容相当复杂,包含不可打印的ASCII,因此最好使用例如MyVar=$(python -c 'print("\xff...")').

However, the variable's contents are rather complex, containing non-printable ASCII, and so is best set using e.g. MyVar=$(python -c 'print("\xff...")').

我有两个选择:

  1. 在运行gdb之前在bash中设置MyVar.然后在gdb内部,使用unset environment NAME单独删除所有其他环境变量(非常繁琐!).

  1. Set the MyVar in bash before running gdb. Then inside gdb, remove all other environment variables individually using unset environment NAME (very tedious!).

使用unset environment清除所有环境变量.然后在gdb内,使用shell命令(如上)设置MyVar(如何?)

Clear all environment variables using unset environment. Then inside gdb, set MyVar using a shell command (as above) (how?)

有什么想法吗?

推荐答案

选项2是

选项1可以通过 env(1) 完成

Option 1 can be done with env(1).

$ env -i MyVar=$(python -c 'print("xyz")') gdb
(gdb) show environment
MyVar=xyz
LINES=35
COLUMNS=80

然后,您只需要清除LINES和COLUMNS.

Then you just have to clear LINES and COLUMNS.

这篇关于如何使用shell命令在GDB中设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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