From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19893 invoked by alias); 6 Jun 2005 13:52:34 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 19826 invoked by uid 22791); 6 Jun 2005 13:52:30 -0000 Received: from zigzag.lvk.cs.msu.su (HELO zigzag.lvk.cs.msu.su) (158.250.17.23) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Mon, 06 Jun 2005 13:52:30 +0000 Received: from Debian-exim by zigzag.lvk.cs.msu.su with spam-scanned (Exim 4.50) id 1DfI1g-0003gy-Bk for gdb@sources.redhat.com; Mon, 06 Jun 2005 17:52:24 +0400 Received: from zigzag.lvk.cs.msu.su ([158.250.17.23]) by zigzag.lvk.cs.msu.su with esmtp (Exim 4.50) id 1DfI1Q-0003dr-VF; Mon, 06 Jun 2005 17:52:08 +0400 From: Vladimir Prus To: Daniel Jacobowitz Subject: Re: printing "variable-sized" registers Date: Mon, 06 Jun 2005 13:52:00 -0000 User-Agent: KMail/1.7.2 Cc: gdb@sources.redhat.com References: <20050530165817.GA24005@nevyn.them.org> In-Reply-To: <20050530165817.GA24005@nevyn.them.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: Multipart/Mixed; boundary="Boundary-00=_IUFpCAhiNG9vrK1" Message-Id: <200506061752.08077.ghost@cs.msu.su> X-SW-Source: 2005-06/txt/msg00043.txt.bz2 --Boundary-00=_IUFpCAhiNG9vrK1 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1714 On Monday 30 May 2005 20:58, Daniel Jacobowitz wrote: > On Mon, May 30, 2005 at 06:22:19PM +0400, Vladimir Prus wrote: > > Hello, > > I'm working on a gdb port, and have problems with printing certain > > registers of my target. The problem is that those registers are vector > > buffers that can hold from 0 to 32 values at any given moment. I would > > like the 'info registers' command to print exactly the number of values > > that are present in a buffer. That is, on one invocation I might get 4 > > values printed, and on another 15, depending on the current processor > > state. > > > > However, I don't see an easy way to do this. The > > 'default_print_registers_info' function uses 'val_print' to print the > > value, and 'val_print' uses register type (struct type*), which has a > > fixed size. Anything I can do? Or I should just write arch-specific > > 'print_registers_info' function? > > The last one. The best you can do the rest of the time is going to be > giving them a type containing the maximum number of values and fill in > with dummies - maybe also including the count? This's what I was doing -- assigning "array of 32 uin64s" type to those registers and they are printed with "info all-registers", but the dummy values do no look nice when presented to the user. > If you want "print $reg" to display them nicely, you're going to need > to teach GDB's type system about it somehow. I have no idea what that > change would look like or how it would work, but it could be generally > useful - it's the same concept as prettyprinting a tagged union, I think. Ok, understood. With the attached patch I get what I want, but I have no idea if this patch is good or not. - Volodya --Boundary-00=_IUFpCAhiNG9vrK1 Content-Type: text/x-diff; charset="iso-8859-1"; name="variable_sized_array.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="variable_sized_array.diff" Content-length: 1154 diff -u gdb-6.3-orig/gdb/gdbtypes.h gdb-6.3/gdb/gdbtypes.h --- gdb-6.3-orig/gdb/gdbtypes.h 2004-10-01 14:23:09.000000000 +0400 +++ gdb-6.3/gdb/gdbtypes.h 2005-05-31 10:19:42.000000000 +0400 @@ -304,6 +304,12 @@ #define TYPE_FLAG_FIXED_INSTANCE (1 << 15) + +#define TYPE_FLAG_VARIABLE_SIZED_ARRAY (1 << 16) +#define TYPE_VARIABLE_SIZED_ARRAY(t) (TYPE_INSTANCE_FLAGS(t) \ + & TYPE_FLAG_VARIABLE_SIZED_ARRAY) + + /* Array bound type. */ enum array_bound_type { diff -u gdb-6.3-orig/gdb/valprint.c gdb-6.3/gdb/valprint.c --- gdb-6.3-orig/gdb/valprint.c 2004-09-12 20:13:04.000000000 +0400 +++ gdb-6.3/gdb/valprint.c 2005-05-31 11:23:09.000000000 +0400 @@ -774,10 +774,15 @@ elttype = TYPE_TARGET_TYPE (type); eltlen = TYPE_LENGTH (check_typedef (elttype)); - len = TYPE_LENGTH (type) / eltlen; annotate_array_section_begin (i, elttype); + if (TYPE_VARIABLE_SIZED_ARRAY(type)) { + len = *(unsigned int*)valaddr; + valaddr += sizeof(unsigned int); + } else + len = TYPE_LENGTH (type) / eltlen; + for (; i < len && things_printed < print_max; i++) { if (i != 0) --Boundary-00=_IUFpCAhiNG9vrK1--