【发布时间】:2018-10-27 01:46:35
【问题描述】:
我正在使用 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-commands,如 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
【问题讨论】: