GDB question: Pretty-Printing a 2D Array?

前端 未结 5 526
温柔的废话
温柔的废话 2020-12-14 22:11

I have a 2d array matrix[10][10] that I\'d like to inspect at debug time.

I understand that I can do this in GDB using

p *matrix@10

5条回答
  •  北海茫月
    2020-12-14 22:46

    Can you do this?:

    p *((double (*)[3][3])pointerToMatrix3x3)
    
       (double [3][3]) $6 = {
      [0] = ([0] = 1821.8790830216928, [1] = 0, [2] = 1622.4513098457062)
      [1] = ([0] = 0, [1] = 1172.3930433142486, [2] = 1314.4812787191868)
      [2] = ([0] = 0, [1] = 0, [2] = 1)
    
    p *((double (*)[4])pointerToVector4)
    
      (double [3]) $7 = ([0] = 1821.8790830216928, [1] = 0, [2] = 1622.4513098457062)
    

    It works in lldb - Haven't tried it in gdb. It seems a lot easier.

提交回复
热议问题