是什么原因导致“EXC_BAD_ACCESS”?获取wifi信息时出错?

发布于 2024-08-11 01:03:56 字数 650 浏览 9 评论 0原文

我收到以下错误

程序收到信号:“EXC_BAD_ACCESS”。
警告:check_safe_call:无法恢复当前帧

警告:无法恢复之前选择的帧。
警告:无法恢复先前选择的帧。

我的应用程序是获取 wifi 信息

libHandle = dlopen("/System/Library/PrivateFrameworks/ MobileWiFi.framework/MobileWiFi",RTLD_LAZY);

open = dlsym(libHandle, "Apple80211Open");
bind = dlsym(libHandle, "Apple80211BindToInterface");
close = dlsym(libHandle, "Apple80211Close");
scan = dlsym(libHandle, "Apple80211Scan");

open(&airportHandle);

bind(airportHandle, @"en0");

当代码到达 open(&airportHandle) 时,我收到错误,但我不确定,因为在这一行它停止了。

我该如何解决这个问题?

I'm getting the following error

Program received signal: “EXC_BAD_ACCESS”.
warning: check_safe_call: could not restore current frame

warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.

My app is to get wifi information

libHandle = dlopen("/System/Library/PrivateFrameworks/ MobileWiFi.framework/MobileWiFi",RTLD_LAZY);

open = dlsym(libHandle, "Apple80211Open");
bind = dlsym(libHandle, "Apple80211BindToInterface");
close = dlsym(libHandle, "Apple80211Close");
scan = dlsym(libHandle, "Apple80211Scan");

open(&airportHandle);

bind(airportHandle, @"en0");

When the code reaches open(&airportHandle), I receive the error but I'm not sure because at this line it stops.

How can I resolve this?

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

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

发布评论

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

评论(5

谜泪 2024-08-18 01:03:56

对于任何 EXC_BAD_ACCESS 错误,您通常尝试向已释放的对象发送消息。追踪这些的最佳方法是使用NSZombieEnabled

这是通过从不真正释放一个对象,而是通过将其包装为“僵尸”并在其中设置一个标志来表示它通常会被释放来实现的。这样,如果您尝试再次访问它,它仍然知道您犯错误之前的情况,并且有了这一点信息,您通常可以回溯以查看问题所在。

当调试器有时会放弃任何有用的信息时,它在后台线程中尤其有用。

非常重要的是要注意,但是,您需要 100% 确保这仅在您的调试代码中,而不是在您的分发代码中。因为没有任何东西被发布,所以你的应用程序将会泄漏、泄漏、泄漏。为了提醒我这样做,我将此日志放入我的应用程序委托中:

if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
  NSLog(@"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");

如果您需要帮助找到确切的行,请执行构建和调试 (CMD-Y),而不是构建和运行 (CMD-R)。当应用程序崩溃时,调试器将准确地显示哪一行,并结合 NSZombieEnabled,您应该能够找出确切的原因。

For any EXC_BAD_ACCESS errors, you are usually trying to send a message to a released object. The BEST way to track these down is use NSZombieEnabled.

This works by never actually releasing an object, but by wrapping it up as a "zombie" and setting a flag inside it that says it normally would have been released. This way, if you try to access it again, it still know what it was before you made the error, and with this little bit of information, you can usually backtrack to see what the issue was.

It especially helps in background threads when the Debugger sometimes craps out on any useful information.

VERY IMPORTANT TO NOTE however, is that you need to 100% make sure this is only in your debug code and not your distribution code. Because nothing is ever released, your app will leak and leak and leak. To remind me to do this, I put this log in my appdelegate:

if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
  NSLog(@"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");

If you need help finding the exact line, Do a Build-and-Debug (CMD-Y) instead of a Build-and-Run (CMD-R). When the app crashes, the debugger will show you exactly which line and in combination with NSZombieEnabled, you should be able to find out exactly why.

韵柒 2024-08-18 01:03:56

当访问已经释放的内存时,总是会发生 EXC_BAD_ACCESS。在您的示例代码中,我看不到 airportHandle 的初始化位置,或者它是否已初始化。

如果它已经初始化,但您只是忘记发布该代码,您应该尝试检查是否在某处释放了句柄。

要调试此类访问冲突,将 NSZombieEnabled 环境标志设置为 YES 通常很有用。这将导致 Obj-C 运行时将对已释放内存的访问记录到控制台。您可以找到完整教程,了解如何将该信息与 Instruments 结合使用来查找问题。

EXC_BAD_ACCESS always occurs when accessing memory you already have released. In your sample code, I can't see where airportHandle is initialized, or wheter it is initialized at all for that matter.

If it has been initialized but you just forgot to post that code, you should try checking if you released the handle somewhere.

To debug such an access violation, it is often useful to set the NSZombieEnabled Environment flag to YES. This will cause the Obj-C runtime to log access to released memory to the console. You can find a full tutorial on how to use that information together with Instruments to find your problem.

任性一次 2024-08-18 01:03:56

EXC_BAD_ACCESS。主要是在您释放将来需要的任何对象时找到的。它无法找到,但有解决方案可以找出您必须处于调试模式。然后按照这些链接

http://www.codza.com/how-to -debug-exc_bad_access-on-iphone

它确实有效

EXC_BAD_ACCESS. is mainly found when u released any object which you have further needed in future.it is unable to find but there is solution to find out u must have to be in a DEBUG mode . then follow these links

http://www.codza.com/how-to-debug-exc_bad_access-on-iphone

it really works

岁月染过的梦 2024-08-18 01:03:56

我正在做同样的事情,也遇到了同样的问题。如果您进入调试模式,您可以看到当我们使用 open = dlsym(libHandle, "Apple80211Open"); 时,函数仍然等于 0。

所以在我看来,您正在寻找 Apple80211Open 在不包含此功能的框架中。

Apple80211Open 位于 Apple80211 私有框架中,该框架在 >iOS 2.x SDK 中已过时。 MobileWifi 框架中针对 3.x 和 4.x SDK 的等效项是 /System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager 而不是 /System/Library/ PrivateFrameworks/MobileWiFi.framework/MobileWiFi

I'm working on the same thing, and I get the same issue. If you enter in debug mode, you can see that when we use open = dlsym(libHandle, "Apple80211Open"); the function still equals to 0.

So in my opinion you are looking for the Apple80211Open in a framework which did not contain this function.

Apple80211Open is in the Apple80211 private framework which is outdated in >iOS 2.x SDK. The equivalent in the MobileWifi framework, which is for the 3.x and 4.x SDK, is /System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager instead of /System/Library/PrivateFrameworks/MobileWiFi.framework/MobileWiFi

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