样例源代码:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define GIGABYTE 1024*1024*1024
int
main (void)
{
void *foo;
int result;
foo = (void *) malloc (GIGABYTE*5);
result = errno;
if (foo != NULL) {
return 2;
} else {
fprintf (stderr, "ERROR: %d\n", result);
return 1;
}
return 0;
}
问题:
- 如何指示gdb (
# gdb -silent ./huge_malloc
) 在malloc()
返回0x0
时停止/暂停执行,而不需要检查foo
是否为0x0
malloc
的返回值和foo
的结果值)? - NPEmalloc()
上打断点,然后使用命令列表首先退出malloc()
,然后有条件地继续,如果$eax != 0
? - Georg Fritzsche