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

时间:2023-01-18 09:13:17

Does anybody know how to 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. Thanks for answer.

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

3 个解决方案

#1


54  

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

lldb will answer with something like...

lldb会回答类似......

Breakpoint 1: 4345 locations

Now just press the Continue button.

现在只需按“继续”按钮即可。

breakpoint set is 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 -s option is used to limit the scope to your executable (needed to exclude frameworks).

断点集是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).

要禁用断点,请键入断点delete 1(插入正确的断点号)。

#2


12  

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”表示选择器。

#3


3  

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

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

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

断点设置-r'\ [ClassName。* \] $'

to add breakpoints to all methods in class

将断点添加到类中的所有方法

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

断点设置-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 ' *- *\('

断点设置-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前缀

This line (wzbozon answer):

这一行(wzbozon答案):

breakpoint set -n viewDidLoad

断点设置-n viewDidLoad

will set breakpoints on all methods viewDidLoad in all classes.

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

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

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

#1


54  

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

lldb will answer with something like...

lldb会回答类似......

Breakpoint 1: 4345 locations

Now just press the Continue button.

现在只需按“继续”按钮即可。

breakpoint set is 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 -s option is used to limit the scope to your executable (needed to exclude frameworks).

断点集是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).

要禁用断点,请键入断点delete 1(插入正确的断点号)。

#2


12  

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”表示选择器。

#3


3  

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

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

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

断点设置-r'\ [ClassName。* \] $'

to add breakpoints to all methods in class

将断点添加到类中的所有方法

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

断点设置-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 ' *- *\('

断点设置-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前缀

This line (wzbozon answer):

这一行(wzbozon答案):

breakpoint set -n viewDidLoad

断点设置-n viewDidLoad

will set breakpoints on all methods viewDidLoad in all classes.

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

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

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