1999-04-16 09:35:26 +08:00
|
|
|
/* Fortran language support definitions for GDB, the GNU debugger.
|
2005-01-28 Andrew Cagney <cagney@gnu.org>
* language.h (struct language_defn): Make la_val_print's buffer
parameter a const bfd_byte.
* cp-valprint.c (cp_print_value_fields, cp_print_value): Update.
* ada-lang.c (ada_aligned_value_addr)
(ada_value_primitive_packed_val, ada_which_variant_applies): Update.
* valprint.c (val_print_array_elements): Update.
* valprint.h (val_print_array_elements): Update.
* ada-lang.h (ada_val_print, ada_aligned_value_addr)
(ada_value_primitive_packed_val, ada_which_variant_applies): Update.
* ada-valprint.c (ada_val_print, struct ada_val_print_args)
(ada_val_print_1, ada_print_floating, printable_val_type)
(print_record, val_print_packed_array_elements)
(print_field_values, print_variant_part): Update.
* c-lang.h (c_val_print, cp_print_value_fields): Update.
* c-valprint.c (c_val_print): Update.
* f-lang.h (f_val_print): Update.
* f-valprint.c (f_val_print, f77_print_array_1)
(f77_print_array): Update.
* jv-lang.h (java_val_print): Update.
* jv-valprint.c (java_print_value_fields, java_val_print): Update.
* language.c (unk_lang_val_print): Update.
* m2-lang.h (m2_val_print): Update.
* m2-valprint.c (m2_val_print): Update.
* p-lang.h (pascal_val_print): Update.
(pascal_object_print_value_fields): Update.
* p-valprint.c (pascal_val_print)
(pascal_object_print_value_fields, pascal_object_print_value)
(pascal_object_print_value): Update.
* scm-lang.h (scm_val_print): Update.
* scm-valprint.c (scm_val_print): Update.
* value.h (val_print): Update.
2005-01-29 09:59:31 +08:00
|
|
|
|
2024-01-12 23:30:44 +08:00
|
|
|
Copyright (C) 1992-2024 Free Software Foundation, Inc.
|
2005-01-28 Andrew Cagney <cagney@gnu.org>
* language.h (struct language_defn): Make la_val_print's buffer
parameter a const bfd_byte.
* cp-valprint.c (cp_print_value_fields, cp_print_value): Update.
* ada-lang.c (ada_aligned_value_addr)
(ada_value_primitive_packed_val, ada_which_variant_applies): Update.
* valprint.c (val_print_array_elements): Update.
* valprint.h (val_print_array_elements): Update.
* ada-lang.h (ada_val_print, ada_aligned_value_addr)
(ada_value_primitive_packed_val, ada_which_variant_applies): Update.
* ada-valprint.c (ada_val_print, struct ada_val_print_args)
(ada_val_print_1, ada_print_floating, printable_val_type)
(print_record, val_print_packed_array_elements)
(print_field_values, print_variant_part): Update.
* c-lang.h (c_val_print, cp_print_value_fields): Update.
* c-valprint.c (c_val_print): Update.
* f-lang.h (f_val_print): Update.
* f-valprint.c (f_val_print, f77_print_array_1)
(f77_print_array): Update.
* jv-lang.h (java_val_print): Update.
* jv-valprint.c (java_print_value_fields, java_val_print): Update.
* language.c (unk_lang_val_print): Update.
* m2-lang.h (m2_val_print): Update.
* m2-valprint.c (m2_val_print): Update.
* p-lang.h (pascal_val_print): Update.
(pascal_object_print_value_fields): Update.
* p-valprint.c (pascal_val_print)
(pascal_object_print_value_fields, pascal_object_print_value)
(pascal_object_print_value): Update.
* scm-lang.h (scm_val_print): Update.
* scm-valprint.c (scm_val_print): Update.
* value.h (val_print): Update.
2005-01-29 09:59:31 +08:00
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
Contributed by Motorola. Adapted from the C definitions by Farooq Butt
|
|
|
|
(fmbutt@engage.sps.mot.com).
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
This file is part of GDB.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
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
|
2007-08-24 02:08:50 +08:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-07-08 04:19:36 +08:00
|
|
|
(at your option) any later version.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
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.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-24 02:08:50 +08:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2019-01-28 03:51:36 +08:00
|
|
|
#ifndef F_LANG_H
|
|
|
|
#define F_LANG_H
|
|
|
|
|
2022-12-14 11:34:31 +08:00
|
|
|
#include "language.h"
|
2020-09-16 23:27:30 +08:00
|
|
|
#include "valprint.h"
|
|
|
|
|
* ada-lang.c (user_select_syms, ada_print_subexp): Pass flags
to type-printing functions.
* ada-lang.h (ada_print_type): Add argument.
* ada-typeprint.c (print_array_type, print_variant_clauses,
print_variant_part, print_selected_record_field_types,
print_record_field_types, print_unchecked_union_type,
print_func_type, ada_print_type): Add flags argument.
(ada_print_typedef): Update.
* c-exp.y (OPERATOR conversion_type_id): Update.
* c-lang.h (c_print_type, c_type_print_base): Update.
* c-typeprint.c (c_print_type, c_type_print_varspec_prefix,
c_type_print_modifier, c_type_print_args,
c_type_print_varspec_suffix, c_type_print_base): Add flags
argument.
* cp-valprint.c (cp_print_class_member): Update.
* dwarf2read.c (dwarf2_compute_name): Update.
* f-lang.h (f_print_type): Add argument.
* f-typeprint.c (f_print_type): Add flags argument.
* gnu-v3-abi.c (gnuv3_print_method_ptr): Update.
* go-lang.h (go_print_type): Add argument.
* go-typeprint.c (go_print_type): Add flags argument.
* jv-lang.h (java_print_type): Add argument.
* jv-typeprint.c (java_type_print_base, java_print_type): Add
flags argument.
* language.c (unk_lang_print_type): Add flags argument.
* language.h (struct language_defn) <la_print_type>: Add flags
argument.
(LA_PRINT_TYPE): Likewise.
* m2-lang.h (m2_print_type): Add argument.
* m2-typeprint.c (m2_print_type, m2_range, m2_typedef,
m2_array, m2_pointer, m2_ref, m2_procedure, m2_long_set,
m2_unbounded_array, m2_record_fields): Add flags argument.
* p-lang.h (pascal_print_type, pascal_type_print_base,
pascal_type_print_varspec_prefix): Add argument.
* p-typeprint.c (pascal_print_type,
pascal_type_print_varspec_prefix, pascal_print_func_args,
pascal_type_print_varspec_suffix, pascal_type_print_base): Add
flags argument.
* symmisc.c (print_symbol): Update.
* typeprint.c (type_print_raw_options, default_ptype_flags):
New globals.
(type_print): Update.
* typeprint.h (struct type_print_options): New.
(type_print_raw_options): Declare.
(c_type_print_varspec_suffix, c_type_print_args): Add argument.
2012-11-13 01:14:55 +08:00
|
|
|
struct type_print_options;
|
Remove `expout*' globals from parser-defs.h
This commit removes the "expout*" globals from our parser code, turning
them into a structure that is passed when an expression needs to be
evaluated. This is the initial step to make our parser less
"globalized".
This is mostly a mechanical patch, which creates a structure containing
the "expout*" globals and then modify all the functions that handle them
in order to take the structure as argument. It is big, and has been
reviewed at least 4 times, so I think everything is covered.
Below you can see the message links from the discussions:
- First attempt:
<https://sourceware.org/ml/gdb-patches/2012-01/msg00522.html>
Message-ID: <m3k44s7qej.fsf@gmail.com>
- Second attempt:
<https://sourceware.org/ml/gdb-patches/2012-06/msg00054.html>
Message-Id: <1338665528-5932-1-git-send-email-sergiodj@redhat.com>
- Third attempt:
<https://sourceware.org/ml/gdb-patches/2014-01/msg00949.html>
Message-Id: <1390629467-27139-1-git-send-email-sergiodj@redhat.com>
- Fourth (last) attempt:
<https://sourceware.org/ml/gdb-patches/2014-03/msg00546.html>
Message-Id: <1395463432-29750-1-git-send-email-sergiodj@redhat.com>
gdb/
2014-03-27 Sergio Durigan Junior <sergiodj@redhat.com>
Remove some globals from our parser.
* language.c (unk_lang_parser): Add "struct parser_state"
argument.
* language.h (struct language_defn) <la_parser>: Likewise.
* parse.c (expout, expout_size, expout_ptr): Remove variables.
(initialize_expout): Add "struct parser_state" argument.
Rewrite function to use the parser state.
(reallocate_expout, write_exp_elt, write_exp_elt_opcode,
write_exp_elt_sym, write_exp_elt_block, write_exp_elt_objfile,
write_exp_elt_longcst, write_exp_elt_dblcst,
write_exp_elt_decfloatcst, write_exp_elt_type,
write_exp_elt_intern, write_exp_string, write_exp_string_vector,
write_exp_bitstring, write_exp_msymbol, mark_struct_expression,
write_dollar_variable): Likewise.
(parse_exp_in_context_1): Use parser state.
(insert_type_address_space): Add "struct parser_state" argument.
Use parser state.
(increase_expout_size): New function.
* parser-defs.h: Forward declare "struct language_defn" and
"struct parser_state".
(expout, expout_size, expout_ptr): Remove extern declarations.
(parse_gdbarch, parse_language): Rewrite macro declarations to
accept the parser state.
(struct parser_state): New struct.
(initialize_expout, reallocate_expout, write_exp_elt_opcode,
write_exp_elt_sym, write_exp_elt_longcst, write_exp_elt_dblcst,
write_exp_elt_decfloatcst, write_exp_elt_type,
write_exp_elt_intern, write_exp_string, write_exp_string_vector,
write_exp_bitstring, write_exp_elt_block, write_exp_elt_objfile,
write_exp_msymbol, write_dollar_variable,
mark_struct_expression, insert_type_address_space): Add "struct
parser_state" argument.
(increase_expout_size): New function.
* utils.c (do_clear_parser_state): New function.
(make_cleanup_clear_parser_state): Likewise.
* utils.h (make_cleanup_clear_parser_state): New function
prototype.
* aarch64-linux-tdep.c (aarch64_stap_parse_special_token):
Update calls to write_exp* in order to pass the parser state.
* arm-linux-tdep.c (arm_stap_parse_special_token): Likewise.
* i386-tdep.c (i386_stap_parse_special_token_triplet): Likewise.
(i386_stap_parse_special_token_three_arg_disp): Likewise.
* ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise.
* stap-probe.c (stap_parse_register_operand): Likewise.
(stap_parse_single_operand): Likewise.
(stap_parse_argument_1): Likewise.
(stap_parse_argument): Use parser state.
* stap-probe.h: Include "parser-defs.h".
(struct stap_parse_info) <pstate>: New field.
* c-exp.y (parse_type): Rewrite to use parser state.
(yyparse): Redefine to c_parse_internal.
(pstate): New global variable.
(parse_number): Add "struct parser_state" argument.
(write_destructor_name): Likewise.
(type_exp): Update calls to write_exp* and similars in order to
use parser state.
(exp1, exp, variable, qualified_name, space_identifier,
typename, typebase): Likewise.
(write_destructor_name, parse_number, lex_one_token,
classify_name, classify_inner_name, c_parse): Add "struct
parser_state" argument. Update function to use parser state.
* c-lang.h: Forward declare "struct parser_state".
(c_parse): Add "struct parser_state" argument.
* ada-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to ada_parse_internal.
(pstate): New variable.
(write_int, write_object_renaming, write_var_or_type,
write_name_assoc, write_exp_op_with_string, write_ambiguous_var,
type_int, type_long, type_long_long, type_float, type_double,
type_long_double, type_char, type_boolean, type_system_address):
Add "struct parser_state" argument.
(exp1, primary, simple_exp, relation, and_exp, and_then_exp,
or_exp, or_else_exp, xor_exp, type_prefix, opt_type_prefix,
var_or_type, aggregate, aggregate_component_list,
positional_list, others, component_group,
component_associations): Update calls to write_exp* and similar
functions in order to use parser state.
(ada_parse, write_var_from_sym, write_int,
write_exp_op_with_string, write_object_renaming,
find_primitive_type, write_selectors, write_ambiguous_var,
write_var_or_type, write_name_assoc, type_int, type_long,
type_long_long, type_float, type_double, type_long_double,
type_char, type_boolean, type_system_address): Add "struct
parser_state" argument. Adjust function to use parser state.
* ada-lang.c (parse): Likewise.
* ada-lang.h: Forward declare "struct parser_state".
(ada_parse): Add "struct parser_state" argument.
* ada-lex.l (processInt, processReal): Likewise. Adjust all
calls to both functions.
* f-exp.y (parse_type, parse_f_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro to f_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp, subrange, typebase): Update calls to write_exp*
and similars in order to use parser state.
(parse_number): Adjust code to use parser state.
(yylex): Likewise.
(f_parse): New function.
* f-lang.h: Forward declare "struct parser_state".
(f_parse): Add "struct parser_state" argument.
* jv-exp.y (parse_type, parse_java_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro for java_parse_internal.
(pstate): New variable.
(push_expression_name, push_expression_name, insert_exp): Add
"struct parser_state" argument.
(type_exp, StringLiteral, Literal, PrimitiveType, IntegralType,
FloatingPointType, exp1, PrimaryNoNewArray, FieldAccess,
FuncStart, MethodInvocation, ArrayAccess, PostfixExpression,
PostIncrementExpression, PostDecrementExpression,
UnaryExpression, PreIncrementExpression, PreDecrementExpression,
UnaryExpressionNotPlusMinus, CastExpression,
MultiplicativeExpression, AdditiveExpression, ShiftExpression,
RelationalExpression, EqualityExpression, AndExpression,
ExclusiveOrExpression, InclusiveOrExpression,
ConditionalAndExpression, ConditionalOrExpression,
ConditionalExpression, Assignment, LeftHandSide): Update
calls to write_exp* and similars in order to use parser state.
(parse_number): Ajust code to use parser state.
(yylex): Likewise.
(java_parse): New function.
(push_variable): Add "struct parser_state" argument. Adjust
code to user parser state.
(push_fieldnames, push_qualified_expression_name,
push_expression_name, insert_exp): Likewise.
* jv-lang.h: Forward declare "struct parser_state".
(java_parse): Add "struct parser_state" argument.
* m2-exp.y (parse_type, parse_m2_type): Rewrite macros to use
parser state.
(yyparse): Redefine macro to m2_parse_internal.
(pstate): New variable.
(type_exp, exp, fblock, variable, type): Update calls to
write_exp* and similars to use parser state.
(yylex): Likewise.
(m2_parse): New function.
* m2-lang.h: Forward declare "struct parser_state".
(m2_parse): Add "struct parser_state" argument.
* objc-lang.c (end_msglist): Add "struct parser_state" argument.
* objc-lang.h: Forward declare "struct parser_state".
(end_msglist): Add "struct parser_state" argument.
* p-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to pascal_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp1, exp, qualified_name, variable): Update calls to
write_exp* and similars in order to use parser state.
(parse_number, yylex): Adjust code to use parser state.
(pascal_parse): New function.
* p-lang.h: Forward declare "struct parser_state".
(pascal_parse): Add "struct parser_state" argument.
* go-exp.y (parse_type): Rewrite macro to use parser state.
(yyparse): Redefine macro to go_parse_internal.
(pstate): New variable.
(parse_number): Add "struct parser_state" argument.
(type_exp, exp1, exp, variable, type): Update calls to
write_exp* and similars in order to use parser state.
(parse_number, lex_one_token, classify_name, yylex): Adjust code
to use parser state.
(go_parse): Likewise.
* go-lang.h: Forward declare "struct parser_state".
(go_parse): Add "struct parser_state" argument.
2014-03-28 06:10:40 +08:00
|
|
|
struct parser_state;
|
* ada-lang.c (user_select_syms, ada_print_subexp): Pass flags
to type-printing functions.
* ada-lang.h (ada_print_type): Add argument.
* ada-typeprint.c (print_array_type, print_variant_clauses,
print_variant_part, print_selected_record_field_types,
print_record_field_types, print_unchecked_union_type,
print_func_type, ada_print_type): Add flags argument.
(ada_print_typedef): Update.
* c-exp.y (OPERATOR conversion_type_id): Update.
* c-lang.h (c_print_type, c_type_print_base): Update.
* c-typeprint.c (c_print_type, c_type_print_varspec_prefix,
c_type_print_modifier, c_type_print_args,
c_type_print_varspec_suffix, c_type_print_base): Add flags
argument.
* cp-valprint.c (cp_print_class_member): Update.
* dwarf2read.c (dwarf2_compute_name): Update.
* f-lang.h (f_print_type): Add argument.
* f-typeprint.c (f_print_type): Add flags argument.
* gnu-v3-abi.c (gnuv3_print_method_ptr): Update.
* go-lang.h (go_print_type): Add argument.
* go-typeprint.c (go_print_type): Add flags argument.
* jv-lang.h (java_print_type): Add argument.
* jv-typeprint.c (java_type_print_base, java_print_type): Add
flags argument.
* language.c (unk_lang_print_type): Add flags argument.
* language.h (struct language_defn) <la_print_type>: Add flags
argument.
(LA_PRINT_TYPE): Likewise.
* m2-lang.h (m2_print_type): Add argument.
* m2-typeprint.c (m2_print_type, m2_range, m2_typedef,
m2_array, m2_pointer, m2_ref, m2_procedure, m2_long_set,
m2_unbounded_array, m2_record_fields): Add flags argument.
* p-lang.h (pascal_print_type, pascal_type_print_base,
pascal_type_print_varspec_prefix): Add argument.
* p-typeprint.c (pascal_print_type,
pascal_type_print_varspec_prefix, pascal_print_func_args,
pascal_type_print_varspec_suffix, pascal_type_print_base): Add
flags argument.
* symmisc.c (print_symbol): Update.
* typeprint.c (type_print_raw_options, default_ptype_flags):
New globals.
(type_print): Update.
* typeprint.h (struct type_print_options): New.
(type_print_raw_options): Declare.
(c_type_print_varspec_suffix, c_type_print_args): Add argument.
2012-11-13 01:14:55 +08:00
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
/* Class representing the Fortran language. */
|
|
|
|
|
|
|
|
class f_language : public language_defn
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
f_language ()
|
|
|
|
: language_defn (language_fortran)
|
|
|
|
{ /* Nothing. */ }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
const char *name () const override
|
|
|
|
{ return "fortran"; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
const char *natural_name () const override
|
|
|
|
{ return "Fortran"; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
const std::vector<const char *> &filename_extensions () const override
|
|
|
|
{
|
|
|
|
static const std::vector<const char *> extensions = {
|
|
|
|
".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
|
|
|
|
".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08"
|
|
|
|
};
|
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
2022-01-20 05:55:10 +08:00
|
|
|
/* See language.h. */
|
|
|
|
void print_array_index (struct type *index_type,
|
|
|
|
LONGEST index,
|
|
|
|
struct ui_file *stream,
|
|
|
|
const value_print_options *options) const override;
|
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
/* See language.h. */
|
|
|
|
void language_arch_info (struct gdbarch *gdbarch,
|
|
|
|
struct language_arch_info *lai) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
unsigned int search_name_hash (const char *name) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
2021-10-04 22:44:22 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
|
|
|
|
int options) const override
|
2020-09-16 23:27:30 +08:00
|
|
|
{
|
|
|
|
/* We could support demangling here to provide module namespaces
|
|
|
|
also for inferiors with only minimal symbol table (ELF symbols).
|
|
|
|
Just the mangling standard is not standardized across compilers
|
|
|
|
and there is no DW_AT_producer available for inferiors with only
|
|
|
|
the ELF symbols to check the mangling kind. */
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void print_type (struct type *type, const char *varstring,
|
|
|
|
struct ui_file *stream, int show, int level,
|
|
|
|
const struct type_print_options *flags) const override;
|
|
|
|
|
|
|
|
/* See language.h. This just returns default set of word break
|
|
|
|
characters but with the modules separator `::' removed. */
|
|
|
|
|
|
|
|
const char *word_break_characters (void) const override
|
|
|
|
{
|
|
|
|
static char *retval;
|
|
|
|
|
|
|
|
if (!retval)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
retval = xstrdup (language_defn::word_break_characters ());
|
|
|
|
s = strchr (retval, ':');
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
char *last_char = &s[strlen (s) - 1];
|
|
|
|
|
|
|
|
*s = *last_char;
|
|
|
|
*last_char = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void collect_symbol_completion_matches (completion_tracker &tracker,
|
|
|
|
complete_symbol_mode mode,
|
|
|
|
symbol_name_match_type name_match_type,
|
|
|
|
const char *text, const char *word,
|
|
|
|
enum type_code code) const override
|
|
|
|
{
|
|
|
|
/* Consider the modules separator :: as a valid symbol name character
|
|
|
|
class. */
|
|
|
|
default_collect_symbol_completion_matches_break_on (tracker, mode,
|
|
|
|
name_match_type,
|
|
|
|
text, word, ":",
|
|
|
|
code);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void value_print_inner
|
|
|
|
(struct value *val, struct ui_file *stream, int recurse,
|
|
|
|
const struct value_print_options *options) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
2024-05-24 00:30:16 +08:00
|
|
|
struct block_symbol lookup_symbol_local
|
|
|
|
(const char *scope,
|
|
|
|
const char *name,
|
|
|
|
const struct block *block,
|
|
|
|
const domain_search_flags domain) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
struct block_symbol lookup_symbol_nonlocal
|
|
|
|
(const char *name, const struct block *block,
|
2023-03-31 13:00:26 +08:00
|
|
|
const domain_search_flags domain) const override;
|
2020-09-16 23:27:30 +08:00
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
int parser (struct parser_state *ps) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void emitchar (int ch, struct type *chtype,
|
|
|
|
struct ui_file *stream, int quoter) const override
|
|
|
|
{
|
|
|
|
const char *encoding = get_encoding (chtype);
|
|
|
|
generic_emit_char (ch, chtype, stream, quoter, encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void printchar (int ch, struct type *chtype,
|
|
|
|
struct ui_file *stream) const override
|
|
|
|
{
|
2022-01-03 02:36:44 +08:00
|
|
|
gdb_puts ("'", stream);
|
2020-10-20 20:41:18 +08:00
|
|
|
emitchar (ch, chtype, stream, '\'');
|
2022-01-03 02:36:44 +08:00
|
|
|
gdb_puts ("'", stream);
|
2020-09-16 23:27:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
void printstr (struct ui_file *stream, struct type *elttype,
|
|
|
|
const gdb_byte *string, unsigned int length,
|
|
|
|
const char *encoding, int force_ellipses,
|
|
|
|
const struct value_print_options *options) const override
|
|
|
|
{
|
|
|
|
const char *type_encoding = get_encoding (elttype);
|
|
|
|
|
2022-09-21 23:05:21 +08:00
|
|
|
if (elttype->length () == 4)
|
2022-01-03 02:36:44 +08:00
|
|
|
gdb_puts ("4_", stream);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
if (!encoding || !*encoding)
|
|
|
|
encoding = type_encoding;
|
2019-07-09 22:47:19 +08:00
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
generic_printstr (stream, elttype, string, length, encoding,
|
|
|
|
force_ellipses, '\'', 0, options);
|
|
|
|
}
|
2019-07-09 22:47:19 +08:00
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
/* See language.h. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
void print_typedef (struct type *type, struct symbol *new_symbol,
|
|
|
|
struct ui_file *stream) const override;
|
2020-03-14 07:39:52 +08:00
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool is_string_type_p (struct type *type) const override
|
|
|
|
{
|
|
|
|
type = check_typedef (type);
|
|
|
|
return (type->code () == TYPE_CODE_STRING
|
|
|
|
|| (type->code () == TYPE_CODE_ARRAY
|
2022-07-31 10:43:54 +08:00
|
|
|
&& type->target_type ()->code () == TYPE_CODE_CHAR));
|
2020-09-16 23:27:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
gdb: building inferior strings from within GDB
History Of This Patch
=====================
This commit aims to address PR gdb/21699. There have now been a
couple of attempts to fix this issue. Simon originally posted two
patches back in 2021:
https://sourceware.org/pipermail/gdb-patches/2021-July/180894.html
https://sourceware.org/pipermail/gdb-patches/2021-July/180896.html
Before Pedro then posted a version of his own:
https://sourceware.org/pipermail/gdb-patches/2021-July/180970.html
After this the conversation halted. Then in 2023 I (Andrew) also took
a look at this bug and posted two versions:
https://sourceware.org/pipermail/gdb-patches/2023-April/198570.html
https://sourceware.org/pipermail/gdb-patches/2023-April/198680.html
The approach taken in my first patch was pretty similar to what Simon
originally posted back in 2021. My second attempt was only a slight
variation on the first.
Pedro then pointed out his older patch, and so we arrive at this
patch. The GDB changes here are mostly Pedro's work, but updated by
me (Andrew), any mistakes are mine.
The tests here are a combinations of everyone's work, and the commit
message is new, but copies bits from everyone's earlier work.
Problem Description
===================
Bug PR gdb/21699 makes the observation that using $_as_string with
GDB's printf can cause GDB to print unexpected data from the
inferior. The reproducer is pretty simple:
#include <stddef.h>
static char arena[100];
/* Override malloc() so value_coerce_to_target() gets a known
pointer, and we know we"ll see an error if $_as_string() gives
a string that isn't null terminated. */
void
*malloc (size_t size)
{
memset (arena, 'x', sizeof (arena));
if (size > sizeof (arena))
return NULL;
return arena;
}
int
main ()
{
return 0;
}
And then in a GDB session:
$ gdb -q test
Reading symbols from /tmp/test...
(gdb) start
Temporary breakpoint 1 at 0x4004c8: file test.c, line 17.
Starting program: /tmp/test
Temporary breakpoint 1, main () at test.c:17
17 return 0;
(gdb) printf "%s\n", $_as_string("hello")
"hello"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(gdb) quit
The problem above is caused by how value_cstring is used within
py-value.c, but once we understand the issue then it turns out that
value_cstring is used in an unexpected way in many places within GDB.
Within py-value.c we have a null-terminated C-style string. We then
pass a pointer to this string, along with the length of this
string (so not including the null-character) to value_cstring.
In value_cstring GDB allocates an array value of the given character
type, and copies in requested number of characters. However
value_cstring does not add a null-character of its own. This means
that the value created by calling value_cstring is only
null-terminated if the null-character is included in the passed in
length. In py-value.c this is not the case, and indeed, in most uses
of value_cstring, this is not the case.
When GDB tries to print one of these strings the value contents are
pushed to the inferior, and then read back as a C-style string, that
is, GDB reads inferior memory until it finds a null-terminator. For
the py-value.c case, no null-terminator is pushed into the inferior,
so GDB will continue reading inferior memory until a null-terminator
is found, with unpredictable results.
Patch Description
=================
The first thing this patch does is better define what the arguments
for the two function value_cstring and value_string should represent.
The comments in the header file are updated to describe whether the
length argument should, or should not, include a null-character.
Also, the data argument is changed to type gdb_byte. The functions as
they currently exist will handle wide-characters, in which case more
than one 'char' would be needed for each character. As such using
gdb_byte seems to make more sense.
To avoid adding casts throughout GDB, I've also added an overload that
still takes a 'char *', but asserts that the character type being used
is of size '1'.
The value_cstring function is now responsible for adding a null
character at the end of the string value it creates.
However, once we start looking at how value_cstring is used, we
realise there's another, related, problem. Not every language's
strings are null terminated. Fortran and Ada strings, for example,
are just an array of characters, GDB already has the function
value_string which can be used to create such values.
Consider this example using current GDB:
(gdb) set language ada
(gdb) p $_gdb_setting("arch")
$1 = (97, 117, 116, 111)
(gdb) ptype $
type = array (1 .. 4) of char
(gdb) p $_gdb_maint_setting("test-settings string")
$2 = (0)
(gdb) ptype $
type = array (1 .. 1) of char
This shows two problems, first, the $_gdb_setting and
$_gdb_maint_setting functions are calling value_cstring using the
builtin_char character, rather than a language appropriate type. In
the first call, the 'arch' case, the value_cstring call doesn't
include the null character, so the returned array only contains the
expected characters. But, in the $_gdb_maint_setting example we do
end up including the null-character, even though this is not expected
for Ada strings.
This commit adds a new language method language_defn::value_string,
this function takes a pointer and length and creates a language
appropriate value that represents the string. For C, C++, etc this
will be a null-terminated string (by calling value_cstring), and for
Fortran and Ada this can be a bounded array of characters with no null
terminator. Additionally, this new language_defn::value_string
function is responsible for selecting a language appropriate character
type.
After this commit the only calls to value_cstring are from the C
expression evaluator and from the default language_defn::value_string.
And the only calls to value_string are from Fortan, Ada, and ObjectC
related code.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21699
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
Co-Authored-By: Pedro Alves <pedro@palves.net>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2021-07-14 02:44:27 +08:00
|
|
|
struct value *value_string (struct gdbarch *gdbarch,
|
|
|
|
const char *ptr, ssize_t len) const override;
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
const char *struct_too_deep_ellipsis () const override
|
|
|
|
{ return "(...)"; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool c_style_arrays_p () const override
|
|
|
|
{ return false; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
bool range_checking_on_by_default () const override
|
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
enum case_sensitivity case_sensitivity () const override
|
|
|
|
{ return case_sensitive_off; }
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
enum array_ordering array_ordering () const override
|
|
|
|
{ return array_column_major; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/* See language.h. */
|
|
|
|
|
|
|
|
symbol_name_matcher_ftype *get_symbol_name_matcher_inner
|
|
|
|
(const lookup_name_info &lookup_name) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* Return the encoding that should be used for the character type
|
|
|
|
TYPE. */
|
|
|
|
|
|
|
|
static const char *get_encoding (struct type *type);
|
|
|
|
|
|
|
|
/* Print any asterisks or open-parentheses needed before the variable
|
|
|
|
name (to describe its type).
|
|
|
|
|
|
|
|
On outermost call, pass 0 for PASSED_A_PTR.
|
|
|
|
On outermost call, SHOW > 0 means should ignore
|
|
|
|
any typename for TYPE and show its details.
|
|
|
|
SHOW is always zero on recursive calls. */
|
|
|
|
|
|
|
|
void f_type_print_varspec_prefix (struct type *type,
|
|
|
|
struct ui_file * stream,
|
|
|
|
int show, int passed_a_ptr) const;
|
|
|
|
|
|
|
|
/* Print any array sizes, function arguments or close parentheses needed
|
|
|
|
after the variable name (to describe its type). Args work like
|
|
|
|
c_type_print_varspec_prefix.
|
|
|
|
|
|
|
|
PRINT_RANK_ONLY is true when TYPE is an array which should be printed
|
|
|
|
without the upper and lower bounds being specified, this will occur
|
|
|
|
when the array is not allocated or not associated and so there are no
|
|
|
|
known upper or lower bounds. */
|
|
|
|
|
|
|
|
void f_type_print_varspec_suffix (struct type *type,
|
|
|
|
struct ui_file *stream,
|
|
|
|
int show, int passed_a_ptr,
|
|
|
|
int demangled_args,
|
|
|
|
int arrayprint_recurse_level,
|
|
|
|
bool print_rank_only) const;
|
|
|
|
|
2022-04-05 23:44:46 +08:00
|
|
|
/* If TYPE is an extended type, then print out derivation information.
|
|
|
|
|
|
|
|
A typical output could look like this:
|
|
|
|
"Type, extends(point) :: waypoint"
|
|
|
|
" Type point :: point"
|
|
|
|
" real(kind=4) :: angle"
|
|
|
|
"End Type waypoint". */
|
|
|
|
|
|
|
|
void f_type_print_derivation_info (struct type *type,
|
|
|
|
struct ui_file *stream) const;
|
|
|
|
|
2020-09-16 23:27:30 +08:00
|
|
|
/* Print the name of the type (or the ultimate pointer target, function
|
|
|
|
value or array element), or the description of a structure or union.
|
|
|
|
|
|
|
|
SHOW nonzero means don't print this type as just its name;
|
|
|
|
show its real definition even if it has a name.
|
|
|
|
SHOW zero means print just typename or struct tag if there is one
|
|
|
|
SHOW negative means abbreviate structure elements.
|
|
|
|
SHOW is decremented for printing of structure elements.
|
|
|
|
|
|
|
|
LEVEL is the depth to indent by. We increase it for some recursive
|
|
|
|
calls. */
|
|
|
|
|
|
|
|
void f_type_print_base (struct type *type, struct ui_file *stream, int show,
|
|
|
|
int level) const;
|
|
|
|
};
|
2020-03-14 07:39:52 +08:00
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
/* Language-specific data structures */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2012-09-27 03:38:32 +08:00
|
|
|
/* A common block. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2012-09-27 03:38:32 +08:00
|
|
|
struct common_block
|
|
|
|
{
|
|
|
|
/* The number of entries in the block. */
|
|
|
|
size_t n_entries;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2012-09-27 03:38:32 +08:00
|
|
|
/* The contents of the block, allocated using the struct hack. All
|
|
|
|
pointers in the array are non-NULL. */
|
|
|
|
struct symbol *contents[1];
|
|
|
|
};
|
1999-04-16 09:35:26 +08:00
|
|
|
|
Allow really large fortran array bounds: fortran type/value printers
This is the fortran part of the patch, including tests, which
are essentially unchanged from Siddhesh's original 2012 submission:
https://sourceware.org/ml/gdb-patches/2012-08/msg00562.html
There is, however, one large departure. In the above thread,
Jan pointed out problems with GCC debuginfo for -m32 builds
(filed usptream as gcc/54934). After investigating the issue,
I am dropping the hand-tweaked assembler source file to workaround
this case.
While I would normally do something to accommodate this, in
this case, given the ubiquity of 64-bit systems today (where
the tests pass) and the apparent lack of urgency on the compiler
side (by users), I don't think the additional complexity and
maintenance costs are worth it. It will be very routinely tested
on 64-bit systems. [For example, at Red Hat, we always
test -m64 and -m32 configurations for all GDB releases.]
gdb/ChangeLog:
From Siddhesh Poyarekar:
* f-lang.h (f77_get_upperbound): Return LONGEST.
(f77_get_lowerbound): Likewise.
* f-typeprint.c (f_type_print_varspec_suffix): Expand
UPPER_BOUND and LOWER_BOUND to LONGEST. Use plongest to format
print them.
(f_type_print_base): Expand UPPER_BOUND to LONGEST. Use
plongest to format print it.
* f-valprint.c (f77_get_lowerbound): Return LONGEST.
(f77_get_upperbound): Likewise.
(f77_get_dynamic_length_of_aggregate): Expand UPPER_BOUND,
LOWER_BOUND to LONGEST.
(f77_create_arrayprint_offset_tbl): Likewise.
gdb/testsuite/ChangeLog:
* gdb.fortran/array-bounds.exp: New file.
* gdb.fortran/array-bounds.f90: New file.
2019-03-30 01:15:38 +08:00
|
|
|
extern LONGEST f77_get_upperbound (struct type *);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
Allow really large fortran array bounds: fortran type/value printers
This is the fortran part of the patch, including tests, which
are essentially unchanged from Siddhesh's original 2012 submission:
https://sourceware.org/ml/gdb-patches/2012-08/msg00562.html
There is, however, one large departure. In the above thread,
Jan pointed out problems with GCC debuginfo for -m32 builds
(filed usptream as gcc/54934). After investigating the issue,
I am dropping the hand-tweaked assembler source file to workaround
this case.
While I would normally do something to accommodate this, in
this case, given the ubiquity of 64-bit systems today (where
the tests pass) and the apparent lack of urgency on the compiler
side (by users), I don't think the additional complexity and
maintenance costs are worth it. It will be very routinely tested
on 64-bit systems. [For example, at Red Hat, we always
test -m64 and -m32 configurations for all GDB releases.]
gdb/ChangeLog:
From Siddhesh Poyarekar:
* f-lang.h (f77_get_upperbound): Return LONGEST.
(f77_get_lowerbound): Likewise.
* f-typeprint.c (f_type_print_varspec_suffix): Expand
UPPER_BOUND and LOWER_BOUND to LONGEST. Use plongest to format
print them.
(f_type_print_base): Expand UPPER_BOUND to LONGEST. Use
plongest to format print it.
* f-valprint.c (f77_get_lowerbound): Return LONGEST.
(f77_get_upperbound): Likewise.
(f77_get_dynamic_length_of_aggregate): Expand UPPER_BOUND,
LOWER_BOUND to LONGEST.
(f77_create_arrayprint_offset_tbl): Likewise.
gdb/testsuite/ChangeLog:
* gdb.fortran/array-bounds.exp: New file.
* gdb.fortran/array-bounds.f90: New file.
2019-03-30 01:15:38 +08:00
|
|
|
extern LONGEST f77_get_lowerbound (struct type *);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2000-05-28 09:12:42 +08:00
|
|
|
extern int calc_f77_array_dims (struct type *);
|
* gdbtypes.h (builtin_type_void_data_ptr, builtin_type_void_func_ptr,
builtin_type_CORE_ADDR, builtin_type_char, builtin_type_short,
builtin_type_int, builtin_type_long, builtin_type_signed_char,
builtin_type_unsigned_char, builtin_type_unsigned_short,
builtin_type_unsigned_int, builtin_type_unsigned_long,
builtin_type_float, builtin_type_double, builtin_type_long_double,
builtin_type_complex, builtin_type_double_complex, builtin_type_string,
builtin_type_bool, builtin_type_long_long,
builtin_type_unsigned_long_long): Remove macros.
(builtin_type_f_character, builtin_type_f_integer,
builtin_type_f_integer_s2, builtin_type_f_logical,
builtin_type_f_logical_s1, builtin_type_f_logical_s2,
builtin_type_f_real, builtin_type_f_real_s8, builtin_type_f_real_s16,
builtin_type_f_complex_s8, builtin_type_f_complex_s16,
builtin_type_f_complex_s32): Likewise.
(builtin_type_m2_char, builtin_type_m2_int, builtin_type_m2_card,
builtin_type_m2_real, builtin_type_m2_bool): Likewise.
(struct builtin_f_type, builtin_f_type): Move to f-lang.h.
(struct builtin_m2_type, builtin_m2_type): Move to m2-lang.h.
* f-lang.h (struct builtin_f_type, builtin_f_type): Move here.
* m2-lang.h (struct builtin_m2_type, builtin_m2_type): Move here.
2008-09-11 22:31:43 +08:00
|
|
|
|
|
|
|
/* Fortran (F77) types */
|
|
|
|
|
|
|
|
struct builtin_f_type
|
|
|
|
{
|
2022-06-02 05:31:15 +08:00
|
|
|
struct type *builtin_character = nullptr;
|
|
|
|
struct type *builtin_integer_s1 = nullptr;
|
|
|
|
struct type *builtin_integer_s2 = nullptr;
|
|
|
|
struct type *builtin_integer = nullptr;
|
|
|
|
struct type *builtin_integer_s8 = nullptr;
|
|
|
|
struct type *builtin_logical_s1 = nullptr;
|
|
|
|
struct type *builtin_logical_s2 = nullptr;
|
|
|
|
struct type *builtin_logical = nullptr;
|
|
|
|
struct type *builtin_logical_s8 = nullptr;
|
|
|
|
struct type *builtin_real = nullptr;
|
|
|
|
struct type *builtin_real_s8 = nullptr;
|
|
|
|
struct type *builtin_real_s16 = nullptr;
|
|
|
|
struct type *builtin_complex = nullptr;
|
|
|
|
struct type *builtin_complex_s8 = nullptr;
|
|
|
|
struct type *builtin_complex_s16 = nullptr;
|
|
|
|
struct type *builtin_void = nullptr;
|
* gdbtypes.h (builtin_type_void_data_ptr, builtin_type_void_func_ptr,
builtin_type_CORE_ADDR, builtin_type_char, builtin_type_short,
builtin_type_int, builtin_type_long, builtin_type_signed_char,
builtin_type_unsigned_char, builtin_type_unsigned_short,
builtin_type_unsigned_int, builtin_type_unsigned_long,
builtin_type_float, builtin_type_double, builtin_type_long_double,
builtin_type_complex, builtin_type_double_complex, builtin_type_string,
builtin_type_bool, builtin_type_long_long,
builtin_type_unsigned_long_long): Remove macros.
(builtin_type_f_character, builtin_type_f_integer,
builtin_type_f_integer_s2, builtin_type_f_logical,
builtin_type_f_logical_s1, builtin_type_f_logical_s2,
builtin_type_f_real, builtin_type_f_real_s8, builtin_type_f_real_s16,
builtin_type_f_complex_s8, builtin_type_f_complex_s16,
builtin_type_f_complex_s32): Likewise.
(builtin_type_m2_char, builtin_type_m2_int, builtin_type_m2_card,
builtin_type_m2_real, builtin_type_m2_bool): Likewise.
(struct builtin_f_type, builtin_f_type): Move to f-lang.h.
(struct builtin_m2_type, builtin_m2_type): Move to m2-lang.h.
* f-lang.h (struct builtin_f_type, builtin_f_type): Move here.
* m2-lang.h (struct builtin_m2_type, builtin_m2_type): Move here.
2008-09-11 22:31:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Return the Fortran type table for the specified architecture. */
|
|
|
|
extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch);
|
|
|
|
|
Fortran function calls with arguments
Prior to this patch, calling functions on the inferior with arguments and
then using these arguments within a function resulted in an invalid
memory access. This is because Fortran arguments are typically passed as
pointers to values.
It is possible to call Fortran functions, but memory must be allocated in
the inferior, so a pointer can be passed to the function, and the
language must be set to C to enable C-style casting. This is cumbersome
and not a pleasant debug experience.
This patch implements the GNU Fortran argument passing conventions with
caveats. Firstly, it does not handle the VALUE attribute as there is
insufficient DWARF information to determine when this is the case.
Secondly, functions with optional parameters can only be called with all
parameters present. Both these cases are marked as KFAILS in the test.
Since the GNU Fortran argument passing convention has been implemented,
there is no guarantee that this patch will work correctly, in all cases,
with other compilers.
Despite these limitations, this patch improves the ease with which
functions can be called in many cases, without taking away the existing
approach of calling with the language set to C.
Regression tested on x86_64, aarch64 and POWER9 with GCC 7.3.0.
Regression tested with Ada on x86_64.
Regression tested with native-extended-gdbserver target board.
gdb/ChangeLog:
* eval.c (evaluate_subexp_standard): Call Fortran argument
wrapping logic.
* f-lang.c (struct value): A value which can be passed into a
Fortran function call.
(fortran_argument_convert): Wrap Fortran arguments in a pointer
where appropriate.
(struct type): Value ready for a Fortran function call.
(fortran_preserve_arg_pointer): Undo check_typedef, the pointer
is needed.
* f-lang.h (fortran_argument_convert): Declaration.
(fortran_preserve_arg_pointer): Declaration.
* infcall.c (value_arg_coerce): Call Fortran argument logic.
gdb/testsuite/ChangeLog:
* gdb.fortran/function-calls.exp: New file.
* gdb.fortran/function-calls.f90: New test.
2019-03-06 16:23:00 +08:00
|
|
|
/* Ensures that function argument TYPE is appropriate to inform the debugger
|
|
|
|
that ARG should be passed as a pointer. Returns the potentially updated
|
|
|
|
argument type.
|
|
|
|
|
|
|
|
If ARG is of type pointer then the type of ARG is returned, otherwise
|
|
|
|
TYPE is returned untouched.
|
|
|
|
|
|
|
|
This function exists to augment the types of Fortran function call
|
|
|
|
parameters to be pointers to the reported value, when the corresponding ARG
|
|
|
|
has also been wrapped in a pointer (by fortran_argument_convert). This
|
|
|
|
informs the debugger that these arguments should be passed as a pointer
|
|
|
|
rather than as the pointed to type. */
|
|
|
|
|
|
|
|
extern struct type *fortran_preserve_arg_pointer (struct value *arg,
|
|
|
|
struct type *type);
|
|
|
|
|
gdb/fortran: Add support for Fortran array slices at the GDB prompt
This commit brings array slice support to GDB.
WARNING: This patch contains a rather big hack which is limited to
Fortran arrays, this can be seen in gdbtypes.c and f-lang.c. More
details on this below.
This patch rewrites two areas of GDB's Fortran support, the code to
extract an array slice, and the code to print an array.
After this commit a user can, from the GDB prompt, ask for a slice of
a Fortran array and should get the correct result back. Slices can
(optionally) have the lower bound, upper bound, and a stride
specified. Slices can also have a negative stride.
Fortran has the concept of repacking array slices. Within a compiled
Fortran program if a user passes a non-contiguous array slice to a
function then the compiler may have to repack the slice, this involves
copying the elements of the slice to a new area of memory before the
call, and copying the elements back to the original array after the
call. Whether repacking occurs will depend on which version of
Fortran is being used, and what type of function is being called.
This commit adds support for both packed, and unpacked array slicing,
with the default being unpacked.
With an unpacked array slice, when the user asks for a slice of an
array GDB creates a new type that accurately describes where the
elements of the slice can be found within the original array, a
value of this type is then returned to the user. The address of an
element within the slice will be equal to the address of an element
within the original array.
A user can choose to select packed array slices instead using:
(gdb) set fortran repack-array-slices on|off
(gdb) show fortran repack-array-slices
With packed array slices GDB creates a new type that reflects how the
elements of the slice would look if they were laid out in contiguous
memory, allocates a value of this type, and then fetches the elements
from the original array and places then into the contents buffer of
the new value.
One benefit of using packed slices over unpacked slices is the memory
usage, taking a small slice of N elements from a large array will
require (in GDB) N * ELEMENT_SIZE bytes of memory, while an unpacked
array will also include all of the "padding" between the
non-contiguous elements. There are new tests added that highlight
this difference.
There is also a new debugging flag added with this commit that
introduces these commands:
(gdb) set debug fortran-array-slicing on|off
(gdb) show debug fortran-array-slicing
This prints information about how the array slices are being built.
As both the repacking, and the array printing requires GDB to walk
through a multi-dimensional Fortran array visiting each element, this
commit adds the file f-array-walk.h, which introduces some
infrastructure to support this process. This means the array printing
code in f-valprint.c is significantly reduced.
The only slight issue with this commit is the "rather big hack" that I
mentioned above. This hack allows us to handle one specific case,
array slices with negative strides. This is something that I don't
believe the current GDB value contents model will allow us to
correctly handle, and rather than rewrite the value contents code
right now, I'm hoping to slip this hack in as a work around.
The problem is that, as I see it, the current value contents model
assumes that an object base address will be the lowest address within
that object, and that the contents of the object start at this base
address and occupy the TYPE_LENGTH bytes after that.
( We do have the embedded_offset, which is used for C++ sub-classes,
such that an object can start at some offset from the content buffer,
however, the assumption that the object then occupies the next
TYPE_LENGTH bytes is still true within GDB. )
The problem is that Fortran arrays with a negative stride don't follow
this pattern. In this case the base address of the object points to
the element with the highest address, the contents of the array then
start at some offset _before_ the base address, and proceed for one
element _past_ the base address.
As the stride for such an array would be negative then, in theory the
TYPE_LENGTH for this type would also be negative. However, in many
places a value in GDB will degrade to a pointer + length, and the
length almost always comes from the TYPE_LENGTH.
It is my belief that in order to correctly model this case the value
content handling of GDB will need to be reworked to split apart the
value's content buffer (which is a block of memory with a length), and
the object's in memory base address and length, which could be
negative.
Things are further complicated because arrays with negative strides
like this are always dynamic types. When a value has a dynamic type
and its base address needs resolving we actually store the address of
the object within the resolved dynamic type, not within the value
object itself.
In short I don't currently see an easy path to cleanly support this
situation within GDB. And so I believe that leaves two options,
either add a work around, or catch cases where the user tries to make
use of a negative stride, or access an array with a negative stride,
and throw an error.
This patch currently goes with adding a work around, which is that
when we resolve a dynamic Fortran array type, if the stride is
negative, then we adjust the base address to point to the lowest
address required by the array. The printing and slicing code is aware
of this adjustment and will correctly slice and print Fortran arrays.
Where this hack will show through to the user is if they ask for the
address of an array in their program with a negative array stride, the
address they get from GDB will not match the address that would be
computed within the Fortran program.
gdb/ChangeLog:
* Makefile.in (HFILES_NO_SRCDIR): Add f-array-walker.h.
* NEWS: Mention new options.
* f-array-walker.h: New file.
* f-lang.c: Include 'gdbcmd.h' and 'f-array-walker.h'.
(repack_array_slices): New static global.
(show_repack_array_slices): New function.
(fortran_array_slicing_debug): New static global.
(show_fortran_array_slicing_debug): New function.
(value_f90_subarray): Delete.
(skip_undetermined_arglist): Delete.
(class fortran_array_repacker_base_impl): New class.
(class fortran_lazy_array_repacker_impl): New class.
(class fortran_array_repacker_impl): New class.
(fortran_value_subarray): Complete rewrite.
(set_fortran_list): New static global.
(show_fortran_list): Likewise.
(_initialize_f_language): Register new commands.
(fortran_adjust_dynamic_array_base_address_hack): New function.
* f-lang.h (fortran_adjust_dynamic_array_base_address_hack):
Declare.
* f-valprint.c: Include 'f-array-walker.h'.
(class fortran_array_printer_impl): New class.
(f77_print_array_1): Delete.
(f77_print_array): Delete.
(fortran_print_array): New.
(f_value_print_inner): Update to call fortran_print_array.
* gdbtypes.c: Include 'f-lang.h'.
(resolve_dynamic_type_internal): Call
fortran_adjust_dynamic_array_base_address_hack.
gdb/testsuite/ChangeLog:
* gdb.fortran/array-slices-bad.exp: New file.
* gdb.fortran/array-slices-bad.f90: New file.
* gdb.fortran/array-slices-sub-slices.exp: New file.
* gdb.fortran/array-slices-sub-slices.f90: New file.
* gdb.fortran/array-slices.exp: Rewrite tests.
* gdb.fortran/array-slices.f90: Rewrite tests.
* gdb.fortran/vla-sizeof.exp: Correct expected results.
gdb/doc/ChangeLog:
* gdb.texinfo (Debugging Output): Document 'set/show debug
fortran-array-slicing'.
(Special Fortran Commands): Document 'set/show fortran
repack-array-slices'.
2020-10-08 23:45:59 +08:00
|
|
|
/* Fortran arrays can have a negative stride. When this happens it is
|
|
|
|
often the case that the base address for an object is not the lowest
|
|
|
|
address occupied by that object. For example, an array slice (10:1:-1)
|
|
|
|
will be encoded with lower bound 1, upper bound 10, a stride of
|
|
|
|
-ELEMENT_SIZE, and have a base address pointer that points at the
|
|
|
|
element with the highest address in memory.
|
|
|
|
|
|
|
|
This really doesn't play well with our current model of value contents,
|
|
|
|
but could easily require a significant update in order to be supported
|
|
|
|
"correctly".
|
|
|
|
|
|
|
|
For now, we manually force the base address to be the lowest addressed
|
|
|
|
element here. Yes, this will break some things, but it fixes other
|
|
|
|
things. The hope is that it fixes more than it breaks. */
|
|
|
|
|
|
|
|
extern CORE_ADDR fortran_adjust_dynamic_array_base_address_hack
|
|
|
|
(struct type *type, CORE_ADDR address);
|
|
|
|
|
2019-01-28 03:51:36 +08:00
|
|
|
#endif /* F_LANG_H */
|