无法在 malloc() 处设置断点

Sur*_*shi 2 c linux malloc gcc gdb

代码示例(foo.c)

int main(){
 int *x=(int*)malloc(sizeof(int));  // break here
 *x=10;
 free(x);
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

我想在 malloc 处中断。这是我尝试的:

# gcc -g foo.c -o bar
# gdb bar
(gdb) b main
Breakpoint 1 at 0x80484cf: file src.c, line 7.
(gdb) r
Breakpoint 1, main () at src.c:7
(gdb) b malloc
Breakpoint 2 at 0x550944
(gdb) c
Program exited normally.
Run Code Online (Sandbox Code Playgroud)

我的系统规格是:

  • 操作系统:CentOS 5.5
  • gcc:gcc(GCC)4.1.2 20080704(红帽4.1.2-52)
  • gdb:GNU gdb (GDB) 红帽企业 Linux (7.0.1-42.el5)

请告诉我哪里错了!!

Ark*_*kku 5

我无法可靠地重现该错误,但在 Linux 上,您可以尝试中断__libc_malloc而不是malloc.