6

I am trying to get a formatted print of a long 2D array, of width 8, of floats. When using the x command, I get the array printed as four-column table:

(gdb) x/16f 0x81000000
0x81000000: 0   0   1   0
0x81000010: 2   0   3   0
0x81000020: 4   0   5   0
0x81000030: 6   0   7   0

When using the p command, I get an unformatted output, the width of the terminal:

(gdb) p/f *(0x81000000)@16
$27 = {0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0}

Required output, something like:

(gdb) x/16f 0x81000000
0x81000000: 0   0   1   0   2   0   3   0
0x81000020: 4   0   5   0   6   0   7   0

or:

(gdb) p/f *(0x81000000)@16
$27 = {0, 0, 1, 0, 2, 0, 3, 0,
       4, 0, 5, 0, 6, 0, 7, 0}

Is there a simple way to format the output for a specific width?

ysap
  • 7,723
  • 7
  • 59
  • 122

1 Answers1

-2

Use python scripting:

I think this is pretty close, if pretty obscure:

python print "\n".join(", ".join(gdb.execute('x/f 0x%x' % a, False, True).split()[-1] for a in range(s, s+32, 4)) for s in range(0x81000000, 0x81000040, 32))

dianders
  • 77
  • 5
  • 1
    Thanks. I am totally absolutely unfamiliar with Python. Am I supposed to type this in the gdb prompt? – ysap Oct 19 '12 at 01:00