附加到进程的Xcode不会显示NSLog

时间:2022-09-06 20:51:36

I'm just getting started with Apple Watch. I found instructions from "Five Minute Watchkit", on getting the iOS app and the watch kit app both running in the simulator and both processes attached to the LLDB debugger.

我刚开始用Apple Watch。我找到了来自“五分钟观察工具包”的指令,关于让iOS应用程序和watch kit应用程序同时在模拟器中运行,以及连接到LLDB调试器的两个进程。

What I do is launch and quit the iOS app to install a current version in the sim. Then I switch to the watchKit scheme and launch that, which displays my watch app UI on the watch simulator.

我所做的就是启动并退出iOS应用程序,在sim中安装当前版本。然后我切换到watchKit方案并启动它,它在手表模拟器上显示我的手表应用程序UI。

I then launch the corresponding iOS app in the simulator, then user "attach to process" in the Xcode menu to attach the debugger to the running iOS app.

然后在模拟器中启动相应的iOS app,在Xcode菜单中用户“attach to process”将调试器附加到正在运行的iOS app上。

This works. I can set breakpoints in either the watch kit InterfaceController or in my iOS app and the debugger breaks there when it should.

这个作品。我可以在watch kit InterfaceController或者我的iOS应用中设置断点,调试器会在需要的时候中断。

However, I'm not seeing NSLog() statements in the debug console from my iOS app. (I do see log statements from the WatchKit extension code.) If I set a breakpoint in my iOS app, it does stop at that breakpoint when it should. I assume the lack of console output from NSLog has SOMETHING to do with attaching to a running process on the sim rather than launching it from Xcode, but I don't know what that something is.

但是,我没有在我的iOS应用程序的调试控制台中看到NSLog()语句(我确实看到了来自WatchKit扩展代码的日志语句)。如果我在我的iOS应用程序中设置了一个断点,它会在该断点时停止。我假设NSLog中控制台输出的缺乏与附加到sim上运行的进程有关,而不是从Xcode启动它,但我不知道这是什么。

