Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Peter Toft <pto@linuxbog.dk>
To: gdb@sourceware.org
Subject: Re: gdb printing of dynamically allocated matrix
Date: Wed, 18 Jul 2007 21:56:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.64.0707182228230.4288@pto.linuxbog.dk> (raw)
In-Reply-To: <Pine.LNX.4.64.0707182124570.4288@pto.linuxbog.dk>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1954 bytes --]

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

  reply	other threads:[~2007-07-18 20:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-18 17:59 Peter Toft
2007-07-18 19:32 ` Daniel Jacobowitz
2007-07-18 20:32   ` Peter Toft
2007-07-18 21:56     ` Peter Toft [this message]
2007-07-19  3:10       ` Daniel Jacobowitz
2007-07-20 18:48         ` Peter Toft
2007-07-20 19:08       ` Jim Blandy
2007-07-21 14:16         ` Peter Toft
2007-07-23 17:05           ` Jim Blandy
2007-07-23 21:38             ` Peter Toft

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0707182228230.4288@pto.linuxbog.dk \
    --to=pto@linuxbog.dk \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox