LLDB:实现接受用户输入的自定义命令
lldb: implement custom command taking user input
我正在使用python通过自定义命令gm
扩展lldb,该命令调用C++函数cli(const char* params)
然后。 因此,可以暂停 xcode(从而启动 lldb)并键入...
(lldb) gm set value
以触发呼叫cli("set value")
然后。
C++函数cli
可以利用std::cout
来打印某种状态,但我不能使这个函数"交互式",即消耗用户输入:
void cli(const char* params) {
std::cout << "params: " << params << std::endl; // works
std::string userInput;
std::cin >> userInput; // does not work; is simply ignored
}
问题:如何使cli
具有交互性,使其消耗(并进一步处理)用户输入?
为了进一步展示我想要实现的目标:有内置的lldb命令,如expr
(没有参数),它们进入交互模式:
(lldb) expr
Enter expressions, then terminate with an empty line to evaluate:
1 2+2
2
(int) $0 = 4
我希望在自己的命令中具有类似的行为,即输入gm
然后交互地询问参数:
(lldb) gm
Enter generic model parameters; Terminate interactive mode with "end":
1 set value
2 params: set value
3 end
为了完整起见,请参阅当前用于调用cli
-function 的 python 脚本:
def gm(debugger, command, result, internal_dict):
cmd = "po cli(""+command+"")"
lldb.debugger.HandleCommand(cmd)
# And the initialization code to add your commands
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f gm.gm gm')
print 'The "gm" python command has been installed and is ready for use.'
以及注册此脚本的.lldbinit
-文件中的行:
command script import ~/my_commands.py
lldb 在内部保留了一堆"I/O 处理程序",因此例如expr
只是将"Expr I/O 处理程序"推送到堆栈上,收集输入直到完成,然后从堆栈中弹出自己并运行命令。
在C++ SB API中,有一个看起来像SB类(SBInputReader)的第一个草图,但我认为它不完整,目前还没有暴露给Python。 所以我认为还没有足够的连接让你从 Python 做这件事。
相关文章:
- 如何使用运算符>>在自定义字符串中输入多个单词?
- CLion 是否支持自定义输入?如果是,我在哪里输入它们?
- 编译一个自定义的tf操作,其中输入是5d张量
- 尝试检查输入的文本与我自己的自定义答案
- LLDB:实现接受用户输入的自定义命令
- 自定义 LowLevelMouseProc 回调函数不阻止输入
- 字符串流中的自定义字符串输入
- 访问自定义OP的输入值时的segmenation故障
- 自定义张量流操作获取可变输入张量的列表
- 处理自定义QT小部件中的输入事件
- QlineEdit:显示一个处理过的文本,而不是输入的文本,而是保留它(自定义回声模式)
- DirectX Toolkit加载了带有自定义HLSL着色器"顶点"着色器输入签名的模型
- 通过管道将自定义标准输入传输到C++中的系统调用
- 自定义运行对话框输入
- 运算符 -> 不适用于自定义输入迭代器
- 自定义 sprintf(..) 样式函数,仅具有可变输入
- C++自定义用户输入调用变量
- 使用"<<"将值输入到自定义类中
- 矢量排序只是使用自定义比较器反转输入
- SWIG参考输入,自定义类输出