python-lldb脚本完成后继续 [英] Continue after python-lldb script has finished

查看:99
本文介绍了python-lldb脚本完成后继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 python-lldb 脚本完成之后,是否有更好的方法来发出 continue 命令?

Is there a better way to issue the continue command, after my python-lldb script has finished ?

def HelloWorld(debugger, command, result, internal_dict):
    """
        HelloWorld function. It will print "Hello World", regardless of where lldb stopped.
        Auto-Continues after script has ran.
    """
    target = debugger.GetSelectedTarget()
    process = target.GetProcess()
    print("[*] Hello World from :{}".format(process))
    process.Continue()

该示例将控制权交还给该应用,但我不再具有交互式 lldb 控制台.

The example gives control back to the app but I no longer have the interactive lldb console.

此页面上的答案没有帮助: LLDB:Python脚本执行完毕后,静默继续

The answers on this page didn't help: LLDB: silently continue after python script is done executing

旁注:如果我通过 XCode Terminal 附加,则行为相同.

Sidenote: same behavior if I attach via XCode or Terminal.

推荐答案

lldb可以在两种模式下同步"运行.或异步".

lldb can run in two modes "synchronous" or "asynchronous".

在异步模式下,所有执行控制命令(步骤,下一步等)都将完成,并在被调试者开始执行后立即将控制权返回给lldb.

In asynchronous mode, all execution control commands (step, next, etc.) complete and return control to lldb as soon as the debugee starts executing.

在同步模式下,执行控制命令等待进程停止后再返回.

In synchronous mode, execution control commands wait for the process to stop before returning.

lldb可以通过启发式找出正确的同步/异步行为,但也可以使用 SBDebugger.SetAsync API手动设置.

The correct sync/async behavior is figured out heuristically by lldb, but can also be set by hand using the SBDebugger.SetAsync API.

在执行Python支持的lldb命令时,lldb会将自己设置为同步模式.这通常就是您想要的,例如,如果您希望命令执行某个步骤,检查某项内容并执行另一步骤,那么您不希望第一个 step 命令在该过程中的实际步骤执行之前返回完成或您的检查"行动将为时过早.

When executing a Python backed lldb command, lldb sets itself into synchronous mode. That's generally what you want, for instance if you want your command do a step, check something and do another step, you wouldn't want the first step command to return before the actual step in the process was complete or your "check something" action would happen too soon.

但是,如果希望命令在继续执行后立即返回控制权,而不是等待进程停止,则可以在最后的进程之前调用 debugger.SetAsync(True)在您的Python支持的命令中继续.(p .

However, if you want your command to return control immediately after continuing, not waiting for the process to stop, then you can call debugger.SetAsync(True) right before the final process.Continue() in your Python backed command.

请注意,这个故事还有另一个复杂之处.当lldb启动进程时,默认行为是与调试对象共享终端.因此,在进程运行时,它将拥有终端,并且在进程停止之前,您不会看到lldb提示符(该消息会覆盖进程输出)或输入命令的方式.如果要在进程运行时让调试器处于活动状态并接受命令,则需要给lldb&该应用程序的单独终端.在lldb中,使用 process launch --tty ,在Xcode中,运行方案的选项"选项卡中有一组单选按钮,可让您选择一个单独的终端,而不使用Xcode控制台.

Note, there's one other complication to this story. When a process is launched by lldb, the default behavior is to share the terminal with the debugee. So while the process is running, it will own the terminal, and until the process stops you won't see an lldb prompt (that would overwrite process output) or have a way to enter commands. If you want to have the debugger live and accepting commands while the process is running you need to give lldb & the app separate terminals. In lldb, use process launch --ttyand in Xcode there's a set of radio buttons in the Options tab of the Run scheme that lets you choose a separate terminal instead of using the Xcode Console.

顺便说一句,听起来像是从exe_ctx参数获得的过程(在此版本中已将其遗漏)对您不起作用?,但这也许与其他问题混淆了.如果我在继续之前先设置SetAsync(True),则继续 exe_ctx.process 对我来说效果很好.

BTW, it sounded from your note like the process you got from the exe_ctx argument (which you've left out in this version) wasn't working for you?, But maybe that's confused with other issues. If I SetAsync(True) before doing the continue, then continuing exe_ctx.process works fine for me.

最后,如果您的Python命令确实将进程状态从停止"切换为运行",则应通过调用以下命令告知lldb:

And finally, if your Python command does switch the process state from stopped to running, you should tell lldb that by calling:

result.SetStatus(lldb.eReturnStatusSuccessContinuingResult)

result.SetStatus(lldb.eReturnStatusSuccessContinuingNoResult)

这很重要,如果您的命令在断点回调或停止挂接中使用,则lldb使用结果来跟踪断点命令或停止挂接是否强制重启了目标.

This matters if your command gets used in a breakpoint callback or stop-hook, where lldb uses the result to track whether the breakpoint command or stop hook forcibly restarted the target.

这篇关于python-lldb脚本完成后继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