GDB question: Pretty-Printing a 2D Array?

前端 未结 5 554
温柔的废话
温柔的废话 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 23:08

    This is a more helpful extension of the last post. Also you can use: print var @cols@rows

    define printMatrix
    set $arr = $arg0
    set $rows = $arg1
    set $cols = $arg2
    set $i = 0
    printf "\n"
    while $i < $rows
    set $j = 0
    while $j < $cols
    printf "%8.4f,",$arr[$i*$cols + $j]
    set $j = $j + 1
    end
    printf "\n"
    set $i = $i + 1
    end
    

提交回复
热议问题