嗨,我正在学习一些调试概念。在这个程序中,我试图模拟核心转储。我希望核心会被转储但它不会生成核心。程序执行没有任何问题。
首先,我为 ptr 分配 20 个字节。我将一个新字符串复制到 ptr。然后我释放 ptr 然后打印 ptr 它在没有任何 pblm 的情况下工作。最后,我重新分配了一些其他字符串,我希望这次它可能会生成核心转储。但我没有得到任何核心转储。任何人都可以解释为什么它不生成核心转储。
int main()
{
char *ptr;
ptr =(char*) malloc (20);
strcpy(ptr,"MemoryOperations");
printf("Before Free memory : %s\n",ptr);
free(ptr);
printf("After Free memory : %s\n",ptr);
strcpy(ptr,"MemReassign");
printf("After Re Assigning : %s\n",ptr);
return 0;
}
我使用 dbx 运行的相同代码,
(dbx) check -all
access checking - ON
memuse checking - ON
(dbx) run
Running: a.out
(process id 19081)
RTC: Enabling Error Checking...
RTC: Running program...
Before Free memory : MemoryOperations
Read from unallocated (rua):
Attempting to read 1 byte at address 0x100101a48
which is 2232 bytes into the heap; no blocks allocated
stopped in _ndoprnt at 0xffffffff671abbf0
0xffffffff671abbf0: _ndoprnt+0x1c04: call _PROCEDURE_LINKAGE_TABLE_+0x620 [PLT] ! 0xffffffff67340d20
(dbx) exit