我正在玩指针,只是做一些基本的事情来巩固我对它们的理解。当我尝试使用 GDB 的“下一步”和“步骤”调试并遵循我在网上找到的这个示例时,GDB 会在函数的末尾运行。在它到达语句“return 0;”之后 它告诉我它“无法在 start() 中访问地址 0x0 0x0000000100000de4 的内存
这是代码:
#include <cstdio>
#include <ctype.h>
int main()
{
char my_str[] = "hello world";
*my_str = toupper(*my_str);
*(my_str + 6) = toupper(*(my_str + 6));
printf("%s", my_str); // prints, "Hello World"
return 0;
}
这是 gdb 的输出:
Breakpoint 1, main () at pwp.cpp:10
10 return 0;
(gdb) n
Cannot access memory at address 0x0
0x0000000100000de4 in start ()
(gdb) s
Single stepping until exit from function start,
which has no line number information.
0x0000000100000ed6 in dyld_stub_exit ()
(gdb) n
Single stepping until exit from function dyld_stub_exit,
which has no line number information.
0x0000000100000f08 in dyld_stub_printf ()
(gdb) n
Cannot find bounds of current function
(gdb) q
发生了什么导致这种情况?