NDK堆栈不能得到完整的堆栈堆栈、完整、NDK

2023-09-07 00:45:15 作者:喂我好饿

我写了一张code,为了测试NDK堆栈这里是code片段

I wrote a piece of code, in order to test the ndk-stack Here is the code fragment

libtest.so

libtest.so

    std::vector<int> testVec;

    testVec.at(500);

但我得到的是不完整的协议栈

But I get was incomplete stack

********** Crash dump: **********
Build fingerprint: 'MI/casablanca_icntv/casablanca:4.2.2/CADEV/1253:user/release-keys'
pid: 24989, tid: 24989  >>> com.ktcp.video <<<
signal 11 (SIGSEGV), fault addr deadbaad
Stack frame #00  pc 0001a852  /system/lib/libc.so: Routine ????:0
Stack frame #01  pc 00018190  /system/lib/libc.so (abort): Routine ????:0
Stack frame #00  pc 0001a852  /system/lib/libc.so: Routine ????:0
Stack frame #01  pc 00018190  /system/lib/libc.so (abort): Routine ????:0
Stack frame #00  pc 0001a852  /system/lib/libc.so: Routine ????:0
Stack frame #01  pc 00018190  /system/lib/libc.so (abort): Routine ????:0
Stack frame #00  pc 0001a852  /system/lib/libc.so: Routine ????:0
Stack frame #01  pc 00018190  /system/lib/libc.so (abort): Routine ????:0
^C^C

在堆栈中没有看到我的code,不完整的协议栈

In the stack did not see my code, incomplete stack

如何解决它。

推荐答案

0xdeadbaad 被使用仿生libc中,表示有意中止。你可以看到堆栈的片段你得到中止()到的电话。我猜你是触发一个断言失败(这将在logcat中显示出来)。

0xdeadbaad was used by Bionic libc to indicate a deliberate abort. You can see a call to abort() on the fragment of stack you do get. I'm guessing you're triggering an assertion failure (which would show up in logcat).

在Android上的一些版本,在某些情况下,你没有得到从一个很好的跟踪中止()。问题的部分原因是该函数被标记与不返回的属性,所以当你做这样的事情,编译器会吐不出来抱怨:

On some versions of Android, in some circumstances, you don't get a good trace from abort(). Part of the problem is that the function was tagged with the noreturn attribute so the compiler wouldn't spit out complaints when you did something like this:

int foo(int x) {
    if (x == 0) {
        return 12345;
    } else {
        abort();
    }
}

如果中止()返回,这个方法会返回一个未定义的值。在ARM,返回地址住在LR寄存器,并必要时在栈上preserved ......但如果​​函数没有返回,那么就没有必要保存的返回地址,所以编译器允许把它扔掉。直到你想有一个地址堆栈跟踪这工作了巨大的。如果LR被重新使用,而旧的值没有溢出到堆栈,它只是不见了。

If abort() returned, this method would return an undefined value. On ARM, the return address lives in the LR register, and is preserved on the stack if necessary... but if the function doesn't return, then there's no need to save the return address, so the compiler is allowed to throw it away. This works out great until you want to have that address for the stack trace. If LR gets re-used, and the old value wasn't spilled to the stack, it's simply gone.

我觉得可能是一个版本编译器在哪里的问题是固定的,但一些汇编元数据是错误的,导致类似的麻烦。

I think there might have been a release where the compiler issue was fixed, but some assembler meta-data was wrong, leading to similar trouble.

Android的最新版本不应出现此行为。最新版本也换成与更传统的SIGABRT访问 0xdeadbaad ,让你再也看不到这个特定的崩溃签名。

Recent versions of Android should not exhibit this behavior. Recent versions also replaced access to 0xdeadbaad with the more traditional SIGABRT, so you no longer see this particular crash signature.

(FWIW,你可以看到不返回的 在4.2.2(见注释)。它工作在早期版本的系统。)

(FWIW, you can see an attempted workaround for noreturn in 4.2.2 (see comments). It worked in earlier versions of the system.)

 
精彩推荐
图片推荐