OS X 相当于 OutputDebugString() ?
我正在研究将现有 Windows MFC 控件移植到 OS X/Carbon 的可行性。 我的测试床是使用 XCode 3 Wizard 生成的 C++ Carbon 应用程序。
我正在寻找一种快速方法将一些跟踪信息转储到调试器或 OS X 的 DbgView 等效项。 在 Win32 上我会使用 OutputDebugString() - OS X 上有什么用? 有没有办法查看从 Carbon 应用程序写入 std::cout 的测试?
谢谢杰瑞
I'm examining the feasibility of porting an existing Windows MFC control to OS X/Carbon.
My test bed is a C++ Carbon application generated using the XCode 3 Wizard.
I'm looking for a quick way to dump some trace info to the debugger or the OS X equivalent of DbgView. On Win32 I'd use OutputDebugString() - what's the deal on OS X? Is there a way to view test written to std::cout from a Carbon app?
Thanks
Jerry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有真正的等价物。 Xcode 在底层使用 GDB,所以你基本上要处理它。 但是,您可以自己实现。 仅当调试器存在时,下面的代码示例才会生成标准输出的输出。 如果编译时存在 NDEBUG,您可以通过将其作为宏包装在预处理器指令中并编译出来(或编译成内联 nil 函数)来进一步保护它。 应用程序生成的任何输出都将定向到 Xcode 中的调试控制台。
There is no real equivalent. Xcode uses GDB under the hood, so you're basically dealing with that. You could, however, implement it yourself. The code sample below will produce output to standard out only when the debugger is present. You could further protect this by wrapping it in preprocessor directives as a macro and compile it out (or into an inline nil function) if NDEBUG is present at compile time. Any output produced by an application will be directed to the debugging console in Xcode.
首先,Carbon 现在和将来都不会在 64 位版本中提供。 如果 Apple 放弃 32 位 Mac OS X(可以肯定地认为迟早会发生),您的应用程序将无法运行。 使用可可。
也就是说,有几种方法可以进行日志记录:
这是一个 Cocoa 函数,但您也可以在 Carbon 应用程序中使用它。 链接到 Foundation 框架,但不包含标头。 自己声明:
您将传递 CFSTR 文字作为格式:
NSLog 的优点是您可以使用 %@ 格式化程序打印 CF 属性列表对象(字符串、数据对象、日期、数字、数组和字典)。 例如:
旧的 C 标准库备用。
#include
来获取它们。 在 GUI 应用程序中这并不重要,但您应该使用 stderr 来保持整洁:fprintf(stderr, "Count: %u\n", count);
About as old as f?printf ,我猜,但更强大。 这是一个实际的日志系统,而不仅仅是写入文件。 您可以指定优先级等内容,从而允许您在 Beta 测试人员的系统上抑制调试日志消息,同时仍然能够在您自己的系统上读取它们。 (最终版本根本不应该包含日志记录代码。)
Apple System Logger 的一部分,Apple 更通用的 syslog 替代品。 我有一系列关于 ASL 的帖子 在我的博客上。
First off, Carbon isn't and won't be available in 64-bit. If Apple ever drops 32-bit Mac OS X (which it's safe to assume will happen sooner or later), your app will not run. Use Cocoa.
That said, there are several ways to do logging:
This is a Cocoa function, but you can use it in Carbon apps, too. Link against the Foundation framework, but don't include the header. Declare it yourself:
You'll pass a CFSTR literal as the format:
The advantage of NSLog is that you can print CF property-list objects (strings, data objects, dates, numbers, arrays, and dictionaries) using the %@ formatter. For example:
The old C standard library standbys.
#include <stdio.h>
to get them. It doesn't matter much in a GUI app, but you should use stderr for cleanliness:fprintf(stderr, "Count: %u\n", count);
About as old as f?printf, I'd guess, but more powerful. This is an actual logging system, not just writing to a file. You can specify things like priority, allowing you to suppress your debug log messages on beta testers' systems while still being able to read them on your own system. (Final releases should not contain logging code at all.)
Part of Apple System Logger, Apple's more general replacement for syslog. I have a series of posts about ASL on my blog.
您可能需要查看
syslog
,因为它是基于 UNIX 的系统上事实上的诊断方法。 例如:Google syslog 了解更多信息。 您还必须调整 syslog.conf 中的一些位以将输出定向到日志或控制台。 然后,您可以在终端窗口中或使用控制台应用程序查看输出。
You might want to look into
syslog
since it is the de facto diagnostic method on UNIX-based systems. Something like:Google syslog for more information. You will also have to twiddle some bits in
syslog.conf
to direct the output to a log or console. Then you can view the output in a terminal window or using the Console application.在 Xcode 中,您可以在“控制台”窗口(运行 -> 控制台)中看到
std::cout
/std::cerr
的输出。还有 Console.app(位于 /Applications/Utilities 中),它记录从 GUI 应用程序写入
std::cerr
的所有输出。In Xcode you can see the output of
std::cout
/std::cerr
in the "console" window (Run->Console).There is also Console.app (in /Applications/Utilities) which logs all output written to
std::cerr
from GUI applications.