SIGTRAP recieved while trying to call C function from GDB

Avi Gozlan
2009-09-06T15:03:50Z

Hello,

We get SIGTRAP when trying to call C functions in GDB prompt. Following is an example program:

#include <stdio.h>

class A{
public:
A() {}
};

int main(int argc, char **argv)
{
A *a = new A;

printf("hello, world\n");
}

Scenario:
1. Run gdb a.out
2. b main
3. r
4. n (GDB stops prior to the printf() call)
5. p atoi(“1”)

(gdb) p atoi(“1”)

Program received signal SIGTRAP, Trace/breakpoint trap.
0x004b7411 in malloc () from /lib/ld-linux.so.2
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (malloc) will be abandoned.
(gdb)

This does not happen if calling ‘p atoi(“1”)’ immediately when running the program or following the printf() function call.

GDB version: 6.8
Linux Release: Red Hat Enterprise Linux Server release 5.1 (Tikanga)
Kernel version: 2.6.18-53.1.13.el5PAE
Compiler: either gcc 4.1.2 20070626 or gcc 3.2.3 20030502
Compilation command: gcc –g –l stdc++   myprog.cc

Thanks,

Avi