From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10918 invoked by alias); 4 Mar 2016 14:42:37 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 10904 invoked by uid 89); 4 Mar 2016 14:42:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Pretty, Hx-languages-length:1063, rpms, pkgsfedoraprojectorg X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 04 Mar 2016 14:42:36 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 1834832A89B; Fri, 4 Mar 2016 14:42:35 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u24EgWtn032691 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 4 Mar 2016 09:42:34 -0500 Date: Fri, 04 Mar 2016 14:42:00 -0000 From: Jan Kratochvil To: Neven Sajko Cc: gdb@sourceware.org Subject: Re: Printing a 2D array in a C program Message-ID: <20160304144231.GA7767@host1.jankratochvil.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00007.txt.bz2 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