简体   繁体   English

gdb如何检查2D数组元素

[英]gdb how to inspect 2D array elements

I was happily debugging in GDB and then I hit a 2D array that might hold incorrect values. 我很高兴在GDB中进行调试,然后遇到了可能包含错误值的2D数组。 However I cant seem to be able to print an single element. 但是我似乎无法打印单个元素。

p array2D[0][0]

gives me 给我

Cannot perform pointer math on incomplete types, try casting to a known type, or void *. 无法对不完整的类型执行指针数学运算,请尝试强制转换为已知类型,或者无效*。

I tried to google this but I can't find anything and I am not sure if I am missing something obvious. 我试图用谷歌搜索,但是找不到任何东西,我不确定是否缺少明显的东西。

p arr[0][0] works for me my test code: p arr[0][0]对我p arr[0][0]我的测试代码:

#include<stdio.h>
int main()
{
  int a[3][3];
  a[0][0]=1;
  a[0][1]=2;
  return 0;
}

on gdb: 在gdb上:

(gdb) b test.c:6
Breakpoint 1 at 0x400473: file test.c, line 6.
(gdb) r
Starting program: a.out

Breakpoint 1, main () at test.c:6
6       a[0][1]=2;
(gdb) p a[0][0]
$1 = 1
(gdb) ptype a
type = int [3][3]

so its not p arr[0][0] which is the problem but something else. 所以不是问题p arr[0][0]而是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM