可可应用程序中的 objc_msgSend() 和 EXC_BAD_ACCESS

发布于 2024-11-01 01:47:06 字数 7119 浏览 1 评论 0原文

一般来说,我们如何避免 Mac 应用程序中的 objc_msgSend() 崩溃?另外,我们如何避免 EXC_BAD_ACCESS 崩溃?为什么我们会得到它?我们如何管理这些类型的错误?他们在我们的应用程序上的数量不断增加,并希望就此事寻求指导和帮助。

我们使用的是 XCode 3.2.5,我们的项目是 Cocoa 项目,使用 Objective-C 语言。我们的网络服务是一个由 IIS 驱动的 ASP.Net 网站(我们可以从中下载/上传 XML 文件和图像)。

我们正在 Mac 上开发一个可可应用程序,在启动该应用程序的十次尝试中,我们遇到了两次这种情况。这个应用程序有一个草图应用程序,当我们运行该应用程序时,它只是在 1 分钟内冻结并崩溃,没有执行任何操作。这个应用程序的一些功能是:

  • 从网络下载 xml 并在我们的应用程序上进行解释
  • 登录到网络服务
  • 有一个草图板
  • 有一个计时器
  • 拖放功能
  • 上传 xml 数据
  • 下载图像并在我们的应用程序上显示

崩溃不仅限于帖子- 启动应用程序。有时,当在我们的 Mac 应用程序上操作拖放、下载数据集以及执行添加/编辑/删除功能等程序时,应用程序也会崩溃。

老实说,我们对这个开发平台和环境还比较陌生,而且还在学习中。您能指导我们解决这个问题吗?喜欢一些关于我们哪里做错了的资源或提示吗?非常感谢这里的每个人以及更多的力量。


以下是崩溃报告的示例:

Process:         Sketch [63065]
Path:            /Users/william_hooley_27Inch/Desktop/untitled folder/MacGlass.app/Contents/MacOS/Sketch
Identifier:      com.apple.CocoaExamples.Sketch
Version:         1.049 (48.1)
Code Type:       X86 (Native)
Parent Process:  launchd [116]
Date/Time:       2011-04-14 13:12:15.421 +1000
OS Version:      Mac OS X 10.6.5 (10H574)
Report Version:  6
Interval Since Last Report:          714907 sec
Crashes Since Last Report:           17
Per-App Interval Since Last Report:  206437 sec

Per-App Crashes Since Last Report:   5
Anonymous UUID:                     
086C860F-E28E-4256-84F9-9692782AAD01
Exception Type:  EXC_BAD_ACCESS
(SIGBUS) Exception Codes:
KERN_PROTECTION_FAILURE at
0x0000000000000044 Crashed Thread:  0 
Dispatch queue: com.apple.main-thread
Thread 0 Crashed:  Dispatch queue:
com.apple.main-thread 0  
com.apple.AppKit             
0x91a8e6cb
_recursiveInvalidateCachedVisibleRectValue
+ 24 1   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
2   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 3   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
4   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 5   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
6   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 7   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
8   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 9   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
10  com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 11  com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
12  com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 13  com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
14  com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 15  com.apple.AppKit              0x91a8e2e1 -[NSView _setSuperview:] +
684 16  com.apple.AppKit             
0x91a8db02 -[NSView addSubview:] + 383
17  com.apple.CocoaExamples.Sketch
0x00094cbf -[viewTasksDisplay Appear:]
+ 242 18  com.apple.CocoaExamples.Sketch
0x000c2e8f -[MainWindow
ShowLeftScreen:] + 964 19 
com.apple.CocoaExamples.Sketch
0x0003e301 -[viewOptionMenuItemmouseDown:] + 2055 20 
com.apple.AppKit             
0x91bc6c68 -[NSWindow sendEvent:] +
5549 21  com.apple.AppKit             
0x91adf817 -[NSApplication sendEvent:]
+ 6431 22  com.apple.AppKit              0x91a732a7 -[NSApplication run] + 917
23  com.apple.AppKit             
0x91a6b2d9 NSApplicationMain + 574 24 
com.apple.CocoaExamples.Sketch
0x0001b33e main + 30 25 
com.apple.CocoaExamples.Sketch
0x00001eba start + 54 Thread 1: 
Dispatch queue:
com.apple.libdispatch-manager 0  
libSystem.B.dylib            
0x98002982 kevent + 10 1  
libSystem.B.dylib            
0x9800309c _dispatch_mgr_invoke + 215
2   libSystem.B.dylib            
0x98002559 _dispatch_queue_invoke +
163 3   libSystem.B.dylib            
0x980022fe _dispatch_worker_thread2 +
240 4   libSystem.B.dylib            
0x98001d81 _pthread_wqthread + 390 5  
libSystem.B.dylib            
0x98001bc6 start_wqthread + 30 Thread
2: 0   libSystem.B.dylib            
0x97fdc0fa mach_msg_trap + 10 1  
libSystem.B.dylib            
0x97fdc867 mach_msg + 68 2  
com.apple.CoreFoundation     
0x995f837f __CFRunLoopRun + 2079

