This repository hosts the GDB Variable Length Array (VLA) implementation for C99 and Fortran (dynamic arrays).
Introduction
A variable length array (VLA) is an array, whose size resp. length is computed at run time and not at compile time for languages, which have automatic storage duration. This means that a variable will be allocated and deallocated automatically when the program flow enters and leaves its context. VLA's will be also called dynamic arrays in the Fortran area. In the past VLA's were just an GCC extension and later the concept was included into C99. Although C99 supports dynamic arrays, C++ doesn't, also not with the latest standard C++0x.
This project will add VLA support for C99 and Fortran to GDB. This means that it is not possible to get the type or the value of a VLA using GDB in C and Fortran.
Examples
A basic C99 example of a variable length array, whose size will be computed at run-time:
void func(int n) { int array[n]; }
Example for a VLA in Fortran:
program VLA implicit none real, allocatable :: array(:) allocate (array(100)) end program VLA
VLA approach
Dwarf allows certain attributes e.g upper/lower bound, allocated/associated status to be computed dynamically. To support this dwarf features with the current gdb type-system, this project will introduce dynamic type properties, which will be "normalized" when requested. This means types with dynamic properties are converted to types with static properties and can then be handled by GDB like before this series. To convert a type with dynamic properties into one with static properties access to the inferior memory is required. Therefore we hooked into the following value constructors:
- value_at
- value_at_lazy
- value_from_contents_and_address
struct value *val = value_at (my_vla_type, at_address);this was always true:
TYPE_LENGTH (value_type (val)) == TYPE_LENGTH (my_vla_type)This is not the case anymore after applying this patch series. Type normalization is done in the mentioned value constructors and might change the value type including attributes, such as the length.
Structure of the repository
The repository is a clone of the GDB repository, which will be updated on a non-regular basis. The main development of the VLA feature is done on branches.
Current active branches:
- vla-c99: C99 variable length array (VLA) support.
- vla-fortran: Fortran dynamic array (aka. VLA) support.
- enhanced_fortran_support: Various Fortran fixes for GDB.