Xcode 调试器有时不显示变量值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3221504/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:27:51  来源:igfitidea点击:

Xcode debugger sometimes doesn't display variable values?

xcodedebugging

提问by William Jockusch

This happens to me pretty often. For example, right now I have the debugger stopped at a breakpoint in a method . . . and it isn't displaying any variable values at all. Other times, it displays some, but not others.

这经常发生在我身上。例如,现在我让调试器在方法中的断点处停止。. . 它根本不显示任何变量值。其他时候,它显示一些,但不显示其他。

Can anyone explain?

谁能解释一下?

回答by Paul R

The most common reason for this is that you're trying to debug code compiled with optimisation enabled and/or no debug symbols. Typically this will be because you're trying to debug a Release build rather than a Debug build but it can also happen with Debug builds if you've made inappropriate changes to the Debug build settings.

最常见的原因是您试图调试在启用优化和/或没有调试符号的情况下编译的代码。通常,这是因为您尝试调试的是发布版本而不是调试版本,但如果您对调试版本设置进行了不适当的更改,调试版本也可能会发生这种情况。

Another less common possibility is that you've hosed the stack.

另一种不太常见的可能性是您已经冲洗了堆栈。

回答by Anil

I had this issue (using Swift), I spent ages crawling through my gitcommits to find where to problem started.

我遇到了这个问题(使用 Swift),我花了很长时间在我的git提交中爬行以找到问题开始的地方。

xcode debugging variables not working or showing

xcode 调试变量不起作用或显示



For me, I was using Facebook Tweaks library, but I was (unnecessarily) importing it from my project-bridging-header.hfile.

对我来说,我使用的是 Facebook Tweaks 库,但我(不必要地)从我的project-bridging-header.h文件中导入了它。

Once I got rid of it, I got my debugging back.

一旦我摆脱了它,我就恢复了我的调试。

for example, in my bridging header I had:

例如,在我的桥接头中,我有:

#ifndef PROJECT_Bridging_Header_h
#define PROJECT_Bridging_Header_h
// Facebook Tweaks
#import "FBTweak.h"
#import "FBTweakStore.h"
#import "FBTweakCategory.h"
#import "FBTweakCollection.h"
#import "FBTweakViewController.h"
#import "FBTweakShakeWindow.h"
#endif

I removed all the imports and just imported it as usual in my AppDelegate import Tweaks.

我删除了所有导入,然后像往常一样在我的 AppDelegate 中导入它import Tweaks

e.g:

例如:

#ifndef PROJECT_Bridging_Header_h
#define PROJECT_Bridging_Header_h
// Removed Facebook Tweaks
#endif

and in my AppDelegate.swift

在我的 AppDelegate.swift

import Tweaks

This fixed all my debugging issues, everything works as expected and I can also using Facebook Tweaks.

这解决了我所有的调试问题,一切都按预期工作,我也可以使用 Facebook Tweaks。

Note:I don't think this is an issue with Facebook Tweaks itself, you may have some other library causing the same issue. The idea is to remove things from your bridging-headerone by one and see if you can narrow down the issue.

I think I read somewhere that if a library is causing many issues behind the scenes, this can stop your debugger working.

If this doesn't help, try crawling through your git commits and see at what stage the debugging stopped.

注意:我认为这不是 Facebook Tweaks 本身的问题,您可能有其他一些库导致了同样的问题。这个想法是从你的东西中bridging-header一一删除,看看你是否可以缩小问题的范围。

我想我在某处读到,如果一个库在幕后引起了许多问题,这可能会阻止您的调试器工作。

如果这没有帮助,请尝试浏览您的 git 提交并查看调试在哪个阶段停止。

other similar issues on SO:

关于 SO 的其他类似问题:

Xcode Debugging not showing values

Xcode 调试未显示值

Xcode debugger doesn't display variable information after installing CocoaPods Podfile

安装 CocoaPods Podfile 后,Xcode 调试器不显示变量信息

If you're having similar issues hope this helps!

如果你有类似的问题希望这会有所帮助!

回答by augustos10

A possible solution is to set the Optimization Level for your current target Debug scheme to none.

一种可能的解决方案是将当前目标调试方案的优化级别设置为无。

Project -> Target -> Build settings -> Optimization level -> Debug (or whatever fits your project) -> None

项目 -> 目标 -> 构建设置 -> 优化级别 -> 调试(或任何适合您的项目)-> 无

Source:

来源:

https://stackoverflow.com/a/14948486/3590753

https://stackoverflow.com/a/14948486/3590753

回答by IMFletcher

I've had similar issues using LLDB. Switching it back to GDB seems to address it. Obviously this isn't solving the problem, but its a workaround anyway

我在使用 LLDB 时遇到过类似的问题。将其切换回 GDB 似乎可以解决这个问题。显然这并不能解决问题,但无论如何它都是一种解决方法

回答by danielweberdlc

My issue was that I had address sanitizer enabled. Disabling sanitizer resolved my issue in XCode 8.2.1

我的问题是我启用了地址清理程序。禁用消毒剂解决了我在 XCode 8.2.1 中的问题

回答by Sandro Vezzali

You can get the value of any variable in the console by writing:

您可以通过编写以下命令获取控制台中任何变量的值:

po name_of_an_objectCVar

or

或者

print name_of_a_cVar

回答by devjme

If your breakpoint has "automatically continue after evaluating options" set, then it won't write to the variable view - FYI

如果您的断点设置了“评估选项后自动继续”,则它不会写入变量视图 - 仅供参考

回答by avuthless

I know this is old, but i ran into same problem too. I could not see any summaries of any objects, just types and some address code. After 4 hours of struggling with compilers, debuggers and other solutions i was about to give up when by accident i found this option in debugger. "Show Summaries". Just by clicking it everything got fixed and now i see all variable summaries!

我知道这很旧,但我也遇到了同样的问题。我看不到任何对象的任何摘要,只有类型和一些地址代码。在与编译器、调试器和其他解决方案苦苦挣扎 4 小时后,我正要放弃,但无意中在调试器中找到了这个选项。“显示摘要”。只需单击它,一切都得到了修复,现在我可以看到所有变量摘要!

enter image description here

在此处输入图片说明

回答by d0ye

For Swift mix OC Project which use pod

对于使用 pod 的 Swift mix OC 项目

Fixing it by removing useless header(that import with framework by pod) xx-Bridging-Header.h

通过删除无用的标头(通过 pod 使用框架导入)来修复它 xx-Bridging-Header.h

eg. In the past I import header with #import "GCDAsyncSocket.h"which I was added in podfile

例如。过去,我导入#import "GCDAsyncSocket.h"了在 podfile 中添加的标头

platform:ios, '8.0' use_frameworks! target "roocontrollerphone" do pod 'CocoaAsyncSocket' end

platform:ios, '8.0' use_frameworks! target "roocontrollerphone" do pod 'CocoaAsyncSocket' end

just remove it in that xx-Bridging-Header.hfile

只需在该xx-Bridging-Header.h文件中删除它

回答by Marcos Reboucas

Had the same issue using Xcode 6.4 running the app on device. Running on simulator will show all variables on debugging variables panel.

使用 Xcode 6.4 在设备上运行应用程序时遇到了同样的问题。在模拟器上运行将在调试变量面板上显示所有变量。