2013-03-11 38 views
3

产卵壳我有一个庞大的代码这个C函数:无法用gdb

void test() { 
    char *arg[] = {"/bin/sh", 0}; 
    execve("/bin/sh", arg, 0); 
} 

我试图用gdb

 
(gdb) call test() 
process 1948 is executing new program: /bin/dash 
warning: Selected architecture i386:x86-64 is not compatible with reported target architecture i386 
Architecture of file not recognized. 
An error occurred while in a function called from GDB. 
Evaluation of the expression containing the function 
(test) will be abandoned. 
When the function is done executing, GDB will silently stop. 

因此,外壳不产卵调试代码。如何去做呢?

+0

你正在使用哪个版本的gdb? – Hasturkun 2013-03-11 16:04:04

+0

GNU gdb(Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04 – leet 2013-03-11 16:05:01

+0

如果在没有gdb的情况下运行,它会启动shell吗? – teppic 2013-03-11 16:07:40

回答

2

gdb不允许您使用不同架构来执行二进制文件,即使它在您的平台上兼容。如果您尝试从64位的可执行文件执行一个32位可执行文件,则会发生同样的情况。这也发生在gdb的最新版本(7.5.1)上。

如果你可以编译你的代码为32位而不会导致其他问题,这将是一个解决方法。

根据Hasturkun的评论,有一个补丁可用here