public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Joost van der Sluis <joost@cnoc.nl>
Cc: archer@sourceware.org
Subject: Re: Calculating array length
Date: Sun, 07 Jun 2009 14:48:00 -0000	[thread overview]
Message-ID: <20090607144745.GA21154@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <1244370173.22994.14.camel@wsjoost>

On Sun, 07 Jun 2009 12:22:53 +0200, Joost van der Sluis wrote:
> But I also have a lot of questions, I hope this is the right place for
> them.

Yes, VLA support is currently still not integrated with FSF GDB.


> First question is the calculation of the length of an array-type in
> type_length_get(), gdbtypes.c. (I'm using the archer-jankratochvil-sla
> branch to improve the handling of arrays)
> 
> The length is calculated as follows: (count-1)*byte_stride+element_size.
> 
> Ok, so why 'count-1'? Count is the actual item-count, why substract it
> with one? And why is the element_size added? byte_stride (when defined)
> should replace the element_size?
> 
> It doesn't make sense to me, as it should be: 'count*byte_stride'?

It depends which length do you want to calculate.  According to what you
describe you want to set the FULL_SPAN parameter of type_length_get to be
true.  Then it will really return 'count*byte_stride'.

Still the function uses FULL_SPAN as true only internally.  When GDB wants to
know the type length it uses it for transferring data from the debuggee memory
into a local GDB copy (for its printing to the user etc.).  For such case we
want a _minimal_ (but still complete) contiguous memory range.

Fortran example:

subroutine sub (p)
  integer :: p (2, 1)
  print *, p (1, 1)
  print *, p (2, 1)
end subroutine sub
program subarray
  integer :: a (2, 2)
  a (1, 1) = 1
  a (1, 2) = 2
  a (2, 1) = 3
  a (2, 2) = 4
  call sub (a (1:2, 2:2))
end

Array `a' in the main program has layout (here the first index is row, second
one is column):
  1 2
  3 4
  X Y (these are uninitialized / nonexisting / unused memory locations after
       the end of array)
Subroutine `sub' will print:
           2
           4
Subroutine `sub' know only about a table with 2 rows and 1 column.  To make it
working with the original array `a' memory layout without any copy the
pointers to the array are setup as:
  array start: row 1 column 2 (element content `2')
  rows, therefore number of elements of p: 2
  columns, therefore number of elements of p row: 1
  element size of p (one row byte length): sizeof (integer) * 1
  element size of p row (one element byte length): sizeof (integer)
  byte stride of p (offset to the next row): sizeof (integer) * 2
  byte stride of p row: sizeof (integer)

Now if you in `sub' do `print p' GDB has to transfer the `p' memory from
inferior.  Currently it will transfer contiguous block with content {2,3,4}.

If we would always use FULL_SPAN true then GDB would transfer in this case
a contiguous memory block with content {2,3,4,X}.  But X is after the end of
the array and for very large arrays (thousands of elements or elements of size
in kilobytes) memory for X may no longer be mapped and GDB would fail
retrieving the memory of variable being wished to be printed.  (+It would be
also less effective.)

GDB has to transfer only the memory it knows that belongs to a variable.


Regards,
Jan

  reply	other threads:[~2009-06-07 14:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-07 10:23 Joost van der Sluis
2009-06-07 14:48 ` Jan Kratochvil [this message]
2009-06-07 16:06   ` Joost van der Sluis
2009-06-07 17:49     ` Jan Kratochvil
2009-06-07 17:59       ` Jan Kratochvil
2009-06-12 21:24       ` Joost van der Sluis
2009-06-15 11:57         ` Jan Kratochvil
2009-06-15 12:16           ` Jan Kratochvil
2009-06-14 20:30       ` Joost van der Sluis
2009-06-20 22:34         ` Jan Kratochvil
2009-06-22 12:07           ` Joost van der Sluis
2009-06-22 12:15             ` Jan Kratochvil

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=20090607144745.GA21154@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=archer@sourceware.org \
    --cc=joost@cnoc.nl \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).