LLDB:使用SBTarget.EvaluateExpression对断点进行Python回调

问题描述 投票:0回答:1

我正在尝试在调用某个函数时执行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来自存储库。

python lldb
1个回答
0
投票

IgnoreBreakpoints设置并不意味着您在运行时不会遇到断点。例如,您会注意到断点命中计数将以任何方式更新。相反,它意味着:

是的:如果我们遇到断点,我们将自动恢复

错误:如果我们遇到断点,我们将会停止

False功能用于调用函数,因为您希望在函数中停止它或为调试该函数而调用的函数。因此,重写断点条件和命令是正确的做法。

出于您的目的,我认为您希望IgnoreBreakpoints为True,因为您还希望表达式求值成功。

OTOH,如果我理解你的意图,导致你出问题的是当IgnoreBreakpoints为false时,lldb不会调用断点的命令。当我们强行停止时,它应该只跳过那一点工作。

© www.soinside.com 2019 - 2024. All rights reserved.