gdb: make get_discrete_bounds check for non-constant range bounds
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 13 Jul 2020 02:58:51 +0000 (22:58 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 13 Jul 2020 02:58:51 +0000 (22:58 -0400)
commit7c6f271296319576fa00587928e5ff52ced9c1bb
treea48617d8e5305d9e79bec46ccd3bb328e30d90da
parent599088e3ffa13edcccc68b6d7a39e7488123004a
gdb: make get_discrete_bounds check for non-constant range bounds

The next patch adds getters to the `dynamic_prop` structure.  These
getters validate that the accessed data matches the property kind (for
example, to access the `const_val` field, the property must be of kind
`PROP_CONST`).  It found one instance where we are accessing the
`const_val` data of a property that has the undefined kind.

This happens in function `get_discrete_bounds`, and is exposed by test
gdb.base/ptype.exp, amongst others.  Without this patch, we would get:

    $ ./gdb -q -nx --data-directory=data-directory testsuite/outputs/gdb.base/ptype/ptype -ex "ptype t_char_array"
    Reading symbols from testsuite/outputs/gdb.base/ptype/ptype...
    type = char [
    /home/smarchi/src/binutils-gdb/gdb/gdbtypes.h:526: internal-error: LONGEST dynamic_prop::const_val() const: Assertion `m_kind == PROP_CONST' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    Quit this debugging session? (y or n)

The `get_discrete_bounds` function returns the bounds of a type (not
only range types).  For range types, it naturally uses the bound
properties that are intrinsic to the range type.  It accesses these
properties using TYPE_LOW_BOUND and TYPE_HIGH_BOUND, which assume the
properties are defined and have constant values.  This is sometimes not
the case, and the passed range type (as in the example above) has an
undefined high/upper bound.

Given its current interface (returning two LONGEST values for low and
high), `get_discrete_bounds` can't really work if the range type's
bounds are not both defined and both constant values.

This patch changes the function to return -1 (failure to get the bounds)
if any of the range type's bounds is not a constant value.  It is
sufficient to fix the issue and it seems to keep the callers happy, at
least according to the testsuite.

A bit in `get_array_bounds` could be removed, since
`get_discrete_bounds` no longer returns 1 if a bound is undefined.

gdb/ChangeLog:

* gdbtypes.c (get_discrete_bounds): Return failure if
the range type's bounds are not both defined and constant
values.
(get_array_bounds): Update comment.  Remove undefined bound check.

Change-Id: I047a3beee2c1e275f888cfc4778228339922bde9
gdb/ChangeLog
gdb/gdbtypes.c
This page took 0.026126 seconds and 4 git commands to generate.