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]

Dynamic array bounds problem


Hello,

Just like Fortran90, (Delphi-style) Object Pascal knows dynamic arrays. I'm trying to add support for them to the dwarf debugging information generated by the Free Pascal Compiler, but I'm running into a small hitch.

First of all, the structure (expressed in C) of these dynamic arrays is like this (much simpler than in case of Fortran):

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.

I've adapted our compiler to generate the following debug information for a dynamic "array of byte" (a byte = unsigned 8 bits integer):

# array type
<1><d3>: Abbrev Number: 6 (DW_TAG_array_type)
DW_AT_byte_size : 1
DW_AT_stride_size : 8
DW_AT_type : <#f1>
DW_AT_allocated : 2 byte block: 97 6 (DW_OP_push_object_address; DW_OP_deref)
DW_AT_data_location: 2 byte block: 97 6 (DW_OP_push_object_address; DW_OP_deref)
# index type
<2><e0>: Abbrev Number: 7 (DW_TAG_subrange_type)
DW_AT_lower_bound : 0
DW_AT_upper_bound : 4 byte block: 97 34 1c 6 (DW_OP_push_object_address; DW_OP_lit4; DW_OP_minus; DW_OP_deref)
DW_AT_type : <#fe>
# reference to array type, used for call-by-reference parameters of this type
<1><ec>: Abbrev Number: 8 (DW_TAG_reference_type)
DW_AT_type : <#d3>
# byte type
<1><f1>: Abbrev Number: 9 (DW_TAG_base_type)
DW_AT_name : Byte
DW_AT_encoding : 7 (unsigned)
DW_AT_byte_size : 1
# reference to byte type
<1><f9>: Abbrev Number: 10 (DW_TAG_reference_type)
DW_AT_type : <#f1>
# longint type (I compiled for Intel 32 bits, so intptr_t = 4 bytes)
<1><fe>: Abbrev Number: 11 (DW_TAG_base_type)
DW_AT_name : LongInt
DW_AT_encoding : 5 (signed)
DW_AT_byte_size : 4


The problem is that gdb always displays the array as an array[0..0] (i.e., lower and upper index = 0), regardless of the actual length (and also when printing the contents, it just prints the first element). So it seems that I didn't specify the upper bound of the index type properly, but I can't figure out what's wrong. I've also verified with the gdb "x" command that the length field indeed lies 4 bytes before the actual array data and contains the correct value.

When I change the language in gdb from Pascal to Fortran it still prints the array as being "type = Byte (0:0)" and also only displays the first element, so it does not appear to be simply an issue in the Pascal expression printer.

I'm new to git (I know cvs and svn) so I'm not sure what the proper way is to identify the revision I'm using, but the last commit in my git log is f2deac9fa3dfd4d9010e3590963ded5f0d56fe0a (I checked out the archer repository yesterday and then merged the origin/archer- jankratochvil-vla branch, but just read in the mailing list archives that this one actually was merged couple of days ago).

Any hints on what I might be doing wrong? I can provide a compiled program if required.

Thanks,


Jonas



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