(BTW, attaching an action to a breakpoint that invokes NSLog from the breakpoint also doesn't display, but the "log message" debugger command DOES display. Does anybody have any insights?)

顺便说一句,将一个动作附加到从断点调用NSLog的断点上也不会显示,但是“日志消息”调试器命令会显示。有人有什么见解吗?

EDIT: The code in the iOS app doesn't seem to matter. In my case, it was a dirt simple IBAction that was attached to a button in the iOS app storyboard:

编辑:iOS应用程序中的代码似乎并不重要。在我的例子中,这是一个极其简单的IBAction,它被附加到iOS app故事板中的一个按钮上:

- (IBAction)buttonAction:(UIButton *)sender;
{
  NSLog(@"Button clicked on iPhone");
}

I can set a breakpoint on that NSLog statement. The debugger stops at that line, but I don't see the log statement in the debug console.

我可以在NSLog语句上设置断点。调试器停在这一行,但是我在调试控制台中看不到日志语句。

6 个解决方案

#1


14  

I can reproduce that with a simple test app, sans WatchKit. The app consists of a NSTimer that prints "Timer fired" every second. (This code is 100% correct ;). Nothing shows in the log after I have manually attached to the process.
As far as I know NSLog outputs to stderr, I guess attaching the debugger does not redirect stderr to the Xcode terminal.

我可以用一个简单的测试应用程序,sans WatchKit进行复制。该应用程序由一个NSTimer组成,它每秒钟打印一次“定时发射”。(此代码100%正确;)在我手工附加到过程之后,日志中没有显示任何内容。据我所知,NSLog输出到stderr,我想附加调试器不会将stderr重定向到Xcode终端。

If you are okay with using the console app or the terminal to look at your logs you can do that. iOS8 stores simulator logs in ~/Library/Logs/CoreSimulator/<Device-UUID>. In this directory you will find a system.log, which contains all your NSLog output.

如果你可以使用控制台应用程序或终端查看日志,你可以这样做。iOS8将模拟器日志存储在~/Library/ logs /CoreSimulator/< device - uid >中。在这个目录中,您将找到一个系统。日志,它包含所有的NSLog输出。

You can look at it in terminal (cat, grep, tail), or open it in the Console.app.

你可以在终端(cat, grep, tail)中查看它,或者在Console.app中打开它。

附加到进程的Xcode不会显示NSLog


Apple confirms that (at least for GDB) in Technical Note TN2239: iOS Debugging Magic.

苹果在技术说明TN2239: iOS调试魔术中证实了这一点(至少对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:

许多程序,甚至许多系统框架,都将调试消息打印到stderr。这个输出的目的地最终由程序控制:它可以将stderr重定向到它选择的任何目的地。但是,在大多数情况下,程序不会重定向stderr,因此输出将转到程序从其启动环境继承的默认目的地。这通常是下列之一:

  • 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.
  • 如果您像普通用户一样启动GUI应用程序,系统会将stderr上打印的任何消息重定向到系统日志。您可以使用前面描述的技术查看这些消息。
  • 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).
  • 如果您在Xcode中运行一个程序,您可以在Xcode的调试器控制台窗口中看到它的stderr输出(从run菜单中选择Console菜单项以查看此窗口)。

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

连接到正在运行的程序(使用Xcode的Attach to Process菜单,或GDB中的Attach命令)不会自动地将程序的stderr连接到GDB窗口。您可以在GDB内部使用“在附加技术说明TN2030后查看stdout和stderr”一节中描述的技巧来实现这一点,“GDB用于MacsBug老兵”。

The mentioned TN2030 is no longer available on their server (mirror). It showed how you can redirect stdout and stderr to the Xcode console. However, since shell tty isn't a valid command for LLDB it won't help much. But maybe there is a different way to access the tty Xcodes console uses, so I attach the important part of that TN.

上面提到的TN2030不再在他们的服务器(mirror)上可用。它展示了如何将stdout和stderr重定向到Xcode控制台。但是,由于shell tty不是LLDB的有效命令,所以它不会有多大帮助。但是,也许有一种不同的方式来访问tty Xcodes控制台的使用,所以我附加了TN的重要部分。

Seeing stdout and stderr After Attaching

见stdout和stderr连接后

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.

如果将GDB附加到进程(而不是从GDB内部启动进程),您将看不到进程打印到stdout或stderr的任何内容。查找程序启动的程序通常具有stdout和stderr连接到“/dev/console”,因此它们打印的信息将被发送到控制台。您可以通过启动控制台应用程序(在实用程序文件夹中)来查看这一点,但是,必须查看单独的窗口是不方便的。另一种方法是将进程的stdout或stderr连接到GDB终端窗口的终端设备。清单9展示了如何做到这一点。

Listing 9. Connecting stdout and stderr to GDB's terminal device.

清单9所示。连接stdout和stderr到GDB的终端设备。

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

#2


5  

With Xcode Version 7.2 and iOS 9.2 etc, I found the following works:

通过Xcode 7.2和ios9.2等,我找到了以下工作:

0) Kill both the phone app and watch apps
1) Select the Watch Extension Target and hit Cmd+R (build and run)
2) Select the Phone target and hit Ctrl+Cmd+R (Run without building)

1)选择手表扩展目标,点击Cmd+R (build and run) 2)选择手机目标,按Ctrl+Cmd+R (run without building)

In my case, I have both apps up in their simulators and get NSLog output for both. I don't need to attach separately. Hope this helps.

在我的例子中,我将两个应用程序都放在它们的模拟器中,并获得两个应用程序的NSLog输出。我不需要分开连接。希望这个有帮助。

#3


5  

To add onto Filipp Keks answer, here's a visual representation of a much much simpler way to do it than the accepted answer.

为了增加Filipp Keks的答案,这是一种比公认的答案更简单的方法。

From Filipp Keks's answer: "1) Plug in the device and open Xcode

Filipp Keks的回答是:“1)插入设备并打开Xcode

2) Choose Window -> Devices from the menu bar

2)从菜单栏中选择Window ->设备

3) Under the DEVICES section in the left column, choose the device

3)在左侧栏的device部分下,选择设备

4) To see the device console, click the up-triangle at the bottom left of the right hand panel

