如何在依赖的xcode项目中设置断点

时间:2022-06-10 11:29:03

i have a XCode project (my main xcode project which has its executable). It has dependencies on a few other projects (under the Project tab in Detail View, there are a few other xcode project that it depends on).

我有一个XCode项目(我的主要xcode项目有它的可执行文件)。它依赖于其他一些项目(在Detail View的Project选项卡下,还有一些其他xcode项目依赖它)。

My question is how can I setup breakpoint in the code of the dependent project?

我的问题是如何在依赖项目的代码中设置断点?

I tried this, but this does not work 1. open my main xcode project 2. double click one of the dependent xcode project 3. in the source directory, find the file I want to break and add a breakpoint (by click at the side of the border of the editor, a blue 'bookmark thing' shows up) 4. Go back to 'Build and Go', my application does run but it never breaks at the break point I set in #3.

我尝试了这个,但这不起作用1.打开我的主要xcode项目2.双击一个依赖的xcode项目3.在源目录中,找到我要打破的文件并添加一个断点(通过点击侧面编辑器的边框,显示一个蓝色的“书签事物”)4。回到“Build and Go”,我的应用程序确实运行但它从未在我在#3中设置的断点处中断。

Can someone please help me? I have spent days on this, I can't figure it why.

有人可以帮帮我吗?我花了几天时间,我无法理解为什么。

Thank you.

7 个解决方案

#1


1) Add the breakpoint in your project

1)在项目中添加断点

2) Go into breakpoints view in xcode (top left besides project navigator) The view's icon is like a breakpoint icon

2)进入xcode中的断点视图(项目导航器旁边的左上角)视图的图标就像一个断点图标

3) Right click on the required breakpoint and select "Move to" -> "User"

3)右键单击所需的断点并选择“移至” - >“用户”

If the breakpoint is under "User" project, then it is accessible by all projects.

如果断点位于“用户”项目下,则所有项目都可以访问它。

#2


Whenever I've had trouble setting breakpoints with the Xcode GUI, I've managed to do it with the debugger command line (that is to say, the "lldb" prompt in the output window). For example, to set a breakpoint in source file "client.m" at line 42, type:

每当我在使用Xcode GUI设置断点时遇到问题,我都设法用调试器命令行(也就是输出窗口中的“lldb”提示符)来完成。例如,要在第42行的源文件“client.m”中设置断点,请键入:

(lldb) b client.m:42

Besides being a fix for this particular problem, debugging on the command-line offers far more flexibility and automatability than any GUI could. A good place to start would be the LLDB tutorial. (Full disclosure: I'm a longtime fan of unix and gdb, so there's some bias here).

除了解决这个特定问题之外,在命令行上进行调试提供了比任何GUI更多的灵活性和自动化。一个好的起点是LLDB教程。 (完全披露:我是unix和gdb的长期粉丝,所以这里有一些偏见)。

Of course, as others have mentioned, make sure the library/dependant project is compiled with debug symbols. Hope this helps; good luck.

当然,正如其他人提到的那样,确保使用调试符号编译库/依赖项目。希望这可以帮助;祝好运。

#3


I'll echo Jon-Eric here and also add that if you habitually run your project with Cmd+Enter, you should consider switching to Cmd+Y to enable gdb each time.

我将在这里回应Jon-Eric,并补充一点,如果您习惯性地使用Cmd + Enter运行项目,则应考虑切换到Cmd + Y以每次启用gdb。

#4


a few things here...(some obvious some not)

这里有一些东西......(有些显而易见的不是)

1) be sure that the dependant project is compiled with debug symbols (i'm assuming its a library)

1)确保依赖项目使用调试符号编译(我假设它是一个库)

2) be sure that your active executable is linking against the debug version of your dependent library

2)确保您的活动可执行文件链接到依赖库的调试版本

3) set a breakpoint in your main project just before calling into the entry point of your lib, and set a bp on the entry-point of the lib... (in addition to the real breakpoint you are looking to hit...)

3)在调用lib的入口点之前在主项目中设置一个断点,并在lib的入口点设置一个bp ...(除了你要点击的真正断点之外... )

I have found that the best way to debug a library is to open the lib project and set the active executable to be the main project, and then just hit "build and debug" directly from the library project.

我发现调试库的最佳方法是打开lib项目并将活动可执行文件设置为主项目,然后直接从库项目中单击“构建和调试”。

I hope this helps, good luck, and have fun!

我希望这有帮助,祝你好运,玩得开心!

#5


I've had similar problems with Xcode. The solution for me is to make sure that there is also a breakpoint in the main project that gets hit (as Kent mentions in his third point). I don't understand why this works though.

我和Xcode有类似的问题。对我来说,解决方案是确保主项目中还有一个受到攻击的断点(正如肯特在第三点中提到的那样)。我不明白为什么这有效。

You should also only set breakpoints in a project when you've got it open. If you don't, they can start misbehaving: still stopping the flow of execution after you've disabled or deleted them, or not working when you think they're enabled.

您还应该只在项目打开时在项目中设置断点。如果不这样做,他们可能会开始行为不端:在您禁用或删除它们之后仍然停止执行流程,或者在您认为启用它们时不工作。

#6