另一个崩溃报告:

Date/Time:       2011-04-14 13:27:02
+1000 OS Version:      10.6.5 (Build 10H574) Architecture:    x86_64 Report
Version:  6 Command:         MacGlass
Path:           
/Users/william_hooley_27Inch/Desktop/untitled
folder/MacGlass.app/Contents/MacOS/Sketch
Version:         1.050 (48.1) Parent: 
launchd [116] PID:             63101
Event:           hang Duration:       
3.58s (sampling started after 2 seconds) Steps:           16 (100ms
sampling interval) Pageins:         0
Pageouts:        0 Process:        
Sketch [63101] Path:           
/Users/william_hooley_27Inch/Desktop/untitled
folder/MacGlass.app/Contents/MacOS/Sketch
UID:             501   Thread edef3d4 
DispatchQueue 100   User stack:
    16 start + 54 (in Sketch) [0x1f6a]
      16 main + 30 (in Sketch) [0x1b3ee]
        16 NSApplicationMain + 574 (in AppKit) [0x91a6b2d9]
          16 -[NSApplication run] + 821 (in AppKit) [0x91a73247]
            16 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
+ 156 (in AppKit) [0x91ab0fce]
              16 _DPSNextEvent + 847 (in AppKit) [0x91ab178d]
                16 BlockUntilNextEventMatchingListInMode
+ 81 (in HIToolbox) [0x95bd0bd6]
                  16 ReceiveNextEventCommon + 354 (in
HIToolbox) [0x95bd0d51]
                    16 RunCurrentEventLoopInMode + 392 (in
HIToolbox) [0x95bd0f9c]
                      16 CFRunLoopRunInMode + 97 (in
CoreFoundation) [0x995f7291]
                        16 CFRunLoopRunSpecific + 452 (in
CoreFoundation) [0x995f7464]
                          16 __CFRunLoopRun + 8059 (in CoreFoundation) [0x995f9adb]
                            16 __NSFireTimer + 141 (in Foundation) [0x972c39b0]
                              16 _handleWindowNeedsDisplay + 696 (in AppKit) [0x91adb28a]
                                16 -[NSWindow displayIfNeeded] + 204 (in AppKit) [0x91aa9d40]
                                  16 -[NSView displayIfNeeded] + 818 (in AppKit) [0x91ae0a57]
                                    16 -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:]
+ 4122 (in AppKit) [0x91b801cf]
                                      16 CAViewEndDraw + 134 (in QuartzCore)
[0x961bd926]
                                        16 pthread_cond_wait$UNIX2003 + 73 (in
libSystem.B.dylib) [0x9800b9f8]
                                          16 __semwait_signal + 10 (in
libSystem.B.dylib) [0x9800a0a6]  
Kernel stack:
    15 semaphore_wait_continue + 0 [0x22a3dd]
    1 lo_alltraps + 454 [0x2a08a6]
      1 i386_astintr + 47 [0x2a9a9a]
        1 ast_taken + 247 [0x219107]
          1 bsd_ast + 806 [0x489088]
            1 postsig + 432 [0x4861df]
              1 exit1 + 449 [0x47ab28]
                1 task_terminate_internal + 315
