mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
f168693bc9
I think that the CHECK_TYPEDEF macro is not necessary, and even a bit annoying. It makes unclear the fact that the "type" variables gets overwritten. It has actually bitten me a few times. I think the following, explicit form, is better. type = check_typedef (type); This patches changes all instances of CHECK_TYPEDEF for an equivalent call to check_typedef. The bulk of the change was done with this sed: sed -i 's/CHECK_TYPEDEF (\([^)]*\));/\1 = check_typedef (\1);/' <file>.c The ChangeLog was generated using David Malcom's generate_changelog.py. I manually fixed those places where it gets the wrong function name, hopefully all of them. The patch was built-tested, and I ran a few smoke tests. gdb/ChangeLog: * gdbtypes.h (CHECK_TYPEDEF): Remove. * aarch64-tdep.c (aarch64_return_in_memory): Replace CHECK_TYPEDEF with check_typedef. * ada-lang.c (decode_constrained_packed_array_type): Likewise. (ada_array_length): Likewise. (find_parallel_type_by_descriptive_type): Likewise. (ada_check_typedef): Likewise. * arm-tdep.c (arm_return_in_memory): Likewise. * ax-gdb.c (gen_trace_static_fields): Likewise. (gen_struct_ref_recursive): Likewise. * c-exp.y (exp : SIZEOF '(' type ')' %prec UNARY): Likewise. (variable: block COLONCOLON name): Likewise. (qualified_name: TYPENAME COLONCOLON name): Likewise. * c-lang.c (classify_type): Likewise. * c-typeprint.c (c_print_type): Likewise. (c_print_typedef): Likewise. (c_type_print_base): Likewise. * c-valprint.c (c_val_print): Likewise. * compile/compile-c-types.c (convert_type): Likewise. * compile/compile-object-load.c (get_out_value_type): Likewise. * completer.c (add_struct_fields): Likewise. (expression_completer): Likewise. * cp-namespace.c (cp_find_type_baseclass_by_name): Likewise. (cp_lookup_nested_symbol_1): Likewise. (cp_lookup_nested_symbol): Likewise. * cp-valprint.c (cp_print_value_fields): Likewise. (cp_print_static_field): Likewise. * d-valprint.c (d_val_print): Likewise. * eval.c (evaluate_subexp_standard): Likewise. (evaluate_subexp_for_sizeof): Likewise. * f-exp.y (exp : SIZEOF '(' type ')' %prec UNARY): Likewise. * f-typeprint.c (f_type_print_base): Likewise. * f-valprint.c (f_val_print): Likewise. * gdbtypes.c (get_discrete_bounds): Likewise. (create_array_type_with_stride): Likewise. (type_name_no_tag_or_error): Likewise. (lookup_struct_elt_type): Likewise. (get_unsigned_type_max): Likewise. (internal_type_vptr_fieldno): Likewise. (set_type_vptr_fieldno): Likewise. (internal_type_vptr_basetype): Likewise. (set_type_vptr_basetype): Likewise. (get_vptr_fieldno): Likewise. (is_integral_type): Likewise. (is_scalar_type): Likewise. (is_scalar_type_recursive): Likewise. (distance_to_ancestor): Likewise. (is_unique_ancestor_worker): Likewise. (check_types_equal): Likewise. * gnu-v2-abi.c (gnuv2_value_rtti_type): Likewise. * gnu-v3-abi.c (gnuv3_dynamic_class): Likewise. (gnuv3_get_vtable): Likewise. (gnuv3_pass_by_reference): Likewise. * go-exp.y (exp : SIZEOF_KEYWORD '(' type ')' %prec UNARY): Likewise. * go-lang.c (gccgo_string_p): Likewise. (go_classify_struct_type): Likewise. * go-typeprint.c (go_print_type): Likewise. * go-valprint.c (go_val_print): Likewise. * guile/scm-math.c (vlscm_binop): Likewise. * guile/scm-value.c (gdbscm_value_dynamic_type): Likewise. (gdbscm_value_to_bytevector): Likewise. (gdbscm_value_to_bool): Likewise. (gdbscm_value_to_integer): Likewise. (gdbscm_value_to_real): Likewise. * infcall.c (call_function_by_hand_dummy): Likewise. * infcmd.c (get_return_value): Likewise. * jv-lang.c (is_object_type): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_print_value_fields): Likewise. (java_val_print): Likewise. * linespec.c (find_methods): Likewise. (collect_one_symbol): Likewise. * m2-typeprint.c (m2_print_type): Likewise. (m2_print_typedef): Likewise. (m2_get_discrete_bounds): Likewise. * m2-valprint.c (m2_print_long_set): Likewise. (m2_print_unbounded_array): Likewise. (m2_print_array_contents): Likewise. (m2_val_print): Likewise. * opencl-lang.c (opencl_print_type): Likewise. * p-exp.y (exp : SIZEOF '(' type ')' %prec UNARY): Likewise. * p-typeprint.c (pascal_print_type): Likewise. (pascal_print_typedef): Likewise. (pascal_type_print_base): Likewise. * p-valprint.c (pascal_val_print): Likewise. (pascal_object_print_value_fields): Likewise. (pascal_object_print_static_field): Likewise. * python/py-type.c (typy_fields_items): Likewise. (typy_get_composite): Likewise. * python/py-value.c (valpy_get_dynamic_type): Likewise. (valpy_binop): Likewise. (valpy_long): Likewise. (valpy_float): Likewise. * stack.c (return_command): Likewise. * symtab.c (check_field): Likewise. (lookup_symbol_aux): Likewise. * tic6x-tdep.c (tic6x_return_value): Likewise. * typeprint.c (print_type_scalar): Likewise. * valarith.c (value_vector_widen): Likewise. * valops.c (value_cast): Likewise. (value_assign): Likewise. (do_search_struct_field): Likewise. (search_struct_method): Likewise. (find_method_list): Likewise. * valprint.c (val_print_scalar_type_p): Likewise. (valprint_check_validity): Likewise. (generic_val_print): Likewise. * value.c (unpack_double): Likewise. (value_primitive_field): Likewise. (unpack_bits_as_long): Likewise.
124 lines
3.7 KiB
C
124 lines
3.7 KiB
C
/* Support for printing Go values for GDB, the GNU debugger.
|
|
|
|
Copyright (C) 2012-2015 Free Software Foundation, Inc.
|
|
|
|
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/>.
|
|
|
|
NOTE: This currently only provides special support for printing gccgo
|
|
strings. 6g objects are handled in Python.
|
|
The remaining gccgo types may also be handled in Python.
|
|
Strings are handled specially here, at least for now, in case the Python
|
|
support is unavailable. */
|
|
|
|
#include "defs.h"
|
|
#include "gdbtypes.h"
|
|
#include "gdbcore.h"
|
|
#include "go-lang.h"
|
|
#include "c-lang.h"
|
|
#include "valprint.h"
|
|
|
|
/* Print a Go string.
|
|
|
|
Note: We assume
|
|
gdb_assert (go_classify_struct_type (type) == GO_TYPE_STRING). */
|
|
|
|
static void
|
|
print_go_string (struct type *type, const gdb_byte *valaddr,
|
|
int embedded_offset, CORE_ADDR address,
|
|
struct ui_file *stream, int recurse,
|
|
const struct value *val,
|
|
const struct value_print_options *options)
|
|
{
|
|
struct gdbarch *gdbarch = get_type_arch (type);
|
|
struct type *elt_ptr_type = TYPE_FIELD_TYPE (type, 0);
|
|
struct type *elt_type = TYPE_TARGET_TYPE (elt_ptr_type);
|
|
LONGEST length;
|
|
/* TODO(dje): The encapsulation of what a pointer is belongs in value.c.
|
|
I.e. If there's going to be unpack_pointer, there should be
|
|
unpack_value_field_as_pointer. Do this until we can get
|
|
unpack_value_field_as_pointer. */
|
|
LONGEST addr;
|
|
|
|
gdb_assert (valaddr == value_contents_for_printing_const (val));
|
|
|
|
if (! unpack_value_field_as_long (type, valaddr, embedded_offset, 0,
|
|
val, &addr))
|
|
error (_("Unable to read string address"));
|
|
|
|
if (! unpack_value_field_as_long (type, valaddr, embedded_offset, 1,
|
|
val, &length))
|
|
error (_("Unable to read string length"));
|
|
|
|
/* TODO(dje): Print address of struct or actual string? */
|
|
if (options->addressprint)
|
|
{
|
|
fputs_filtered (paddress (gdbarch, addr), stream);
|
|
fputs_filtered (" ", stream);
|
|
}
|
|
|
|
if (length < 0)
|
|
{
|
|
fputs_filtered (_("<invalid length: "), stream);
|
|
fputs_filtered (plongest (addr), stream);
|
|
fputs_filtered (">", stream);
|
|
return;
|
|
}
|
|
|
|
/* TODO(dje): Perhaps we should pass "UTF8" for ENCODING.
|
|
The target encoding is a global switch.
|
|
Either choice is problematic. */
|
|
val_print_string (elt_type, NULL, addr, length, stream, options);
|
|
}
|
|
|
|
/* Implements the la_val_print routine for language Go. */
|
|
|
|
void
|
|
go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
|
|
CORE_ADDR address, struct ui_file *stream, int recurse,
|
|
const struct value *val,
|
|
const struct value_print_options *options)
|
|
{
|
|
type = check_typedef (type);
|
|
|
|
switch (TYPE_CODE (type))
|
|
{
|
|
case TYPE_CODE_STRUCT:
|
|
{
|
|
enum go_type go_type = go_classify_struct_type (type);
|
|
|
|
switch (go_type)
|
|
{
|
|
case GO_TYPE_STRING:
|
|
if (! options->raw)
|
|
{
|
|
print_go_string (type, valaddr, embedded_offset, address,
|
|
stream, recurse, val, options);
|
|
return;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/* Fall through. */
|
|
|
|
default:
|
|
c_val_print (type, valaddr, embedded_offset, address, stream,
|
|
recurse, val, options);
|
|
break;
|
|
}
|
|
}
|