【问题标题】:LLDB: Python callback on breakpoint with SBTarget.EvaluateExpressionLLDB:使用 SBTarget.EvaluateExpression 在断点上进行 Python 回调
【发布时间】: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,来自存储库。

【问题讨论】:

    标签: python lldb


    【解决方案1】:

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

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

    错误:如果我们遇到断点,我们无论如何都会停止

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

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

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

    【讨论】:

      猜你喜欢
      • 2022-06-12
      • 1970-01-01
      • 2017-01-06
      • 2014-07-06
      • 2018-05-13
      • 1970-01-01
      • 2023-04-05
      • 2014-09-03
      • 2019-05-21
      相关资源
      最近更新 更多