[0x22c56a]

Generally speaking, how do we avoid objc_msgSend() crashes in our Mac Apps? Also, how do we avoid the EXC_BAD_ACCESS crashes? Why do we get it? How can we manage these kinds of errors? They are on the increase on our app and would like to ask guidance and help on this matter.

We are using XCode 3.2.5 and our project is a Cocoa one, using Objective-C language. Our webservice is an IIS-powered ASP.Net website (from where we can download/upload an XML files and images).

We are developing a cocoa-app in Mac, and we encounter this like two times in ten tries of launching the app. This app has a sketch app, and when we run the app, it just freezes and crashes within 1 minute without doing anything. Some functions this app does is:

  • download xml from web and interpret on our app
  • login to a web service
  • has a sketch pad
  • has a timer
  • drag and drop functions
  • upload xml data
  • download images and display on our app

The crash is not limited to the post-launch of the app. Sometimes, when manipulating the program like drag-drop, downloading dataset, and doing add/edit/delete functions on our mac app, the app crashes as well.

Honestly speaking, we are relatively new to this development platform and environment, and we are still learning. Can you guide us on this issue? Like some resources or hints on where we did it wrong? Thanks a lot and more power to everyone here.


The folowing is an example of a crash report:

Process:         Sketch [63065]
Path:            /Users/william_hooley_27Inch/Desktop/untitled folder/MacGlass.app/Contents/MacOS/Sketch
Identifier:      com.apple.CocoaExamples.Sketch
Version:         1.049 (48.1)
Code Type:       X86 (Native)
Parent Process:  launchd [116]
Date/Time:       2011-04-14 13:12:15.421 +1000
OS Version:      Mac OS X 10.6.5 (10H574)
Report Version:  6
Interval Since Last Report:          714907 sec
Crashes Since Last Report:           17
Per-App Interval Since Last Report:  206437 sec

Per-App Crashes Since Last Report:   5
Anonymous UUID:                     
086C860F-E28E-4256-84F9-9692782AAD01
Exception Type:  EXC_BAD_ACCESS
(SIGBUS) Exception Codes:
KERN_PROTECTION_FAILURE at
0x0000000000000044 Crashed Thread:  0 
Dispatch queue: com.apple.main-thread
Thread 0 Crashed:  Dispatch queue:
com.apple.main-thread 0  
com.apple.AppKit             
0x91a8e6cb
_recursiveInvalidateCachedVisibleRectValue
+ 24 1   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
2   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 3   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
4   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 5   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
6   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 7   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
8   com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 9   com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
10  com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 11  com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
12  com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 13  com.apple.CoreFoundation      0x995f02c0 CFArrayApplyFunction + 224
14  com.apple.AppKit             
0x91a8e70d
_recursiveInvalidateCachedVisibleRectValue
+ 90 15  com.apple.AppKit              0x91a8e2e1 -[NSView _setSuperview:] +
684 16  com.apple.AppKit             
0x91a8db02 -[NSView addSubview:] + 383
17  com.apple.CocoaExamples.Sketch
0x00094cbf -[viewTasksDisplay Appear:]
+ 242 18  com.apple.CocoaExamples.Sketch
0x000c2e8f -[MainWindow
ShowLeftScreen:] + 964 19 
com.apple.CocoaExamples.Sketch
0x0003e301 -[viewOptionMenuItemmouseDown:] + 2055 20 
com.apple.AppKit             
0x91bc6c68 -[NSWindow sendEvent:] +
5549 21  com.apple.AppKit             
0x91adf817 -[NSApplication sendEvent:]
+ 6431 22  com.apple.AppKit              0x91a732a7 -[NSApplication run] + 917
23  com.apple.AppKit             
0x91a6b2d9 NSApplicationMain + 574 24 
com.apple.CocoaExamples.Sketch
0x0001b33e main + 30 25 
com.apple.CocoaExamples.Sketch
0x00001eba start + 54 Thread 1: 
Dispatch queue:
com.apple.libdispatch-manager 0  
libSystem.B.dylib            
0x98002982 kevent + 10 1  
libSystem.B.dylib            
0x9800309c _dispatch_mgr_invoke + 215
2   libSystem.B.dylib            
0x98002559 _dispatch_queue_invoke +
163 3   libSystem.B.dylib            
0x980022fe _dispatch_worker_thread2 +
240 4   libSystem.B.dylib            
0x98001d81 _pthread_wqthread + 390 5  
libSystem.B.dylib            
0x98001bc6 start_wqthread + 30 Thread
2: 0   libSystem.B.dylib            
0x97fdc0fa mach_msg_trap + 10 1  
libSystem.B.dylib            
0x97fdc867 mach_msg + 68 2  
com.apple.CoreFoundation     
0x995f837f __CFRunLoopRun + 2079