4)要查看设备控制台,请单击右侧面板左下角的上三角

5) Click the down arrow on the bottom right to save the console as a file"

5)点击右下方的向下箭头,将控制台保存为文件。

This screenshot was taken in Xcode 7.3.1 of the Devices window.

这个屏幕截图是在设备窗口的Xcode 7.3.1中拍摄的。

附加到进程的Xcode不会显示NSLog

#4


3  

https://developer.apple.com/library/ios/qa/qa1747/_index.html

https://developer.apple.com/library/ios/qa/qa1747/_index.html

1) Plug in the device and open Xcode

1)插入设备,打开Xcode。

2) Choose Window -> Devices from the menu bar

2)从菜单栏中选择Window ->设备

3) Under the DEVICES section in the left column, choose the device

3)在左侧栏的device部分下,选择设备

4) To see the device console, click the up-triangle at the bottom left of the right hand panel

4)要查看设备控制台,请单击右侧面板左下角的上三角

5) Click the down arrow on the bottom right to save the console as a file

5)点击右下角的向下箭头,将控制台保存为文件。

#5


0  

In my case a set Automatically to see NSLog, before don't show at all

在我的例子中,设置一个自动查看NSLog的集合,然后就不显示了

附加到进程的Xcode不会显示NSLog

#6


0  

When your Provisioning profile is set to AdHoc or Distribution then Xcode doesnot show log, you need set development to view log

当您的配置文件被设置为AdHoc或Distribution时,Xcode不会显示日志,您需要设置development来查看日志

#1


14  

I can reproduce that with a simple test app, sans WatchKit. The app consists of a NSTimer that prints "Timer fired" every second. (This code is 100% correct ;). Nothing shows in the log after I have manually attached to the process.
As far as I know NSLog outputs to stderr, I guess attaching the debugger does not redirect stderr to the Xcode terminal.

我可以用一个简单的测试应用程序,sans WatchKit进行复制。该应用程序由一个NSTimer组成,它每秒钟打印一次“定时发射”。(此代码100%正确;)在我手工附加到过程之后,日志中没有显示任何内容。据我所知,NSLog输出到stderr,我想附加调试器不会将stderr重定向到Xcode终端。

If you are okay with using the console app or the terminal to look at your logs you can do that. iOS8 stores simulator logs in ~/Library/Logs/CoreSimulator/<Device-UUID>. In this directory you will find a system.log, which contains all your NSLog output.

如果你可以使用控制台应用程序或终端查看日志,你可以这样做。iOS8将模拟器日志存储在~/Library/ logs /CoreSimulator/< device - uid >中。在这个目录中,您将找到一个系统。日志,它包含所有的NSLog输出。

You can look at it in terminal (cat, grep, tail), or open it in the Console.app.

你可以在终端(cat, grep, tail)中查看它,或者在Console.app中打开它。

附加到进程的Xcode不会显示NSLog


Apple confirms that (at least for GDB) in Technical Note TN2239: iOS Debugging Magic.

苹果在技术说明TN2239: iOS调试魔术中证实了这一点(至少对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:

许多程序,甚至许多系统框架,都将调试消息打印到stderr。这个输出的目的地最终由程序控制:它可以将stderr重定向到它选择的任何目的地。但是,在大多数情况下,程序不会重定向stderr,因此输出将转到程序从其启动环境继承的默认目的地。这通常是下列之一:

  • 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.
  • 如果您像普通用户一样启动GUI应用程序,系统会将stderr上打印的任何消息重定向到系统日志。您可以使用前面描述的技术查看这些消息。
  • 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).
  • 如果您在Xcode中运行一个程序,您可以在Xcode的调试器控制台窗口中看到它的stderr输出(从run菜单中选择Console菜单项以查看此窗口)。

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

连接到正在运行的程序(使用Xcode的Attach to Process菜单,或GDB中的Attach命令)不会自动地将程序的stderr连接到GDB窗口。您可以在GDB内部使用“在附加技术说明TN2030后查看stdout和stderr”一节中描述的技巧来实现这一点,“GDB用于MacsBug老兵”。

