- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我刚刚开始使用 Apple Watch。我从“Five Minute Watchkit”中找到了有关让 iOS 应用程序和 watch 套件应用程序都在模拟器中运行以及将两个进程附加到 LLDB 调试器的说明。
我所做的是启动并退出 iOS 应用程序以在 sim 卡中安装当前版本。然后我切换到 watchKit 方案并启动它,它会在 watch 模拟器上显示我的 watch 应用程序 UI。
然后我在模拟器中启动相应的 iOS 应用程序,然后用户在 Xcode 菜单中“附加到进程”以将调试器附加到正在运行的 iOS 应用程序。
这行得通。我可以在 watch 套件 InterfaceController 或我的 iOS 应用程序中设置断点,调试器会在它应该中断的地方中断。
但是,我在我的 iOS 应用程序的调试控制台中没有看到 NSLog() 语句。 (我确实看到了来自 WatchKit 扩展代码的日志语句。)如果我在我的 iOS 应用程序中设置了一个断点,它会在它应该停止的时候停在那个断点处。我假设 NSLog 缺少控制台输出与附加到 sim 上正在运行的进程有关,而不是从 Xcode 启动它,但我不知道那是什么。
(顺便说一句,将操作附加到从断点调用 NSLog 的断点也不会显示,但会显示“日志消息”调试器命令。有人有任何见解吗?)
编辑:iOS 应用程序中的代码似乎并不重要。在我的例子中,它是一个非常简单的 IBAction,它附加到 iOS 应用 Storyboard中的一个按钮:
- (IBAction)buttonAction:(UIButton *)sender;
{
NSLog(@"Button clicked on iPhone");
}
我可以在该 NSLog 语句上设置断点。调试器在该行停止,但我没有在调试控制台中看到日志语句。
最佳答案
我可以用一个简单的测试应用重现它,没有 WatchKit。该应用程序包含一个 NSTimer,它每秒打印一次“Timer fired”。 (此代码 100% 正确;)。在我手动附加到进程后,日志中没有任何显示。
据我所知,NSLog 输出到 stderr,我想附加调试器不会将 stderr 重定向到 Xcode 终端。
如果您可以使用控制台应用程序或终端查看您的日志,则可以这样做。 iOS8存储模拟器登录~/Library/Logs/CoreSimulator/<Device-UUID>
.在此目录中,您会找到一个 system.log,其中包含您所有的 NSLog
输出。
您可以在终端( cat
、 grep
、 tail
)中查看它,或在 Console.app 中打开它。
Apple 在 Technical Note TN2239: iOS Debugging Magic 中确认(至少对于 GDB) .
Console Output
Many programs, and indeed many system frameworks, print debugging messages to stderr. The destination for this output is ultimately controlled by the program: it can redirect stderr to whatever destination it chooses. However, in most cases a program does not redirect stderr, so the output goes to the default destination inherited by the program from its launch environment. This is typically one of the following:
- If you launch a GUI application as it would be launched by a normal user, the system redirects any messages printed on stderr to the system log. You can view these messages using the techniques described earlier.
- If you run a program from within Xcode, you can see its stderr output in Xcode's debugger Console window (choose the Console menu item from the Run menu to see this window).
Attaching to a running program (using Xcode's Attach to Process menu, or the attach command in GDB) does not automatically connect the program's stderr to your GDB window. You can do this from within GDB using the trick described in the "Seeing stdout and stderr After Attaching" section of Technical Note TN2030, 'GDB for MacsBug Veterans'.
提到的 TN2030 在他们的服务器上不再可用 (mirror)。它展示了如何将 stdout 和 stderr 重定向到 Xcode 控制台。然而,由于 shell tty
不是 LLDB 的有效命令,它不会有太大帮助。但也许有不同的方式来访问 Xcodes 控制台使用的 tty,所以我附上了那个 TN 的重要部分。
Seeing stdout and stderr After Attaching
If you attach GDB to a process (as opposed to starting the process from within GDB), you won't be able to see anything that the process prints to stdout or stderr. Programs launched by the Finder typically have stdout and stderr connected to "/dev/console", so the information they print goes to the console. You can view this by launching the Console application (in the Utilities folder), however, it's inconvenient to have to look in a separate window. Another alternative is to connect the process's stdout or stderr to the terminal device for GDB's Terminal window. Listing 9 shows how to do this.
Listing 9. Connecting stdout and stderr to GDB's terminal device.
(gdb) attach 795
[... output omitted ...]
(gdb) call (void) DebugPrintMenuList()
No output )-:
Close the stdout and stderr file descriptors.
(gdb) call (void) close(1)
(gdb) call (void) close(2)
Determine the name of the terminal device for GDB itself.
(gdb) shell tty
/dev/ttyp1
Reopen stdout and stderr, but connected to GDB's terminal.
The function results should be 1 and 2; if not, something
is horribly wrong.
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$1 = 1
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$2 = 2
Try the DebugPrintMenuList again.
(gdb) call (void) DebugPrintMenuList()
Yay output!
Index MenuRef ID Title
----- ---------- ---- -----
<regular menus>
00001 0x767725D3 -21629 Ed
00002 0x76772627 1128 <Apple>
00003 0x767726CF 1129 File
00004 0x76772567 1130 Edit
[... remaining output omitted ...]
关于ios - Xcode 附加到进程不显示 NSLog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29106019/
我是 Mac OS 编程的新手。我想知道 NSLog 在哪里定义? 最佳答案 在NSObjCRuntime.h文件中: FOUNDATION_EXPORT void NSLog(NSString *f
我不明白这里发生了什么。我有一个按钮连接到 AppDelegate 中的以下操作: - (IBAction)openWindow:(id)sender { self.winCon = [[NS
#import int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePo
我有一个 Xcode 项目,我已经工作了几个月了。我从来没有遇到过 NSLog 问题,但升级到 Xcode 4.2 后,控制台上不会记录任何内容。我什至尝试将其放入 viewDidLoad 中:
首先,当我使用 nslog 记录数组的内容时,为什么数组中的某些对象(所有字符串)都有引号,而有些则没有? 日志将如下所示: "Item 1", "item 2", item3, "item4" 这引
我很不幸地提交了一个 NSLog 仍然处于事件状态的应用程序。它很少触发,但我想知道我的应用程序因此被拒绝的可能性有多大? 我不是在问如何抑制 NSLogs。我已经知道该怎么做了。它只是一个错误进入的
我正在尝试使用 NSLog 来打印控制台消息。问题是有时我在调用它时收到“EXC_BAD_ACCESS”错误 -(void)willRotateToInterfaceOrientation:(UIIn
我的 Mac OS X 应用程序中有以下代码行: NSLog(@"number of items: %ld", [urlArray count]); 我收到警告:“格式指定类型‘long’,但参数类型
与 NSLog 功能最接近的 Core Foundation 函数是什么? 最佳答案 CFShow() 类似,但没有前缀。或者,正如 wbyoung 所说,使用 NSLog()。如果您不想使用 Obj
NSNumber *weekNum = [dictionary valueForKey:@"inSeasonFor"]; NSDecimalNumber *newWeekNum = ([weekNum
我目前正在开发一个低功耗蓝牙应用程序,我想在其中使用 NSLog 来打印我收集到的信息。 这是我在 didUpdateValueForCharacteristic 方法末尾使用的代码,此时所有属性都已
当我尝试用它NSLog我的图像时; NSLog([images description]); 这出现了: 2012-06-05 10:31:38.801 Project1[1180:1a303] (
我如何准确地检测对象的坐标,例如名为“content”的 View ,并将其输出到日志中?感谢您的帮助! 最佳答案 你也可以这样做 NSLog(@"position: %@",NSStringFrom
-(void) print { NSLog(@"%i/%i", numberator, denominator); } Fraction *myFraction = [Fraction n
我有一部连接到 Xcode 的 iPhone。我在主页上有一个 NSLog(@"test")。当我从 Xcode 构建(运行)我的应用程序时,我看到它正在调试区域打印 test。 然后...我从设备屏
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improv
这个问题在这里已经有了答案: 关闭 10 年前。
我是 Objective-C 的新手,我开始学习简单的东西。在本例中,我想使用 * 符号创建一个 金字塔。 问题:每次打印 * 时,它都包含一个换行符。我怎样才能摆脱它来创建金字塔外观?我以为我必须添
我在 IBAction 中有以下代码。我想测量 AVSpeechSynthesizer 运行一个方向列表所花费的确切时间。但是,executionTime 会立即记录,而不是在循环结束时记录(返回不到
我想从两个日期之间添加的核心数据中检索所有条目。我正在使用 NSPredicate。由于我没有得到正确的结果,我尝试记录日期。它显示了以前的日期。谷歌搜索了一段时间后,我添加了 [dateFormat
我是一名优秀的程序员,十分优秀!