如何在Xcode中存储/替换在调试器LLDB中的本地变量

发布于 2025-02-06 06:49:58 字数 491 浏览 1 评论 0 原文

我是Xcode的新手,并由Pycharm来了。在Pycharm中,我可以使用Watcher执行语句,并在调试器模式下作为本地变量存储。我怎么能从Xcode Debugger LLDB做同样的事情? 例如,

let a = 5
letba = 5
let aPlusb = Self.addFunc(a, b)

第3行上的一个位置调试器。如何调用self.addfunc()并存储到一些变量 xy

我尝试过表达式或e在 lldb 下,然后 po xy ,但它不适合错误

error: expression failed to parse:
error: <EXPR>:8:1: error: cannot find 'xy' in scope
`xy`

I am new to Xcode and came by pycharm. In pycharm, I am able to use watcher to execute the statement and store as local variable in debugger mode. How could I do that same thing from Xcode debugger lldb?
for example

let a = 5
letba = 5
let aPlusb = Self.addFunc(a, b)

after place debugger on line 3. how can i call Self.addFunc() and store into some variable xy

I have tried expression or e under lldb and then po xy but it does not work with error

error: expression failed to parse:
error: <EXPR>:8:1: error: cannot find 'xy' in scope
`xy`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红衣飘飘貌似仙 2025-02-13 06:49:58

表达式解析器是您要使用的命令来创建可以在LLDB中记录值的刮擦变量的命令。有两种方法可以做到这一点。

首先,当您使用LLDB表达式解析器评估任何表达式时,LLDB会创建一个“结果变量”,该变量存储了表达式的结果:

(lldb) expr myVar
(Int) $R0 = 10

可以在将来的表达式中使用,例如:

(lldb) expr print($R0)
10

您可以做到的另一种方法是利用优势在LLDB表达式中以 $ 开头的标识符被视为LLDB“持续声明”,可以在以后的表达中使用。除了几个这样的例外外,LLDB解析的表达与当前帧的上下文中编译的源代码中的表达完全相同。因此,您只使用与Swift中定义标识符相同的语法,因此:

(lldb) expr var $myVar = 10
(lldb) expr print($myVar)
10

顺便说一句,我不会使用“标识符”而不是上面的“变量”来抽象。对于标识符的其他实例,例如类型和功能定义也是如此。

You're right that the expression parser is the command you want to use to create scratch variables that can record values in lldb. There are two ways to do this.

First of all, when you evaluate any expression using lldb's expression parser, lldb creates a "result variable" which stores the result of the expression:

(lldb) expr myVar
(Int) $R0 = 10

This can be used in future expressions, e.g.:

(lldb) expr print($R0)
10

The other way you can do this is to take advantage of the lldb convention that an identifier in an lldb expression which begins with a $ is treated as an lldb "persistent declaration", and can be used in future expressions. Except for a very few exceptions like this, lldb parses expressions exactly as they would be in source code compiled in the context of the current frame. So you just use the same syntax you would use to define the identifier in swift, so:

(lldb) expr var $myVar = 10
(lldb) expr print($myVar)
10

BTW, I'm not being abstruse using "identifier" instead of "variable" above. The same convention holds for other instances of identifiers, e.g. for type and function definitions as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文