Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 无法使用GDB找到堆栈粉碎函数_C_Gcc_Gdb - Fatal编程技术网

C 无法使用GDB找到堆栈粉碎函数

C 无法使用GDB找到堆栈粉碎函数,c,gcc,gdb,C,Gcc,Gdb,我有以下C应用程序: #include <stdio.h> void smash() { int i; char buffer[16]; for(i = 0; i < 17; i++) // <-- exceeds the limit of the buffer { buffer[i] = i; } } int main() { printf("Starting\n"); smash();

我有以下C应用程序:

#include <stdio.h>

void smash()
{
    int i;
    char buffer[16];
    for(i = 0; i < 17; i++)  // <-- exceeds the limit of the buffer
    {
        buffer[i] = i;
    }
}

int main()
{
    printf("Starting\n");
    smash();
    return 0;
}
这样调用:

armv5l-linux-gnueabi-gcc -ggdb3 -fstack-protector-all -O0 test.c
在目标上运行时,它输出:

Starting
*** stack smashing detected ***: ./a.out terminated
Aborted (core dumped)
我在gdb中加载生成的核心转储,产生以下回溯:

GNU gdb (GDB) 7.0.1
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i486-linux-gnu --target=armv5l-linux-gnueabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/andersn/workspace/stacktest/a.out...done.
Reading symbols from /home/andersn/workspace/stacktest/linux/toolchain/lib/libc.so.6...done.
Loaded symbols for /home/andersn/workspace/stacktest/linux/toolchain/lib/libc.so.6
Reading symbols from /home/andersn/workspace/stacktest/linux/toolchain/lib/ld-linux.so.3...done.
Loaded symbols for /home/andersn/workspace/stacktest/linux/toolchain/lib/ld-linux.so.3
Reading symbols from /home/andersn/workspace/stacktest/linux/toolchain    /lib/libgcc_s.so.1...done.
Loaded symbols for /home/andersn/workspace/stacktest/linux/toolchain/lib/libgcc_s.so.1
Core was generated by `./a.out'.
Program terminated with signal 6, Aborted.
#0  0x40052d4c in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
67  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    in ../nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) bt
#0  0x40052d4c in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
#1  0x40054244 in *__GI_abort () at abort.c:92
#2  0x40054244 in *__GI_abort () at abort.c:92
#3  0x40054244 in *__GI_abort () at abort.c:92
#4  0x40054244 in *__GI_abort () at abort.c:92
#5  0x40054244 in *__GI_abort () at abort.c:92
#6  0x40054244 in *__GI_abort () at abort.c:92
... and so on ...
GNU gdb(gdb)7.0.1
版权所有(C)2009免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。键入“显示复制”
和“显示保修”了解详细信息。
此GDB配置为“-host=i486 linux gnu--target=armv5l linux gnueabi”。
有关错误报告说明,请参阅:
...
从/home/andersn/workspace/stacktest/a.out读取符号…完成。
从/home/andersn/workspace/stacktest/linux/toolchain/lib/libc.so.6读取符号…完成。
加载了/home/andersn/workspace/stacktest/linux/toolchain/lib/libc.so.6的符号
从/home/andersn/workspace/stacktest/linux/toolchain/lib/ld linux.so.3读取符号…完成。
加载了/home/andersn/workspace/stacktest/linux/toolchain/lib/ld linux.so.3的符号
从/home/andersn/workspace/stacktest/linux/toolchain/lib/libgcc_.so.1读取符号…完成。
为/home/andersn/workspace/stacktest/linux/toolchain/lib/libgcc_.so.1加载的符号
核心由“./a.out”生成。
程序以信号6终止,中止。
#0 0x40052d4c在../nptl/sysdeps/unix/sysv/linux/raise.c:67处的*GI_raise(sig=6)中
67../nptl/sysdeps/unix/sysv/linux/raise.c:没有这样的文件或目录。
在../nptl/sysdeps/unix/sysv/linux/raise.c中
(gdb)英国电信
#0 0x40052d4c在../nptl/sysdeps/unix/sysv/linux/raise.c:67处的*GI_raise(sig=6)中
#1 0x40054244英寸*\uuuu GI\u abort()位于abort.c:92
#2 0x40054244英寸*\uuuu GI\u abort()位于abort.c:92
#3 0x40054244 in*\uuu GI\u abort()位于abort.c:92
#4 0x40054244英寸*\uuuu GI\u abort()位于abort.c:92
#5 0x40054244英寸*\uuuu GI\u abort()位于abort.c:92
#6 0x40054244英寸*\uuuu GI\u abort()位于abort.c:92
... 等等
现在,问题是:
我完全无法从GDB中找到导致堆栈崩溃的函数,即使smash()函数不覆盖堆栈的任何结构数据,只覆盖堆栈保护器本身。我该怎么办?

你有没有试过解决这个问题:“
。/nptl/sysdeps/unix/sysv/linux/raise.c:没有这样的文件或目录。
”看看能不能真正解决符号会有帮助?

GDB并不是总能解决一个崩溃的堆栈发生了什么问题,即使使用-fstack-protector-all(甚至使用-Wstack protector来警告具有未受保护的帧的函数)


在这些情况下,堆栈保护器已经完成了它的工作(杀死了一个行为不端的应用程序),但没有对调试器做任何帮助。(典型的例子是堆栈崩溃,其中写入操作以足够大的步幅发生,以至于跳过了金丝雀。)在这些情况下,可能需要通过断点对代码进行二进制搜索,以缩小代码的哪个区域导致了破坏,然后单步通过破坏来查看它是如何发生的。

问题是编译目标libc.so.6的GCC版本有缺陷,并且没有发出正确的展开描述符对于
\uu GI\u raise
。使用不正确的展开描述符,GDB在展开堆栈时进入循环

您可以使用检查展开描述符

readelf -wf /home/andersn/workspace/stacktest/linux/toolchain/lib/libc.so.6
我希望在GDB中,任何调用abort的程序都会得到完全相同的结果,例如

#include <stdlib.h>
void foo() { abort(); }
int main() { foo(); return 0; }
#包括
void foo(){abort();}
int main(){foo();返回0;}

不幸的是,除了尝试构建新版本的GCC,然后用它重建整个“世界”之外,你无能为力。

我认为你的“等等”可能遗漏了一些重要信息。u GI_abort真的是堆栈的底部吗?我尝试继续GDB输出,并在放弃之前达到了#11087…所有帧都相等。您正在显式破坏堆栈-不要期望核心文件具有整齐链接的调用帧:)我认为堆栈应该是完全有效的,因为我只超出了合法范围1个字节,这就是堆栈的位置protector@NikolaiN Fetissov:gcc(x86_64 4.4.5)上的Linux AMD64(2.6.35)上的测试按照上述方法(循环增加到31,ulimit-c unlimited)给出了一个核心转储,其中堆栈帧是gdb(7.2)的没有,但GDB在给定位置没有丢失符号信息,只有清单的源代码文件。不过,我会试试你的建议。。。谢谢你,我试过了,运气不好。GDB在raise.c中显示了源代码行,但回溯仍然损坏。是的,简而言之,应该是这样。但是,使用新编译器重建libc.so可能就足够了。仅重建libc.so.6可能还不够:毕竟,也不能保证foo()将使用“old”GCC获得正确的展开描述符。
#include <stdlib.h>
void foo() { abort(); }
int main() { foo(); return 0; }