The mentioned TN2030 is no longer available on their server (mirror). It showed how you can redirect stdout and stderr to the Xcode console. However, since shell tty isn't a valid command for LLDB it won't help much. But maybe there is a different way to access the tty Xcodes console uses, so I attach the important part of that TN.

上面提到的TN2030不再在他们的服务器(mirror)上可用。它展示了如何将stdout和stderr重定向到Xcode控制台。但是,由于shell tty不是LLDB的有效命令,所以它不会有多大帮助。但是,也许有一种不同的方式来访问tty Xcodes控制台的使用,所以我附加了TN的重要部分。

Seeing stdout and stderr After Attaching

见stdout和stderr连接后

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.

如果将GDB附加到进程(而不是从GDB内部启动进程),您将看不到进程打印到stdout或stderr的任何内容。查找程序启动的程序通常具有stdout和stderr连接到“/dev/console”,因此它们打印的信息将被发送到控制台。您可以通过启动控制台应用程序(在实用程序文件夹中)来查看这一点,但是,必须查看单独的窗口是不方便的。另一种方法是将进程的stdout或stderr连接到GDB终端窗口的终端设备。清单9展示了如何做到这一点。

Listing 9. Connecting stdout and stderr to GDB's terminal device.

清单9所示。连接stdout和stderr到GDB的终端设备。

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

#2


5  

With Xcode Version 7.2 and iOS 9.2 etc, I found the following works:

通过Xcode 7.2和ios9.2等,我找到了以下工作:

0) Kill both the phone app and watch apps
1) Select the Watch Extension Target and hit Cmd+R (build and run)
2) Select the Phone target and hit Ctrl+Cmd+R (Run without building)

1)选择手表扩展目标,点击Cmd+R (build and run) 2)选择手机目标,按Ctrl+Cmd+R (run without building)

In my case, I have both apps up in their simulators and get NSLog output for both. I don't need to attach separately. Hope this helps.

在我的例子中,我将两个应用程序都放在它们的模拟器中,并获得两个应用程序的NSLog输出。我不需要分开连接。希望这个有帮助。

#3


5  

To add onto Filipp Keks answer, here's a visual representation of a much much simpler way to do it than the accepted answer.

为了增加Filipp Keks的答案,这是一种比公认的答案更简单的方法。

From Filipp Keks's answer: "1) Plug in the device and open Xcode

Filipp Keks的回答是:“1)插入设备并打开Xcode

2) Choose Window -> Devices from the menu bar

2)从菜单栏中选择Window ->设备

3) Under the DEVICES section in the left column, choose the device

3)在左侧栏的device部分下,选择设备

4) To see the device console, click the up-triangle at the bottom left of the right hand panel

4)要查看设备控制台,请单击右侧面板左下角的上三角

5) Click the down arrow on the bottom right to save the console as a file"

5)点击右下方的向下箭头,将控制台保存为文件。

This screenshot was taken in Xcode 7.3.1 of the Devices window.

这个屏幕截图是在设备窗口的Xcode 7.3.1中拍摄的。

附加到进程的Xcode不会显示NSLog

#4


3  

https://developer.apple.com/library/ios/qa/qa1747/_index.html

https://developer.apple.com/library/ios/qa/qa1747/_index.html

1) Plug in the device and open Xcode

1)插入设备,打开Xcode。

2) Choose Window -> Devices from the menu bar

2)从菜单栏中选择Window ->设备

3) Under the DEVICES section in the left column, choose the device

3)在左侧栏的device部分下,选择设备

4) To see the device console, click the up-triangle at the bottom left of the right hand panel

4)要查看设备控制台,请单击右侧面板左下角的上三角

5) Click the down arrow on the bottom right to save the console as a file

5)点击右下角的向下箭头,将控制台保存为文件。

#5


0  

In my case a set Automatically to see NSLog, before don't show at all

在我的例子中,设置一个自动查看NSLog的集合,然后就不显示了

附加到进程的Xcode不会显示NSLog

#6


0  

When your Provisioning profile is set to AdHoc or Distribution then Xcode doesnot show log, you need set development to view log

当您的配置文件被设置为AdHoc或Distribution时,Xcode不会显示日志,您需要设置development来查看日志