2013-03-11 36 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