Make sure you select 'Build and Debug' (for step #4). 'Go' sometimes means 'Run' (breakpoints disabled) and sometimes means 'Debug' (breakpoints enabled).

确保选择“构建和调试”(对于步骤#4)。 'Go'有时意味着'Run'(禁用断点),有时意味着'Debug'(启用断点)。

Also, make sure that you leave the dependent project open while you debug the main project.

此外,确保在调试主项目时保持依赖项目处于打开状态。

#7


In addition to kent reply about debug symbols, check COPY_PHASE_STRIP value in the build settings of the main project, and be sure it is set to NO in debug.

除了关于调试符号的肯定回复之外,请检查主项目的构建设置中的COPY_PHASE_STRIP值,并确保在调试中将其设置为NO。

#1


1) Add the breakpoint in your project

1)在项目中添加断点

2) Go into breakpoints view in xcode (top left besides project navigator) The view's icon is like a breakpoint icon

2)进入xcode中的断点视图(项目导航器旁边的左上角)视图的图标就像一个断点图标

3) Right click on the required breakpoint and select "Move to" -> "User"

3)右键单击所需的断点并选择“移至” - >“用户”

If the breakpoint is under "User" project, then it is accessible by all projects.

如果断点位于“用户”项目下,则所有项目都可以访问它。

#2


Whenever I've had trouble setting breakpoints with the Xcode GUI, I've managed to do it with the debugger command line (that is to say, the "lldb" prompt in the output window). For example, to set a breakpoint in source file "client.m" at line 42, type:

每当我在使用Xcode GUI设置断点时遇到问题,我都设法用调试器命令行(也就是输出窗口中的“lldb”提示符)来完成。例如,要在第42行的源文件“client.m”中设置断点,请键入:

(lldb) b client.m:42

Besides being a fix for this particular problem, debugging on the command-line offers far more flexibility and automatability than any GUI could. A good place to start would be the LLDB tutorial. (Full disclosure: I'm a longtime fan of unix and gdb, so there's some bias here).

除了解决这个特定问题之外,在命令行上进行调试提供了比任何GUI更多的灵活性和自动化。一个好的起点是LLDB教程。 (完全披露:我是unix和gdb的长期粉丝,所以这里有一些偏见)。

Of course, as others have mentioned, make sure the library/dependant project is compiled with debug symbols. Hope this helps; good luck.

当然,正如其他人提到的那样,确保使用调试符号编译库/依赖项目。希望这可以帮助;祝好运。

#3


I'll echo Jon-Eric here and also add that if you habitually run your project with Cmd+Enter, you should consider switching to Cmd+Y to enable gdb each time.

我将在这里回应Jon-Eric,并补充一点,如果您习惯性地使用Cmd + Enter运行项目,则应考虑切换到Cmd + Y以每次启用gdb。

#4


a few things here...(some obvious some not)

这里有一些东西......(有些显而易见的不是)

1) be sure that the dependant project is compiled with debug symbols (i'm assuming its a library)

1)确保依赖项目使用调试符号编译(我假设它是一个库)

2) be sure that your active executable is linking against the debug version of your dependent library

2)确保您的活动可执行文件链接到依赖库的调试版本

3) set a breakpoint in your main project just before calling into the entry point of your lib, and set a bp on the entry-point of the lib... (in addition to the real breakpoint you are looking to hit...)

3)在调用lib的入口点之前在主项目中设置一个断点,并在lib的入口点设置一个bp ...(除了你要点击的真正断点之外... )

I have found that the best way to debug a library is to open the lib project and set the active executable to be the main project, and then just hit "build and debug" directly from the library project.

我发现调试库的最佳方法是打开lib项目并将活动可执行文件设置为主项目,然后直接从库项目中单击“构建和调试”。

I hope this helps, good luck, and have fun!

我希望这有帮助,祝你好运,玩得开心!

#5


I've had similar problems with Xcode. The solution for me is to make sure that there is also a breakpoint in the main project that gets hit (as Kent mentions in his third point). I don't understand why this works though.

我和Xcode有类似的问题。对我来说,解决方案是确保主项目中还有一个受到攻击的断点(正如肯特在第三点中提到的那样)。我不明白为什么这有效。

You should also only set breakpoints in a project when you've got it open. If you don't, they can start misbehaving: still stopping the flow of execution after you've disabled or deleted them, or not working when you think they're enabled.

您还应该只在项目打开时在项目中设置断点。如果不这样做,他们可能会开始行为不端:在您禁用或删除它们之后仍然停止执行流程,或者在您认为启用它们时不工作。

#6


Make sure you select 'Build and Debug' (for step #4). 'Go' sometimes means 'Run' (breakpoints disabled) and sometimes means 'Debug' (breakpoints enabled).

确保选择“构建和调试”(对于步骤#4)。 'Go'有时意味着'Run'(禁用断点),有时意味着'Debug'(启用断点)。

Also, make sure that you leave the dependent project open while you debug the main project.

此外,确保在调试主项目时保持依赖项目处于打开状态。

#7


In addition to kent reply about debug symbols, check COPY_PHASE_STRIP value in the build settings of the main project, and be sure it is set to NO in debug.

除了关于调试符号的肯定回复之外,请检查主项目的构建设置中的COPY_PHASE_STRIP值,并确保在调试中将其设置为NO。