2010-04-29 22:45:39 +08:00
|
|
|
/* Support for printing D values for GDB, the GNU debugger.
|
|
|
|
|
2016-01-01 12:33:14 +08:00
|
|
|
Copyright (C) 2008-2016 Free Software Foundation, Inc.
|
2010-04-29 22:45:39 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "gdbtypes.h"
|
|
|
|
#include "gdbcore.h"
|
|
|
|
#include "d-lang.h"
|
|
|
|
#include "c-lang.h"
|
|
|
|
|
2012-03-02 03:26:13 +08:00
|
|
|
/* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is a
|
|
|
|
dynamic array, and then print its value to STREAM. Return zero if
|
|
|
|
TYPE is a dynamic array, non-zero otherwise. */
|
|
|
|
|
2010-04-29 22:45:39 +08:00
|
|
|
static int
|
|
|
|
dynamic_array_type (struct type *type, const gdb_byte *valaddr,
|
2016-04-13 03:02:57 +08:00
|
|
|
LONGEST embedded_offset, CORE_ADDR address,
|
2010-04-29 22:45:39 +08:00
|
|
|
struct ui_file *stream, int recurse,
|
2010-06-11 23:36:10 +08:00
|
|
|
const struct value *val,
|
2010-04-29 22:45:39 +08:00
|
|
|
const struct value_print_options *options)
|
|
|
|
{
|
|
|
|
if (TYPE_NFIELDS (type) == 2
|
|
|
|
&& TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
|
|
|
|
&& strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
|
2010-06-11 23:36:10 +08:00
|
|
|
&& strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
|
Handle partially optimized out values similarly to unavailable values
This fixes PR symtab/14604, PR symtab/14605, and Jan's test at
https://sourceware.org/ml/gdb-patches/2014-07/msg00158.html, in a tree
with bddbbed reverted:
2014-07-22 Pedro Alves <palves@redhat.com>
* value.c (allocate_optimized_out_value): Don't mark value as
non-lazy.
The PRs are about variables described by the DWARF as being split over
multiple registers using DWARF piece information, but some of those
registers being marked as optimised out (not saved) by a later frame.
GDB currently incorrectly mishandles these partially-optimized-out
values.
Even though we can usually tell from the debug info whether a local or
global is optimized out, handling the case of a local living in a
register that was not saved in a frame requires fetching the variable.
GDB also needs to fetch a value to tell whether parts of it are
"<unavailable>". Given this, it's not worth it to try to avoid
fetching lazy optimized-out values based on debug info alone.
So this patch makes GDB track which chunks of a value's contents are
optimized out like it tracks <unavailable> contents. That is, it
makes value->optimized_out be a bit range vector instead of a boolean,
and removes the struct lval_funcs check_validity and check_any_valid
hooks.
Unlike Andrew's series which this is based on (at
https://sourceware.org/ml/gdb-patches/2013-08/msg00300.html, note some
pieces have gone in since), this doesn't merge optimized out and
unavailable contents validity/availability behind a single interface,
nor does it merge the bit range vectors themselves (at least yet).
While it may be desirable to have a single entry point that returns
existence of contents irrespective of what may make them
invalid/unavailable, several places want to treat optimized out /
unavailable / etc. differently, so each spot that potentially could
use it will need to be careful considered on case-by-case basis, and
best done as a separate change.
This fixes Jan's test, because value_available_contents_eq wasn't
considering optimized out value contents. It does now, and because of
that it's been renamed to value_contents_eq.
A new intro comment is added to value.h describing "<optimized out>",
"<not saved>" and "<unavailable>" values.
gdb/
PR symtab/14604
PR symtab/14605
* ada-lang.c (coerce_unspec_val_to_type): Use
value_contents_copy_raw.
* ada-valprint.c (val_print_packed_array_elements): Adjust.
* c-valprint.c (c_val_print): Use value_bits_any_optimized_out.
* cp-valprint.c (cp_print_value_fields): Let the common printing
code handle optimized out values.
(cp_print_value_fields_rtti): Use value_bits_any_optimized_out.
* d-valprint.c (dynamic_array_type): Use
value_bits_any_optimized_out.
* dwarf2loc.c (entry_data_value_funcs): Remove check_validity and
check_any_valid fields.
(check_pieced_value_bits): Delete and inline ...
(check_pieced_synthetic_pointer): ... here.
(check_pieced_value_validity): Delete.
(check_pieced_value_invalid): Delete.
(pieced_value_funcs): Remove check_validity and check_any_valid
fields.
(read_pieced_value): Use mark_value_bits_optimized_out.
(write_pieced_value): Switch to use
mark_value_bytes_optimized_out.
(dwarf2_evaluate_loc_desc_full): Copy the value contents instead
of assuming the whole value is optimized out.
* findvar.c (read_frame_register_value): Remove special handling
of optimized out registers.
(value_from_register): Use mark_value_bytes_optimized_out.
* frame-unwind.c (frame_unwind_got_optimized): Use
mark_value_bytes_optimized_out.
* jv-valprint.c (java_value_print): Adjust.
(java_print_value_fields): Let the common printing code handle
optimized out values.
* mips-tdep.c (mips_print_register): Remove special handling of
optimized out registers.
* opencl-lang.c (lval_func_check_validity): Delete.
(lval_func_check_any_valid): Delete.
(opencl_value_funcs): Remove check_validity and check_any_valid
fields.
* p-valprint.c (pascal_object_print_value_fields): Let the common
printing code handle optimized out values.
* stack.c (read_frame_arg): Remove special handling of optimized
out values. Fetch both VAL and ENTRYVAL before comparing
contents. Adjust to value_available_contents_eq rename.
* valprint.c (valprint_check_validity)
(val_print_scalar_formatted): Use value_bits_any_optimized_out.
(val_print_array_elements): Adjust.
* value.c (struct value) <optimized_out>: Now a VEC(range_s).
(value_bits_any_optimized_out): New function.
(value_entirely_covered_by_range_vector): New function, factored
out from value_entirely_unavailable.
(value_entirely_unavailable): Reimplement.
(value_entirely_optimized_out): New function.
(insert_into_bit_range_vector): New function, factored out from
mark_value_bits_unavailable.
(mark_value_bits_unavailable): Reimplement.
(struct ranges_and_idx): New struct.
(find_first_range_overlap_and_match): New function, factored out
from value_available_contents_bits_eq.
(value_available_contents_bits_eq): Rename to ...
(value_contents_bits_eq): ... this. Check both unavailable
contents and optimized out contents.
(value_available_contents_eq): Rename to ...
(value_contents_eq): ... this.
(allocate_value_lazy): Remove reference to the old optimized_out
boolean.
(allocate_optimized_out_value): Use
mark_value_bytes_optimized_out.
(require_not_optimized_out): Adjust to check whether the
optimized_out vec is empty.
(ranges_copy_adjusted): New function, factored out from
value_contents_copy_raw.
(value_contents_copy_raw): Also copy the optimized out ranges.
Assert the destination ranges aren't optimized out.
(value_contents_copy): Update comment, remove call to
require_not_optimized_out.
(value_contents_equal): Adjust to check whether the optimized_out
vec is empty.
(set_value_optimized_out, value_optimized_out_const): Delete.
(mark_value_bytes_optimized_out, mark_value_bits_optimized_out):
New functions.
(value_entirely_optimized_out, value_bits_valid): Delete.
(value_copy): Take a VEC copy of the 'optimized_out' field.
(value_primitive_field): Remove special handling of optimized out.
(value_fetch_lazy): Assert that lazy values have no unavailable
regions. Use value_bits_any_optimized_out. Remove some special
handling for optimized out values.
* value.h: Add intro comment about <optimized out> and
<unavailable>.
(struct lval_funcs): Remove check_validity and check_any_valid
fields.
(set_value_optimized_out, value_optimized_out_const): Remove.
(mark_value_bytes_optimized_out, mark_value_bits_optimized_out):
New declarations.
(value_bits_any_optimized_out): New declaration.
(value_bits_valid): Delete declaration.
(value_available_contents_eq): Rename to ...
(value_contents_eq): ... this, and extend comments.
gdb/testsuite/
PR symtab/14604
PR symtab/14605
* gdb.dwarf2/dw2-op-out-param.exp: Remove kfail branches and use
gdb_test.
2014-08-20 07:07:40 +08:00
|
|
|
&& !value_bits_any_optimized_out (val,
|
|
|
|
TARGET_CHAR_BIT * embedded_offset,
|
|
|
|
TARGET_CHAR_BIT * TYPE_LENGTH (type)))
|
2010-04-29 22:45:39 +08:00
|
|
|
{
|
|
|
|
CORE_ADDR addr;
|
|
|
|
struct type *elttype;
|
|
|
|
struct type *true_type;
|
|
|
|
struct type *ptr_type;
|
2011-02-28 05:24:27 +08:00
|
|
|
struct value *ival;
|
2010-04-29 22:45:39 +08:00
|
|
|
int length;
|
|
|
|
|
|
|
|
length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
|
|
|
|
|
|
|
|
ptr_type = TYPE_FIELD_TYPE (type, 1);
|
|
|
|
elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
|
|
|
|
addr = unpack_pointer (ptr_type,
|
|
|
|
valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
|
|
|
|
+ embedded_offset);
|
|
|
|
true_type = check_typedef (elttype);
|
|
|
|
|
|
|
|
true_type = lookup_array_range_type (true_type, 0, length - 1);
|
2011-02-28 05:24:27 +08:00
|
|
|
ival = value_at (true_type, addr);
|
2013-10-14 15:36:13 +08:00
|
|
|
true_type = value_type (ival);
|
2010-04-29 22:45:39 +08:00
|
|
|
|
2012-03-02 03:26:13 +08:00
|
|
|
d_val_print (true_type,
|
|
|
|
value_contents_for_printing (ival),
|
|
|
|
value_embedded_offset (ival), addr,
|
|
|
|
stream, recurse + 1, ival, options);
|
|
|
|
return 0;
|
2010-04-29 22:45:39 +08:00
|
|
|
}
|
2012-03-02 03:26:13 +08:00
|
|
|
return 1;
|
2010-04-29 22:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Implements the la_val_print routine for language D. */
|
2012-03-02 03:26:13 +08:00
|
|
|
void
|
2010-04-29 22:45:39 +08:00
|
|
|
d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
|
|
|
|
CORE_ADDR address, struct ui_file *stream, int recurse,
|
2010-06-11 23:36:10 +08:00
|
|
|
const struct value *val,
|
2010-04-29 22:45:39 +08:00
|
|
|
const struct value_print_options *options)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2015-07-07 04:05:06 +08:00
|
|
|
type = check_typedef (type);
|
2010-04-29 22:45:39 +08:00
|
|
|
switch (TYPE_CODE (type))
|
|
|
|
{
|
|
|
|
case TYPE_CODE_STRUCT:
|
|
|
|
ret = dynamic_array_type (type, valaddr, embedded_offset, address,
|
2010-06-11 23:36:10 +08:00
|
|
|
stream, recurse, val, options);
|
2012-03-02 03:26:13 +08:00
|
|
|
if (ret == 0)
|
|
|
|
break;
|
2010-04-29 22:45:39 +08:00
|
|
|
default:
|
2012-03-02 03:26:13 +08:00
|
|
|
c_val_print (type, valaddr, embedded_offset, address, stream,
|
|
|
|
recurse, val, options);
|
2010-04-29 22:45:39 +08:00
|
|
|
}
|
|
|
|
}
|