我正在尝试查找数组元素的内存位置。函数基本上是这样的(在 C 中):
int function(struct MyStruct *s)
{
char myArray[16];
printf("\n");
printf("\n");
gets(myArray);
return strcasecmp(s->a,guess);
}
根据在线 GDB 指南,我应该能够执行“x myArray”或“x myArray[0]”或“p myArray”或“p myArray[0]”来查看元素或内存位置。我在 function 和 gets 处设置了断点(并一直持续到 gets 断点),但是当我尝试 GDB 命令时,我得到“没有这样的文件”。我还尝试了“b 15”在数组和“b 16”处设置断点。但我仍然遇到同样的错误。为什么会发生这种情况,我该如何解决?
最佳答案
"break main, break function, break gets, break 15 (which didn't work), break 16 (which didn't work), run, s (until I reach the gets breakpoint), x myArray, x myArray[0], p myArray, p myArray[0]"
你做的错了。
当您遇到 gets
断点时,您会在 gets
中停止。
在那里,myArray
变量是不可见的——它在 function
中,而不是在 gets
中。
你也不能在 gets
中 break 15
,因为你没有 libc
的调试信息(这是 gets
实现)。
您要做的是从gets
中的断点开始finish
(这将使您返回到function
)。 现在您应该可以查看myArray
或break 15
等
关于c - GDB 中的数组错误(用 C 语言编写),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10364093/