LLDB-自动步进并打印行列表,直到断点 [英] LLDB - automatically step, and print list of lines, until a breakpoint

查看:94
本文介绍了LLDB-自动步进并打印行列表,直到断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想继续执行以下命令:

I'd like to keeping on executing the following command:

(lldb) s

直到达到断点.或者只是当它达到某些功能(例如read())

until it reach a breakpoint. Or simply when it reaches some function (eg. read())

在发生这种情况时,我想按照执行顺序保存行号列表(以及文件的完整路径).因此,例如.保存到如下所示的文件(LOG.csv):

While this is happening, I'd like to save the list of line numbers (and the full path of the files) in the order that they were executed. So for eg. save to a file (LOG.csv) that looks like this:

Number;LineNumber;FilePath
1;1080;/Users/user/Documents/zDEVELOP/bash-3.2.57/shell.c
2;1082;/Users/user/Documents/zDEVELOP/bash-3.2.57/shell.c
3;1083;/Users/user/Documents/zDEVELOP/bash-3.2.57/shell.c
4;40;/Users/user/Documents/zDEVELOP/bash-3.2.57/readline.c 
5;71;/Users/user/Documents/zDEVELOP/bash-3.2.57/lib/readline/readline.c 
6;72;/Users/user/Documents/zDEVELOP/bash-3.2.57/lib/readline/readline.c

**请注意,需要文件的完整路径.请参阅第4行与第5行,它们实际上来自2个具有相同名称的不同文件.**数字是指执行顺序.

**Note the full path of the files are needed. See row 4 VS row 5 which are actually from 2 different files with the same name. **Number refers to the order of execution.

格式将类似于上面,但是最好可以自定义.

The format will be something like above, but preferably this can be customised.

**如果可能的话,我也想先将程序运行到某个断点,然后再逐步执行直到另一个断点.

**If possible, I'd also like to run the program first up to some breakpoint, and then step until another breakpoint.

该如何完成?我可以使用Python API还是C API?其他方法也是可能的.

How should this be done? Can I use the Python API, or C API? Other means are also possible.

有关API的答案,请务必提及用于(1)步进(2)检索当前行(3)检索完整文件路径(4)检查是否已达到函数read()的类和方法.

For answers on the API, do mention which class and methods to use for (1) stepping (2) retrieving the current line (3) retrieve the full file path (4) checking that the function read() has been reached

推荐答案

有两种方法可以做到这一点.第一种是直接在Script Interpreter REPL中使用Python(通过lldb中的 script 命令输入).然后,在Python REPL中,您可以编写一个while循环,该循环执行您要执行的任何打印操作,检查停止条件,如果不满意,则在您关注的线程上调用SBThread.StepInto或StepOver.

There are two ways to do this. The first is to use Python directly in the Script Interpreter REPL (enter this with the script command in lldb). Then in the Python REPL, you can write a while loop that does whatever printing you want to do, checks your stop condition, and if it is not satisfied, calls SBThread.StepInto or StepOver on the thread you are following.

有关lldb Python API的更多信息,请点击此处:

More info on the lldb Python API's is here:

https://lldb.llvm.org/python_api.html

您需要了解的一件事是lldb的调试器具有两种运行模式"synchronous"和"synchronous".和异步".如果调试器处于同步"状态,则调试器处于同步"状态.模式,而不是使调试对象运行的任何命令都将等待返回,直到调试对象由于某种原因停止运行.在异步"中,模式下,"SBThread.StepInto","SBThread.StepOver"等方法立即返回,并且您使用lldb的事件系统来通知停止.前者对您的任务更加方便,因此在您的 script 会话开始时,只需执行以下操作:

The one thing you'll want to be aware of is that lldb's debugger has two running modes "synchronous" and "asynchronous". If the debugger is in "synchronous" mode than any command that makes the debugee run waits to return until the debugee stops for some reason. In "asynchronous" mode, the "SBThread.StepInto", "SBThread.StepOver", etc. methods return immediately and you use lldb's event system to be notified of stops. The former is much more convenient for your task, so at the beginning of your script session just do:

>>> lldb.debugger.SetAsync(False)

如果此逻辑使用起来更方便,也可以将其打包在基于Python的命令中.

You can also package this logic in a Python based command if that makes using it more convenient.

更理想的方法是使用lldb脚本化步骤"计划.这里有一些使用该方法的示例:

The fancier way to do this is to use an lldb "scripted step" plan. There are a few examples of ways to use that here:

https://github.com/llvm/llvm-project/blob/main/lldb/examples/python/scripted_step.py

文件开头的标头对此进行了解释,并在此处提供了更多文档:

The header at the beginning of the file has some explanation of how this works, and there's more docs here:

https://lldb.llvm.org/use/python-reference.html#using-the-python-api-to-create-custom-stepping-logic

尽管设置有些令人生畏,但由于您只是在回复一些简单的消息,因此一旦弄清楚了它是如何工作的,最终实现通常很简单.

Though the setup is a little daunting, since you are just replying to a few simple messages, once you figure out how it works, the implementation is often pretty simple in the end.

要记住的另一件事是,在lldb的python解释器中运行的所有代码都共享lldb控制台.因此,如果您在编写的某些代码中调用pdb调试器,则会在控制台中看到pdb提示符,并且可以查看变量并逐步执行python代码.例如.插入:

One other thing to remember is that all the code that runs in lldb's python interpreter shared the lldb console. So if you invoke the pdb debugger in some code you've written, you'll get the pdb prompt in the console and can view variables and step along through your python code. E.g. insert:

import pdb; pdb.set_trace()

在代码中的某处设置断点.

to set a breakpoint somewhere in your code.

这篇关于LLDB-自动步进并打印行列表,直到断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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