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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/924628/
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 18:35:10  来源:igfitidea点击:

How to set breakpoint in a dependent xcode project

xcodemacos

提问by yinglcs

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 项目有它的可执行文件)。它依赖于一些其他项目(在详细信息视图的项目选项卡下,还有一些其他 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.

谢谢你。

回答by Arjan

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.

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

回答by nephtes

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”提示)来完成。例如,要在源文件“client.m”的第 42 行设置断点,请键入:

(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.

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

回答by featherless

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。

回答by vtruant

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。

回答by kent

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, andset 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!

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

回答by Charles Anderson

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 上遇到过类似的问题。我的解决方案是确保主项目中也有一个断点被击中(正如 Kent 在他的第三点中提到的那样)。我不明白为什么这有效。

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.

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

回答by Jon-Eric

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

确保选择“Build and Debug”(第 4 步)。“Go”有时表示“运行”(禁用断点),有时表示“调试”(启用断点)。

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

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