From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29325 invoked by alias); 18 Jul 2007 20:32:26 -0000 Received: (qmail 29317 invoked by uid 22791); 18 Jul 2007 20:32:25 -0000 X-Spam-Check-By: sourceware.org Received: from 0x5731473b.taanxx2.adsl-dhcp.tele.dk (HELO linuxbog.dk) (87.49.71.59) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 18 Jul 2007 20:32:22 +0000 Received: from localhost (localhost [127.0.0.1]) by linuxbog.dk (Postfix) with ESMTP id E246E328CE2 for ; Wed, 18 Jul 2007 22:32:19 +0200 (CEST) Date: Wed, 18 Jul 2007 21:56:00 -0000 From: Peter Toft To: gdb@sourceware.org Subject: Re: gdb printing of dynamically allocated matrix In-Reply-To: Message-ID: References: <20070718183326.GA25345@caradoc.them.org> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-1463811583-2087597040-1184790739=:4288" X-IsSubscribed: yes 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 X-SW-Source: 2007-07/txt/msg00146.txt.bz2 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1463811583-2087597040-1184790739=:4288 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Content-length: 1951 On Wed, 18 Jul 2007, Peter Toft wrote: > On Wed, 18 Jul 2007, Daniel Jacobowitz wrote: > > > On Wed, Jul 18, 2007 at 01:22:33PM +0200, Peter Toft wrote: > > > * However how can I use GDB to see the contents of "b" > > > similar to the contents of "c" and "a"? > > > The best I can do is > > > (gdb) print *b[0] @3 > > > (gdb) print *b[1] @3 > > > Obviously I would like to do the display in one command rather > > > than several, especially if I changed the b-matrix to be b[7][8] > > > > I don't believe this is possible without writing a user-defined > > command for it - see the manual. > > Something like > > define matprint > set $i = 0 > while $i< $arg1 > echo $arg0[$i++][0] @ $arg2 > end > end > > so I then can do > (gdb) matprint c 2 3 > > close but I quess it can be made better[1] or ... define matprint2 set $i = 0 print printf "{{" while $i< $arg1 set $j = 0 printf "%d",$arg0[$i][$j++] while $j< $arg2 printf ", %d",$arg0[$i][$j++] end printf "}" set $i = 1+$i if $i < $arg1 printf ", {" end end printf "}\n" end (gdb) matprint c 2 3 {{2, -2, 22}, {12, -12, 212}} >From the manual I don't understand how the macro is further hacked to also give the exact output format as (gdb) print c $1 = {{2, -2, 22}, {12, -12, -12}} so my matprint does not insert into a dollar variable - can someone help with this last part? /peter > > > > > > > How come that the next vector contains wrong values? > > > > It's printing six consecutive elements from memory. > > Yeah - seems to be the case > > Thanx Daniel > > Best regards > > Peter > > [1] after GDB-101 manual crash reading :) > > -- > Peter Toft, Ph.D. [pto@linuxbog.dk] http://petertoft.dk > Følg min Linux-blog på http://www.version2.dk/blogs/petertoft > -- Peter Toft, Ph.D. [pto@linuxbog.dk] http://petertoft.dk Følg min Linux-blog på http://www.version2.dk/blogs/petertoft ---1463811583-2087597040-1184790739=:4288--