This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Dynamic array bounds problem



On 24 Dec 2008, at 16:22, Jan Kratochvil wrote:


On Wed, 24 Dec 2008 11:11:12 +0100, Jonas Maebe wrote:
struct {
 intptr_t refcount;
 intptr_t high;
 char data[1];
} dynarr_t;

A dynamic array variable is always a pointer which is either NULL (not
allocated) or which points to the "data" field of the above struct (so
the length and refcount are at negative offsets). The lower bound is
always 0, the current upper bound is stored in the "high" field.

Just be sure DW_TAG_variable's DW_AT_location gives the address of the pointer
to dynaddr_t, not the pointer value itself.

This is correct correct.


This GIT tag should work (although there is an update now). You should check
that TYPE_DYNAMIC is present in the sources.

That's a very good point to make. I tried to follow the instructions at http://people.redhat.com/jkratoch/vla/MOVED, but my git (the default one from Scientific Linux 5.2, not sure which version that it is) didn't recognise the "-tb" option for the checkout command (it gave an error). I then left off the "t" and used "checkout -b", and it 'worked' (in the sense that there was no error message anymore). But there was no output as far as I remember, so this may just as well have done something completely different than integrating the changes from your branch.


The kicker is that I cannot check whether or not TYPE_DYNAMIC is present in the sources I compiled, because the machine on which that checkout resides has apparently been turned off for the holidays.

However...

Any hints on what I might be doing wrong?

Some basic hints can be given by `set debug target 1' to at least see which
addresses are being read while evaluating the array boundaries.

I've installed git on my MacBook, checked out everything there (and the git from Fink apparently does know -tb, so now I also know that it means "track branch") and compiled it there (it's great that Mac OS X support is being added to mainline gdb!). I did notice that TYPE_DYNAMIC was not in the sources before I explicitly merged in the archer-jankratochvil-vla branch though, so it seems I misread that it was already merged (looking again, I guess that it was merged into the archer-rmoseley-demo-merge branch rather than in the archer branch).


Anyway, now instead of a [0..0] array I got error messages from gdb stating that it was trying to read invalid memory locations (so my previous checkout probably did not contain TYPE_DYNAMIC). With the "set debug target 1", I discovered that my upper bound expression was wrong: it was missing an initial deref.

So I changed it into the following (no readelf on Mac OS X though, and its copy of dwarfdump doesn't fully decode dwarf opcodes unfortunately):

0x000000ce:         TAG_subrange_type [7]
                     AT_lower_bound( 0x00000000 )
                     AT_upper_bound( <0x5> 97 06 34 1c 06  )
                     AT_type( {0x000000f7} ( LONGINT ) )

That upper bound expression is the following:

DW_OP_push_object_address; DW_OP_deref; DW_OP_lit4; DW_OP_minus; DW_OP_deref

And now everything works perfectly!

Thanks a lot for your help,


Jonas



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]