From: Jim Blandy <jimb@codesourcery.com>
To: Peter Toft <pto@linuxbog.dk>
Cc: gdb@sourceware.org
Subject: Re: gdb printing of dynamically allocated matrix
Date: Mon, 23 Jul 2007 17:05:00 -0000 [thread overview]
Message-ID: <m3abtnginp.fsf@codesourcery.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0707210017350.4288@pto.linuxbog.dk> (Peter Toft's message of "Sat, 21 Jul 2007 00:21:56 +0200 (CEST)")
Peter Toft <pto@linuxbog.dk> writes:
> On Fri, 20 Jul 2007, Jim Blandy wrote:
>
>>
>> Peter Toft <pto@linuxbog.dk> 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.
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.
next prev parent reply other threads:[~2007-07-23 16:59 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
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 [this message]
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=m3abtnginp.fsf@codesourcery.com \
--to=jimb@codesourcery.com \
--cc=gdb@sourceware.org \
--cc=pto@linuxbog.dk \
/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