Another crash report:

Date/Time:       2011-04-14 13:27:02
+1000 OS Version:      10.6.5 (Build 10H574) Architecture:    x86_64 Report
Version:  6 Command:         MacGlass
Path:           
/Users/william_hooley_27Inch/Desktop/untitled
folder/MacGlass.app/Contents/MacOS/Sketch
Version:         1.050 (48.1) Parent: 
launchd [116] PID:             63101
Event:           hang Duration:       
3.58s (sampling started after 2 seconds) Steps:           16 (100ms
sampling interval) Pageins:         0
Pageouts:        0 Process:        
Sketch [63101] Path:           
/Users/william_hooley_27Inch/Desktop/untitled
folder/MacGlass.app/Contents/MacOS/Sketch
UID:             501   Thread edef3d4 
DispatchQueue 100   User stack:
    16 start + 54 (in Sketch) [0x1f6a]
      16 main + 30 (in Sketch) [0x1b3ee]
        16 NSApplicationMain + 574 (in AppKit) [0x91a6b2d9]
          16 -[NSApplication run] + 821 (in AppKit) [0x91a73247]
            16 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
+ 156 (in AppKit) [0x91ab0fce]
              16 _DPSNextEvent + 847 (in AppKit) [0x91ab178d]
                16 BlockUntilNextEventMatchingListInMode
+ 81 (in HIToolbox) [0x95bd0bd6]
                  16 ReceiveNextEventCommon + 354 (in
HIToolbox) [0x95bd0d51]
                    16 RunCurrentEventLoopInMode + 392 (in
HIToolbox) [0x95bd0f9c]
                      16 CFRunLoopRunInMode + 97 (in
CoreFoundation) [0x995f7291]
                        16 CFRunLoopRunSpecific + 452 (in
CoreFoundation) [0x995f7464]
                          16 __CFRunLoopRun + 8059 (in CoreFoundation) [0x995f9adb]
                            16 __NSFireTimer + 141 (in Foundation) [0x972c39b0]
                              16 _handleWindowNeedsDisplay + 696 (in AppKit) [0x91adb28a]
                                16 -[NSWindow displayIfNeeded] + 204 (in AppKit) [0x91aa9d40]
                                  16 -[NSView displayIfNeeded] + 818 (in AppKit) [0x91ae0a57]
                                    16 -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:]
+ 4122 (in AppKit) [0x91b801cf]
                                      16 CAViewEndDraw + 134 (in QuartzCore)
[0x961bd926]
                                        16 pthread_cond_wait$UNIX2003 + 73 (in
libSystem.B.dylib) [0x9800b9f8]
                                          16 __semwait_signal + 10 (in
libSystem.B.dylib) [0x9800a0a6]  
Kernel stack:
    15 semaphore_wait_continue + 0 [0x22a3dd]
    1 lo_alltraps + 454 [0x2a08a6]
      1 i386_astintr + 47 [0x2a9a9a]
        1 ast_taken + 247 [0x219107]
          1 bsd_ast + 806 [0x489088]
            1 postsig + 432 [0x4861df]
              1 exit1 + 449 [0x47ab28]
                1 task_terminate_internal + 315
[0x22c56a]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

岁吢 2024-11-08 01:47:06

造成这种情况的通常原因是过度释放对象。如果您使用 NSZombieEnabled 运行代码,控制台输出应该会给你一个线索,告诉你去哪里寻找。

