This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Printing a 2D array in a C program
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Neven Sajko <nsajko at gmail dot com>
- Cc: gdb at sourceware dot org
- Date: Fri, 4 Mar 2016 15:42:31 +0100
- Subject: Re: Printing a 2D array in a C program
- Authentication-results: sourceware.org; auth=none
- References: <CAL+bK4NidroyapZhGvtVVsiCbu4=Hz56mF4_oU3iXM-rvqY_xw at mail dot gmail dot com>
On Fri, 04 Mar 2016 15:27:14 +0100, Neven Sajko wrote:
> In my C program there is a square matrix implemented as an array
> of arrays, which prints nicely in GDB with `info locals`.
I do not understand how that can happen.
You should always provide sample code / example.
> But how can that nice output be accomplished if you are not in
> the function in which the array was declared, but just have it
> passed as a function parameter.
If it is a pointer (as you say C, not C++ reference) you should be able to:
(gdb) print *thatpointername
Then GDB should IMO print it the same as a local variable is printed.
Printing of C++ vectors of vectors (which is BTW wrong data structure for a 2D
matrix anyway) as a matrix was implemented by Chris Moller as a Python Pretty
printer in some versions of Fedora GDB but it was later discontinued. The
initial implementation was:
http://pkgs.fedoraproject.org/cgit/rpms/gdb.git/commit/?id=6068e6305ed7d05b4a919c28aa5bcb737e1f163b
(gdb) p test2
$2 =
{
{0 1 }
{2 3 }
{4 5 }
}
Jan