使用 Xcode 调试 c++ .cpp 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7340850/
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
Debugging c++ .cpp file using Xcode
提问by wfbarksdale
I have a solitary .cpp file, and I would very much like to debug it.
我有一个单独的 .cpp 文件,我非常想调试它。
Without creating an Xcode project, is there anyway I can debug this using the Xcode debugger?
在不创建 Xcode 项目的情况下,是否可以使用 Xcode 调试器进行调试?
When I open the file in Xcode to edit and set breakpoints, the program doesn't stop at the break points.
当我在 Xcode 中打开文件进行编辑和设置断点时,程序不会在断点处停止。
采纳答案by Jorge Leitao
You can't debug via Xcode without a project because without a project, Xcode works only as a file editor with color highlight and so one.
你不能在没有项目的情况下通过 Xcode 进行调试,因为没有项目,Xcode 只能作为带有颜色突出显示等的文件编辑器。
For debugging you need an executable compiled with debug option, which is produced via a compiler. The easy way (but in my opinion the worse) is to make a Xcode project and put the .cpp file there. There is the hard way too (and probably the best for future reference) that is to learn to do it on the terminal, using for instance the g++ (compiler) and gdb (debugger).
对于调试,您需要使用调试选项编译的可执行文件,该选项是通过编译器生成的。简单的方法(但在我看来更糟)是制作一个 Xcode 项目并将 .cpp 文件放在那里。也有一种困难的方法(可能是最好的供将来参考),那就是学习在终端上进行操作,例如使用 g++(编译器)和 gdb(调试器)。
回答by Kohn1001
If it would help somebody who stumble here when looking for an answer for this topic (similar to what happened to me).
如果它可以帮助那些在寻找这个话题的答案时绊倒的人(类似于我身上发生的事情)。
I'm assuming that you do have a project but not able to start debugging. To succeed in doing so, just make sure that prior to clicking the "play" button you have a breakpoint.
我假设您确实有一个项目但无法开始调试。要成功执行此操作,只需确保在单击“播放”按钮之前您有一个断点。
To add a breakpoint, just click with the mouse next to the line number, and then you should have a marker similar to the one on line 19 (screen shot below). Now click play, and >>> showtime
要添加断点,只需在行号旁边单击鼠标,然后您应该有一个类似于第 19 行上的标记(下面的屏幕截图)。现在点击播放,然后 >>> 放映时间
回答by Alek86
If noone answers you later, maybe this post will help you
如果以后没有人回答你,也许这篇文章会对你有所帮助
I'm not a XCode developer, but I know, that to debug a process you need:
我不是 XCode 开发人员,但我知道,要调试您需要的流程:
a debugger
the corresponding (!) code
the info, which stores a special debugging info, which gives the debugger an opportunity to map from binary process to your C++ (or other) code
and the process, sure :)
调试器
相应的 (!) 代码
存储特殊调试信息的信息,这使调试器有机会从二进制进程映射到 C++(或其他)代码
和过程,当然:)
this link could help to understand if you have debugging info
此链接可以帮助了解您是否有调试信息
http://www.meandmark.com/xcode3debugging.pdf
http://www.meandmark.com/xcode3debugging.pdf
you can search words "Debug Information" and try to understand, if you have it or not
你可以搜索词“调试信息”并尝试理解,如果你有或没有