或者,如果这是针对 10.5 或更高版本的 Macintosh 应用程序,您可以启用垃圾收集,而根本不用担心保留和释放。

The usual cause of something like this is over releasing objects. If you run your code with NSZombieEnabled, the console output should give you a clue as to where to look.

Alternatively, if this is a Macintosh application targeted at 10.5 or greater, you can enable garbage collection and not worry about retain and release at all.

魔法少女 2024-11-08 01:47:06

当与调试器连接的设备上的 iOS 应用程序发生此错误时,您可以通过在调试控制台上键入来找出正在调用的选择器

(gdb)x/s $r1

当加速度计的委托仍设置为已释放的对象时,这帮助我发现了问题。也许此信息对其他人有帮助。

When this error occurs on an iOS app on a device connected with the debugger you can find out the selector being called by typing on the debugging console

(gdb) x/s $r1

This helped me find a problem when the accelerometer had its delegate still set to a deallocated object. Maybe this info is helpful for others.

脸赞 2024-11-08 01:47:06

第二个崩溃报告不是崩溃,而是挂起报告。这意味着您的应用程序运行缓慢,而不是崩溃。

但总的来说,阅读并充分理解 Cocoa 内存管理指南; Cocoa 应用程序的绝大多数崩溃都是由内存管理错误造成的。该指南可以在这里找到:https:// developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html

您还应该能够使用 Xcode 调试器和 Instruments 中的 Zombies 工具等工具来收集更多详细信息有关崩溃的信息。

The second crash report is not a crash, that's a hang report. That means your app was slow, not crashing.

In general though, read and fully understand the Cocoa Memory Management guidelines; mistakes in memory management account for the vast majority of crashes in Cocoa apps. The guide can be found here: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html

You should also be able to use tools like the Xcode debugger, and the Zombies tool in Instruments to gather more detailed information about crashes.

黑色毁心梦 2024-11-08 01:47:06

我能够使用 lldb 找到有问题的选择器,但对我来说,该方法与上面使用 gdb 语义和早期版本的 iOS 的答案所描述的方法不同(我目前正在使用 iOS 8)

我的堆栈跟踪是这样开始的:

libobjc.A.dylib`objc_msgSend:
0x10c160000:  testq  %rdi, %rdi
0x10c160003:  jle    0x10c160068        ; objc_msgSend + 104
0x10c160005:  movq   (%rdi), %r11
0x10c160008:  movq   %rsi, %r10
0x10c16000b:  andl   0x18(%r11), %r10d  <== EXC_BAD_ACCESS

在 lldb 提示符下,我执行了以下操作:

(lldb) register read -G s r10
     r10 = "\xffffffc16\xffffffa4\t\x01"  "isKindOfClass:"

I was able to find the problematic selector with lldb, but the approach was different for me than described by the answer above using gdb semantics and an earlier version of iOS (I'm currently working with iOS 8)

My stack trace started like this:

libobjc.A.dylib`objc_msgSend:
0x10c160000:  testq  %rdi, %rdi
0x10c160003:  jle    0x10c160068        ; objc_msgSend + 104
0x10c160005:  movq   (%rdi), %r11
0x10c160008:  movq   %rsi, %r10
0x10c16000b:  andl   0x18(%r11), %r10d  <== EXC_BAD_ACCESS

At the lldb prompt, I did the following:

(lldb) register read -G s r10
     r10 = "\xffffffc16\xffffffa4\t\x01"  "isKindOfClass:"
强者自强 2024-11-08 01:47:06

我刚刚通过查找覆盖字符串末尾的位置解决了 objc_msgSend 中的 EXC_BAD_ACCESS,从而损坏了存储中的对象......

I just solved an EXC_BAD_ACCESS in objc_msgSend by finding where I'd overwritten the end of a string, corrupting the object in storage....

沉默的熊 2024-11-08 01:47:06

对我来说问题是我从不是 UIAleraction 的选择器调用了 UIAleraction 处理程序

The problem for me was that I called a UIAleraction handler, from a selector which wasn't a UIAleraction

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文