如何在 Xcode 中的所有方法上自动设置断点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9275195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:18:28  来源:igfitidea点击:

How to automatically set breakpoints on all methods in Xcode?

xcodebreakpoints

提问by Matrosov Alexander

How do I automatically set breakpoints on all methods in Xcode? I want to know how my program works, and which methods invoke when I interact with the user interface.

如何在 Xcode 中的所有方法上自动设置断点?我想知道我的程序是如何工作的,以及当我与用户界面交互时调用了哪些方法。

回答by Nikolai Ruhe

  1. Run your app in Xcode.
  2. Press ??Y (Debug -> Pause).
  3. Go to the debugger console: ??C
  4. Type breakpoint set -r . -s <PRODUCT_NAME>(insert your app's name).
  1. 在 Xcode 中运行您的应用程序。
  2. 按??Y(调试-> 暂停)。
  3. 转到调试器控制台:??C
  4. 输入breakpoint set -r . -s <PRODUCT_NAME>(插入您的应用程序名称)。

lldb will answer with something like...

lldb 会回答类似...

Breakpoint 1: 4345 locations

Now just press the Continue button.

现在只需按继续按钮。

breakpoint setis lldb's command to create breakpoints. The location is specified using a regular expression (-r) on function/method names, in this case .which matches any method. The -soption is used to limit the scope to your executable (needed to exclude frameworks).

breakpoint set是 lldb 创建断点的命令。该位置使用-r函数/方法名称上的正则表达式 ( ) 指定,在这种情况下.匹配任何方法。该-s选项用于限制可执行文件的范围(需要排除框架)。

When you run your app lldb will now break whenever the app hits a function from your main executable.

当您运行您的应用程序时,只要应用程序从您的主可执行文件中调用一个函数,lldb 现在就会中断。

To disable the breakpoints type breakpoint delete 1(insert proper breakpoint number).

禁用断点类型breakpoint delete 1(插入正确的断点编号)。

回答by Denis Kutlubaev

In some cases, it is more convenient to set breakpoints only on some of the methods.

在某些情况下,仅在某些方法上设置断点更方便。

Using LLDB we can put breakpoint on all ViewDidLoad methods by name, for example.

例如,使用 LLDB,我们可以按名称在所有 ViewDidLoad 方法上放置断点。

(lldb) breakpoint set -n ViewDidLoad

Here "-n" means by name.

这里的“-n”是指名字。

Also, we can put breakpoints by selector name:

此外,我们可以通过选择器名称放置断点:

(lldb) breakpoint set -S alignLeftEdges:

Here "-S" means by selector.

这里的“-S”表示选择器。

回答by Piotr Wasilewicz

There is many possibilities but there is no way to set breakpoints only to your functions. You can try:

有很多可能性,但没有办法只为您的函数设置断点。你可以试试:

breakpoint set -r '\[ClassName .*\]$'

breakpoint set -r '\[ClassName .*\]$'

to add breakpoints to all methods in class

为类中的所有方法添加断点

breakpoint set -f file.m -p ' *- *\('

breakpoint set -f file.m -p ' *- *\('

to add breakpoints to all methods in file

为文件中的所有方法添加断点

You can also use it with many files:

您还可以将它与许多文件一起使用:

breakpoint set -f file1.m -f file2.m -p ' *- *\('

breakpoint set -f file1.m -f file2.m -p ' *- *\('

Shortcut:

捷径:

br se -f file1.m -f file2.m -p ' *- *\('

br se -f file1.m -f file2.m -p ' *- *\('

You can add breakpoints to all methods in all classes with some prefix (and it could me only your classes)

您可以使用一些前缀为所有类中的所有方法添加断点(它只能是您的类)

br se -r . -s Prefix

br se -r . -s Prefix

This line (wzbozon answer):

这一行(wzbozon 回答):

breakpoint set -n viewDidLoad

breakpoint set -n viewDidLoad

will set breakpoints on all methods viewDidLoadin all classes.

viewDidLoad在所有类的所有方法上设置断点。

I tried but I couldn't set breakpoints only on our own methods.

我试过了,但我不能只在我们自己的方法上设置断点。