From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24783 invoked by alias); 23 Jul 2007 19:22:32 -0000 Received: (qmail 24774 invoked by uid 22791); 23 Jul 2007 19:22:31 -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; Mon, 23 Jul 2007 19:22:29 +0000 Received: from localhost (localhost [127.0.0.1]) by linuxbog.dk (Postfix) with ESMTP id 2F89A329629; Mon, 23 Jul 2007 21:22:26 +0200 (CEST) Date: Mon, 23 Jul 2007 21:38:00 -0000 From: Peter Toft To: Jim Blandy cc: 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-757306675-1185218546=: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/msg00165.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-757306675-1185218546=:4288 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Content-length: 1438 On Mon, 23 Jul 2007, Jim Blandy wrote: > > Peter Toft writes: > > On Fri, 20 Jul 2007, Jim Blandy wrote: > > > >> > >> Peter Toft writes: > >> >> (gdb) matprint c 2 3 > >> > >> Could you use sizeof to compute the dimensions automatically? Or at > >> least one of them? > > > > Dear Jim > > > > I think I understand which direction you are point me to, but > > "sizeof" in GDB does not ring a bell here. In C yes, but in GDB no. > > > > Can you give me an example e.g. for 1D arrays? We might target this > > snippet befor we move to 2D matrices; > > > > int *a; > > a=(int *)malloc(3*sizeof(int)); > > a[0] = 1; > > a[1] = 6; > > a[2] = 8; > > Ah, if you're allocating dynamically, then there's no way to do it > using sizeof. Clearly my focus is dynamic memory allocation. > GDB supports the C 'sizeof' operator; in your example above, 'print > sizeof (a)' will give you '4' or '8' or whatever is appropriate for a > pointer on the program being debugged. There are no facilities (in C > or in GDB) for finding the size of a malloc block; since the library > may round up the size of the block, it might be impossible to do > without changing the heap data structure. Ok - we are now on the same (memory) page :-) I was just a bit confused by your answer. -- Peter Toft, Ph.D. [pto@linuxbog.dk] http://petertoft.dk Følg min Linux-blog på http://www.version2.dk/blogs/petertoft ---1463811583-757306675-1185218546=:4288--