开发者

IOS EXC_BAD_INSTRUCTION while "int y = 0;"

I have this call in UIViewController-inheritor class context:

+ (void) smthPressed: (id) caller
{
    // some code here
    // ...

    startTimers();
}

startTimers declared as:

inline void startTimers()
{
    NSString * x = @""; // falls here with EXC_BAD_INS开发者_运维技巧TRUCTION

    // some other codes here
}

What the HELL is going on?

P.S.:

inline void startTimers()
{
    int x = 0;

    int y = 0; // EXC_BAD_INSTRUCTION here. Stack couldn't end there!

    // ...

P.P.S.:

Documentation says: "For most non-memory access exceptions (for example, EXC_BAD_INSTRUCTION ...)", so it is NOT mem-access fault.

P.P.P.S.: arch is Standart (armv6 armv7). Nothing changes if I set Optimized (armv7).


Perhaps you have corrupted your stack accidentally. Does it occur when you place the startTimers() code elsewhere in your program?

Try using NSZombieEnabled and the static analyser to look for other places in your code you might be making memory-management errors that could lead to a write to a stack variable being invalid (overflowing arrays on the stack, bad pointers, etc).

You could also try switching compilers, if that option is available to you, in the extremely rare case that you hit a complier bug.


I think there is compiler issue here. Now, 6 years since your raising the issue, if I try to get your original code to compile it fails. It's down to the static keyword. The following code compiles and runs ok:

#import "ViewController.h"

@interface ViewController () 

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [ViewController smthPressed:self];
}

// Without the "static" keyword compile fails
static inline void fakeStartTimers() {
    int x = 0;
    int y = 0;
    printf("x and y are %d %d", x, y);
}

+ (void)smthPressed:(id) caller
{
    fakeStartTimers();
}

@end

This is with the compiler

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --version
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