如何使用 Xcode 调试 dylib?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4720098/
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
How to debug dylib with Xcode?
提问by prosseek
I have a Xcode project for library arith. I could build it with debug configuration, and I need to debug it. How can I do that?
我有一个用于库算法的 Xcode 项目。我可以用调试配置来构建它,我需要调试它。我怎样才能做到这一点?
The ideal method would be to set up a test code to build an execution in a project file, and then set a breakpoint in a source code in arith library.
理想的方法是设置测试代码以在项目文件中构建执行,然后在 arith 库中的源代码中设置断点。
However, it seems that Xcode arith project doesn't allow to add another use_arith project that uses the arith library.
但是,Xcode arith 项目似乎不允许添加另一个使用 arith 库的 use_arith 项目。
What method people use to debug a dynamic library in Xcode?
人们使用什么方法在 Xcode 中调试动态库?
ADDED
添加
I googled and found some ways to debug dll. Attaching to a running process can be one way of debugging dynamic library. And, for iPhone/iPad programming dynamic library is not allowed, so static library is used.
我用谷歌搜索并找到了一些调试 dll 的方法。附加到正在运行的进程可以是调试动态库的一种方式。并且,对于 iPhone/iPad 编程动态库是不允许的,所以使用静态库。
Attaching to a Running Process - http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Attaching-to-a-Running-Process.html
Debugging a library with Xcode - Debugging a library with Xcode
Easy, Modular Code Sharing Across iPhone Apps: Static Libraries and Cross-Project References - http://www.clintharris.net/2009/iphone-app-shared-libraries/
附加到正在运行的进程 - http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Attaching-to-a-Running-Process.html
跨 iPhone 应用程序轻松、模块化的代码共享:静态库和跨项目引用 - http://www.clintharris.net/2009/iphone-app-shared-libraries/
采纳答案by prosseek
I could find a way to debug dynamic library in Xcode.
我可以找到一种在 Xcode 中调试动态库的方法。
Build
建造
- Make a library, I'll call this arith library. Debug build to make libarith.dylib.
- Make a project to use the library, I'll call this usearith.
- For userarith, Project->Add To Project, and add the arith library.
- Open Project info, and open the Build tab.
- Go to Search Paths/Library Search Paths, drag and drop the arith library. You should remove the library name as you need only specify the path. Specify the header directory with 'Header Search Paths'.
- Go to Linking, set Other Linker Flags, add -larith
- 创建一个库,我将其称为算术库。调试构建以生成 libarith.dylib。
- 制作一个项目来使用这个库,我称之为usearith。
- 对于 userarith,Project->Add To Project,并添加 arith 库。
- 打开项目信息,然后打开构建选项卡。
- 转到搜索路径/库搜索路径,拖放算术库。您应该删除库名称,因为您只需要指定路径。使用“标题搜索路径”指定标题目录。
- 转到链接,设置其他链接器标志,添加 -larith
Running
跑步
Now, you should be able to link the execution binary to the library. For running, you need to copy the dynamic library to the directory where the execution binary is located.
现在,您应该能够将执行二进制文件链接到库。为了运行,需要将动态库复制到执行二进制文件所在的目录中。
Debugging
调试
You need to set the breakpoints both arith/usearith. You can run debugger in arith and use the step into to debug the code in a arith project.
您需要同时设置 arith/usearith 断点。您可以在 arith 中运行调试器并使用 step into 来调试 arith 项目中的代码。
回答by Malick
I faced the same problem and no one of the previous answer worked for my case so I share my solution (for Xcode):
我遇到了同样的问题,之前的答案都不适用于我的案例,所以我分享了我的解决方案(对于 Xcode):
If you need to debug a c/c++ dylib which is loaded by an external (executable) program:
如果您需要调试由外部(可执行)程序加载的 ac/c++ dylib:
- First be sure that your dylib is build with the same architecture as your external program.
- Then Go to --> Product —>Scheme—>Edit scheme
- Got to Tab Run(Debug) and check "Debug Executable" , then select into the dropdown button your external program as executable. Then check "Launch Automatically"
- Additionally if you program needs extra argument you can add it into the "Arguments" tab.
- Finally you set some breakpoints to your c source file and finally click run.
- 首先确保你的 dylib 是用与你的外部程序相同的架构来构建的。
- 然后转到--> 产品--> 方案-> 编辑方案
- 转到 Tab Run(Debug) 并选中“Debug Executable”,然后在下拉按钮中选择您的外部程序作为可执行文件。然后勾选“自动启动”
- 此外,如果您的程序需要额外的参数,您可以将其添加到“参数”选项卡中。
- 最后,您为 c 源文件设置了一些断点,最后单击运行。