简体   繁体   中英

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. 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:

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

on 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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