This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gdb - Printing multiple arrays or arrays of arrays


Dedeco <dedeco@ufmg.br> writes:

>    But what if I have:
>
> int **vec = malloc( 9 * sizeof(int*));
> for (i=0; i<10; i++)
>     vec[i] = malloc(10 *sizeof(int*));
>
>    How to print the 90 values I have?

set $i = 0
while $i < 9
  p vec[$i++]@10
end

>    Further, how would I print other such complex things? Like arrays of
> structures with an array inside the last.

You can define your own commands and use print, output and echo to format
the output in pretty much any way you want.  Or you could add some
functions to your program that output the structure and call them from
gdb.  The GCC sources have examples of both.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]