2

我正在使用 Xcode 4.5 中的 X86_64 程序。我收到警告要中断 _NSWarnForDrawingImageWithNoCurrentContext 并停止在没有上下文的情况下进行绘图调用。该调用发生在一组深度的 CALayer/NSView 调用中。我想知道这与什么观点有关。

#0  0x00007fff9033f823 in _NSWarnForDrawingImageWithNoCurrentContext ()
#1  0x00007fff8ffd2cf3 in -[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:] ()
#2  0x00007fff901444ea in -[NSImageRep _newCGImageForProposedRect:context:hints:flipped:] ()
#3  0x00007fff8ffd3acb in -[NSImageRep CGImageForProposedRect:context:hints:] ()
#4  0x00007fff9006be1d in -[NSImageRep CGImageForProposedRect:context:hints:flipped:] ()
#5  0x00007fff900f0346 in -[NSImage _newSnapshotRepForRep:rect:context:processedHints:] ()
#6  0x00007fff900923c8 in -[NSImage _snapshotRepForRep:rect:context:processedHints:] ()
#7  0x00007fff9006bd77 in __48-[NSImage CGImageForProposedRect:context:hints:]_block_invoke_0 ()
#8  0x00007fff8ffd14d6 in -[NSImage _usingBestRepresentationForRect:context:hints:body:] ()
#9  0x00007fff9006b9e5 in -[NSImage CGImageForProposedRect:context:hints:] ()
#10 0x00007fff8ff14754 in -[_NSImageLayerContents CA_copyRenderValue] ()
#11 0x00007fff890350c3 in -[CALayer(CALayerPrivate) _copyRenderLayer:layerFlags:commitFlags:] ()
#12 0x00007fff89034a7c in CA::Context::commit_layer(CA::Layer*, unsigned int, unsigned int, void*) ()
#13 0x00007fff890349a4 in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#14 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#15 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#16 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#17 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#18 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#19 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#20 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#21 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#22 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#23 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#24 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#25 0x00007fff8903492f in CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) ()
#26 0x00007fff890258d6 in CA::Context::commit_transaction(CA::Transaction*) ()
#27 0x00007fff89025423 in CA::Transaction::commit() ()
#28 0x00007fff9010f032 in -[NSView(NSLayerKitGlue) _drawRectAsLayerTree:] ()
#29 0x00007fff8ffbe35a in -[NSView _drawRect:clip:] ()
#30 0x00007fff8ffbb093 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#31 0x00007fff8ffbbb24 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#32 0x00007fff8ffba223 in -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#33 0x00007fff8ffb5e4d in -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] ()
#34 0x00007fff8ff7fd73 in -[NSView displayIfNeeded] ()
#35 0x00007fff8ff7f2ac in _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints ()
#36 0x00007fff9054a971 in __83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke_01208 ()

如何找出正在调用哪个视图 _drawRect:clip: ?

我尝试切换到第 29 帧,然后执行 a p/x $arg1,但这给出了错误

错误:无法实现结构:无法读取 rdi(实现)

我只查找与此错误相关的源代码和提交日志,无法弄清楚它的含义。任何帮助将不胜感激,因为这也将有助于避免有关使用不推荐使用的调用的 Apple 代码的消息给我警告。

4

1 回答 1

3

您可以尝试使用“register read”命令,例如“reg read arg1”,但这里真正的问题是 rdi 是 SysV x86_64 ABI 的易失性寄存器。这意味着每当您进行函数调用时,rdi 的内容可能已被覆盖而没有保存在任何地方。一旦第 29 帧调用第 28 帧,调试器将假定 rdi 已被覆盖(第 29 帧可能在其中存储了一些内容作为第 28 帧的 arg)并且将无法检索第 29 帧之前的 rdi 内容入口。

被称为“非易失性”或“被调用者保留”的寄存器保证即使在堆栈中间也可以检索。在 x86_64 上,这些包括 rbx 和 r12-r15。如果第 29 帧使用 r12 保存变量,调用第 28 帧并且第 28 帧想要使用 r12,它必须将旧值保存到堆栈中,然后在返回到第 29 帧之前恢复该值。调试器知道如何找到这个保存位置并可以在第 29 帧中显示 r12 的内容——通过查看第 28 帧保存它的位置并检索值。

您唯一的希望是(1)在第 29 帧上放置一个断点并在该点打印 arg1 的值,或者(2)查看第 29 帧的汇编指令并查看函数是否将其第一个参数保存在某处(在堆栈,在非易失性寄存器中),您仍然可以检查。否则,当您深入 28 个堆栈帧时,参数寄存器的内容早已不复存在。

于 2012-10-08T19:12:07.040 回答