在我的代码中,我映射了一些内存,可以从中读取和写入。出于某种原因,当我在gdb中运行代码时,gbd无法访问它。问题是什么?
有问题的代码
cout << "creating temp" << endl;
int *temp = mmap(... PROT_READ | PROT_WRITE ...);
*temp = 5;
cout << "temp = " << *temp << endl;
运行时的输出
creating temp
temp = 5
我的gdb提示
(gdb) n
77 *temp = 5;
(gdb) p temp
$1 = (int *)0x7fffec4000;
(gdb) x temp
0x7fffec4000: cannot access memory at 0x7fffec4000
(gdb) n
78 cout << "temp = " << *temp << endl;
(gdb) x temp
0x7fffec4000: cannot access memory at 0x7fffec4000
(gdb) n
temp = 5
(gdb) x temp
0x7fffec4000: cannot access memory at 0x7fffec4000