可以用汇编来实现。代码如下:
int main(void)
{
int i = 0;
#ifdef X86
asm ("int $0x03");
#endif
#ifdef ARM
asm ("bkpt");
#endif
i = 10;
return 0;
}
执行的时候,不用设置断点:
$ gdb setbreakpoint --silent
Reading symbols from setbreakpoint...done.
(gdb) r
Starting program: /home/charles/code/setbreakpoint
Program received signal SIGTRAP, Trace/breakpoint trap.
main () at setbreakpoint.c:10
10 i = 10;
(gdb)
ARM下的测试结果:
gdb setbreakpoint --sil
ent
Reading symbols from setbreakpoint...done.
(gdb) r
Starting program: /mnt/code/setbreakpoint
Unhandled prefetch abort: debug event (0x002) at 0xb6ecbee0
Program received signal SIGBUS, Bus error.
main () at setbreakpoint.c:8
8 asm ("bkpt");
(gdb) where
#0 main () at setbreakpoint.c:8