当我们的进程发生了coredump,而我们想看一下core文件中是否包含某字符串,应该怎么做呢?
举个简单的例子:
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
int main()
{
char *testStr = "test_info";
while(1)
{
char *verifyStr = (char*)malloc(sizeof(testStr));
strncpy(verifyStr,testStr,strlen(testStr));
free(verifyStr);
}
return 0;
}
如上代码中,会在全局变量区保存字符串test_info