【发布时间】:2018-09-07 00:15:52
【问题描述】:
我正在尝试在调用某个函数时执行 Python 回调。如果通过运行进程调用该函数,它可以工作,但是当我使用SBTarget.EvaluateExpression调用该函数时它会失败
这是我的 C 代码:
#include <stdio.h>
int foo(void) {
printf("foo() called\n");
return 42;
}
int main(int argc, char **argv) {
foo();
return 0;
}
这是我的 Python 脚本:
import lldb
import os
def breakpoint_cb(frame, bpno, err):
print('breakpoint callback')
return False
debugger = lldb.SBDebugger.Create()
debugger.SetAsync(False)
target = debugger.CreateTargetWithFileAndArch('foo', 'x86_64-pc-linux')
assert target
# Break at main and start the process.
main_bp = target.BreakpointCreateByName('main')
process = target.LaunchSimple(None, None, os.getcwd())
assert process.state == lldb.eStateStopped
foo_bp = target.BreakpointCreateByName('foo')
foo_bp.SetScriptCallbackFunction('breakpoint_cb')
# Callback is executed if foo() is called from the program
#process.Continue()
# This causes an error and the callback is never called.
opt = lldb.SBExpressionOptions()
opt.SetIgnoreBreakpoints(False)
v = target.EvaluateExpression('foo()', opt)
err = v.GetError()
if err.fail:
print(err.GetCString())
else:
print(v.value)
我收到以下错误:
error: Execution was interrupted, reason: breakpoint 2.1.
The process has been left at the point where it was interrupted, use "thread
return -x" to return to the state before expression evaluation
当断点没有回调时,我得到了同样的错误,所以确实是断点导致了问题,而不是回调。在设置opt.SetIgnoreBreakpoints(True) 时评估表达式,但这对我的情况没有帮助。
这是可以修复的问题,还是错误或缺失的功能?
操作系统为 Arch Linux,LLDB 版本为 6.0.0,来自存储库。
【问题讨论】: