Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to spawn a shell using gdb

Tags:

c++

c

bash

gdb

I have this C function in a huge code:

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

I am trying to debug this code using 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.

Hence the shell is not spawning. How to go about it?

like image 670
leet Avatar asked Apr 21 '26 21:04

leet


1 Answers

gdb isn't allowing you to exec a binary with a different architecture, even though it's compatible on your platform. The same occurs if you try to exec a 32bit executable from a 64bit one. This occurs on the latest version (7.5.1) of gdb as well.

If you can compile your code as 32bit without it causing other problems, it would be a workaround.

As per Hasturkun's comment, there is a patch available here.

like image 116
teppic Avatar answered Apr 24 '26 12:04

teppic