How to debug EXC_BAD_ACCESS bug

前端 未结 3 1604
孤城傲影
孤城傲影 2020-12-14 01:17

I received an error

EXC_BAD_ACCESS code=2 at0xb0987654

I am wondering how to print out the value at 0xb0987654?

3条回答
  •  没有蜡笔的小新
    2020-12-14 01:50

    It looks like maybe you are trying to write onto a code page or something? EXC_BAD_ACCESS is described in /usr/include/mach/exception_types.h:

    #define EXC_BAD_ACCESS          1       /* Could not access memory */
                /* Code contains kern_return_t describing error. */
                /* Subcode contains bad memory address. */
    

    And from kern_return.h:

    #define KERN_PROTECTION_FAILURE         2
                /* Specified memory is valid, but does not permit the
                 * required forms of access.
                 */
    

    You can see WHERE that address is in your binary by doing:

    (lldb) image lookup -va 0xb0987654
    

    But what you really need to figure out is who is trying to write there. If the problem is simple this might tell you what's wrong, but as Jasper suggests, this is probably some use-after-free or other such problem, and the bad actor is long gone by the time you crash. guardmalloc can also sometimes catch this sort of error (you can enable this in Xcode in the Run scheme.)

提交回复
热议问题