binutils-gdb/gdb/rust-lang.c

2155 lines
56 KiB
C
Raw Normal View History

/* Rust language support routines for GDB, the GNU debugger.
Copyright (C) 2016-2020 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/>. */
#include "defs.h"
#include <ctype.h>
#include "block.h"
#include "c-lang.h"
#include "charset.h"
#include "cp-support.h"
Move logic out of symbol_find_demangled_name This patch moves most of the demangling logic out of symbol_find_demangled_name into the various language_defn objects. The simplest way to do this seemed to be to add a new method to language_defn. This is shame given the existing la_demangle, but given Ada's unusual needs, and the differing demangling options between languages, la_demangle didn't seem to fit. In order to make this work, I made enum language order-sensitive. This helps preserve the current ordering of demangling operations. 2016-06-23 Tom Tromey <tom@tromey.com> * symtab.c (symbol_find_demangled_name): Loop over languages and use language_sniff_from_mangled_name. * rust-lang.c (rust_sniff_from_mangled_name): New function. (rust_language_defn): Update. * p-lang.c (pascal_language_defn): Update. * opencl-lang.c (opencl_language_defn): Update. * objc-lang.c (objc_sniff_from_mangled_name): New function. (objc_language_defn): Update. * m2-lang.c (m2_language_defn): Update. * language.h (struct language_defn) <la_sniff_from_mangled_name>: New field. (language_sniff_from_mangled_name): Declare. * language.c (language_sniff_from_mangled_name): New function. (unknown_language_defn, auto_language_defn, local_language_defn): Update. * jv-lang.c (java_sniff_from_mangled_name): New function. (java_language_defn): Use it. * go-lang.c (go_sniff_from_mangled_name): New function. (go_language_defn): Use it. * f-lang.c (f_language_defn): Update. * defs.h (enum language): Reorder. * d-lang.c (d_sniff_from_mangled_name): New function. (d_language_defn): Use it. * cp-support.h (gdb_sniff_from_mangled_name): Declare. * cp-support.c (gdb_sniff_from_mangled_name): New function. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Update. * ada-lang.c (ada_sniff_from_mangled_name): New function. (ada_language_defn): Use it.
2016-05-26 23:04:07 +02:00
#include "demangle.h"
#include "gdbarch.h"
#include "infcall.h"
#include "objfiles.h"
Handle dereferencing Rust trait objects In Rust, virtual tables work a bit differently than they do in C++. In C++, as you know, they are connected to a particular class hierarchy. Rust, instead, can generate a virtual table for potentially any type -- in fact, one such virtual table for each trait (a trait is similar to an abstract class or to a Java interface) that a type implements. Objects that are referenced via a trait can't currently be inspected by gdb. This patch implements the Rust equivalent of "set print object". gdb relies heavily on the C++ ABI to decode virtual tables; primarily to make "set print object" work; but also "info vtbl". However, Rust does not currently have a specified ABI, so this approach seems unwise to emulate. Instead, I've changed the Rust compiler to emit some DWARF that describes trait objects (previously their internal structure was opaque), vtables (currently just a size -- but I hope to expand this in the future), and the concrete type for which a vtable was emitted. The concrete type is expressed as a DW_AT_containing_type on the vtable's type. This is a small extension to DWARF. This patch adds a new entry to quick_symbol_functions to return the symtab that holds a data address. Previously there was no way in gdb to look up a full (only minimal) non-text symbol by address. The psymbol implementation of this method works by lazily filling in a map that is added to the objfile. This avoids slowing down psymbol reading for a feature that is likely to not be used too frequently. I did not update .gdb_index. My thinking here is that the DWARF 5 indices will obsolete .gdb_index soon-ish, meaning that adding a new feature to them is probably wasted work. If necessary I can update the DWARF 5 index code when it lands in gdb. Regression tested on x86-64 Fedora 25. 2017-11-17 Tom Tromey <tom@tromey.com> * symtab.h (struct symbol) <is_rust_vtable>: New member. (struct rust_vtable_symbol): New. (find_symbol_at_address): Declare. * symtab.c (find_symbol_at_address): New function. * symfile.h (struct quick_symbol_functions) <find_compunit_symtab_by_address>: New member. * symfile-debug.c (debug_qf_find_compunit_symtab_by_address): New function. (debug_sym_quick_functions): Link to debug_qf_find_compunit_symtab_by_address. * rust-lang.c (rust_get_trait_object_pointer): New function. (rust_evaluate_subexp) <case UNOP_IND>: New case. Call rust_get_trait_object_pointer. * psymtab.c (psym_relocate): Clear psymbol_map. (psym_fill_psymbol_map, psym_find_compunit_symtab_by_address): New functions. (psym_functions): Link to psym_find_compunit_symtab_by_address. * objfiles.h (struct objfile) <psymbol_map>: New member. * dwarf2read.c (dwarf2_gdb_index_functions): Update. (process_die) <DW_TAG_variable>: New case. Call read_variable. (rust_containing_type, read_variable): New functions. 2017-11-17 Tom Tromey <tom@tromey.com> * gdb.rust/traits.rs: New file. * gdb.rust/traits.exp: New file.
2017-07-06 14:44:38 +02:00
#include "psymtab.h"
#include "rust-lang.h"
#include "typeprint.h"
#include "valprint.h"
#include "varobj.h"
#include <algorithm>
#include <string>
#include <vector>
Introduce metadata style This introduces a new "metadata" style and changes many places in gdb to use it. The idea here is to let the user distinguish gdb output from output that (conceptually at least) comes directly from the inferior. The newly-styled category includes text that gdb traditionally surrounds in "<...>", like "<unavailable>". I only added a single test for this. In many cases this output is difficult to test. Also, while developing this errors in the implementation of the new printf formats showed up as regressions. gdb/ChangeLog 2019-10-01 Tom Tromey <tom@tromey.com> * p-lang.c (pascal_printstr): Use metadata style. * value.c (show_convenience): Use metadata style. * valprint.c (valprint_check_validity, val_print_optimized_out) (val_print_not_saved, val_print_unavailable) (val_print_invalid_address, generic_val_print, val_print) (value_check_printable, val_print_array_elements): Use metadata style. * ui-out.h (class ui_out) <field_fmt>: New overload. <do_field_fmt>: Add style parameter. * ui-out.c (ui_out::field_fmt): New overload. * typeprint.c (type_print_unknown_return_type) (val_print_not_allocated, val_print_not_associated): Use metadata style. * tui/tui-out.h (class tui_ui_out) <do_field_fmt>: Add style parameter. * tui/tui-out.c (tui_ui_out::do_field_fmt): Update. * tracepoint.c (tvariables_info_1): Use metadata style. * stack.c (print_frame_arg, print_frame_info, print_frame) (info_frame_command_core): Use metadata style. * skip.c (info_skip_command): Use metadata style. * rust-lang.c (rust_print_enum): Use metadata style. * python/py-prettyprint.c (print_stack_unless_memory_error): Use metadata style. * python/py-framefilter.c (py_print_single_arg): Use metadata style. * printcmd.c (do_one_display, print_variable_and_value): Use metadata style. * p-valprint.c (pascal_val_print) (pascal_object_print_value_fields): Use metadata style. * p-typeprint.c (pascal_type_print_base): Use metadata style. * mi/mi-out.h (class mi_ui_out) <do_field_fmt>: Add style parameter. * mi/mi-out.c (mi_ui_out::do_field_fmt): Update. * m2-valprint.c (m2_print_long_set): Use metadata style. * m2-typeprint.c (m2_print_type): Use metadata style. * infcmd.c (print_return_value_1): Use metadata style. * gnu-v3-abi.c (print_one_vtable): Use metadata style. * f-valprint.c (info_common_command_for_block): Use metadata style. * f-typeprint.c (f_type_print_base): Use metadata style. * expprint.c (print_subexp_standard): Use metadata style. * cp-valprint.c (cp_print_value_fields): Use metadata style. * cli/cli-style.h (class cli_style_option): Add constructor. (metadata_style): Declare. * cli/cli-style.c (metadata_style): New global. (_initialize_cli_style): Register metadata style. * cli-out.h (class cli_ui_out) <do_field_fmt>: Add style parameter. * cli-out.c (cli_ui_out::do_field_fmt): Update. * c-typeprint.c (c_type_print_base_struct_union) (c_type_print_base_1): Use metadata style. * breakpoint.c (watchpoint_value_print) (print_one_breakpoint_location): Use metadata style. * break-catch-syscall.c (print_one_catch_syscall): Use metadata style. * break-catch-sig.c (signal_catchpoint_print_one): Use metadata style. * ada-valprint.c (val_print_packed_array_elements, printstr) (print_field_values, ada_val_print_ref, ada_val_print): Use metadata style. * ada-typeprint.c (print_array_type, ada_print_type): Use metadata style. * ada-tasks.c (print_ada_task_info, info_task): Use metadata style. * ada-lang.c (user_select_syms): Use metadata style. gdb/testsuite/ChangeLog 2019-10-01 Tom Tromey <tom@tromey.com> * lib/gdb-utils.exp (style): Handle "metadata" argument. * gdb.base/style.exp: Add metadata style test.
2019-04-03 04:00:18 +02:00
#include "cli/cli-style.h"
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
/* See rust-lang.h. */
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
const char *
rust_last_path_segment (const char *path)
{
const char *result = strrchr (path, ':');
if (result == NULL)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
return path;
return result + 1;
}
/* See rust-lang.h. */
std::string
rust_crate_for_block (const struct block *block)
{
const char *scope = block_scope (block);
if (scope[0] == '\0')
return std::string ();
return std::string (scope, cp_find_first_component (scope));
}
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
/* Return true if TYPE, which must be a struct type, represents a Rust
enum. */
static bool
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
rust_enum_p (struct type *type)
{
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
/* is_dynamic_type will return true if any field has a dynamic
attribute -- but we only want to check the top level. */
return TYPE_HAS_VARIANT_PARTS (type);
}
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
/* Return true if TYPE, which must be an already-resolved enum type,
has no variants. */
static bool
rust_empty_enum_p (const struct type *type)
{
return type->num_fields () == 0;
}
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
/* Given an already-resolved enum type and contents, find which
variant is active. */
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
static int
rust_enum_variant (struct type *type)
{
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
/* The active variant is simply the first non-artificial field. */
for (int i = 0; i < type->num_fields (); ++i)
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
if (!TYPE_FIELD_ARTIFICIAL (type, i))
return i;
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
/* Perhaps we could get here by trying to print an Ada variant
record in Rust mode. Unlikely, but an error is safer than an
assert. */
error (_("Could not find active enum variant"));
}
/* See rust-lang.h. */
bool
rust_tuple_type_p (struct type *type)
{
/* The current implementation is a bit of a hack, but there's
nothing else in the debuginfo to distinguish a tuple from a
struct. */
return (type->code () == TYPE_CODE_STRUCT
&& type->name () != NULL
&& type->name ()[0] == '(');
}
/* Return true if all non-static fields of a structlike type are in a
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
sequence like __0, __1, __2. */
static bool
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
rust_underscore_fields (struct type *type)
{
int i, field_number;
field_number = 0;
if (type->code () != TYPE_CODE_STRUCT)
return false;
for (i = 0; i < type->num_fields (); ++i)
{
if (!field_is_static (&type->field (i)))
{
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
char buf[20];
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
xsnprintf (buf, sizeof (buf), "__%d", field_number);
if (strcmp (buf, TYPE_FIELD_NAME (type, i)) != 0)
return false;
field_number++;
}
}
return true;
}
/* See rust-lang.h. */
bool
rust_tuple_struct_type_p (struct type *type)
{
/* This is just an approximation until DWARF can represent Rust more
precisely. We exclude zero-length structs because they may not
be tuple structs, and there's no way to tell. */
return type->num_fields () > 0 && rust_underscore_fields (type);
}
/* Return true if TYPE is a slice type, otherwise false. */
static bool
rust_slice_type_p (struct type *type)
{
return (type->code () == TYPE_CODE_STRUCT
&& type->name () != NULL
&& (strncmp (type->name (), "&[", 2) == 0
|| strcmp (type->name (), "&str") == 0));
}
/* Return true if TYPE is a range type, otherwise false. */
static bool
rust_range_type_p (struct type *type)
{
int i;
if (type->code () != TYPE_CODE_STRUCT
|| type->num_fields () > 2
|| type->name () == NULL
|| strstr (type->name (), "::Range") == NULL)
return false;
if (type->num_fields () == 0)
return true;
i = 0;
if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
{
if (type->num_fields () == 1)
return true;
i = 1;
}
else if (type->num_fields () == 2)
{
/* First field had to be "start". */
return false;
}
return strcmp (TYPE_FIELD_NAME (type, i), "end") == 0;
}
/* Return true if TYPE is an inclusive range type, otherwise false.
This is only valid for types which are already known to be range
types. */
static bool
rust_inclusive_range_type_p (struct type *type)
{
return (strstr (type->name (), "::RangeInclusive") != NULL
|| strstr (type->name (), "::RangeToInclusive") != NULL);
}
/* Return true if TYPE seems to be the type "u8", otherwise false. */
static bool
rust_u8_type_p (struct type *type)
{
return (type->code () == TYPE_CODE_INT
&& TYPE_UNSIGNED (type)
&& TYPE_LENGTH (type) == 1);
}
/* Return true if TYPE is a Rust character type. */
static bool
rust_chartype_p (struct type *type)
{
return (type->code () == TYPE_CODE_CHAR
&& TYPE_LENGTH (type) == 4
&& TYPE_UNSIGNED (type));
}
gdb: Introduce new language field la_is_string_type_p This commit is preparation work for the next commit, and by itself makes no user visible change to GDB. I've split this work into a separate commit in order to make code review easier. This commit adds a new field 'la_is_string_type_p' to the language struct, this predicate will return true if a type is a string type for the given language. Some languages already have a "is this a string" predicate that I was able to reuse, while for other languages I've had to add a new predicate. In this case I took inspiration from the value printing code for that language - what different conditions would result in printing something as a string. A default "is this a string" method has also been added that looks for TYPE_CODE_STRING, this is the fallback I've used for a couple of languages. In this commit I add the new field and initialise it for each language, however at this stage the new field is never used. gdb/ChangeLog: * ada-lang.c (ada_language_defn): Initialise new field. * c-lang.c (c_is_string_type_p): New function. (c_language_defn): Initialise new field. (cplus_language_defn): Initialise new field. (asm_language_defn): Initialise new field. (minimal_language_defn): Initialise new field. * c-lang.h (c_is_string_type_p): Declare new function. * d-lang.c (d_language_defn): Initialise new field. * f-lang.c (f_is_string_type_p): New function. (f_language_defn): Initialise new field. * go-lang.c (go_is_string_type_p): New function. (go_language_defn): Initialise new field. * language.c (default_is_string_type_p): New function. (unknown_language_defn): Initialise new field. (auto_language_defn): Initialise new field. * language.h (struct language_defn) <la_is_string_type_p>: New member variable. (default_is_string_type_p): Declare new function. * m2-lang.c (m2_language_defn): Initialise new field. * objc-lang.c (objc_language_defn): Initialise new field. * opencl-lang.c (opencl_language_defn): Initialise new field. * p-lang.c (pascal_is_string_type_p): New function. (pascal_language_defn): Initialise new field. * rust-lang.c (rust_is_string_type_p): New function. (rust_language_defn): Initialise new field.
2019-04-10 00:06:41 +02:00
/* Return true if TYPE is a string type. */
static bool
rust_is_string_type_p (struct type *type)
{
LONGEST low_bound, high_bound;
type = check_typedef (type);
return ((type->code () == TYPE_CODE_STRING)
|| (type->code () == TYPE_CODE_PTR
&& (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ARRAY
gdb: Introduce new language field la_is_string_type_p This commit is preparation work for the next commit, and by itself makes no user visible change to GDB. I've split this work into a separate commit in order to make code review easier. This commit adds a new field 'la_is_string_type_p' to the language struct, this predicate will return true if a type is a string type for the given language. Some languages already have a "is this a string" predicate that I was able to reuse, while for other languages I've had to add a new predicate. In this case I took inspiration from the value printing code for that language - what different conditions would result in printing something as a string. A default "is this a string" method has also been added that looks for TYPE_CODE_STRING, this is the fallback I've used for a couple of languages. In this commit I add the new field and initialise it for each language, however at this stage the new field is never used. gdb/ChangeLog: * ada-lang.c (ada_language_defn): Initialise new field. * c-lang.c (c_is_string_type_p): New function. (c_language_defn): Initialise new field. (cplus_language_defn): Initialise new field. (asm_language_defn): Initialise new field. (minimal_language_defn): Initialise new field. * c-lang.h (c_is_string_type_p): Declare new function. * d-lang.c (d_language_defn): Initialise new field. * f-lang.c (f_is_string_type_p): New function. (f_language_defn): Initialise new field. * go-lang.c (go_is_string_type_p): New function. (go_language_defn): Initialise new field. * language.c (default_is_string_type_p): New function. (unknown_language_defn): Initialise new field. (auto_language_defn): Initialise new field. * language.h (struct language_defn) <la_is_string_type_p>: New member variable. (default_is_string_type_p): Declare new function. * m2-lang.c (m2_language_defn): Initialise new field. * objc-lang.c (objc_language_defn): Initialise new field. * opencl-lang.c (opencl_language_defn): Initialise new field. * p-lang.c (pascal_is_string_type_p): New function. (pascal_language_defn): Initialise new field. * rust-lang.c (rust_is_string_type_p): New function. (rust_language_defn): Initialise new field.
2019-04-10 00:06:41 +02:00
&& rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)))
&& get_array_bounds (TYPE_TARGET_TYPE (type), &low_bound,
&high_bound)))
|| (type->code () == TYPE_CODE_STRUCT
gdb: Introduce new language field la_is_string_type_p This commit is preparation work for the next commit, and by itself makes no user visible change to GDB. I've split this work into a separate commit in order to make code review easier. This commit adds a new field 'la_is_string_type_p' to the language struct, this predicate will return true if a type is a string type for the given language. Some languages already have a "is this a string" predicate that I was able to reuse, while for other languages I've had to add a new predicate. In this case I took inspiration from the value printing code for that language - what different conditions would result in printing something as a string. A default "is this a string" method has also been added that looks for TYPE_CODE_STRING, this is the fallback I've used for a couple of languages. In this commit I add the new field and initialise it for each language, however at this stage the new field is never used. gdb/ChangeLog: * ada-lang.c (ada_language_defn): Initialise new field. * c-lang.c (c_is_string_type_p): New function. (c_language_defn): Initialise new field. (cplus_language_defn): Initialise new field. (asm_language_defn): Initialise new field. (minimal_language_defn): Initialise new field. * c-lang.h (c_is_string_type_p): Declare new function. * d-lang.c (d_language_defn): Initialise new field. * f-lang.c (f_is_string_type_p): New function. (f_language_defn): Initialise new field. * go-lang.c (go_is_string_type_p): New function. (go_language_defn): Initialise new field. * language.c (default_is_string_type_p): New function. (unknown_language_defn): Initialise new field. (auto_language_defn): Initialise new field. * language.h (struct language_defn) <la_is_string_type_p>: New member variable. (default_is_string_type_p): Declare new function. * m2-lang.c (m2_language_defn): Initialise new field. * objc-lang.c (objc_language_defn): Initialise new field. * opencl-lang.c (opencl_language_defn): Initialise new field. * p-lang.c (pascal_is_string_type_p): New function. (pascal_language_defn): Initialise new field. * rust-lang.c (rust_is_string_type_p): New function. (rust_language_defn): Initialise new field.
2019-04-10 00:06:41 +02:00
&& !rust_enum_p (type)
&& rust_slice_type_p (type)
&& strcmp (type->name (), "&str") == 0));
gdb: Introduce new language field la_is_string_type_p This commit is preparation work for the next commit, and by itself makes no user visible change to GDB. I've split this work into a separate commit in order to make code review easier. This commit adds a new field 'la_is_string_type_p' to the language struct, this predicate will return true if a type is a string type for the given language. Some languages already have a "is this a string" predicate that I was able to reuse, while for other languages I've had to add a new predicate. In this case I took inspiration from the value printing code for that language - what different conditions would result in printing something as a string. A default "is this a string" method has also been added that looks for TYPE_CODE_STRING, this is the fallback I've used for a couple of languages. In this commit I add the new field and initialise it for each language, however at this stage the new field is never used. gdb/ChangeLog: * ada-lang.c (ada_language_defn): Initialise new field. * c-lang.c (c_is_string_type_p): New function. (c_language_defn): Initialise new field. (cplus_language_defn): Initialise new field. (asm_language_defn): Initialise new field. (minimal_language_defn): Initialise new field. * c-lang.h (c_is_string_type_p): Declare new function. * d-lang.c (d_language_defn): Initialise new field. * f-lang.c (f_is_string_type_p): New function. (f_language_defn): Initialise new field. * go-lang.c (go_is_string_type_p): New function. (go_language_defn): Initialise new field. * language.c (default_is_string_type_p): New function. (unknown_language_defn): Initialise new field. (auto_language_defn): Initialise new field. * language.h (struct language_defn) <la_is_string_type_p>: New member variable. (default_is_string_type_p): Declare new function. * m2-lang.c (m2_language_defn): Initialise new field. * objc-lang.c (objc_language_defn): Initialise new field. * opencl-lang.c (opencl_language_defn): Initialise new field. * p-lang.c (pascal_is_string_type_p): New function. (pascal_language_defn): Initialise new field. * rust-lang.c (rust_is_string_type_p): New function. (rust_language_defn): Initialise new field.
2019-04-10 00:06:41 +02:00
}
Handle dereferencing Rust trait objects In Rust, virtual tables work a bit differently than they do in C++. In C++, as you know, they are connected to a particular class hierarchy. Rust, instead, can generate a virtual table for potentially any type -- in fact, one such virtual table for each trait (a trait is similar to an abstract class or to a Java interface) that a type implements. Objects that are referenced via a trait can't currently be inspected by gdb. This patch implements the Rust equivalent of "set print object". gdb relies heavily on the C++ ABI to decode virtual tables; primarily to make "set print object" work; but also "info vtbl". However, Rust does not currently have a specified ABI, so this approach seems unwise to emulate. Instead, I've changed the Rust compiler to emit some DWARF that describes trait objects (previously their internal structure was opaque), vtables (currently just a size -- but I hope to expand this in the future), and the concrete type for which a vtable was emitted. The concrete type is expressed as a DW_AT_containing_type on the vtable's type. This is a small extension to DWARF. This patch adds a new entry to quick_symbol_functions to return the symtab that holds a data address. Previously there was no way in gdb to look up a full (only minimal) non-text symbol by address. The psymbol implementation of this method works by lazily filling in a map that is added to the objfile. This avoids slowing down psymbol reading for a feature that is likely to not be used too frequently. I did not update .gdb_index. My thinking here is that the DWARF 5 indices will obsolete .gdb_index soon-ish, meaning that adding a new feature to them is probably wasted work. If necessary I can update the DWARF 5 index code when it lands in gdb. Regression tested on x86-64 Fedora 25. 2017-11-17 Tom Tromey <tom@tromey.com> * symtab.h (struct symbol) <is_rust_vtable>: New member. (struct rust_vtable_symbol): New. (find_symbol_at_address): Declare. * symtab.c (find_symbol_at_address): New function. * symfile.h (struct quick_symbol_functions) <find_compunit_symtab_by_address>: New member. * symfile-debug.c (debug_qf_find_compunit_symtab_by_address): New function. (debug_sym_quick_functions): Link to debug_qf_find_compunit_symtab_by_address. * rust-lang.c (rust_get_trait_object_pointer): New function. (rust_evaluate_subexp) <case UNOP_IND>: New case. Call rust_get_trait_object_pointer. * psymtab.c (psym_relocate): Clear psymbol_map. (psym_fill_psymbol_map, psym_find_compunit_symtab_by_address): New functions. (psym_functions): Link to psym_find_compunit_symtab_by_address. * objfiles.h (struct objfile) <psymbol_map>: New member. * dwarf2read.c (dwarf2_gdb_index_functions): Update. (process_die) <DW_TAG_variable>: New case. Call read_variable. (rust_containing_type, read_variable): New functions. 2017-11-17 Tom Tromey <tom@tromey.com> * gdb.rust/traits.rs: New file. * gdb.rust/traits.exp: New file.
2017-07-06 14:44:38 +02:00
/* If VALUE represents a trait object pointer, return the underlying
pointer with the correct (i.e., runtime) type. Otherwise, return
NULL. */
static struct value *
rust_get_trait_object_pointer (struct value *value)
{
struct type *type = check_typedef (value_type (value));
if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
Handle dereferencing Rust trait objects In Rust, virtual tables work a bit differently than they do in C++. In C++, as you know, they are connected to a particular class hierarchy. Rust, instead, can generate a virtual table for potentially any type -- in fact, one such virtual table for each trait (a trait is similar to an abstract class or to a Java interface) that a type implements. Objects that are referenced via a trait can't currently be inspected by gdb. This patch implements the Rust equivalent of "set print object". gdb relies heavily on the C++ ABI to decode virtual tables; primarily to make "set print object" work; but also "info vtbl". However, Rust does not currently have a specified ABI, so this approach seems unwise to emulate. Instead, I've changed the Rust compiler to emit some DWARF that describes trait objects (previously their internal structure was opaque), vtables (currently just a size -- but I hope to expand this in the future), and the concrete type for which a vtable was emitted. The concrete type is expressed as a DW_AT_containing_type on the vtable's type. This is a small extension to DWARF. This patch adds a new entry to quick_symbol_functions to return the symtab that holds a data address. Previously there was no way in gdb to look up a full (only minimal) non-text symbol by address. The psymbol implementation of this method works by lazily filling in a map that is added to the objfile. This avoids slowing down psymbol reading for a feature that is likely to not be used too frequently. I did not update .gdb_index. My thinking here is that the DWARF 5 indices will obsolete .gdb_index soon-ish, meaning that adding a new feature to them is probably wasted work. If necessary I can update the DWARF 5 index code when it lands in gdb. Regression tested on x86-64 Fedora 25. 2017-11-17 Tom Tromey <tom@tromey.com> * symtab.h (struct symbol) <is_rust_vtable>: New member. (struct rust_vtable_symbol): New. (find_symbol_at_address): Declare. * symtab.c (find_symbol_at_address): New function. * symfile.h (struct quick_symbol_functions) <find_compunit_symtab_by_address>: New member. * symfile-debug.c (debug_qf_find_compunit_symtab_by_address): New function. (debug_sym_quick_functions): Link to debug_qf_find_compunit_symtab_by_address. * rust-lang.c (rust_get_trait_object_pointer): New function. (rust_evaluate_subexp) <case UNOP_IND>: New case. Call rust_get_trait_object_pointer. * psymtab.c (psym_relocate): Clear psymbol_map. (psym_fill_psymbol_map, psym_find_compunit_symtab_by_address): New functions. (psym_functions): Link to psym_find_compunit_symtab_by_address. * objfiles.h (struct objfile) <psymbol_map>: New member. * dwarf2read.c (dwarf2_gdb_index_functions): Update. (process_die) <DW_TAG_variable>: New case. Call read_variable. (rust_containing_type, read_variable): New functions. 2017-11-17 Tom Tromey <tom@tromey.com> * gdb.rust/traits.rs: New file. * gdb.rust/traits.exp: New file.
2017-07-06 14:44:38 +02:00
return NULL;
/* Try to be a bit resilient if the ABI changes. */
int vtable_field = 0;
for (int i = 0; i < 2; ++i)
{
if (strcmp (TYPE_FIELD_NAME (type, i), "vtable") == 0)
vtable_field = i;
else if (strcmp (TYPE_FIELD_NAME (type, i), "pointer") != 0)
return NULL;
}
CORE_ADDR vtable = value_as_address (value_field (value, vtable_field));
struct symbol *symbol = find_symbol_at_address (vtable);
if (symbol == NULL || symbol->subclass != SYMBOL_RUST_VTABLE)
Handle dereferencing Rust trait objects In Rust, virtual tables work a bit differently than they do in C++. In C++, as you know, they are connected to a particular class hierarchy. Rust, instead, can generate a virtual table for potentially any type -- in fact, one such virtual table for each trait (a trait is similar to an abstract class or to a Java interface) that a type implements. Objects that are referenced via a trait can't currently be inspected by gdb. This patch implements the Rust equivalent of "set print object". gdb relies heavily on the C++ ABI to decode virtual tables; primarily to make "set print object" work; but also "info vtbl". However, Rust does not currently have a specified ABI, so this approach seems unwise to emulate. Instead, I've changed the Rust compiler to emit some DWARF that describes trait objects (previously their internal structure was opaque), vtables (currently just a size -- but I hope to expand this in the future), and the concrete type for which a vtable was emitted. The concrete type is expressed as a DW_AT_containing_type on the vtable's type. This is a small extension to DWARF. This patch adds a new entry to quick_symbol_functions to return the symtab that holds a data address. Previously there was no way in gdb to look up a full (only minimal) non-text symbol by address. The psymbol implementation of this method works by lazily filling in a map that is added to the objfile. This avoids slowing down psymbol reading for a feature that is likely to not be used too frequently. I did not update .gdb_index. My thinking here is that the DWARF 5 indices will obsolete .gdb_index soon-ish, meaning that adding a new feature to them is probably wasted work. If necessary I can update the DWARF 5 index code when it lands in gdb. Regression tested on x86-64 Fedora 25. 2017-11-17 Tom Tromey <tom@tromey.com> * symtab.h (struct symbol) <is_rust_vtable>: New member. (struct rust_vtable_symbol): New. (find_symbol_at_address): Declare. * symtab.c (find_symbol_at_address): New function. * symfile.h (struct quick_symbol_functions) <find_compunit_symtab_by_address>: New member. * symfile-debug.c (debug_qf_find_compunit_symtab_by_address): New function. (debug_sym_quick_functions): Link to debug_qf_find_compunit_symtab_by_address. * rust-lang.c (rust_get_trait_object_pointer): New function. (rust_evaluate_subexp) <case UNOP_IND>: New case. Call rust_get_trait_object_pointer. * psymtab.c (psym_relocate): Clear psymbol_map. (psym_fill_psymbol_map, psym_find_compunit_symtab_by_address): New functions. (psym_functions): Link to psym_find_compunit_symtab_by_address. * objfiles.h (struct objfile) <psymbol_map>: New member. * dwarf2read.c (dwarf2_gdb_index_functions): Update. (process_die) <DW_TAG_variable>: New case. Call read_variable. (rust_containing_type, read_variable): New functions. 2017-11-17 Tom Tromey <tom@tromey.com> * gdb.rust/traits.rs: New file. * gdb.rust/traits.exp: New file.
2017-07-06 14:44:38 +02:00
return NULL;
struct rust_vtable_symbol *vtable_sym
= static_cast<struct rust_vtable_symbol *> (symbol);
struct type *pointer_type = lookup_pointer_type (vtable_sym->concrete_type);
return value_cast (pointer_type, value_field (value, 1 - vtable_field));
}
/* la_emitchar implementation for Rust. */
static void
rust_emitchar (int c, struct type *type, struct ui_file *stream, int quoter)
{
if (!rust_chartype_p (type))
generic_emit_char (c, type, stream, quoter,
target_charset (get_type_arch (type)));
else if (c == '\\' || c == quoter)
fprintf_filtered (stream, "\\%c", c);
else if (c == '\n')
fputs_filtered ("\\n", stream);
else if (c == '\r')
fputs_filtered ("\\r", stream);
else if (c == '\t')
fputs_filtered ("\\t", stream);
else if (c == '\0')
fputs_filtered ("\\0", stream);
else if (c >= 32 && c <= 127 && isprint (c))
fputc_filtered (c, stream);
else if (c <= 255)
fprintf_filtered (stream, "\\x%02x", c);
else
fprintf_filtered (stream, "\\u{%06x}", c);
}
/* la_printchar implementation for Rust. */
static void
rust_printchar (int c, struct type *type, struct ui_file *stream)
{
fputs_filtered ("'", stream);
LA_EMIT_CHAR (c, type, stream, '\'');
fputs_filtered ("'", stream);
}
/* la_printstr implementation for Rust. */
static void
rust_printstr (struct ui_file *stream, struct type *type,
const gdb_byte *string, unsigned int length,
const char *user_encoding, int force_ellipses,
const struct value_print_options *options)
{
/* Rust always uses UTF-8, but let the caller override this if need
be. */
const char *encoding = user_encoding;
if (user_encoding == NULL || !*user_encoding)
{
/* In Rust strings, characters are "u8". */
if (rust_u8_type_p (type))
encoding = "UTF-8";
else
{
/* This is probably some C string, so let's let C deal with
it. */
c_printstr (stream, type, string, length, user_encoding,
force_ellipses, options);
return;
}
}
/* This is not ideal as it doesn't use our character printer. */
generic_printstr (stream, type, string, length, encoding, force_ellipses,
'"', 0, options);
}
static void rust_value_print_inner (struct value *val, struct ui_file *stream,
int recurse,
const struct value_print_options *options);
/* Helper function to print a string slice. */
static void
rust_val_print_str (struct ui_file *stream, struct value *val,
const struct value_print_options *options)
{
struct value *base = value_struct_elt (&val, NULL, "data_ptr", NULL,
"slice");
struct value *len = value_struct_elt (&val, NULL, "length", NULL, "slice");
val_print_string (TYPE_TARGET_TYPE (value_type (base)), "UTF-8",
value_as_address (base), value_as_long (len), stream,
options);
}
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
/* rust_val_print helper for structs and untagged unions. */
static void
val_print_struct (struct value *val, struct ui_file *stream, int recurse,
const struct value_print_options *options)
{
int i;
int first_field;
struct type *type = check_typedef (value_type (val));
if (rust_slice_type_p (type) && strcmp (type->name (), "&str") == 0)
{
/* If what we are printing here is actually a string within a
structure then VAL will be the original parent value, while TYPE
will be the type of the structure representing the string we want
to print.
However, RUST_VAL_PRINT_STR looks up the fields of the string
inside VAL, assuming that VAL is the string.
So, recreate VAL as a value representing just the string. */
val = value_at_lazy (type, value_address (val));
rust_val_print_str (stream, val, options);
return;
}
bool is_tuple = rust_tuple_type_p (type);
bool is_tuple_struct = !is_tuple && rust_tuple_struct_type_p (type);
struct value_print_options opts;
if (!is_tuple)
{
if (type->name () != NULL)
fprintf_filtered (stream, "%s", type->name ());
if (type->num_fields () == 0)
return;
if (type->name () != NULL)
fputs_filtered (" ", stream);
}
if (is_tuple || is_tuple_struct)
fputs_filtered ("(", stream);
else
fputs_filtered ("{", stream);
opts = *options;
opts.deref_ref = 0;
first_field = 1;
for (i = 0; i < type->num_fields (); ++i)
{
if (field_is_static (&type->field (i)))
continue;
if (!first_field)
fputs_filtered (",", stream);
if (options->prettyformat)
{
fputs_filtered ("\n", stream);
print_spaces_filtered (2 + 2 * recurse, stream);
}
else if (!first_field)
fputs_filtered (" ", stream);
first_field = 0;
if (!is_tuple && !is_tuple_struct)
{
Style field names in "print" This changes gdb to use the "variable" style when printing field names. I've added new tests for C and Rust, but not other languages. I chose "variable" because that seemed most straightforward. However, another option would be to introduce a new "field" style. Similarly, this patch uses the variable style for enumerator constants -- but again, a new style could be used if that's preferred. gdb/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * valprint.c (generic_val_print_enum_1) (val_print_type_code_flags): Style member names. * rust-lang.c (val_print_struct, rust_print_enum) (rust_print_struct_def, rust_internal_print_type): Style member names. * p-valprint.c (pascal_object_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. * m2-typeprint.c (m2_record_fields, m2_enum): Style member names. * f-valprint.c (f_val_print): Style member names. * f-typeprint.c (f_type_print_base): Style member names. * cp-valprint.c (cp_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. (cp_print_class_member): Style member names. * c-typeprint.c (c_print_type_1, c_type_print_base_1): Style member names. * ada-valprint.c (ada_print_scalar): Style enum names. (ada_val_print_enum): Likewise. * ada-typeprint.c (print_enum_type): Style enum names. gdb/testsuite/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * gdb.rust/rust-style.rs: New file. * gdb.rust/rust-style.exp: New file. * gdb.base/style.exp: Test structure printing. * gdb.base/style.c (struct some_struct): New type. (enum etype): New type. (struct_value): New global. Change-Id: I070e1293c6cc830c9ea916af8243410aa384e944
2020-02-22 18:02:42 +01:00
fputs_styled (TYPE_FIELD_NAME (type, i),
variable_name_style.style (), stream);
fputs_filtered (": ", stream);
}
rust_value_print_inner (value_field (val, i), stream, recurse + 1,
&opts);
}
if (options->prettyformat)
{
fputs_filtered ("\n", stream);
print_spaces_filtered (2 * recurse, stream);
}
if (is_tuple || is_tuple_struct)
fputs_filtered (")", stream);
else
fputs_filtered ("}", stream);
}
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
/* rust_val_print helper for discriminated unions (Rust enums). */
static void
rust_print_enum (struct value *val, struct ui_file *stream, int recurse,
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
const struct value_print_options *options)
{
struct value_print_options opts = *options;
struct type *type = check_typedef (value_type (val));
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
opts.deref_ref = 0;
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
gdb_assert (rust_enum_p (type));
gdb::array_view<const gdb_byte> view (value_contents_for_printing (val),
TYPE_LENGTH (value_type (val)));
type = resolve_dynamic_type (type, view, value_address (val));
if (rust_empty_enum_p (type))
{
/* Print the enum type name here to be more clear. */
Introduce metadata style This introduces a new "metadata" style and changes many places in gdb to use it. The idea here is to let the user distinguish gdb output from output that (conceptually at least) comes directly from the inferior. The newly-styled category includes text that gdb traditionally surrounds in "<...>", like "<unavailable>". I only added a single test for this. In many cases this output is difficult to test. Also, while developing this errors in the implementation of the new printf formats showed up as regressions. gdb/ChangeLog 2019-10-01 Tom Tromey <tom@tromey.com> * p-lang.c (pascal_printstr): Use metadata style. * value.c (show_convenience): Use metadata style. * valprint.c (valprint_check_validity, val_print_optimized_out) (val_print_not_saved, val_print_unavailable) (val_print_invalid_address, generic_val_print, val_print) (value_check_printable, val_print_array_elements): Use metadata style. * ui-out.h (class ui_out) <field_fmt>: New overload. <do_field_fmt>: Add style parameter. * ui-out.c (ui_out::field_fmt): New overload. * typeprint.c (type_print_unknown_return_type) (val_print_not_allocated, val_print_not_associated): Use metadata style. * tui/tui-out.h (class tui_ui_out) <do_field_fmt>: Add style parameter. * tui/tui-out.c (tui_ui_out::do_field_fmt): Update. * tracepoint.c (tvariables_info_1): Use metadata style. * stack.c (print_frame_arg, print_frame_info, print_frame) (info_frame_command_core): Use metadata style. * skip.c (info_skip_command): Use metadata style. * rust-lang.c (rust_print_enum): Use metadata style. * python/py-prettyprint.c (print_stack_unless_memory_error): Use metadata style. * python/py-framefilter.c (py_print_single_arg): Use metadata style. * printcmd.c (do_one_display, print_variable_and_value): Use metadata style. * p-valprint.c (pascal_val_print) (pascal_object_print_value_fields): Use metadata style. * p-typeprint.c (pascal_type_print_base): Use metadata style. * mi/mi-out.h (class mi_ui_out) <do_field_fmt>: Add style parameter. * mi/mi-out.c (mi_ui_out::do_field_fmt): Update. * m2-valprint.c (m2_print_long_set): Use metadata style. * m2-typeprint.c (m2_print_type): Use metadata style. * infcmd.c (print_return_value_1): Use metadata style. * gnu-v3-abi.c (print_one_vtable): Use metadata style. * f-valprint.c (info_common_command_for_block): Use metadata style. * f-typeprint.c (f_type_print_base): Use metadata style. * expprint.c (print_subexp_standard): Use metadata style. * cp-valprint.c (cp_print_value_fields): Use metadata style. * cli/cli-style.h (class cli_style_option): Add constructor. (metadata_style): Declare. * cli/cli-style.c (metadata_style): New global. (_initialize_cli_style): Register metadata style. * cli-out.h (class cli_ui_out) <do_field_fmt>: Add style parameter. * cli-out.c (cli_ui_out::do_field_fmt): Update. * c-typeprint.c (c_type_print_base_struct_union) (c_type_print_base_1): Use metadata style. * breakpoint.c (watchpoint_value_print) (print_one_breakpoint_location): Use metadata style. * break-catch-syscall.c (print_one_catch_syscall): Use metadata style. * break-catch-sig.c (signal_catchpoint_print_one): Use metadata style. * ada-valprint.c (val_print_packed_array_elements, printstr) (print_field_values, ada_val_print_ref, ada_val_print): Use metadata style. * ada-typeprint.c (print_array_type, ada_print_type): Use metadata style. * ada-tasks.c (print_ada_task_info, info_task): Use metadata style. * ada-lang.c (user_select_syms): Use metadata style. gdb/testsuite/ChangeLog 2019-10-01 Tom Tromey <tom@tromey.com> * lib/gdb-utils.exp (style): Handle "metadata" argument. * gdb.base/style.exp: Add metadata style test.
2019-04-03 04:00:18 +02:00
fprintf_filtered (stream, _("%s {%p[<No data fields>%p]}"),
type->name (),
Introduce metadata style This introduces a new "metadata" style and changes many places in gdb to use it. The idea here is to let the user distinguish gdb output from output that (conceptually at least) comes directly from the inferior. The newly-styled category includes text that gdb traditionally surrounds in "<...>", like "<unavailable>". I only added a single test for this. In many cases this output is difficult to test. Also, while developing this errors in the implementation of the new printf formats showed up as regressions. gdb/ChangeLog 2019-10-01 Tom Tromey <tom@tromey.com> * p-lang.c (pascal_printstr): Use metadata style. * value.c (show_convenience): Use metadata style. * valprint.c (valprint_check_validity, val_print_optimized_out) (val_print_not_saved, val_print_unavailable) (val_print_invalid_address, generic_val_print, val_print) (value_check_printable, val_print_array_elements): Use metadata style. * ui-out.h (class ui_out) <field_fmt>: New overload. <do_field_fmt>: Add style parameter. * ui-out.c (ui_out::field_fmt): New overload. * typeprint.c (type_print_unknown_return_type) (val_print_not_allocated, val_print_not_associated): Use metadata style. * tui/tui-out.h (class tui_ui_out) <do_field_fmt>: Add style parameter. * tui/tui-out.c (tui_ui_out::do_field_fmt): Update. * tracepoint.c (tvariables_info_1): Use metadata style. * stack.c (print_frame_arg, print_frame_info, print_frame) (info_frame_command_core): Use metadata style. * skip.c (info_skip_command): Use metadata style. * rust-lang.c (rust_print_enum): Use metadata style. * python/py-prettyprint.c (print_stack_unless_memory_error): Use metadata style. * python/py-framefilter.c (py_print_single_arg): Use metadata style. * printcmd.c (do_one_display, print_variable_and_value): Use metadata style. * p-valprint.c (pascal_val_print) (pascal_object_print_value_fields): Use metadata style. * p-typeprint.c (pascal_type_print_base): Use metadata style. * mi/mi-out.h (class mi_ui_out) <do_field_fmt>: Add style parameter. * mi/mi-out.c (mi_ui_out::do_field_fmt): Update. * m2-valprint.c (m2_print_long_set): Use metadata style. * m2-typeprint.c (m2_print_type): Use metadata style. * infcmd.c (print_return_value_1): Use metadata style. * gnu-v3-abi.c (print_one_vtable): Use metadata style. * f-valprint.c (info_common_command_for_block): Use metadata style. * f-typeprint.c (f_type_print_base): Use metadata style. * expprint.c (print_subexp_standard): Use metadata style. * cp-valprint.c (cp_print_value_fields): Use metadata style. * cli/cli-style.h (class cli_style_option): Add constructor. (metadata_style): Declare. * cli/cli-style.c (metadata_style): New global. (_initialize_cli_style): Register metadata style. * cli-out.h (class cli_ui_out) <do_field_fmt>: Add style parameter. * cli-out.c (cli_ui_out::do_field_fmt): Update. * c-typeprint.c (c_type_print_base_struct_union) (c_type_print_base_1): Use metadata style. * breakpoint.c (watchpoint_value_print) (print_one_breakpoint_location): Use metadata style. * break-catch-syscall.c (print_one_catch_syscall): Use metadata style. * break-catch-sig.c (signal_catchpoint_print_one): Use metadata style. * ada-valprint.c (val_print_packed_array_elements, printstr) (print_field_values, ada_val_print_ref, ada_val_print): Use metadata style. * ada-typeprint.c (print_array_type, ada_print_type): Use metadata style. * ada-tasks.c (print_ada_task_info, info_task): Use metadata style. * ada-lang.c (user_select_syms): Use metadata style. gdb/testsuite/ChangeLog 2019-10-01 Tom Tromey <tom@tromey.com> * lib/gdb-utils.exp (style): Handle "metadata" argument. * gdb.base/style.exp: Add metadata style test.
2019-04-03 04:00:18 +02:00
metadata_style.style ().ptr (), nullptr);
return;
}
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
int variant_fieldno = rust_enum_variant (type);
val = value_field (val, variant_fieldno);
struct type *variant_type = type->field (variant_fieldno).type ();
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
int nfields = variant_type->num_fields ();
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
bool is_tuple = rust_tuple_struct_type_p (variant_type);
fprintf_filtered (stream, "%s", variant_type->name ());
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
if (nfields == 0)
{
/* In case of a nullary variant like 'None', just output
the name. */
return;
}
/* In case of a non-nullary variant, we output 'Foo(x,y,z)'. */
if (is_tuple)
fprintf_filtered (stream, "(");
else
{
/* struct variant. */
fprintf_filtered (stream, "{");
}
bool first_field = true;
for (int j = 0; j < variant_type->num_fields (); j++)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
{
if (!first_field)
fputs_filtered (", ", stream);
first_field = false;
if (!is_tuple)
Style field names in "print" This changes gdb to use the "variable" style when printing field names. I've added new tests for C and Rust, but not other languages. I chose "variable" because that seemed most straightforward. However, another option would be to introduce a new "field" style. Similarly, this patch uses the variable style for enumerator constants -- but again, a new style could be used if that's preferred. gdb/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * valprint.c (generic_val_print_enum_1) (val_print_type_code_flags): Style member names. * rust-lang.c (val_print_struct, rust_print_enum) (rust_print_struct_def, rust_internal_print_type): Style member names. * p-valprint.c (pascal_object_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. * m2-typeprint.c (m2_record_fields, m2_enum): Style member names. * f-valprint.c (f_val_print): Style member names. * f-typeprint.c (f_type_print_base): Style member names. * cp-valprint.c (cp_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. (cp_print_class_member): Style member names. * c-typeprint.c (c_print_type_1, c_type_print_base_1): Style member names. * ada-valprint.c (ada_print_scalar): Style enum names. (ada_val_print_enum): Likewise. * ada-typeprint.c (print_enum_type): Style enum names. gdb/testsuite/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * gdb.rust/rust-style.rs: New file. * gdb.rust/rust-style.exp: New file. * gdb.base/style.exp: Test structure printing. * gdb.base/style.c (struct some_struct): New type. (enum etype): New type. (struct_value): New global. Change-Id: I070e1293c6cc830c9ea916af8243410aa384e944
2020-02-22 18:02:42 +01:00
fprintf_filtered (stream, "%ps: ",
styled_string (variable_name_style.style (),
TYPE_FIELD_NAME (variant_type, j)));
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
rust_value_print_inner (value_field (val, j), stream, recurse + 1,
&opts);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
}
if (is_tuple)
fputs_filtered (")", stream);
else
fputs_filtered ("}", stream);
}
static const struct generic_val_print_decorations rust_decorations =
{
/* Complex isn't used in Rust, but we provide C-ish values just in
case. */
"",
" + ",
" * I",
"true",
"false",
"()",
"[",
"]"
};
/* la_value_print_inner implementation for Rust. */
static void
rust_value_print_inner (struct value *val, struct ui_file *stream,
int recurse,
const struct value_print_options *options)
{
struct value_print_options opts = *options;
opts.deref_ref = 1;
if (opts.prettyformat == Val_prettyformat_default)
opts.prettyformat = (opts.prettyformat_structs
? Val_prettyformat : Val_no_prettyformat);
struct type *type = check_typedef (value_type (val));
switch (type->code ())
{
case TYPE_CODE_PTR:
{
LONGEST low_bound, high_bound;
if (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ARRAY
&& rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)))
&& get_array_bounds (TYPE_TARGET_TYPE (type), &low_bound,
&high_bound))
{
/* We have a pointer to a byte string, so just print
that. */
struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
CORE_ADDR addr = value_as_address (val);
struct gdbarch *arch = get_type_arch (type);
if (opts.addressprint)
{
fputs_filtered (paddress (arch, addr), stream);
fputs_filtered (" ", stream);
}
fputs_filtered ("b", stream);
val_print_string (TYPE_TARGET_TYPE (elttype), "ASCII", addr,
high_bound - low_bound + 1, stream,
&opts);
break;
}
}
goto generic_print;
case TYPE_CODE_METHODPTR:
case TYPE_CODE_MEMBERPTR:
c_value_print_inner (val, stream, recurse, &opts);
break;
case TYPE_CODE_INT:
/* Recognize the unit type. */
if (TYPE_UNSIGNED (type) && TYPE_LENGTH (type) == 0
&& type->name () != NULL && strcmp (type->name (), "()") == 0)
{
fputs_filtered ("()", stream);
break;
}
goto generic_print;
case TYPE_CODE_STRING:
{
LONGEST low_bound, high_bound;
if (!get_array_bounds (type, &low_bound, &high_bound))
error (_("Could not determine the array bounds"));
/* If we see a plain TYPE_CODE_STRING, then we're printing a
byte string, hence the choice of "ASCII" as the
encoding. */
fputs_filtered ("b", stream);
rust_printstr (stream, TYPE_TARGET_TYPE (type),
value_contents_for_printing (val),
high_bound - low_bound + 1, "ASCII", 0, &opts);
}
break;
case TYPE_CODE_ARRAY:
{
LONGEST low_bound, high_bound;
if (get_array_bounds (type, &low_bound, &high_bound)
&& high_bound - low_bound + 1 == 0)
fputs_filtered ("[]", stream);
else
goto generic_print;
}
break;
case TYPE_CODE_UNION:
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
/* Untagged unions are printed as if they are structs. Since
the field bit positions overlap in the debuginfo, the code
for printing a union is same as that for a struct, the only
difference is that the input type will have overlapping
fields. */
val_print_struct (val, stream, recurse, &opts);
break;
case TYPE_CODE_STRUCT:
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
if (rust_enum_p (type))
rust_print_enum (val, stream, recurse, &opts);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
else
val_print_struct (val, stream, recurse, &opts);
break;
default:
generic_print:
/* Nothing special yet. */
generic_value_print (val, stream, recurse, &opts, &rust_decorations);
}
}
static void
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
rust_internal_print_type (struct type *type, const char *varstring,
struct ui_file *stream, int show, int level,
const struct type_print_options *flags,
bool for_rust_enum, print_offset_data *podata);
/* Print a struct or union typedef. */
static void
rust_print_struct_def (struct type *type, const char *varstring,
struct ui_file *stream, int show, int level,
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
const struct type_print_options *flags,
bool for_rust_enum, print_offset_data *podata)
{
/* Print a tuple type simply. */
if (rust_tuple_type_p (type))
{
fputs_filtered (type->name (), stream);
return;
}
/* If we see a base class, delegate to C. */
if (TYPE_N_BASECLASSES (type) > 0)
c_print_type (type, varstring, stream, show, level, flags);
if (flags->print_offsets)
{
/* Temporarily bump the level so that the output lines up
correctly. */
level += 2;
}
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
/* Compute properties of TYPE here because, in the enum case, the
rest of the code ends up looking only at the variant part. */
const char *tagname = type->name ();
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
bool is_tuple_struct = rust_tuple_struct_type_p (type);
bool is_tuple = rust_tuple_type_p (type);
bool is_enum = rust_enum_p (type);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
if (for_rust_enum)
{
/* Already printing an outer enum, so nothing to print here. */
}
else
{
/* This code path is also used by unions and enums. */
if (is_enum)
{
fputs_filtered ("enum ", stream);
dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
if (prop != nullptr && prop->kind == PROP_TYPE)
type = prop->data.original_type;
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
}
else if (type->code () == TYPE_CODE_STRUCT)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
fputs_filtered ("struct ", stream);
else
fputs_filtered ("union ", stream);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
if (tagname != NULL)
fputs_filtered (tagname, stream);
}
if (type->num_fields () == 0 && !is_tuple)
return;
if (for_rust_enum && !flags->print_offsets)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
fputs_filtered (is_tuple_struct ? "(" : "{", stream);
else
fputs_filtered (is_tuple_struct ? " (\n" : " {\n", stream);
/* When printing offsets, we rearrange the fields into storage
order. This lets us show holes more clearly. We work using
field indices here because it simplifies calls to
print_offset_data::update below. */
std::vector<int> fields;
for (int i = 0; i < type->num_fields (); ++i)
{
if (field_is_static (&type->field (i)))
continue;
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
if (is_enum && TYPE_FIELD_ARTIFICIAL (type, i))
continue;
fields.push_back (i);
}
if (flags->print_offsets)
std::sort (fields.begin (), fields.end (),
[&] (int a, int b)
{
return (TYPE_FIELD_BITPOS (type, a)
< TYPE_FIELD_BITPOS (type, b));
});
for (int i : fields)
{
QUIT;
gdb_assert (!field_is_static (&type->field (i)));
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
gdb_assert (! (is_enum && TYPE_FIELD_ARTIFICIAL (type, i)));
if (flags->print_offsets)
podata->update (type, i, stream);
/* We'd like to print "pub" here as needed, but rustc
doesn't emit the debuginfo, and our types don't have
cplus_struct_type attached. */
/* For a tuple struct we print the type but nothing
else. */
if (!for_rust_enum || flags->print_offsets)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
print_spaces_filtered (level + 2, stream);
if (is_enum)
Style field names in "print" This changes gdb to use the "variable" style when printing field names. I've added new tests for C and Rust, but not other languages. I chose "variable" because that seemed most straightforward. However, another option would be to introduce a new "field" style. Similarly, this patch uses the variable style for enumerator constants -- but again, a new style could be used if that's preferred. gdb/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * valprint.c (generic_val_print_enum_1) (val_print_type_code_flags): Style member names. * rust-lang.c (val_print_struct, rust_print_enum) (rust_print_struct_def, rust_internal_print_type): Style member names. * p-valprint.c (pascal_object_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. * m2-typeprint.c (m2_record_fields, m2_enum): Style member names. * f-valprint.c (f_val_print): Style member names. * f-typeprint.c (f_type_print_base): Style member names. * cp-valprint.c (cp_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. (cp_print_class_member): Style member names. * c-typeprint.c (c_print_type_1, c_type_print_base_1): Style member names. * ada-valprint.c (ada_print_scalar): Style enum names. (ada_val_print_enum): Likewise. * ada-typeprint.c (print_enum_type): Style enum names. gdb/testsuite/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * gdb.rust/rust-style.rs: New file. * gdb.rust/rust-style.exp: New file. * gdb.base/style.exp: Test structure printing. * gdb.base/style.c (struct some_struct): New type. (enum etype): New type. (struct_value): New global. Change-Id: I070e1293c6cc830c9ea916af8243410aa384e944
2020-02-22 18:02:42 +01:00
fputs_styled (TYPE_FIELD_NAME (type, i), variable_name_style.style (),
stream);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
else if (!is_tuple_struct)
Style field names in "print" This changes gdb to use the "variable" style when printing field names. I've added new tests for C and Rust, but not other languages. I chose "variable" because that seemed most straightforward. However, another option would be to introduce a new "field" style. Similarly, this patch uses the variable style for enumerator constants -- but again, a new style could be used if that's preferred. gdb/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * valprint.c (generic_val_print_enum_1) (val_print_type_code_flags): Style member names. * rust-lang.c (val_print_struct, rust_print_enum) (rust_print_struct_def, rust_internal_print_type): Style member names. * p-valprint.c (pascal_object_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. * m2-typeprint.c (m2_record_fields, m2_enum): Style member names. * f-valprint.c (f_val_print): Style member names. * f-typeprint.c (f_type_print_base): Style member names. * cp-valprint.c (cp_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. (cp_print_class_member): Style member names. * c-typeprint.c (c_print_type_1, c_type_print_base_1): Style member names. * ada-valprint.c (ada_print_scalar): Style enum names. (ada_val_print_enum): Likewise. * ada-typeprint.c (print_enum_type): Style enum names. gdb/testsuite/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * gdb.rust/rust-style.rs: New file. * gdb.rust/rust-style.exp: New file. * gdb.base/style.exp: Test structure printing. * gdb.base/style.c (struct some_struct): New type. (enum etype): New type. (struct_value): New global. Change-Id: I070e1293c6cc830c9ea916af8243410aa384e944
2020-02-22 18:02:42 +01:00
fprintf_filtered (stream, "%ps: ",
styled_string (variable_name_style.style (),
TYPE_FIELD_NAME (type, i)));
rust_internal_print_type (type->field (i).type (), NULL,
stream, (is_enum ? show : show - 1),
level + 2, flags, is_enum, podata);
if (!for_rust_enum || flags->print_offsets)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
fputs_filtered (",\n", stream);
/* Note that this check of "I" is ok because we only sorted the
fields by offset when print_offsets was set, so we won't take
this branch in that case. */
else if (i + 1 < type->num_fields ())
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
fputs_filtered (", ", stream);
}
if (flags->print_offsets)
{
/* Undo the temporary level increase we did above. */
level -= 2;
podata->finish (type, level, stream);
print_spaces_filtered (print_offset_data::indentation, stream);
if (level == 0)
print_spaces_filtered (2, stream);
}
if (!for_rust_enum || flags->print_offsets)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
print_spaces_filtered (level, stream);
fputs_filtered (is_tuple_struct ? ")" : "}", stream);
}
/* la_print_typedef implementation for Rust. */
static void
rust_print_typedef (struct type *type,
struct symbol *new_symbol,
struct ui_file *stream)
{
type = check_typedef (type);
Replace SYMBOL_*_NAME accessors with member functions Similar to the MSYMBOL version of this patch, improves readability and will eventually allow making name private. gdb/ChangeLog: 2019-11-22 Christian Biesinger <cbiesinger@google.com> * ada-exp.y: Update. * ada-lang.c (sort_choices): Update. (ada_print_symbol_signature): Update. (resolve_subexp): Update. (ada_parse_renaming): Update. (ada_read_renaming_var_value): Update. (lesseq_defined_than): Update. (remove_extra_symbols): Update. (remove_irrelevant_renamings): Update. (ada_add_block_symbols): Update. (ada_collect_symbol_completion_matches): Update. (ada_is_renaming_symbol): Update. (aggregate_assign_from_choices): Update. (ada_evaluate_subexp): Update. (ada_has_this_exception_support): Update. (ada_is_non_standard_exception_sym): Update. (ada_add_exceptions_from_frame): Update. (ada_add_global_exceptions): Update. (ada_print_subexp): Update. * ax-gdb.c (gen_var_ref): Update. (gen_maybe_namespace_elt): Update. (gen_expr_for_cast): Update. (gen_expr): Update. * block.h: Update. * blockframe.c (find_pc_partial_function): Update. * breakpoint.c (print_breakpoint_location): Update. (update_static_tracepoint): Update. * btrace.c (ftrace_print_function_name): Update. (ftrace_function_switched): Update. * buildsym.c (find_symbol_in_list): Update. * c-exp.y: Update. * c-typeprint.c (c_print_typedef): Update. (c_type_print_template_args): Update. * cli/cli-cmds.c (edit_command): Update. (list_command): Update. (print_sal_location): Update. * coffread.c (patch_opaque_types): Update. (process_coff_symbol): Update. (coff_read_enum_type): Update. * compile/compile-c-symbols.c (c_symbol_substitution_name): Update. (convert_one_symbol): Update. (hash_symname): Update. (eq_symname): Update. * compile/compile-cplus-symbols.c (convert_one_symbol): Update. * compile/compile-cplus-types.c (debug_print_scope): Update. * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update. * compile/compile-object-load.c (get_out_value_type): Update. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Update. (search_symbol_list): Update. (cp_lookup_symbol_imports_or_template): Update. * cp-support.c (overload_list_add_symbol): Update. * ctfread.c (psymtab_to_symtab): Update. * dbxread.c (cp_set_block_scope): Update. * dictionary.c (iter_match_first_hashed): Update. (iter_match_next_hashed): Update. (insert_symbol_hashed): Update. (iter_match_next_linear): Update. * dictionary.h: Update. * dwarf2loc.c (func_get_frame_base_dwarf_block): Update. (locexpr_describe_location_piece): Update. (locexpr_describe_location_1): Update. (locexpr_generate_c_location): Update. (loclist_describe_location): Update. (loclist_generate_c_location): Update. * dwarf2read.c (dw2_debug_names_lookup_symbol): Update. (read_func_scope): Update. (process_enumeration_scope): Update. (new_symbol): Update. (dwarf2_const_value): Update. (dwarf2_symbol_mark_computed): Update. * eval.c (evaluate_funcall): Update. (evaluate_subexp_standard): Update. * expprint.c (print_subexp_standard): Update. (dump_subexp_body_standard): Update. * f-valprint.c (info_common_command_for_block): Update. * findvar.c (get_hosting_frame): Update. (default_read_var_value): Update. * go-lang.c (go_symbol_package_name): Update. * guile/scm-block.c (bkscm_print_block_smob): Update. * guile/scm-symbol.c (syscm_print_symbol_smob): Update. (gdbscm_symbol_name): Update. (gdbscm_symbol_linkage_name): Update. (gdbscm_symbol_print_name): Update. * infcall.c (get_function_name): Update. * infcmd.c (jump_command): Update. (finish_command): Update. * infrun.c (insert_exception_resume_breakpoint): Update. * linespec.c (canonicalize_linespec): Update. (create_sals_line_offset): Update. (convert_linespec_to_sals): Update. (complete_label): Update. (find_label_symbols_in_block): Update. * m2-typeprint.c (m2_print_typedef): Update. * mdebugread.c (mdebug_reg_to_regnum): Update. (parse_symbol): Update. (mylookup_symbol): Update. * mi/mi-cmd-stack.c (list_arg_or_local): Update. (list_args_or_locals): Update. * objc-lang.c (compare_selectors): Update. (info_selectors_command): Update. (compare_classes): Update. (info_classes_command): Update. (find_imps): Update. * p-typeprint.c (pascal_print_typedef): Update. * printcmd.c (build_address_symbolic): Update. (info_address_command): Update. (print_variable_and_value): Update. * python/py-framefilter.c (extract_sym): Update. (py_print_single_arg): Update. * python/py-symbol.c (sympy_str): Update. (sympy_get_name): Update. (sympy_get_linkage_name): Update. * python/python.c (gdbpy_rbreak): Update. * record-btrace.c (btrace_get_bfun_name): Update. (btrace_call_history): Update. * rust-lang.c (rust_print_typedef): Update. * solib-frv.c (frv_fdpic_find_canonical_descriptor): Update. * stabsread.c (stab_reg_to_regnum): Update. (define_symbol): Update. (read_enum_type): Update. (common_block_end): Update. (cleanup_undefined_types_1): Update. (scan_file_globals): Update. * stack.c (print_frame_arg): Update. (print_frame_args): Update. (find_frame_funname): Update. (info_frame_command_core): Update. (iterate_over_block_locals): Update. (print_block_frame_labels): Update. (do_print_variable_and_value): Update. (iterate_over_block_arg_vars): Update. (return_command): Update. * symmisc.c (dump_symtab_1): Update. (print_symbol): Update. * symtab.c (eq_symbol_entry): Update. (symbol_cache_dump): Update. (lookup_language_this): Update. (find_pc_sect_line): Update. (skip_prologue_sal): Update. (symbol_search::compare_search_syms): Update. (treg_matches_sym_type_name): Update. (search_symbols): Update. (print_symbol_info): Update. (rbreak_command): Update. (completion_list_add_symbol): Update. (find_gnu_ifunc): Update. (get_symbol_address): Update. (search_module_symbols): Update. (info_module_subcommand): Update. * symtab.h (SYMBOL_NATURAL_NAME): Remove. (SYMBOL_LINKAGE_NAME): Remove. (SYMBOL_DEMANGLED_NAME): Remove. (SYMBOL_PRINT_NAME): Remove. (SYMBOL_SEARCH_NAME): Remove. * tracepoint.c (set_traceframe_context): Update. (validate_actionline): Update. (collection_list::collect_symbol): Update. (encode_actions_1): Update. (info_scope_command): Update. (print_one_static_tracepoint_marker): Update. * typeprint.c (typedef_hash_table::add_template_parameters): Update. * valops.c (address_of_variable): Update. (find_overload_match): Update. (find_oload_champ): Update. Change-Id: I76bdc8b44eea6876bf03af9d351f8e90cc0154b2
2019-11-22 19:05:14 +01:00
fprintf_filtered (stream, "type %s = ", new_symbol->print_name ());
type_print (type, "", stream, 0);
fprintf_filtered (stream, ";");
}
/* la_print_type implementation for Rust. */
static void
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
rust_internal_print_type (struct type *type, const char *varstring,
struct ui_file *stream, int show, int level,
const struct type_print_options *flags,
bool for_rust_enum, print_offset_data *podata)
{
QUIT;
if (show <= 0
&& type->name () != NULL)
{
/* Rust calls the unit type "void" in its debuginfo,
but we don't want to print it as that. */
if (type->code () == TYPE_CODE_VOID)
fputs_filtered ("()", stream);
else
fputs_filtered (type->name (), stream);
return;
}
type = check_typedef (type);
switch (type->code ())
{
case TYPE_CODE_VOID:
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
/* If we have an enum, we've already printed the type's
unqualified name, and there is nothing else to print
here. */
if (!for_rust_enum)
fputs_filtered ("()", stream);
break;
case TYPE_CODE_FUNC:
/* Delegate varargs to the C printer. */
if (TYPE_VARARGS (type))
goto c_printer;
fputs_filtered ("fn ", stream);
if (varstring != NULL)
fputs_filtered (varstring, stream);
fputs_filtered ("(", stream);
for (int i = 0; i < type->num_fields (); ++i)
{
QUIT;
if (i > 0)
fputs_filtered (", ", stream);
rust_internal_print_type (type->field (i).type (), "", stream,
-1, 0, flags, false, podata);
}
fputs_filtered (")", stream);
/* If it returns unit, we can omit the return type. */
if (TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_VOID)
{
fputs_filtered (" -> ", stream);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
rust_internal_print_type (TYPE_TARGET_TYPE (type), "", stream,
-1, 0, flags, false, podata);
}
break;
case TYPE_CODE_ARRAY:
{
LONGEST low_bound, high_bound;
fputs_filtered ("[", stream);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
rust_internal_print_type (TYPE_TARGET_TYPE (type), NULL,
stream, show - 1, level, flags, false,
podata);
if (TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCEXPR
|| TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCLIST)
fprintf_filtered (stream, "; variable length");
else if (get_array_bounds (type, &low_bound, &high_bound))
fprintf_filtered (stream, "; %s",
plongest (high_bound - low_bound + 1));
fputs_filtered ("]", stream);
}
break;
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
case TYPE_CODE_UNION:
case TYPE_CODE_STRUCT:
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
rust_print_struct_def (type, varstring, stream, show, level, flags,
for_rust_enum, podata);
break;
case TYPE_CODE_ENUM:
{
Simple -Wshadow=local fixes This fixes all the straightforward -Wshadow=local warnings in gdb. A few standard approaches are used here: * Renaming an inner (or outer, but more commonly inner) variable; * Lowering a declaration to avoid a clash; * Moving a declaration into a more inner scope to avoid a clash, including the special case of moving a declaration into a loop header. I did not consider any of the changes in this patch to be particularly noteworthy, though of course they should all still be examined. gdb/ChangeLog 2018-10-04 Tom Tromey <tom@tromey.com> * ctf.c (SET_ARRAY_FIELD): Rename "u32". * p-valprint.c (pascal_val_print): Split inner "i" variable. * xtensa-tdep.c (xtensa_push_dummy_call): Declare "i" in loop header. * xstormy16-tdep.c (xstormy16_push_dummy_call): Declare "val" in more inner scope. * xcoffread.c (read_xcoff_symtab): Rename inner "symbol". * varobj.c (varobj_update): Rename inner "newobj", "type_changed". * valprint.c (generic_emit_char): Rename inner "buf". * valops.c (find_overload_match): Rename inner "temp". (value_struct_elt_for_reference): Declare "v" in more inner scope. * v850-tdep.c (v850_push_dummy_call): Rename "len". * unittests/array-view-selftests.c (run_tests): Rename inner "vec". * tui/tui-stack.c (tui_show_frame_info): Declare "i" in loop header. * tracepoint.c (merge_uploaded_trace_state_variables): Declare "tsv" in more inner scope. (print_one_static_tracepoint_marker): Rename inner "tuple_emitter". * tic6x-tdep.c (tic6x_analyze_prologue): Declare "inst" lower. (tic6x_push_dummy_call): Don't redeclare "addr". * target-float.c: Declare "dto" lower. * symtab.c (lookup_local_symbol): Rename inner "sym". (find_pc_sect_line): Rename inner "pc". * stack.c (print_frame): Don't redeclare "gdbarch". (return_command): Rename inner "gdbarch". * s390-tdep.c (s390_prologue_frame_unwind_cache): Renam inner "sp". * rust-lang.c (rust_internal_print_type): Declare "i" in loop header. * rs6000-tdep.c (ppc_process_record): Rename inner "addr". * riscv-tdep.c (riscv_push_dummy_call): Declare "info" in inner scope. * remote.c (remote_target::update_thread_list): Don't redeclare "tp". (remote_target::process_initial_stop_replies): Rename inner "thread". (remote_target::remote_parse_stop_reply): Don't redeclare "p". (remote_target::wait_as): Don't redeclare "stop_reply". (remote_target::get_thread_local_address): Rename inner "result". (remote_target::get_tib_address): Likewise.
2018-04-22 00:16:27 +02:00
int len = 0;
fputs_filtered ("enum ", stream);
if (type->name () != NULL)
{
fputs_filtered (type->name (), stream);
fputs_filtered (" ", stream);
len = strlen (type->name ());
}
fputs_filtered ("{\n", stream);
for (int i = 0; i < type->num_fields (); ++i)
{
const char *name = TYPE_FIELD_NAME (type, i);
QUIT;
if (len > 0
&& strncmp (name, type->name (), len) == 0
&& name[len] == ':'
&& name[len + 1] == ':')
name += len + 2;
Style field names in "print" This changes gdb to use the "variable" style when printing field names. I've added new tests for C and Rust, but not other languages. I chose "variable" because that seemed most straightforward. However, another option would be to introduce a new "field" style. Similarly, this patch uses the variable style for enumerator constants -- but again, a new style could be used if that's preferred. gdb/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * valprint.c (generic_val_print_enum_1) (val_print_type_code_flags): Style member names. * rust-lang.c (val_print_struct, rust_print_enum) (rust_print_struct_def, rust_internal_print_type): Style member names. * p-valprint.c (pascal_object_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. * m2-typeprint.c (m2_record_fields, m2_enum): Style member names. * f-valprint.c (f_val_print): Style member names. * f-typeprint.c (f_type_print_base): Style member names. * cp-valprint.c (cp_print_value_fields): Style member names. Only call fprintf_symbol_filtered for static members. (cp_print_class_member): Style member names. * c-typeprint.c (c_print_type_1, c_type_print_base_1): Style member names. * ada-valprint.c (ada_print_scalar): Style enum names. (ada_val_print_enum): Likewise. * ada-typeprint.c (print_enum_type): Style enum names. gdb/testsuite/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * gdb.rust/rust-style.rs: New file. * gdb.rust/rust-style.exp: New file. * gdb.base/style.exp: Test structure printing. * gdb.base/style.c (struct some_struct): New type. (enum etype): New type. (struct_value): New global. Change-Id: I070e1293c6cc830c9ea916af8243410aa384e944
2020-02-22 18:02:42 +01:00
fprintfi_filtered (level + 2, stream, "%ps,\n",
styled_string (variable_name_style.style (),
name));
}
fputs_filtered ("}", stream);
}
break;
case TYPE_CODE_PTR:
{
if (type->name () != nullptr)
fputs_filtered (type->name (), stream);
else
{
/* We currently can't distinguish between pointers and
references. */
fputs_filtered ("*mut ", stream);
type_print (TYPE_TARGET_TYPE (type), "", stream, 0);
}
}
break;
default:
c_printer:
c_print_type (type, varstring, stream, show, level, flags);
}
}
/* Like arch_composite_type, but uses TYPE to decide how to allocate
-- either on an obstack or on a gdbarch. */
static struct type *
rust_composite_type (struct type *original,
const char *name,
const char *field1, struct type *type1,
const char *field2, struct type *type2)
{
struct type *result = alloc_type_copy (original);
int i, nfields, bitpos;
nfields = 0;
if (field1 != NULL)
++nfields;
if (field2 != NULL)
++nfields;
result->set_code (TYPE_CODE_STRUCT);
result->set_name (name);
result->set_num_fields (nfields);
result->set_fields
((struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field)));
i = 0;
bitpos = 0;
if (field1 != NULL)
{
struct field *field = &result->field (i);
SET_FIELD_BITPOS (*field, bitpos);
bitpos += TYPE_LENGTH (type1) * TARGET_CHAR_BIT;
FIELD_NAME (*field) = field1;
field->set_type (type1);
++i;
}
if (field2 != NULL)
{
struct field *field = &result->field (i);
unsigned align = type_align (type2);
if (align != 0)
{
int delta;
align *= TARGET_CHAR_BIT;
delta = bitpos % align;
if (delta != 0)
bitpos += align - delta;
}
SET_FIELD_BITPOS (*field, bitpos);
FIELD_NAME (*field) = field2;
field->set_type (type2);
++i;
}
if (i > 0)
TYPE_LENGTH (result)
= (TYPE_FIELD_BITPOS (result, i - 1) / TARGET_CHAR_BIT +
TYPE_LENGTH (result->field (i - 1).type ()));
return result;
}
/* See rust-lang.h. */
struct type *
rust_slice_type (const char *name, struct type *elt_type,
struct type *usize_type)
{
struct type *type;
elt_type = lookup_pointer_type (elt_type);
type = rust_composite_type (elt_type, name,
"data_ptr", elt_type,
"length", usize_type);
return type;
}
enum rust_primitive_types
{
rust_primitive_bool,
rust_primitive_char,
rust_primitive_i8,
rust_primitive_u8,
rust_primitive_i16,
rust_primitive_u16,
rust_primitive_i32,
rust_primitive_u32,
rust_primitive_i64,
rust_primitive_u64,
rust_primitive_isize,
rust_primitive_usize,
rust_primitive_f32,
rust_primitive_f64,
rust_primitive_unit,
rust_primitive_str,
nr_rust_primitive_types
};
/* A helper for rust_evaluate_subexp that handles OP_FUNCALL. */
static struct value *
rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
{
int i;
int num_args = exp->elts[*pos + 1].longconst;
const char *method;
struct value *function, *result, *arg0;
struct type *type, *fn_type;
const struct block *block;
struct block_symbol sym;
/* For an ordinary function call we can simply defer to the
generic implementation. */
if (exp->elts[*pos + 3].opcode != STRUCTOP_STRUCT)
return evaluate_subexp_standard (NULL, exp, pos, noside);
/* Skip over the OP_FUNCALL and the STRUCTOP_STRUCT. */
*pos += 4;
method = &exp->elts[*pos + 1].string;
*pos += 3 + BYTES_TO_EXP_ELEM (exp->elts[*pos].longconst + 1);
/* Evaluate the argument to STRUCTOP_STRUCT, then find its
type in order to look up the method. */
arg0 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (noside == EVAL_SKIP)
{
for (i = 0; i < num_args; ++i)
evaluate_subexp (NULL_TYPE, exp, pos, noside);
return arg0;
}
std::vector<struct value *> args (num_args + 1);
args[0] = arg0;
/* We don't yet implement real Deref semantics. */
while (value_type (args[0])->code () == TYPE_CODE_PTR)
args[0] = value_ind (args[0]);
type = value_type (args[0]);
if ((type->code () != TYPE_CODE_STRUCT
&& type->code () != TYPE_CODE_UNION
&& type->code () != TYPE_CODE_ENUM)
|| rust_tuple_type_p (type))
error (_("Method calls only supported on struct or enum types"));
if (type->name () == NULL)
error (_("Method call on nameless type"));
std::string name = std::string (type->name ()) + "::" + method;
block = get_selected_block (0);
sym = lookup_symbol (name.c_str (), block, VAR_DOMAIN, NULL);
if (sym.symbol == NULL)
error (_("Could not find function named '%s'"), name.c_str ());
fn_type = SYMBOL_TYPE (sym.symbol);
if (fn_type->num_fields () == 0)
error (_("Function '%s' takes no arguments"), name.c_str ());
if (fn_type->field (0).type ()->code () == TYPE_CODE_PTR)
args[0] = value_addr (args[0]);
function = address_of_variable (sym.symbol, block);
for (i = 0; i < num_args; ++i)
args[i + 1] = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
result = value_zero (TYPE_TARGET_TYPE (fn_type), not_lval);
else
Use gdb:array_view in call_function_by_hand & friends This replaces a few uses of pointer+length with gdb::array_view, in call_function_by_hand and related code. Unfortunately, due to -Wnarrowing, there are places where we can't brace-initialize an gdb::array_view without an ugly-ish cast. To avoid the cast, this patch introduces a gdb::make_array_view function. Unit tests included. This patch in isolation may not look so interesting, due to gdb::make_array_view uses, but I think it's still worth it. Some of the gdb::make_array_view calls disappear down the series, and others could be eliminated with more (non-trivial) gdb::array_view detangling/conversion (e.g. code around eval_call). See this as a "we have to start somewhere" patch. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_evaluate_subexp): Adjust to pass an array_view. * common/array-view.h (make_array_view): New. * compile/compile-object-run.c (compile_object_run): Adjust to pass an array_view. * elfread.c (elf_gnu_ifunc_resolve_addr): Adjust. * eval.c (eval_call): Adjust to pass an array_view. (evaluate_subexp_standard): Adjust to pass an array_view. * gcore.c (call_target_sbrk): Adjust to pass an array_view. * guile/scm-value.c (gdbscm_value_call): Likewise. * infcall.c (push_dummy_code): Replace pointer + size parameters with an array_view parameter. (call_function_by_hand, call_function_by_hand_dummy): Likewise and adjust. * infcall.h: Include "common/array-view.h". (call_function_by_hand, call_function_by_hand_dummy): Replace pointer + size parameters with an array_view parameter. * linux-fork.c (inferior_call_waitpid): Adjust to use array_view. * linux-tdep.c (linux_infcall_mmap): Likewise. * objc-lang.c (lookup_objc_class, lookup_child_selector) (value_nsstring, print_object_command): Likewise. * python/py-value.c (valpy_call): Likewise. * rust-lang.c (rust_evaluate_funcall): Likewise. * spu-tdep.c (flush_ea_cache): Likewise. * valarith.c (value_x_binop, value_x_unop): Likewise. * valops.c (value_allocate_space_in_inferior): Likewise. * unittests/array-view-selftests.c (run_tests): Add gdb::make_array_view test.
2018-11-21 12:55:11 +01:00
result = call_function_by_hand (function, NULL, args);
return result;
}
/* A helper for rust_evaluate_subexp that handles OP_RANGE. */
static struct value *
rust_range (struct expression *exp, int *pos, enum noside noside)
{
enum range_type kind;
struct value *low = NULL, *high = NULL;
struct value *addrval, *result;
CORE_ADDR addr;
struct type *range_type;
struct type *index_type;
struct type *temp_type;
const char *name;
kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
*pos += 3;
if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT
|| kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (kind == LOW_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT_EXCLUSIVE
|| kind == NONE_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
bool inclusive = (kind == NONE_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT);
if (noside == EVAL_SKIP)
return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
if (low == NULL)
{
if (high == NULL)
{
index_type = NULL;
name = "std::ops::RangeFull";
}
else
{
index_type = value_type (high);
name = (inclusive
? "std::ops::RangeToInclusive" : "std::ops::RangeTo");
}
}
else
{
if (high == NULL)
{
index_type = value_type (low);
name = "std::ops::RangeFrom";
}
else
{
if (!types_equal (value_type (low), value_type (high)))
error (_("Range expression with different types"));
index_type = value_type (low);
name = inclusive ? "std::ops::RangeInclusive" : "std::ops::Range";
}
}
/* If we don't have an index type, just allocate this on the
arch. Here any type will do. */
temp_type = (index_type == NULL
? language_bool_type (exp->language_defn, exp->gdbarch)
: index_type);
/* It would be nicer to cache the range type. */
range_type = rust_composite_type (temp_type, name,
low == NULL ? NULL : "start", index_type,
high == NULL ? NULL : "end", index_type);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return value_zero (range_type, lval_memory);
addrval = value_allocate_space_in_inferior (TYPE_LENGTH (range_type));
addr = value_as_long (addrval);
result = value_at_lazy (range_type, addr);
if (low != NULL)
{
struct value *start = value_struct_elt (&result, NULL, "start", NULL,
"range");
value_assign (start, low);
}
if (high != NULL)
{
struct value *end = value_struct_elt (&result, NULL, "end", NULL,
"range");
value_assign (end, high);
}
result = value_at_lazy (range_type, addr);
return result;
}
/* A helper function to compute the range and kind given a range
value. TYPE is the type of the range value. RANGE is the range
value. LOW, HIGH, and KIND are out parameters. The LOW and HIGH
parameters might be filled in, or might not be, depending on the
kind of range this is. KIND will always be set to the appropriate
value describing the kind of range, and this can be used to
determine whether LOW or HIGH are valid. */
static void
rust_compute_range (struct type *type, struct value *range,
LONGEST *low, LONGEST *high,
enum range_type *kind)
{
int i;
*low = 0;
*high = 0;
*kind = BOTH_BOUND_DEFAULT;
if (type->num_fields () == 0)
return;
i = 0;
if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
{
*kind = HIGH_BOUND_DEFAULT;
*low = value_as_long (value_field (range, 0));
++i;
}
if (type->num_fields () > i
&& strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
{
*kind = (*kind == BOTH_BOUND_DEFAULT
? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
*high = value_as_long (value_field (range, i));
if (rust_inclusive_range_type_p (type))
++*high;
}
}
/* A helper for rust_evaluate_subexp that handles BINOP_SUBSCRIPT. */
static struct value *
rust_subscript (struct expression *exp, int *pos, enum noside noside,
int for_addr)
{
struct value *lhs, *rhs, *result;
struct type *rhstype;
LONGEST low, high_bound;
/* Initialized to appease the compiler. */
enum range_type kind = BOTH_BOUND_DEFAULT;
LONGEST high = 0;
int want_slice = 0;
++*pos;
lhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
rhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (noside == EVAL_SKIP)
return lhs;
rhstype = check_typedef (value_type (rhs));
if (rust_range_type_p (rhstype))
{
if (!for_addr)
error (_("Can't take slice of array without '&'"));
rust_compute_range (rhstype, rhs, &low, &high, &kind);
want_slice = 1;
}
else
low = value_as_long (rhs);
struct type *type = check_typedef (value_type (lhs));
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *base_type = nullptr;
if (type->code () == TYPE_CODE_ARRAY)
base_type = TYPE_TARGET_TYPE (type);
else if (rust_slice_type_p (type))
{
for (int i = 0; i < type->num_fields (); ++i)
{
if (strcmp (TYPE_FIELD_NAME (type, i), "data_ptr") == 0)
{
base_type = TYPE_TARGET_TYPE (type->field (i).type ());
break;
}
}
if (base_type == nullptr)
error (_("Could not find 'data_ptr' in slice type"));
}
else if (type->code () == TYPE_CODE_PTR)
base_type = TYPE_TARGET_TYPE (type);
else
error (_("Cannot subscript non-array type"));
struct type *new_type;
if (want_slice)
{
if (rust_slice_type_p (type))
new_type = type;
else
{
struct type *usize
= language_lookup_primitive_type (exp->language_defn,
exp->gdbarch,
"usize");
new_type = rust_slice_type ("&[*gdb*]", base_type, usize);
}
}
else
new_type = base_type;
return value_zero (new_type, VALUE_LVAL (lhs));
}
else
{
LONGEST low_bound;
struct value *base;
if (type->code () == TYPE_CODE_ARRAY)
{
base = lhs;
if (!get_array_bounds (type, &low_bound, &high_bound))
error (_("Can't compute array bounds"));
if (low_bound != 0)
error (_("Found array with non-zero lower bound"));
++high_bound;
}
else if (rust_slice_type_p (type))
{
struct value *len;
base = value_struct_elt (&lhs, NULL, "data_ptr", NULL, "slice");
len = value_struct_elt (&lhs, NULL, "length", NULL, "slice");
low_bound = 0;
high_bound = value_as_long (len);
}
else if (type->code () == TYPE_CODE_PTR)
{
base = lhs;
low_bound = 0;
high_bound = LONGEST_MAX;
}
else
error (_("Cannot subscript non-array type"));
if (want_slice
&& (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
low = low_bound;
if (low < 0)
error (_("Index less than zero"));
if (low > high_bound)
error (_("Index greater than length"));
result = value_subscript (base, low);
}
if (for_addr)
{
if (want_slice)
{
struct type *usize, *slice;
CORE_ADDR addr;
struct value *addrval, *tem;
if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
high = high_bound;
if (high < 0)
error (_("High index less than zero"));
if (low > high)
error (_("Low index greater than high index"));
if (high > high_bound)
error (_("High index greater than length"));
usize = language_lookup_primitive_type (exp->language_defn,
exp->gdbarch,
"usize");
const char *new_name = ((type != nullptr
&& rust_slice_type_p (type))
? type->name () : "&[*gdb*]");
slice = rust_slice_type (new_name, value_type (result), usize);
addrval = value_allocate_space_in_inferior (TYPE_LENGTH (slice));
addr = value_as_long (addrval);
tem = value_at_lazy (slice, addr);
value_assign (value_field (tem, 0), value_addr (result));
value_assign (value_field (tem, 1),
value_from_longest (usize, high - low));
result = value_at_lazy (slice, addr);
}
else
result = value_addr (result);
}
return result;
}
/* evaluate_exp implementation for Rust. */
static struct value *
rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
int *pos, enum noside noside)
{
struct value *result;
switch (exp->elts[*pos].opcode)
{
Handle dereferencing Rust trait objects In Rust, virtual tables work a bit differently than they do in C++. In C++, as you know, they are connected to a particular class hierarchy. Rust, instead, can generate a virtual table for potentially any type -- in fact, one such virtual table for each trait (a trait is similar to an abstract class or to a Java interface) that a type implements. Objects that are referenced via a trait can't currently be inspected by gdb. This patch implements the Rust equivalent of "set print object". gdb relies heavily on the C++ ABI to decode virtual tables; primarily to make "set print object" work; but also "info vtbl". However, Rust does not currently have a specified ABI, so this approach seems unwise to emulate. Instead, I've changed the Rust compiler to emit some DWARF that describes trait objects (previously their internal structure was opaque), vtables (currently just a size -- but I hope to expand this in the future), and the concrete type for which a vtable was emitted. The concrete type is expressed as a DW_AT_containing_type on the vtable's type. This is a small extension to DWARF. This patch adds a new entry to quick_symbol_functions to return the symtab that holds a data address. Previously there was no way in gdb to look up a full (only minimal) non-text symbol by address. The psymbol implementation of this method works by lazily filling in a map that is added to the objfile. This avoids slowing down psymbol reading for a feature that is likely to not be used too frequently. I did not update .gdb_index. My thinking here is that the DWARF 5 indices will obsolete .gdb_index soon-ish, meaning that adding a new feature to them is probably wasted work. If necessary I can update the DWARF 5 index code when it lands in gdb. Regression tested on x86-64 Fedora 25. 2017-11-17 Tom Tromey <tom@tromey.com> * symtab.h (struct symbol) <is_rust_vtable>: New member. (struct rust_vtable_symbol): New. (find_symbol_at_address): Declare. * symtab.c (find_symbol_at_address): New function. * symfile.h (struct quick_symbol_functions) <find_compunit_symtab_by_address>: New member. * symfile-debug.c (debug_qf_find_compunit_symtab_by_address): New function. (debug_sym_quick_functions): Link to debug_qf_find_compunit_symtab_by_address. * rust-lang.c (rust_get_trait_object_pointer): New function. (rust_evaluate_subexp) <case UNOP_IND>: New case. Call rust_get_trait_object_pointer. * psymtab.c (psym_relocate): Clear psymbol_map. (psym_fill_psymbol_map, psym_find_compunit_symtab_by_address): New functions. (psym_functions): Link to psym_find_compunit_symtab_by_address. * objfiles.h (struct objfile) <psymbol_map>: New member. * dwarf2read.c (dwarf2_gdb_index_functions): Update. (process_die) <DW_TAG_variable>: New case. Call read_variable. (rust_containing_type, read_variable): New functions. 2017-11-17 Tom Tromey <tom@tromey.com> * gdb.rust/traits.rs: New file. * gdb.rust/traits.exp: New file.
2017-07-06 14:44:38 +02:00
case UNOP_IND:
{
if (noside != EVAL_NORMAL)
result = evaluate_subexp_standard (expect_type, exp, pos, noside);
else
{
++*pos;
struct value *value = evaluate_subexp (expect_type, exp, pos,
noside);
struct value *trait_ptr = rust_get_trait_object_pointer (value);
if (trait_ptr != NULL)
value = trait_ptr;
result = value_ind (value);
}
}
break;
case UNOP_COMPLEMENT:
{
struct value *value;
++*pos;
value = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (noside == EVAL_SKIP)
{
/* Preserving the type is enough. */
return value;
}
if (value_type (value)->code () == TYPE_CODE_BOOL)
result = value_from_longest (value_type (value),
value_logical_not (value));
else
result = value_complement (value);
}
break;
case BINOP_SUBSCRIPT:
result = rust_subscript (exp, pos, noside, 0);
break;
case OP_FUNCALL:
result = rust_evaluate_funcall (exp, pos, noside);
break;
case OP_AGGREGATE:
{
int pc = (*pos)++;
struct type *type = exp->elts[pc + 1].type;
int arglen = longest_to_int (exp->elts[pc + 2].longconst);
int i;
CORE_ADDR addr = 0;
struct value *addrval = NULL;
*pos += 3;
if (noside == EVAL_NORMAL)
{
addrval = value_allocate_space_in_inferior (TYPE_LENGTH (type));
addr = value_as_long (addrval);
result = value_at_lazy (type, addr);
}
if (arglen > 0 && exp->elts[*pos].opcode == OP_OTHERS)
{
struct value *init;
++*pos;
init = rust_evaluate_subexp (NULL, exp, pos, noside);
if (noside == EVAL_NORMAL)
{
/* This isn't quite right but will do for the time
being, seeing that we can't implement the Copy
trait anyway. */
value_assign (result, init);
}
--arglen;
}
gdb_assert (arglen % 2 == 0);
for (i = 0; i < arglen; i += 2)
{
int len;
const char *fieldname;
struct value *value, *field;
gdb_assert (exp->elts[*pos].opcode == OP_NAME);
++*pos;
len = longest_to_int (exp->elts[*pos].longconst);
++*pos;
fieldname = &exp->elts[*pos].string;
*pos += 2 + BYTES_TO_EXP_ELEM (len + 1);
value = rust_evaluate_subexp (NULL, exp, pos, noside);
if (noside == EVAL_NORMAL)
{
field = value_struct_elt (&result, NULL, fieldname, NULL,
"structure");
value_assign (field, value);
}
}
if (noside == EVAL_SKIP)
return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
1);
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
result = allocate_value (type);
else
result = value_at_lazy (type, addr);
}
break;
case OP_RUST_ARRAY:
{
Simple unused variable removals This patch holds all the straightforward unused variable deletions. gdb/ChangeLog 2018-07-22 Tom Tromey <tom@tromey.com> * guile/scm-value.c (gdbscm_value_call): Remove unused variables. * guile/scm-math.c (vlscm_unop_gdbthrow, vlscm_binop_gdbthrow) (vlscm_convert_typed_value_from_scheme): Remove unused variable. * buildsym-legacy.c (get_macro_table): Remove unused variable. * stack.c (frame_apply_level_command): Remove unused variable. * tic6x-tdep.c (tic6x_push_dummy_call): Remove unused variable. * sparc64-tdep.c (adi_examine_command): Remove unused variable. * rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Remove unused variable. * nios2-tdep.c (nios2_push_dummy_call): Remove unused variable. * mep-tdep.c (mep_push_dummy_call): Remove unused variable. * ada-lang.c (ada_lookup_symbol_list_worker): Remove unused variable. * amd64-tdep.c (amd64_supply_xsave): Remove unused variable. * arm-tdep.c (arm_record_data_proc_misc_ld_str): Remove unused variable. * breakpoint.c (check_no_tracepoint_commands, update_watchpoint): Remove unused variable. * cli/cli-script.c (recurse_read_control_structure): Remove unused variable. * common/tdesc.c (print_xml_feature::visit): Remove unused variable. * compile/compile-object-load.c (store_regs): Remove unused variables. * complaints.c (clear_complaints): Remove unused variable. * corelow.c (core_target_open): Remove unused variable. * fbsd-tdep.c (fbsd_core_info_proc_status): Remove unused variable. * guile/scm-frame.c (gdbscm_frame_read_var): Remove unused variable. * guile/scm-symtab.c (stscm_print_sal_smob): Remove unused variable. * guile/scm-type.c (gdbscm_field_baseclass_p): Remove unused variable. * guile/scm-utils.c (gdbscm_parse_function_args): Remove unused variable. * hppa-tdep.c (hppa_stub_frame_unwind_cache): Remove unused variable. * ia64-tdep.c (examine_prologue): Remove unused variable. * infcall.c (run_inferior_call): Remove unused variable. * inferior.c (exit_inferior): Remove unused variable. * infrun.c (infrun_thread_ptid_changed): Remove unused variable. * linespec.c (decode_line_2): Remove unused variable. * linux-nat.c (super_close): Remove. * linux-tdep.c (linux_info_proc): Remove unused variable. * mi/mi-main.c (mi_execute_command): Remove unused variable. * microblaze-linux-tdep.c (microblaze_linux_sigtramp_cache): Remove unused variable. * parse.c (find_minsym_type_and_address): Remove unused variable. * printcmd.c (info_symbol_command, printf_floating): Remove unused variable. * python/py-breakpoint.c (bppy_set_commands): Remove unused variable. * python/py-unwind.c (unwind_infopy_dealloc): Remove unused variables. * record-btrace.c (record_btrace_target::store_registers): Remove unused variable. (cmd_show_record_btrace_cpu): Remove unused variable. * riscv-tdep.c (riscv_register_reggroup_p) (riscv_push_dummy_call, riscv_return_value): Remove unused variable. * rust-exp.y (literal): Remove unused variable. * rust-lang.c (rust_evaluate_subexp) <OP_RUST_ARARAY>: Remove unused variable. <STRUCTOP_ANONYMOUS>: Likewise. * s390-linux-tdep.c (s390_linux_init_abi_31) (s390_linux_init_abi_64): Remove unused variable. * ser-ming2.c (ser_windows_read_prim, pipe_select_thread) (file_select_thread, net_windows_open, _initialize_ser_windows): Remove unused variables. * symtab.c (find_pc_sect_line): Remove unused variable. * target-memory.c (compute_garbled_blocks): Remove unused variable. (target_write_memory_blocks): Remove unused variable. * target.c (target_stack::unpush): Remove unused variables. * tracepoint.c (start_tracing, all_tracepoint_actions) (merge_uploaded_trace_state_variables) (print_one_static_tracepoint_marker): Remove unused variable. * unittests/basic_string_view/element_access/char/1.cc (test01): Remove unused variable. * windows-nat.c (windows_continue, windows_add_all_dlls) (do_initial_windows_stuff, windows_nat_target::create_inferior): Remove unused variables.
2018-07-08 20:15:04 +02:00
(*pos)++;
int copies;
struct value *elt;
struct value *ncopies;
elt = rust_evaluate_subexp (NULL, exp, pos, noside);
ncopies = rust_evaluate_subexp (NULL, exp, pos, noside);
copies = value_as_long (ncopies);
if (copies < 0)
error (_("Array with negative number of elements"));
if (noside == EVAL_NORMAL)
{
int i;
std::vector<struct value *> eltvec (copies);
for (i = 0; i < copies; ++i)
eltvec[i] = elt;
result = value_array (0, copies - 1, eltvec.data ());
}
else
{
struct type *arraytype
= lookup_array_range_type (value_type (elt), 0, copies - 1);
result = allocate_value (arraytype);
}
}
break;
case STRUCTOP_ANONYMOUS:
{
/* Anonymous field access, i.e. foo.1. */
struct value *lhs;
int pc, field_number, nfields;
Simple unused variable removals This patch holds all the straightforward unused variable deletions. gdb/ChangeLog 2018-07-22 Tom Tromey <tom@tromey.com> * guile/scm-value.c (gdbscm_value_call): Remove unused variables. * guile/scm-math.c (vlscm_unop_gdbthrow, vlscm_binop_gdbthrow) (vlscm_convert_typed_value_from_scheme): Remove unused variable. * buildsym-legacy.c (get_macro_table): Remove unused variable. * stack.c (frame_apply_level_command): Remove unused variable. * tic6x-tdep.c (tic6x_push_dummy_call): Remove unused variable. * sparc64-tdep.c (adi_examine_command): Remove unused variable. * rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Remove unused variable. * nios2-tdep.c (nios2_push_dummy_call): Remove unused variable. * mep-tdep.c (mep_push_dummy_call): Remove unused variable. * ada-lang.c (ada_lookup_symbol_list_worker): Remove unused variable. * amd64-tdep.c (amd64_supply_xsave): Remove unused variable. * arm-tdep.c (arm_record_data_proc_misc_ld_str): Remove unused variable. * breakpoint.c (check_no_tracepoint_commands, update_watchpoint): Remove unused variable. * cli/cli-script.c (recurse_read_control_structure): Remove unused variable. * common/tdesc.c (print_xml_feature::visit): Remove unused variable. * compile/compile-object-load.c (store_regs): Remove unused variables. * complaints.c (clear_complaints): Remove unused variable. * corelow.c (core_target_open): Remove unused variable. * fbsd-tdep.c (fbsd_core_info_proc_status): Remove unused variable. * guile/scm-frame.c (gdbscm_frame_read_var): Remove unused variable. * guile/scm-symtab.c (stscm_print_sal_smob): Remove unused variable. * guile/scm-type.c (gdbscm_field_baseclass_p): Remove unused variable. * guile/scm-utils.c (gdbscm_parse_function_args): Remove unused variable. * hppa-tdep.c (hppa_stub_frame_unwind_cache): Remove unused variable. * ia64-tdep.c (examine_prologue): Remove unused variable. * infcall.c (run_inferior_call): Remove unused variable. * inferior.c (exit_inferior): Remove unused variable. * infrun.c (infrun_thread_ptid_changed): Remove unused variable. * linespec.c (decode_line_2): Remove unused variable. * linux-nat.c (super_close): Remove. * linux-tdep.c (linux_info_proc): Remove unused variable. * mi/mi-main.c (mi_execute_command): Remove unused variable. * microblaze-linux-tdep.c (microblaze_linux_sigtramp_cache): Remove unused variable. * parse.c (find_minsym_type_and_address): Remove unused variable. * printcmd.c (info_symbol_command, printf_floating): Remove unused variable. * python/py-breakpoint.c (bppy_set_commands): Remove unused variable. * python/py-unwind.c (unwind_infopy_dealloc): Remove unused variables. * record-btrace.c (record_btrace_target::store_registers): Remove unused variable. (cmd_show_record_btrace_cpu): Remove unused variable. * riscv-tdep.c (riscv_register_reggroup_p) (riscv_push_dummy_call, riscv_return_value): Remove unused variable. * rust-exp.y (literal): Remove unused variable. * rust-lang.c (rust_evaluate_subexp) <OP_RUST_ARARAY>: Remove unused variable. <STRUCTOP_ANONYMOUS>: Likewise. * s390-linux-tdep.c (s390_linux_init_abi_31) (s390_linux_init_abi_64): Remove unused variable. * ser-ming2.c (ser_windows_read_prim, pipe_select_thread) (file_select_thread, net_windows_open, _initialize_ser_windows): Remove unused variables. * symtab.c (find_pc_sect_line): Remove unused variable. * target-memory.c (compute_garbled_blocks): Remove unused variable. (target_write_memory_blocks): Remove unused variable. * target.c (target_stack::unpush): Remove unused variables. * tracepoint.c (start_tracing, all_tracepoint_actions) (merge_uploaded_trace_state_variables) (print_one_static_tracepoint_marker): Remove unused variable. * unittests/basic_string_view/element_access/char/1.cc (test01): Remove unused variable. * windows-nat.c (windows_continue, windows_add_all_dlls) (do_initial_windows_stuff, windows_nat_target::create_inferior): Remove unused variables.
2018-07-08 20:15:04 +02:00
struct type *type;
pc = (*pos)++;
field_number = longest_to_int (exp->elts[pc + 1].longconst);
(*pos) += 2;
lhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
type = value_type (lhs);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
if (type->code () == TYPE_CODE_STRUCT)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
{
struct type *outer_type = NULL;
if (rust_enum_p (type))
{
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
gdb::array_view<const gdb_byte> view (value_contents (lhs),
TYPE_LENGTH (type));
type = resolve_dynamic_type (type, view, value_address (lhs));
if (rust_empty_enum_p (type))
error (_("Cannot access field %d of empty enum %s"),
field_number, type->name ());
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
int fieldno = rust_enum_variant (type);
lhs = value_primitive_field (lhs, 0, fieldno, type);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
outer_type = type;
type = value_type (lhs);
}
/* Tuples and tuple structs */
nfields = type->num_fields ();
if (field_number >= nfields || field_number < 0)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
{
if (outer_type != NULL)
error(_("Cannot access field %d of variant %s::%s, "
"there are only %d fields"),
field_number, outer_type->name (),
rust_last_path_segment (type->name ()),
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
nfields);
else
error(_("Cannot access field %d of %s, "
"there are only %d fields"),
field_number, type->name (), nfields);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
}
/* Tuples are tuple structs too. */
if (!rust_tuple_struct_type_p (type))
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
{
if (outer_type != NULL)
error(_("Variant %s::%s is not a tuple variant"),
outer_type->name (),
rust_last_path_segment (type->name ()));
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
else
error(_("Attempting to access anonymous field %d "
"of %s, which is not a tuple, tuple struct, or "
"tuple-like variant"),
field_number, type->name ());
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
}
result = value_primitive_field (lhs, 0, field_number, type);
}
else
error(_("Anonymous field access is only allowed on tuples, \
tuple structs, and tuple-like enum variants"));
}
break;
case STRUCTOP_STRUCT:
{
struct value *lhs;
struct type *type;
int tem, pc;
pc = (*pos)++;
tem = longest_to_int (exp->elts[pc + 1].longconst);
(*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
lhs = evaluate_subexp (NULL_TYPE, exp, pos, noside);
const char *field_name = &exp->elts[pc + 2].string;
type = value_type (lhs);
if (type->code () == TYPE_CODE_STRUCT && rust_enum_p (type))
{
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
gdb::array_view<const gdb_byte> view (value_contents (lhs),
TYPE_LENGTH (type));
type = resolve_dynamic_type (type, view, value_address (lhs));
if (rust_empty_enum_p (type))
error (_("Cannot access field %s of empty enum %s"),
field_name, type->name ());
Rewrite the existing variant part code This rewrites the existing variant part code to follow the new model implemented in the previous patch. The old variant part code is removed. This only affects Rust for the moment. I tested this using various version of the Rust compiler, including one that emits old-style enum debuginfo, exercising the quirks code. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (struct variant_field): Rewrite. (struct variant_part_builder): New. (struct nextfield): Remove "variant" field. Add "offset". (struct field_info): Add "current_variant_part" and "variant_parts". (alloc_discriminant_info): Remove. (alloc_rust_variant): New function. (quirk_rust_enum): Update. (dwarf2_add_field): Set "offset" member. Don't handle DW_TAG_variant_part. (offset_map_type): New typedef. (convert_variant_range, create_one_variant) (create_one_variant_part, create_variant_parts) (add_variant_property): New functions. (dwarf2_attach_fields_to_type): Call add_variant_property. (read_structure_type): Don't handle DW_TAG_variant_part. (handle_variant_part, handle_variant): New functions. (handle_struct_member_die): Use them. (process_structure_scope): Don't handle variant parts. * gdbtypes.h (TYPE_FLAG_DISCRIMINATED_UNION): Remove. (struct discriminant_info): Remove. (enum dynamic_prop_node_kind) <DYN_PROP_DISCRIMINATED>: Remove. (struct main_type) <flag_discriminated_union>: Remove. * rust-lang.c (rust_enum_p, rust_empty_enum_p): Rewrite. (rust_enum_variant): Return int. Remove "contents". Rewrite. (rust_print_enum, rust_print_struct_def, rust_evaluate_subexp): Update. * valops.c (value_union_variant): Remove. * value.h (value_union_variant): Don't declare.
2020-04-24 21:40:31 +02:00
int fieldno = rust_enum_variant (type);
lhs = value_primitive_field (lhs, 0, fieldno, type);
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
struct type *outer_type = type;
type = value_type (lhs);
if (rust_tuple_type_p (type) || rust_tuple_struct_type_p (type))
error (_("Attempting to access named field %s of tuple "
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
"variant %s::%s, which has only anonymous fields"),
field_name, outer_type->name (),
rust_last_path_segment (type->name ()));
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
Rewrite TRY/CATCH This rewrites gdb's TRY/CATCH to plain C++ try/catch. The patch was largely written by script, though one change (to a comment in common-exceptions.h) was reverted by hand. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * xml-support.c: Use C++ exception handling. * x86-linux-nat.c: Use C++ exception handling. * windows-nat.c: Use C++ exception handling. * varobj.c: Use C++ exception handling. * value.c: Use C++ exception handling. * valprint.c: Use C++ exception handling. * valops.c: Use C++ exception handling. * unittests/parse-connection-spec-selftests.c: Use C++ exception handling. * unittests/cli-utils-selftests.c: Use C++ exception handling. * typeprint.c: Use C++ exception handling. * tui/tui.c: Use C++ exception handling. * tracefile-tfile.c: Use C++ exception handling. * top.c: Use C++ exception handling. * thread.c: Use C++ exception handling. * target.c: Use C++ exception handling. * symmisc.c: Use C++ exception handling. * symfile-mem.c: Use C++ exception handling. * stack.c: Use C++ exception handling. * sparc64-linux-tdep.c: Use C++ exception handling. * solib.c: Use C++ exception handling. * solib-svr4.c: Use C++ exception handling. * solib-spu.c: Use C++ exception handling. * solib-frv.c: Use C++ exception handling. * solib-dsbt.c: Use C++ exception handling. * selftest-arch.c: Use C++ exception handling. * s390-tdep.c: Use C++ exception handling. * rust-lang.c: Use C++ exception handling. * rust-exp.y: Use C++ exception handling. * rs6000-tdep.c: Use C++ exception handling. * rs6000-aix-tdep.c: Use C++ exception handling. * riscv-tdep.c: Use C++ exception handling. * remote.c: Use C++ exception handling. * remote-fileio.c: Use C++ exception handling. * record-full.c: Use C++ exception handling. * record-btrace.c: Use C++ exception handling. * python/python.c: Use C++ exception handling. * python/py-value.c: Use C++ exception handling. * python/py-utils.c: Use C++ exception handling. * python/py-unwind.c: Use C++ exception handling. * python/py-type.c: Use C++ exception handling. * python/py-symbol.c: Use C++ exception handling. * python/py-record.c: Use C++ exception handling. * python/py-record-btrace.c: Use C++ exception handling. * python/py-progspace.c: Use C++ exception handling. * python/py-prettyprint.c: Use C++ exception handling. * python/py-param.c: Use C++ exception handling. * python/py-objfile.c: Use C++ exception handling. * python/py-linetable.c: Use C++ exception handling. * python/py-lazy-string.c: Use C++ exception handling. * python/py-infthread.c: Use C++ exception handling. * python/py-inferior.c: Use C++ exception handling. * python/py-gdb-readline.c: Use C++ exception handling. * python/py-framefilter.c: Use C++ exception handling. * python/py-frame.c: Use C++ exception handling. * python/py-finishbreakpoint.c: Use C++ exception handling. * python/py-cmd.c: Use C++ exception handling. * python/py-breakpoint.c: Use C++ exception handling. * python/py-arch.c: Use C++ exception handling. * printcmd.c: Use C++ exception handling. * ppc-linux-tdep.c: Use C++ exception handling. * parse.c: Use C++ exception handling. * p-valprint.c: Use C++ exception handling. * objc-lang.c: Use C++ exception handling. * mi/mi-main.c: Use C++ exception handling. * mi/mi-interp.c: Use C++ exception handling. * mi/mi-cmd-stack.c: Use C++ exception handling. * mi/mi-cmd-break.c: Use C++ exception handling. * main.c: Use C++ exception handling. * linux-thread-db.c: Use C++ exception handling. * linux-tdep.c: Use C++ exception handling. * linux-nat.c: Use C++ exception handling. * linux-fork.c: Use C++ exception handling. * linespec.c: Use C++ exception handling. * language.c: Use C++ exception handling. * jit.c: Use C++ exception handling. * infrun.c: Use C++ exception handling. * infcmd.c: Use C++ exception handling. * infcall.c: Use C++ exception handling. * inf-loop.c: Use C++ exception handling. * i386-tdep.c: Use C++ exception handling. * i386-linux-tdep.c: Use C++ exception handling. * guile/scm-value.c: Use C++ exception handling. * guile/scm-type.c: Use C++ exception handling. * guile/scm-symtab.c: Use C++ exception handling. * guile/scm-symbol.c: Use C++ exception handling. * guile/scm-pretty-print.c: Use C++ exception handling. * guile/scm-ports.c: Use C++ exception handling. * guile/scm-param.c: Use C++ exception handling. * guile/scm-math.c: Use C++ exception handling. * guile/scm-lazy-string.c: Use C++ exception handling. * guile/scm-frame.c: Use C++ exception handling. * guile/scm-disasm.c: Use C++ exception handling. * guile/scm-cmd.c: Use C++ exception handling. * guile/scm-breakpoint.c: Use C++ exception handling. * guile/scm-block.c: Use C++ exception handling. * guile/guile-internal.h: Use C++ exception handling. * gnu-v3-abi.c: Use C++ exception handling. * gdbtypes.c: Use C++ exception handling. * frame.c: Use C++ exception handling. * frame-unwind.c: Use C++ exception handling. * fbsd-tdep.c: Use C++ exception handling. * f-valprint.c: Use C++ exception handling. * exec.c: Use C++ exception handling. * event-top.c: Use C++ exception handling. * event-loop.c: Use C++ exception handling. * eval.c: Use C++ exception handling. * dwarf2read.c: Use C++ exception handling. * dwarf2loc.c: Use C++ exception handling. * dwarf2-frame.c: Use C++ exception handling. * dwarf2-frame-tailcall.c: Use C++ exception handling. * dwarf-index-write.c: Use C++ exception handling. * dwarf-index-cache.c: Use C++ exception handling. * dtrace-probe.c: Use C++ exception handling. * disasm-selftests.c: Use C++ exception handling. * darwin-nat.c: Use C++ exception handling. * cp-valprint.c: Use C++ exception handling. * cp-support.c: Use C++ exception handling. * cp-abi.c: Use C++ exception handling. * corelow.c: Use C++ exception handling. * completer.c: Use C++ exception handling. * compile/compile-object-run.c: Use C++ exception handling. * compile/compile-object-load.c: Use C++ exception handling. * compile/compile-cplus-symbols.c: Use C++ exception handling. * compile/compile-c-symbols.c: Use C++ exception handling. * common/selftest.c: Use C++ exception handling. * common/new-op.c: Use C++ exception handling. * cli/cli-script.c: Use C++ exception handling. * cli/cli-interp.c: Use C++ exception handling. * cli/cli-cmds.c: Use C++ exception handling. * c-varobj.c: Use C++ exception handling. * btrace.c: Use C++ exception handling. * breakpoint.c: Use C++ exception handling. * break-catch-throw.c: Use C++ exception handling. * arch-utils.c: Use C++ exception handling. * amd64-tdep.c: Use C++ exception handling. * ada-valprint.c: Use C++ exception handling. * ada-typeprint.c: Use C++ exception handling. * ada-lang.c: Use C++ exception handling. * aarch64-tdep.c: Use C++ exception handling. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * server.c: Use C++ exception handling. * linux-low.c: Use C++ exception handling. * gdbreplay.c: Use C++ exception handling.
2019-04-04 00:02:42 +02:00
try
{
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
result = value_struct_elt (&lhs, NULL, field_name,
NULL, "structure");
}
Rename gdb exception types This renames the gdb exception types. The old types were only needed due to the macros in common-exception.h that are now gone. The intermediate layer of gdb_exception_RETURN_MASK_ALL did not seem needed, so this patch removes it entirely. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * common/common-exceptions.h (gdb_exception_RETURN_MASK_ALL): Remove. (gdb_exception_error): Rename from gdb_exception_RETURN_MASK_ERROR. (gdb_exception_quit): Rename from gdb_exception_RETURN_MASK_QUIT. (gdb_quit_bad_alloc): Update. * aarch64-tdep.c: Update. * ada-lang.c: Update. * ada-typeprint.c: Update. * ada-valprint.c: Update. * amd64-tdep.c: Update. * arch-utils.c: Update. * break-catch-throw.c: Update. * breakpoint.c: Update. * btrace.c: Update. * c-varobj.c: Update. * cli/cli-cmds.c: Update. * cli/cli-interp.c: Update. * cli/cli-script.c: Update. * common/common-exceptions.c: Update. * common/new-op.c: Update. * common/selftest.c: Update. * compile/compile-c-symbols.c: Update. * compile/compile-cplus-symbols.c: Update. * compile/compile-object-load.c: Update. * compile/compile-object-run.c: Update. * completer.c: Update. * corelow.c: Update. * cp-abi.c: Update. * cp-support.c: Update. * cp-valprint.c: Update. * darwin-nat.c: Update. * disasm-selftests.c: Update. * dtrace-probe.c: Update. * dwarf-index-cache.c: Update. * dwarf-index-write.c: Update. * dwarf2-frame-tailcall.c: Update. * dwarf2-frame.c: Update. * dwarf2loc.c: Update. * dwarf2read.c: Update. * eval.c: Update. * event-loop.c: Update. * event-top.c: Update. * exec.c: Update. * f-valprint.c: Update. * fbsd-tdep.c: Update. * frame-unwind.c: Update. * frame.c: Update. * gdbtypes.c: Update. * gnu-v3-abi.c: Update. * guile/guile-internal.h: Update. * guile/scm-block.c: Update. * guile/scm-breakpoint.c: Update. * guile/scm-cmd.c: Update. * guile/scm-disasm.c: Update. * guile/scm-frame.c: Update. * guile/scm-lazy-string.c: Update. * guile/scm-math.c: Update. * guile/scm-param.c: Update. * guile/scm-ports.c: Update. * guile/scm-pretty-print.c: Update. * guile/scm-symbol.c: Update. * guile/scm-symtab.c: Update. * guile/scm-type.c: Update. * guile/scm-value.c: Update. * i386-linux-tdep.c: Update. * i386-tdep.c: Update. * inf-loop.c: Update. * infcall.c: Update. * infcmd.c: Update. * infrun.c: Update. * jit.c: Update. * language.c: Update. * linespec.c: Update. * linux-fork.c: Update. * linux-nat.c: Update. * linux-tdep.c: Update. * linux-thread-db.c: Update. * main.c: Update. * mi/mi-cmd-break.c: Update. * mi/mi-cmd-stack.c: Update. * mi/mi-interp.c: Update. * mi/mi-main.c: Update. * objc-lang.c: Update. * p-valprint.c: Update. * parse.c: Update. * ppc-linux-tdep.c: Update. * printcmd.c: Update. * python/py-arch.c: Update. * python/py-breakpoint.c: Update. * python/py-cmd.c: Update. * python/py-finishbreakpoint.c: Update. * python/py-frame.c: Update. * python/py-framefilter.c: Update. * python/py-gdb-readline.c: Update. * python/py-inferior.c: Update. * python/py-infthread.c: Update. * python/py-lazy-string.c: Update. * python/py-linetable.c: Update. * python/py-objfile.c: Update. * python/py-param.c: Update. * python/py-prettyprint.c: Update. * python/py-progspace.c: Update. * python/py-record-btrace.c: Update. * python/py-record.c: Update. * python/py-symbol.c: Update. * python/py-type.c: Update. * python/py-unwind.c: Update. * python/py-utils.c: Update. * python/py-value.c: Update. * python/python.c: Update. * record-btrace.c: Update. * record-full.c: Update. * remote-fileio.c: Update. * remote.c: Update. * riscv-tdep.c: Update. * rs6000-aix-tdep.c: Update. * rs6000-tdep.c: Update. * rust-exp.y: Update. * rust-lang.c: Update. * s390-tdep.c: Update. * selftest-arch.c: Update. * solib-dsbt.c: Update. * solib-frv.c: Update. * solib-spu.c: Update. * solib-svr4.c: Update. * solib.c: Update. * sparc64-linux-tdep.c: Update. * stack.c: Update. * symfile-mem.c: Update. * symmisc.c: Update. * target.c: Update. * thread.c: Update. * top.c: Update. * tracefile-tfile.c: Update. * tui/tui.c: Update. * typeprint.c: Update. * unittests/cli-utils-selftests.c: Update. * unittests/parse-connection-spec-selftests.c: Update. * valops.c: Update. * valprint.c: Update. * value.c: Update. * varobj.c: Update. * windows-nat.c: Update. * x86-linux-nat.c: Update. * xml-support.c: Update. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * gdbreplay.c: Update. * linux-low.c: Update. * server.c: Update.
2019-04-03 23:59:07 +02:00
catch (const gdb_exception_error &except)
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
{
error (_("Could not find field %s of struct variant %s::%s"),
field_name, outer_type->name (),
rust_last_path_segment (type->name ()));
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
}
}
else
Convert Rust to use discriminated unions A Rust enum is, essentially, a discriminated union. Currently the Rust language support handles Rust enums locally, in rust-lang.c. However, because I am changing the Rust compiler to use DW_TAG_variant* to represent enums, it seemed better to have a single internal representation for Rust enums in gdb. This patch implements this idea by moving the current Rust enum handling code to dwarf2read. This allows the simplification of some parts of rust-lang.c as well. 2018-02-26 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_last_path_segment): Declare. * rust-lang.c (rust_last_path_segment): Now public. Change contract. (struct disr_info): Remove. (RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL) (RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged) (rust_get_disr_info, rust_tuple_variant_type_p): Remove. (rust_enum_p, rust_enum_variant): New function. (rust_underscore_fields): Remove "offset" parameter. (rust_print_enum): New function. (rust_val_print) <TYPE_CODE_UNION>: Remove enum code. <TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate. (rust_print_struct_def): Add "for_rust_enum" parameter. Handle enums. (rust_internal_print_type): New function, from rust_print_type. Remove enum code. (rust_print_type): Call rust_internal_print_type. (rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>: Update enum handling. * dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field. (rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum) (rust_union_quirks): New functions. (process_full_comp_unit, process_full_type_unit): Call rust_union_quirks. (process_structure_scope): Update rust_unions if necessary. 2018-02-26 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-09 21:31:51 +01:00
result = value_struct_elt (&lhs, NULL, field_name, NULL, "structure");
if (noside == EVAL_AVOID_SIDE_EFFECTS)
result = value_zero (value_type (result), VALUE_LVAL (result));
}
break;
case OP_RANGE:
result = rust_range (exp, pos, noside);
break;
case UNOP_ADDR:
/* We might have &array[range], in which case we need to make a
slice. */
if (exp->elts[*pos + 1].opcode == BINOP_SUBSCRIPT)
{
++*pos;
result = rust_subscript (exp, pos, noside, 1);
break;
}
/* Fall through. */
default:
result = evaluate_subexp_standard (expect_type, exp, pos, noside);
break;
}
return result;
}
/* operator_length implementation for Rust. */
static void
rust_operator_length (const struct expression *exp, int pc, int *oplenp,
int *argsp)
{
int oplen = 1;
int args = 0;
switch (exp->elts[pc - 1].opcode)
{
case OP_AGGREGATE:
/* We handle aggregate as a type and argument count. The first
argument might be OP_OTHERS. After that the arguments
alternate: first an OP_NAME, then an expression. */
oplen = 4;
args = longest_to_int (exp->elts[pc - 2].longconst);
break;
case OP_OTHERS:
oplen = 1;
args = 1;
break;
case STRUCTOP_ANONYMOUS:
oplen = 3;
args = 1;
break;
case OP_RUST_ARRAY:
oplen = 1;
args = 2;
break;
default:
operator_length_standard (exp, pc, oplenp, argsp);
return;
}
*oplenp = oplen;
*argsp = args;
}
/* op_name implementation for Rust. */
-Wwrite-strings: The Rest This is the remainder boring constification that all looks more of less borderline obvious IMO. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * ada-exp.y (yyerror): Constify. * ada-lang.c (bound_name, get_selections) (ada_variant_discrim_type) (ada_variant_discrim_name, ada_value_struct_elt) (ada_lookup_struct_elt_type, is_unchecked_variant) (ada_which_variant_applies, standard_exc, ada_get_next_arg) (catch_ada_exception_command_split) (catch_ada_assert_command_split, catch_assert_command) (ada_op_name): Constify. * ada-lang.h (ada_yyerror, get_selections) (ada_variant_discrim_name, ada_value_struct_elt): Constify. * arc-tdep.c (arc_print_frame_cache): Constify. * arm-tdep.c (arm_skip_stub): Constify. * ax-gdb.c (gen_binop, gen_struct_ref_recursive, gen_struct_ref) (gen_aggregate_elt_ref): Constify. * bcache.c (print_bcache_statistics): Constify. * bcache.h (print_bcache_statistics): Constify. * break-catch-throw.c (catch_exception_command_1): * breakpoint.c (struct ep_type_description::description): Constify. (add_solib_catchpoint): Constify. (catch_fork_command_1): Add cast. (add_catch_command): Constify. * breakpoint.h (add_catch_command, add_solib_catchpoint): Constify. * bsd-uthread.c (bsd_uthread_state): Constify. * buildsym.c (patch_subfile_names): Constify. * buildsym.h (next_symbol_text_func, patch_subfile_names): Constify. * c-exp.y (yyerror): Constify. (token::oper): Constify. * c-lang.h (c_yyerror, cp_print_class_member): Constify. * c-varobj.c (cplus_describe_child): Constify. * charset.c (find_charset_names): Add cast. (find_charset_names): Constify array and add const_cast. * cli/cli-cmds.c (complete_command, cd_command): Constify. (edit_command): Constify. * cli/cli-decode.c (lookup_cmd): Constify. * cli/cli-dump.c (dump_memory_command, dump_value_command): Constify. (struct dump_context): Constify. (add_dump_command, restore_command): Constify. * cli/cli-script.c (get_command_line): Constify. * cli/cli-script.h (get_command_line): Constify. * cli/cli-utils.c (check_for_argument): Constify. * cli/cli-utils.h (check_for_argument): Constify. * coff-pe-read.c (struct read_pe_section_data): Constify. * command.h (lookup_cmd): Constify. * common/print-utils.c (decimal2str): Constify. * completer.c (gdb_print_filename): Constify. * corefile.c (set_gnutarget): Constify. * cp-name-parser.y (yyerror): Constify. * cp-valprint.c (cp_print_class_member): Constify. * cris-tdep.c (cris_register_name, crisv32_register_name): Constify. * d-exp.y (yyerror): Constify. (struct token::oper): Constify. * d-lang.h (d_yyerror): Constify. * dbxread.c (struct header_file_location::name): Constify. (add_old_header_file, add_new_header_file, last_function_name) (dbx_next_symbol_text, add_bincl_to_list) (find_corresponding_bincl_psymtab, set_namestring) (find_stab_function_addr, read_dbx_symtab, start_psymtab) (dbx_end_psymtab, read_ofile_symtab, process_one_symbol): * defs.h (command_line_input, print_address_symbolic) (deprecated_readline_begin_hook): Constify. * dwarf2read.c (anonymous_struct_prefix, dwarf_bool_name): Constify. * event-top.c (handle_line_of_input): Constify and add cast. * exceptions.c (catch_errors): Constify. * exceptions.h (catch_errors): Constify. * expprint.c (print_subexp_standard, op_string, op_name) (op_name_standard, dump_raw_expression, dump_raw_expression): * expression.h (op_name, op_string, dump_raw_expression): Constify. * f-exp.y (yyerror): Constify. (struct token::oper): Constify. (struct f77_boolean_val::name): Constify. * f-lang.c (f_word_break_characters): Constify. * f-lang.h (f_yyerror): Constify. * fork-child.c (fork_inferior): Add cast. * frv-tdep.c (struct gdbarch_tdep::register_names): Constify. (new_variant): Constify. * gdbarch.sh (pstring_ptr, pstring_list): Constify. * gdbarch.c: Regenerate. * gdbcore.h (set_gnutarget): Constify. * go-exp.y (yyerror): Constify. (token::oper): Constify. * go-lang.h (go_yyerror): Constify. * go32-nat.c (go32_sysinfo): Constify. * guile/scm-breakpoint.c (gdbscm_breakpoint_expression): Constify. * guile/scm-cmd.c (cmdscm_function): Constify. * guile/scm-param.c (pascm_param_value): Constify. * h8300-tdep.c (h8300_register_name, h8300s_register_name) (h8300sx_register_name): Constify. * hppa-tdep.c (hppa32_register_name, hppa64_register_name): Constify. * ia64-tdep.c (ia64_register_names): Constify. * infcmd.c (construct_inferior_arguments): Constify. (path_command, attach_post_wait): Constify. * language.c (show_range_command, show_case_command) (unk_lang_error): Constify. * language.h (language_defn::la_error) (language_defn::la_name_of_this): Constify. * linespec.c (decode_line_2): Constify. * linux-thread-db.c (thread_db_err_str): Constify. * lm32-tdep.c (lm32_register_name): Constify. * m2-exp.y (yyerror): Constify. * m2-lang.h (m2_yyerror): Constify. * m32r-tdep.c (m32r_register_names): Constify and make static. * m68hc11-tdep.c (m68hc11_register_names): Constify. * m88k-tdep.c (m88k_register_name): Constify. * macroexp.c (appendmem): Constify. * mdebugread.c (fdr_name, add_data_symbol, parse_type) (upgrade_type, parse_external, parse_partial_symbols) (mdebug_next_symbol_text, cross_ref, mylookup_symbol, new_psymtab) (new_symbol): Constify. * memattr.c (mem_info_command): Constify. * mep-tdep.c (register_name_from_keyword): Constify. * mi/mi-cmd-env.c (mi_cmd_env_path, _initialize_mi_cmd_env): Constify. * mi/mi-cmd-stack.c (list_args_or_locals): Constify. * mi/mi-cmd-var.c (mi_cmd_var_show_attributes): Constify. * mi/mi-main.c (captured_mi_execute_command): Constify and add cast. (mi_execute_async_cli_command): Constify. * mips-tdep.c (mips_register_name): Constify. * mn10300-tdep.c (register_name, mn10300_generic_register_name) (am33_register_name, am33_2_register_name) * moxie-tdep.c (moxie_register_names): Constify. * nat/linux-osdata.c (osdata_type): Constify fields. * nto-tdep.c (nto_parse_redirection): Constify. * objc-lang.c (lookup_struct_typedef, lookup_objc_class) (lookup_child_selector): Constify. (objc_methcall::name): Constify. * objc-lang.h (lookup_objc_class, lookup_child_selector) (lookup_struct_typedef): Constify. * objfiles.c (pc_in_section): Constify. * objfiles.h (pc_in_section): Constify. * p-exp.y (struct token::oper): Constify. (yyerror): Constify. * p-lang.h (pascal_yyerror): Constify. * parser-defs.h (op_name_standard): Constify. (op_print::string): Constify. (exp_descriptor::op_name): Constify. * printcmd.c (print_address_symbolic): Constify. * psymtab.c (print_partial_symbols): Constify. * python/py-breakpoint.c (stop_func): Constify. (bppy_get_expression): Constify. * python/py-cmd.c (cmdpy_completer::name): Constify. (cmdpy_function): Constify. * python/py-event.c (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-event.h (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-evts.c (add_new_registry): Constify. * python/py-finishbreakpoint.c (outofscope_func): Constify. * python/py-framefilter.c (get_py_iter_from_func): Constify. * python/py-inferior.c (get_buffer): Add cast. * python/py-param.c (parm_constant::name): Constify. * python/py-unwind.c (fprint_frame_id): Constify. * python/python.c (gdbpy_parameter_value): Constify. * remote-fileio.c (remote_fio_func_map): Make 'name' const. * remote.c (memory_packet_config::name): Constify. (show_packet_config_cmd, remote_write_bytes) (remote_buffer_add_string): * reverse.c (exec_reverse_once): Constify. * rs6000-tdep.c (variant::name, variant::description): Constify. * rust-exp.y (rustyyerror): Constify. * rust-lang.c (rust_op_name): Constify. * rust-lang.h (rustyyerror): Constify. * serial.h (serial_ops::name): Constify. * sh-tdep.c (sh_sh_register_name, sh_sh3_register_name) (sh_sh3e_register_name, sh_sh2e_register_name) (sh_sh2a_register_name, sh_sh2a_nofpu_register_name) (sh_sh_dsp_register_name, sh_sh3_dsp_register_name) (sh_sh4_register_name, sh_sh4_nofpu_register_name) (sh_sh4al_dsp_register_name): Constify. * sh64-tdep.c (sh64_register_name): Constify. * solib-darwin.c (lookup_symbol_from_bfd): Constify. * spu-tdep.c (spu_register_name, info_spu_dma_cmdlist): Constify. * stabsread.c (patch_block_stabs, read_type_number) (ref_map::stabs, ref_add, process_reference) (symbol_reference_defined, define_symbol, define_symbol) (error_type, read_type, read_member_functions, read_cpp_abbrev) (read_one_struct_field, read_struct_fields, read_baseclasses) (read_tilde_fields, read_struct_type, read_array_type) (read_enum_type, read_sun_builtin_type, read_sun_floating_type) (read_huge_number, read_range_type, read_args, common_block_start) (find_name_end): Constify. * stabsread.h (common_block_start, define_symbol) (process_one_symbol, symbol_reference_defined, ref_add): * symfile.c (get_section_index, add_symbol_file_command): * symfile.h (get_section_index): Constify. * target-descriptions.c (tdesc_type::name): Constify. (tdesc_free_type): Add cast. * target.c (find_default_run_target): (add_deprecated_target_alias, find_default_run_target) (target_announce_detach): Constify. (do_option): Constify. * target.h (add_deprecated_target_alias): Constify. * thread.c (print_thread_info_1): Constify. * top.c (deprecated_readline_begin_hook, command_line_input): Constify. (init_main): Add casts. * top.h (handle_line_of_input): Constify. * tracefile-tfile.c (tfile_write_uploaded_tsv): Constify. * tracepoint.c (tvariables_info_1, trace_status_mi): Constify. (tfind_command): Rename to ... (tfind_command_1): ... this and constify. (tfind_command): New function. (tfind_end_command, tfind_start_command): Adjust. (encode_source_string): Constify. * tracepoint.h (encode_source_string): Constify. * tui/tui-data.c (tui_partial_win_by_name): Constify. * tui/tui-data.h (tui_partial_win_by_name): Constify. * tui/tui-source.c (tui_set_source_content_nil): Constify. * tui/tui-source.h (tui_set_source_content_nil): Constify. * tui/tui-win.c (parse_scrolling_args): Constify. * tui/tui-windata.c (tui_erase_data_content): Constify. * tui/tui-windata.h (tui_erase_data_content): Constify. * tui/tui-winsource.c (tui_erase_source_content): Constify. * tui/tui.c (tui_enable): Add cast. * utils.c (defaulted_query): Constify. (init_page_info): Add cast. (puts_debug, subset_compare): Constify. * utils.h (subset_compare): Constify. * varobj.c (varobj_format_string): Constify. * varobj.h (varobj_format_string): Constify. * vax-tdep.c (vax_register_name): Constify. * windows-nat.c (windows_detach): Constify. * xcoffread.c (process_linenos, xcoff_next_symbol_text): Constify. * xml-support.c (gdb_xml_end_element): Constify. * xml-tdesc.c (tdesc_start_reg): Constify. * xstormy16-tdep.c (xstormy16_register_name): Constify. * xtensa-tdep.c (xtensa_find_register_by_name): Constify. * xtensa-tdep.h (xtensa_register_t::name): Constify. gdb/gdbserver/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * gdbreplay.c (sync_error): Constify. * linux-x86-low.c (push_opcode): Constify.
2017-04-05 20:21:37 +02:00
static const char *
rust_op_name (enum exp_opcode opcode)
{
switch (opcode)
{
case OP_AGGREGATE:
return "OP_AGGREGATE";
case OP_OTHERS:
return "OP_OTHERS";
default:
return op_name_standard (opcode);
}
}
/* dump_subexp_body implementation for Rust. */
static int
rust_dump_subexp_body (struct expression *exp, struct ui_file *stream,
int elt)
{
switch (exp->elts[elt].opcode)
{
case OP_AGGREGATE:
{
int length = longest_to_int (exp->elts[elt + 2].longconst);
int i;
fprintf_filtered (stream, "Type @");
gdb_print_host_address (exp->elts[elt + 1].type, stream);
fprintf_filtered (stream, " (");
type_print (exp->elts[elt + 1].type, NULL, stream, 0);
fprintf_filtered (stream, "), length %d", length);
elt += 4;
for (i = 0; i < length; ++i)
elt = dump_subexp (exp, stream, elt);
}
break;
case OP_STRING:
case OP_NAME:
{
LONGEST len = exp->elts[elt + 1].longconst;
fprintf_filtered (stream, "%s: %s",
(exp->elts[elt].opcode == OP_STRING
? "string" : "name"),
&exp->elts[elt + 2].string);
elt += 4 + BYTES_TO_EXP_ELEM (len + 1);
}
break;
case OP_OTHERS:
elt = dump_subexp (exp, stream, elt + 1);
break;
case STRUCTOP_ANONYMOUS:
{
int field_number;
field_number = longest_to_int (exp->elts[elt + 1].longconst);
fprintf_filtered (stream, "Field number: %d", field_number);
elt = dump_subexp (exp, stream, elt + 3);
}
break;
case OP_RUST_ARRAY:
++elt;
break;
default:
elt = dump_subexp_body_standard (exp, stream, elt);
break;
}
return elt;
}
/* print_subexp implementation for Rust. */
static void
rust_print_subexp (struct expression *exp, int *pos, struct ui_file *stream,
enum precedence prec)
{
switch (exp->elts[*pos].opcode)
{
case OP_AGGREGATE:
{
int length = longest_to_int (exp->elts[*pos + 2].longconst);
int i;
type_print (exp->elts[*pos + 1].type, "", stream, 0);
fputs_filtered (" { ", stream);
*pos += 4;
for (i = 0; i < length; ++i)
{
rust_print_subexp (exp, pos, stream, prec);
fputs_filtered (", ", stream);
}
fputs_filtered (" }", stream);
}
break;
case OP_NAME:
{
LONGEST len = exp->elts[*pos + 1].longconst;
fputs_filtered (&exp->elts[*pos + 2].string, stream);
*pos += 4 + BYTES_TO_EXP_ELEM (len + 1);
}
break;
case OP_OTHERS:
{
fputs_filtered ("<<others>> (", stream);
++*pos;
rust_print_subexp (exp, pos, stream, prec);
fputs_filtered (")", stream);
}
break;
case STRUCTOP_ANONYMOUS:
{
int tem = longest_to_int (exp->elts[*pos + 1].longconst);
(*pos) += 3;
print_subexp (exp, pos, stream, PREC_SUFFIX);
fprintf_filtered (stream, ".%d", tem);
}
break;
case OP_RUST_ARRAY:
++*pos;
fprintf_filtered (stream, "[");
rust_print_subexp (exp, pos, stream, prec);
fprintf_filtered (stream, "; ");
rust_print_subexp (exp, pos, stream, prec);
fprintf_filtered (stream, "]");
break;
default:
print_subexp_standard (exp, pos, stream, prec);
break;
}
}
/* operator_check implementation for Rust. */
static int
rust_operator_check (struct expression *exp, int pos,
int (*objfile_func) (struct objfile *objfile,
void *data),
void *data)
{
switch (exp->elts[pos].opcode)
{
case OP_AGGREGATE:
{
struct type *type = exp->elts[pos + 1].type;
struct objfile *objfile = TYPE_OBJFILE (type);
if (objfile != NULL && (*objfile_func) (objfile, data))
return 1;
}
break;
case OP_OTHERS:
case OP_NAME:
case OP_RUST_ARRAY:
break;
default:
return operator_check_standard (exp, pos, objfile_func, data);
}
return 0;
}
/* Implementation of la_lookup_symbol_nonlocal for Rust. */
static struct block_symbol
rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
const char *name,
const struct block *block,
const domain_enum domain)
{
Remove null_block_symbol This removes null_block_symbol. It seemed simpler to me to change initializations and returns to use value initialization rather than null_block_symbol. This also fixes up a few spots where initialization was done piecemeal. gdb/ChangeLog 2019-03-24 Tom Tromey <tom@tromey.com> * ada-lang.c (standard_lookup): Simplify initialization. (ada_lookup_symbol_nonlocal): Simplify return. * solib-spu.c (spu_lookup_lib_symbol): Simplify return. * solib-darwin.c (darwin_lookup_lib_symbol): Simplify return. * solib-svr4.c (elf_lookup_lib_symbol): Simplify return. * rust-lang.c (rust_lookup_symbol_nonlocal): Simplify initialization. * solib.c (solib_global_lookup): Simplify. * symtab.c (null_block_symbol): Remove. (symbol_cache_lookup): Simplify returns. (lookup_language_this): Simplify returns. (lookup_symbol_aux): Simplify return. (lookup_local_symbol): Simplify returns. (lookup_global_symbol_from_objfile): Simplify return. (lookup_symbol_in_objfile_symtabs) (lookup_symbol_in_objfile_from_linkage_name): Simplify return. (lookup_symbol_via_quick_fns, lookup_symbol_in_static_block) (lookup_static_symbol, lookup_global_symbol): Simplify return. * cp-namespace.c (cp_lookup_bare_symbol) (cp_search_static_and_baseclasses, cp_lookup_symbol_via_imports) (cp_lookup_symbol_via_all_imports, cp_lookup_nested_symbol_1) (cp_lookup_nested_symbol): Don't use null_block_symbol. (cp_lookup_symbol_via_imports): Simplify initialization. (find_symbol_in_baseclass): Likewise. * symtab.h (null_block_symbol): Remove. * d-namespace.c (d_lookup_symbol): Don't use null_block_symbol. (d_lookup_nested_symbol, d_lookup_symbol_imports) (d_lookup_symbol_module): Likewise. (find_symbol_in_baseclass): Simplify initialization.
2019-03-22 23:53:12 +01:00
struct block_symbol result = {};
if (symbol_lookup_debug)
{
fprintf_unfiltered (gdb_stdlog,
"rust_lookup_symbol_non_local"
" (%s, %s (scope %s), %s)\n",
name, host_address_to_string (block),
block_scope (block), domain_name (domain));
}
/* Look up bare names in the block's scope. */
std::string scopedname;
if (name[cp_find_first_component (name)] == '\0')
{
const char *scope = block_scope (block);
if (scope[0] != '\0')
{
scopedname = std::string (scope) + "::" + name;
name = scopedname.c_str ();
}
else
name = NULL;
}
if (name != NULL)
{
result = lookup_symbol_in_static_block (name, block, domain);
if (result.symbol == NULL)
result = lookup_global_symbol (name, block, domain);
}
return result;
}
static const struct exp_descriptor exp_descriptor_rust =
{
rust_print_subexp,
rust_operator_length,
rust_operator_check,
rust_op_name,
rust_dump_subexp_body,
rust_evaluate_subexp
};
Move filename extensions into language_defn This moves filename extensions from a function in symfile.c out to each language_defn. I think this is an improvement because it means less digging around when writing a new language port. 2016-06-23 Tom Tromey <tom@tromey.com> * ada-lang.c (ada_extensions): New array. (ada_language_defn): Use it. * c-lang.c (c_extensions): New array. (c_language_defn): Use it. (cplus_extensions): New array. (cplus_language_defn): Use it. (asm_extensions): New array. (asm_language_defn): Use it. (minimal_language_defn): Update. * d-lang.c (d_extensions): New array. (d_language_defn): Use it. * f-lang.c (f_extensions): New array. (f_language_defn): Use it. * go-lang.c (go_language_defn): Update. * jv-lang.c (java_extensions): New array. (java_language_defn): Use it. * language.c (add_language): Call add_filename_language. (unknown_language_defn, auto_language_defn, local_language_defn): Update. * language.h (struct language_defn) <la_filename_extensions>: New field. * m2-lang.c (m2_language_defn): Update. * objc-lang.c (objc_extensions): New array. (objc_language_defn): Use it. * opencl-lang.c (opencl_language_defn): Update. * p-lang.c (p_extensions): New array. (pascal_language_defn): Use it. * rust-lang.c (rust_extensions): New array. (rust_language_defn): Use it. * symfile.c (add_filename_language): No longer static. Make "ext" const. (init_filename_language_table): Remove. (_initialize_symfile): Update. * symfile.h (add_filename_language): Declare.
2016-05-26 18:33:28 +02:00
static const char *rust_extensions[] =
{
".rs", NULL
};
gdb: Represent all languages as sub-classes of language_defn This commit converts all languages to sub-classes of a language_defn base class. The motivation for this change is to make it easier to add new methods onto languages without having to update all of the individual language structures. In the future it might be possible to move more things, like expression parsing, into the language class(es) for better encapsulation, however I have no plans to tackle this in the short term. This commit sets up a strategy for transitioning from the current language system, where each language is an instance of the language_defn structure, to the class hierarchy system. The plan is to rename the existing language_defn into language_data, and make this a base class for the new language_defn class, something like this: struct language_data { ... old language_defn fields here ... }; struct language_defn : public language_data { language_defn (const language_data d) : language_data (d) { .... } }; Then each existing language, for example ada_language_defn can be converted into an instance of language_data, and passed into the constructor of a new language class, something like this: language_data ada_language_data = { ... old ada_language_defn values here ... }; struct ada_language : public language_defn { ada_language (ada_language_data) { .... } }; What this means is that immediately after the conversion nothing much changes. Every language is now its own class, but all the old language fields still exist and can be accessed in the same way. In later commits I will convert function pointers from the old language_defn structure into real class methods on language_defn, with overrides on sub-classes where needed. At this point I imagine that those fields of the old language_defn structure that contained only data will probably remain as data fields within the new language_data base structure, it is only the methods that I plan to change initially. I tweaked how we manage the list of languages a bit, each language is now registered as it is created, and this resulted in a small number of changes in language.c. Most of the changes in the *-lang.c files are identical. There should be no user visible changes after this commit. gdb/ChangeLog: * gdb/ada-lang.c (ada_language_defn): Convert to... (ada_language_data): ...this. (class ada_language): New class. (ada_language_defn): New static global. * gdb/c-lang.c (c_language_defn): Convert to... (c_language_data): ...this. (class c_language): New class. (c_language_defn): New static global. (cplus_language_defn): Convert to... (cplus_language_data): ...this. (class cplus_language): New class. (cplus_language_defn): New static global. (asm_language_defn): Convert to... (asm_language_data): ...this. (class asm_language): New class. (asm_language_defn): New static global. (minimal_language_defn): Convert to... (minimal_language_data): ...this. (class minimal_language): New class. (minimal_language_defn): New static global. * gdb/d-lang.c (d_language_defn): Convert to... (d_language_data): ...this. (class d_language): New class. (d_language_defn): New static global. * gdb/f-lang.c (f_language_defn): Convert to... (f_language_data): ...this. (class f_language): New class. (f_language_defn): New static global. * gdb/go-lang.c (go_language_defn): Convert to... (go_language_data): ...this. (class go_language): New class. (go_language_defn): New static global. * gdb/language.c (unknown_language_defn): Remove declaration. (current_language): Initialize to nullptr, real initialization is moved to _initialize_language. (languages): Delete global. (language_defn::languages): Define. (set_language_command): Use language_defn::languages. (set_language): Likewise. (range_error): Likewise. (language_enum): Likewise. (language_def): Likewise. (add_set_language_command): Use language_def::languages for the language list, and language_def to lookup language pointers. (skip_language_trampoline): Use language_defn::languages. (unknown_language_defn): Convert to... (unknown_language_data): ...this. (class unknown_language): New class. (unknown_language_defn): New static global. (auto_language_defn): Convert to... (auto_language_data): ...this. (class auto_language): New class. (auto_language_defn): New static global. (language_gdbarch_post_init): Use language_defn::languages. (_initialize_language): Initialize current_language. * gdb/language.h (struct language_defn): Rename to... (struct language_data): ...this. (struct language_defn): New. (auto_language_defn): Delete. (unknown_language_defn): Delete. (minimal_language_defn): Delete. (ada_language_defn): Delete. (asm_language_defn): Delete. (c_language_defn): Delete. (cplus_language_defn): Delete. (d_language_defn): Delete. (f_language_defn): Delete. (go_language_defn): Delete. (m2_language_defn): Delete. (objc_language_defn): Delete. (opencl_language_defn): Delete. (pascal_language_defn): Delete. (rust_language_defn): Delete. * gdb/m2-lang.c (m2_language_defn): Convert to... (m2_language_data): ...this. (class m2_language): New class. (m2_language_defn): New static global. * gdb/objc-lang.c (objc_language_defn): Convert to... (objc_language_data): ...this. (class objc_language): New class. (objc_language_defn): New static global. * gdb/opencl-lang.c (opencl_language_defn): Convert to... (opencl_language_data): ...this. (class opencl_language): New class. (opencl_language_defn): New static global. * gdb/p-lang.c (pascal_language_defn): Convert to... (pascal_language_data): ...this. (class pascal_language): New class. (pascal_language_defn): New static global. * gdb/rust-exp.y (rust_lex_tests): Use language_def to find language pointer, update comment format. * gdb/rust-lang.c (rust_language_defn): Convert to... (rust_language_data): ...this. (class rust_language): New class. (rust_language_defn): New static global.
2020-05-01 13:16:58 +02:00
/* Constant data representing the Rust language. */
extern const struct language_data rust_language_data =
{
"rust",
"Rust",
language_rust,
range_check_on,
case_sensitive_on,
array_row_major,
macro_expansion_no,
Move filename extensions into language_defn This moves filename extensions from a function in symfile.c out to each language_defn. I think this is an improvement because it means less digging around when writing a new language port. 2016-06-23 Tom Tromey <tom@tromey.com> * ada-lang.c (ada_extensions): New array. (ada_language_defn): Use it. * c-lang.c (c_extensions): New array. (c_language_defn): Use it. (cplus_extensions): New array. (cplus_language_defn): Use it. (asm_extensions): New array. (asm_language_defn): Use it. (minimal_language_defn): Update. * d-lang.c (d_extensions): New array. (d_language_defn): Use it. * f-lang.c (f_extensions): New array. (f_language_defn): Use it. * go-lang.c (go_language_defn): Update. * jv-lang.c (java_extensions): New array. (java_language_defn): Use it. * language.c (add_language): Call add_filename_language. (unknown_language_defn, auto_language_defn, local_language_defn): Update. * language.h (struct language_defn) <la_filename_extensions>: New field. * m2-lang.c (m2_language_defn): Update. * objc-lang.c (objc_extensions): New array. (objc_language_defn): Use it. * opencl-lang.c (opencl_language_defn): Update. * p-lang.c (p_extensions): New array. (pascal_language_defn): Use it. * rust-lang.c (rust_extensions): New array. (rust_language_defn): Use it. * symfile.c (add_filename_language): No longer static. Make "ext" const. (init_filename_language_table): Remove. (_initialize_symfile): Update. * symfile.h (add_filename_language): Declare.
2016-05-26 18:33:28 +02:00
rust_extensions,
&exp_descriptor_rust,
rust_parse,
null_post_parser,
rust_printchar, /* Print a character constant */
rust_printstr, /* Function to print string constant */
rust_emitchar, /* Print a single char */
rust_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
problem looking up some symbols when they have a linkage name This patch fixes a known failure in gdb.ada/maint_with_ada.exp (maintenance check-psymtabs). Another way to witness the same issue is by considering the following Ada declarations... type Wrapper is record A : Integer; end record; u00045 : constant Wrapper := (A => 16#060287af#); pragma Export (C, u00045, "symada__cS"); ... which declares a variable name "u00045" but with a linkage name which is "symada__cS". This variable is a record with one component, the Ada equivalent of a struct with one field in C. Trying to print that variable's value currently yields: (gdb) p /x <symada__cS> 'symada(char, signed)' has unknown type; cast it to its declared type This indicates that GDB was only able to find the minimal symbol, but not the full symbol. The expected output is: (gdb) print /x <symada__cS> $1 = (a => 0x60287af) The error message gives a hint about what's happening: We processed the symbol through gdb_demangle, which in the case of this particular symbol name, ends up matching the C++ naming scheme. As a result, the demangler transforms our symbol name into 'symada(char, signed)', thus breaking Ada lookups. This patch fixes the issue by first introducing a new language_defn attribute called la_store_sym_names_in_linkage_form_p, which is a boolean to be set to true for the few languages that do not want their symbols to have their names stored in demangled form, and false otherwise. We then use this language attribute to skip the call to gdb_demangle for all languages whose la_store_sym_names_in_linkage_form_p is true. In terms of the selection of languages for which the new attribute is set to true, the selection errs on the side of preserving the existing behavior, and only changes the behavior for the languages where we are certain storing symbol names in demangling form is not needed. It is conceivable that other languages might be in the same situation, but I not knowing in detail the symbol name enconding strategy, I decided to play it safe and let other language maintainers potentially adjust their language if it makes sense to do so. gdb/ChangeLog: PR gdb/22670 * dwarf2read.c (dwarf2_physname): Do not return the demangled symbol name if the CU's language stores symbol names in linkage format. * language.h (struct language_defn) <la_store_sym_names_in_linkage_form_p>: New field. Adjust all instances of this struct. gdb/testsuite/ChangeLog: * gdb.ada/maint_with_ada.exp: Remove PR gdb/22670 setup_kfail. * gdb.ada/notcplusplus: New testcase. * gdb.base/c-linkage-name.c: New file. * gdb.base/c-linkage-name.exp: New testcase. Tested on x86_64-linux. This also passes AdaCore's internal GDB testsuite.
2018-03-27 15:57:16 +02:00
false, /* la_store_sym_names_in_linkage_form_p */
rust_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
&default_varobj_ops,
gdb: Introduce new language field la_is_string_type_p This commit is preparation work for the next commit, and by itself makes no user visible change to GDB. I've split this work into a separate commit in order to make code review easier. This commit adds a new field 'la_is_string_type_p' to the language struct, this predicate will return true if a type is a string type for the given language. Some languages already have a "is this a string" predicate that I was able to reuse, while for other languages I've had to add a new predicate. In this case I took inspiration from the value printing code for that language - what different conditions would result in printing something as a string. A default "is this a string" method has also been added that looks for TYPE_CODE_STRING, this is the fallback I've used for a couple of languages. In this commit I add the new field and initialise it for each language, however at this stage the new field is never used. gdb/ChangeLog: * ada-lang.c (ada_language_defn): Initialise new field. * c-lang.c (c_is_string_type_p): New function. (c_language_defn): Initialise new field. (cplus_language_defn): Initialise new field. (asm_language_defn): Initialise new field. (minimal_language_defn): Initialise new field. * c-lang.h (c_is_string_type_p): Declare new function. * d-lang.c (d_language_defn): Initialise new field. * f-lang.c (f_is_string_type_p): New function. (f_language_defn): Initialise new field. * go-lang.c (go_is_string_type_p): New function. (go_language_defn): Initialise new field. * language.c (default_is_string_type_p): New function. (unknown_language_defn): Initialise new field. (auto_language_defn): Initialise new field. * language.h (struct language_defn) <la_is_string_type_p>: New member variable. (default_is_string_type_p): Declare new function. * m2-lang.c (m2_language_defn): Initialise new field. * objc-lang.c (objc_language_defn): Initialise new field. * opencl-lang.c (opencl_language_defn): Initialise new field. * p-lang.c (pascal_is_string_type_p): New function. (pascal_language_defn): Initialise new field. * rust-lang.c (rust_is_string_type_p): New function. (rust_language_defn): Initialise new field.
2019-04-10 00:06:41 +02:00
rust_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */
};
gdb: Represent all languages as sub-classes of language_defn This commit converts all languages to sub-classes of a language_defn base class. The motivation for this change is to make it easier to add new methods onto languages without having to update all of the individual language structures. In the future it might be possible to move more things, like expression parsing, into the language class(es) for better encapsulation, however I have no plans to tackle this in the short term. This commit sets up a strategy for transitioning from the current language system, where each language is an instance of the language_defn structure, to the class hierarchy system. The plan is to rename the existing language_defn into language_data, and make this a base class for the new language_defn class, something like this: struct language_data { ... old language_defn fields here ... }; struct language_defn : public language_data { language_defn (const language_data d) : language_data (d) { .... } }; Then each existing language, for example ada_language_defn can be converted into an instance of language_data, and passed into the constructor of a new language class, something like this: language_data ada_language_data = { ... old ada_language_defn values here ... }; struct ada_language : public language_defn { ada_language (ada_language_data) { .... } }; What this means is that immediately after the conversion nothing much changes. Every language is now its own class, but all the old language fields still exist and can be accessed in the same way. In later commits I will convert function pointers from the old language_defn structure into real class methods on language_defn, with overrides on sub-classes where needed. At this point I imagine that those fields of the old language_defn structure that contained only data will probably remain as data fields within the new language_data base structure, it is only the methods that I plan to change initially. I tweaked how we manage the list of languages a bit, each language is now registered as it is created, and this resulted in a small number of changes in language.c. Most of the changes in the *-lang.c files are identical. There should be no user visible changes after this commit. gdb/ChangeLog: * gdb/ada-lang.c (ada_language_defn): Convert to... (ada_language_data): ...this. (class ada_language): New class. (ada_language_defn): New static global. * gdb/c-lang.c (c_language_defn): Convert to... (c_language_data): ...this. (class c_language): New class. (c_language_defn): New static global. (cplus_language_defn): Convert to... (cplus_language_data): ...this. (class cplus_language): New class. (cplus_language_defn): New static global. (asm_language_defn): Convert to... (asm_language_data): ...this. (class asm_language): New class. (asm_language_defn): New static global. (minimal_language_defn): Convert to... (minimal_language_data): ...this. (class minimal_language): New class. (minimal_language_defn): New static global. * gdb/d-lang.c (d_language_defn): Convert to... (d_language_data): ...this. (class d_language): New class. (d_language_defn): New static global. * gdb/f-lang.c (f_language_defn): Convert to... (f_language_data): ...this. (class f_language): New class. (f_language_defn): New static global. * gdb/go-lang.c (go_language_defn): Convert to... (go_language_data): ...this. (class go_language): New class. (go_language_defn): New static global. * gdb/language.c (unknown_language_defn): Remove declaration. (current_language): Initialize to nullptr, real initialization is moved to _initialize_language. (languages): Delete global. (language_defn::languages): Define. (set_language_command): Use language_defn::languages. (set_language): Likewise. (range_error): Likewise. (language_enum): Likewise. (language_def): Likewise. (add_set_language_command): Use language_def::languages for the language list, and language_def to lookup language pointers. (skip_language_trampoline): Use language_defn::languages. (unknown_language_defn): Convert to... (unknown_language_data): ...this. (class unknown_language): New class. (unknown_language_defn): New static global. (auto_language_defn): Convert to... (auto_language_data): ...this. (class auto_language): New class. (auto_language_defn): New static global. (language_gdbarch_post_init): Use language_defn::languages. (_initialize_language): Initialize current_language. * gdb/language.h (struct language_defn): Rename to... (struct language_data): ...this. (struct language_defn): New. (auto_language_defn): Delete. (unknown_language_defn): Delete. (minimal_language_defn): Delete. (ada_language_defn): Delete. (asm_language_defn): Delete. (c_language_defn): Delete. (cplus_language_defn): Delete. (d_language_defn): Delete. (f_language_defn): Delete. (go_language_defn): Delete. (m2_language_defn): Delete. (objc_language_defn): Delete. (opencl_language_defn): Delete. (pascal_language_defn): Delete. (rust_language_defn): Delete. * gdb/m2-lang.c (m2_language_defn): Convert to... (m2_language_data): ...this. (class m2_language): New class. (m2_language_defn): New static global. * gdb/objc-lang.c (objc_language_defn): Convert to... (objc_language_data): ...this. (class objc_language): New class. (objc_language_defn): New static global. * gdb/opencl-lang.c (opencl_language_defn): Convert to... (opencl_language_data): ...this. (class opencl_language): New class. (opencl_language_defn): New static global. * gdb/p-lang.c (pascal_language_defn): Convert to... (pascal_language_data): ...this. (class pascal_language): New class. (pascal_language_defn): New static global. * gdb/rust-exp.y (rust_lex_tests): Use language_def to find language pointer, update comment format. * gdb/rust-lang.c (rust_language_defn): Convert to... (rust_language_data): ...this. (class rust_language): New class. (rust_language_defn): New static global.
2020-05-01 13:16:58 +02:00
/* Class representing the Rust language. */
class rust_language : public language_defn
{
public:
rust_language ()
: language_defn (language_rust, rust_language_data)
{ /* Nothing. */ }
gdb: Convert language la_language_arch_info field to a method This commit changes the language_data::la_language_arch_info function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_arch_info): Delete function, move implementation to... (ada_language::language_arch_info): ...here, a new member function. (ada_language_data): Delete la_language_arch_info. * c-lang.c (c_language_data): Likewise. (c_language::language_arch_info): New member function. (cplus_language_arch_info): Delete function, move implementation to... (cplus_language::language_arch_info): ...here, a new member function. (cplus_language_data): Delete la_language_arch_info. (asm_language_data): Likewise. (asm_language::language_arch_info): New member function. (minimal_language_data): Delete la_language_arch_info. (minimal_language::language_arch_info): New member function. * d-lang.c (d_language_arch_info): Delete function, move implementation to... (d_language::language_arch_info): ...here, a new member function. (d_language_data): Delete la_language_arch_info. * f-lang.c (f_language_arch_info): Delete function, move implementation to... (f_language::language_arch_info): ...here, a new member function. (f_language_data): Delete la_language_arch_info. * go-lang.c (go_language_arch_info): Delete function, move implementation to... (go_language::language_arch_info): ...here, a new member function. (go_language_data): Delete la_language_arch_info. * language.c (unknown_language_data): Likewise. (unknown_language::language_arch_info): New member function. (auto_language_data): Delete la_language_arch_info. (auto_language::language_arch_info): New member function. (language_gdbarch_post_init): Update call to la_language_arch_info. * language.h (language_data): Delete la_language_arch_info function pointer. (language_defn::language_arch_info): New function. * m2-lang.c (m2_language_arch_info): Delete function, move implementation to... (m2_language::language_arch_info): ...here, a new member function. (m2_language_data): Delete la_language_arch_info. * objc-lang.c (objc_language_arch_info): Delete function, move implementation to... (objc_language::language_arch_info): ...here, a new member function. (objc_language_data): Delete la_language_arch_info. * opencl-lang.c (opencl_language_arch_info): Delete function, move implementation to... (opencl_language::language_arch_info): ...here, a new member function. (opencl_language_data): Delete la_language_arch_info. * p-lang.c (pascal_language_arch_info): Delete function, move implementation to... (pascal_language::language_arch_info): ...here, a new member function. (pascal_language_data): Delete la_language_arch_info. * rust-lang.c (rust_language_arch_info): Delete function, move implementation to... (rust_language::language_arch_info): ...here, a new member function. (rust_language_data): Delete la_language_arch_info.
2020-05-01 22:51:15 +02:00
/* See language.h. */
void language_arch_info (struct gdbarch *gdbarch,
struct language_arch_info *lai) const override
{
const struct builtin_type *builtin = builtin_type (gdbarch);
struct type **types
= GDBARCH_OBSTACK_CALLOC (gdbarch, nr_rust_primitive_types + 1,
struct type *);
types[rust_primitive_bool] = arch_boolean_type (gdbarch, 8, 1, "bool");
types[rust_primitive_char] = arch_character_type (gdbarch, 32, 1, "char");
types[rust_primitive_i8] = arch_integer_type (gdbarch, 8, 0, "i8");
types[rust_primitive_u8] = arch_integer_type (gdbarch, 8, 1, "u8");
types[rust_primitive_i16] = arch_integer_type (gdbarch, 16, 0, "i16");
types[rust_primitive_u16] = arch_integer_type (gdbarch, 16, 1, "u16");
types[rust_primitive_i32] = arch_integer_type (gdbarch, 32, 0, "i32");
types[rust_primitive_u32] = arch_integer_type (gdbarch, 32, 1, "u32");
types[rust_primitive_i64] = arch_integer_type (gdbarch, 64, 0, "i64");
types[rust_primitive_u64] = arch_integer_type (gdbarch, 64, 1, "u64");
unsigned int length = 8 * TYPE_LENGTH (builtin->builtin_data_ptr);
types[rust_primitive_isize] = arch_integer_type (gdbarch, length, 0, "isize");
types[rust_primitive_usize] = arch_integer_type (gdbarch, length, 1, "usize");
types[rust_primitive_f32] = arch_float_type (gdbarch, 32, "f32",
floatformats_ieee_single);
types[rust_primitive_f64] = arch_float_type (gdbarch, 64, "f64",
floatformats_ieee_double);
types[rust_primitive_unit] = arch_integer_type (gdbarch, 0, 1, "()");
struct type *tem = make_cv_type (1, 0, types[rust_primitive_u8], NULL);
types[rust_primitive_str] = rust_slice_type ("&str", tem,
types[rust_primitive_usize]);
lai->primitive_type_vector = types;
lai->bool_type_default = types[rust_primitive_bool];
lai->string_char_type = types[rust_primitive_u8];
}
gdb: Convert language la_sniff_from_mangled_name field to a method This commit changes the language_data::la_sniff_from_mangled_name function pointer member variable into a member function of language_defn. Previously the la_sniff_from_mangled_name pointer was NULL for some languages, however, all uses of this function pointer were through the function language_sniff_from_mangled_name which provided a default implementation. This default implementation now becomes the implementation in the base class language_defn, which is then overridden as required in various language sub-classes. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_sniff_from_mangled_name): Delete function, implementation moves to... (ada_language::sniff_from_mangled_name): ...here. Update return type. (ada_language_data): Delete la_sniff_from_mangled_name initializer. * c-lang.c (c_language_data): Likewise. (cplus_language_data): Likewise. (cplus_language::sniff_from_mangled_name): New member function, implementation taken from gdb_sniff_from_mangled_name. (asm_language_data): Delete la_sniff_from_mangled_name initializer. (minimal_language_data): Likewise. * cp-support.c (gdb_sniff_from_mangled_name): Delete, implementation moves to cplus_language::sniff_from_mangled_name. * cp-support.h (gdb_sniff_from_mangled_name): Delete declaration. * d-lang.c (d_sniff_from_mangled_name): Delete, implementation moves to... (d_language::sniff_from_mangled_name): ...here. (d_language_data): Delete la_sniff_from_mangled_name initializer. * f-lang.c (f_language_data): Likewise. * go-lang.c (go_sniff_from_mangled_name): Delete, implementation moves to... (go_language::sniff_from_mangled_name): ...here. (go_language_data): Delete la_sniff_from_mangled_name initializer. * language.c (language_sniff_from_mangled_name): Delete. (unknown_language_data): Delete la_sniff_from_mangled_name initializer. (auto_language_data): Likewise. * language.h (language_data): Delete la_sniff_from_mangled_name field. (language_defn::sniff_from_mangled_name): New function. (language_sniff_from_mangled_name): Delete declaration. * m2-lang.c (m2_language_data): Delete la_sniff_from_mangled_name field. * objc-lang.c (objc_sniff_from_mangled_name): Delete, implementation moves to... (objc_language::sniff_from_mangled_name): ...here. (objc_language_data): Delete la_sniff_from_mangled_name initializer. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_sniff_from_mangled_name): Delete, implementation moves to... (rust_language::sniff_from_mangled_name): ...here. (rust_language_data): Delete la_sniff_from_mangled_name initializer. * symtab.c (symbol_find_demangled_name): Call sniff_from_mangled_name member function.
2020-05-13 19:04:30 +02:00
/* See language.h. */
bool sniff_from_mangled_name (const char *mangled,
char **demangled) const override
{
*demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
return *demangled != NULL;
}
gdb: Convert language la_print_type field to a method This commit changes the language_data::la_print_type function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete la_print_type initializer. (ada_language::print_type): New member function. * c-lang.c (c_language_data): Delete la_print_type initializer. (c_language::print_type): New member function. (cplus_language_data): Delete la_print_type initializer. (cplus_language::print_type): New member function. (asm_language_data): Delete la_print_type initializer. (asm_language::print_type): New member function. (minimal_language_data): Delete la_print_type initializer. (minimal_language::print_type): New member function. * d-lang.c (d_language_data): Delete la_print_type initializer. (d_language::print_type): New member function. * f-lang.c (f_language_data): Delete la_print_type initializer. (f_language::print_type): New member function. * go-lang.c (go_language_data): Delete la_print_type initializer. (go_language::print_type): New member function. * language.c (unk_lang_print_type): Delete. (unknown_language_data): Delete la_print_type initializer. (unknown_language::print_type): New member function. (auto_language_data): Delete la_print_type initializer. (auto_language::print_type): New member function. * language.h (language_data): Delete la_print_type field. (language_defn::print_type): New function. (LA_PRINT_TYPE): Update. * m2-lang.c (m2_language_data): Delete la_print_type initializer. (m2_language::print_type): New member function. * objc-lang.c (objc_language_data): Delete la_print_type initializer. (objc_language::print_type): New member function. * opencl-lang.c (opencl_print_type): Delete, implementation moved to opencl_language::print_type. (opencl_language_data): Delete la_print_type initializer. (opencl_language::print_type): New member function, implementation from opencl_print_type. * p-lang.c (pascal_language_data): Delete la_print_type initializer. (pascal_language::print_type): New member function. * rust-lang.c (rust_print_type): Delete, implementation moved to rust_language::print_type. (rust_language_data): Delete la_print_type initializer. (rust_language::print_type): New member function, implementation from rust_print_type.
2020-05-14 19:41:39 +02:00
/* See language.h. */
gdb: Convert language la_demangle field to a method This commit changes the language_data::la_demangle function pointer member variable into a member function of language_defn. The only slightly "weird" change in this commit is in f-lang.c, where I have given the Fortran language a demangle method that is identical to the default language_defn::demangle. The only reason for this is to give me somewhere to copy the comment that was previously embedded within the f_language_data structure. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete la_demangle initializer. (ada_language::demangle): New member function. * c-lang.c (c_language_data): Delete la_demangle initializer. (cplus_language_data): Delete la_demangle initializer. (cplus_language::demangle): New member function. (asm_language_data): Delete la_demangle initializer. (minimal_language_data): Delete la_demangle initializer. * d-lang.c (d_language_data): Delete la_demangle initializer. (d_language::demangle): New member function. * f-lang.c (f_language_data): Delete la_demangle initializer. (f_language::demangle): New member function. * go-lang.c (go_language_data): Delete la_demangle initializer. (go_language::demangle): New member function. * language.c (language_demangle): Update. (unk_lang_demangle): Delete. (unknown_language_data): Delete la_demangle initializer. (unknown_language::demangle): New member function. (auto_language_data): Delete la_demangle initializer. (auto_language::demangle): New member function. * language.h (language_data): Delete la_demangle field. (language_defn::demangle): New function. * m2-lang.c (m2_language_data): Delete la_demangle initializer. * objc-lang.c (objc_language_data): Delete la_demangle initializer. (objc_language::demangle): New member function. * opencl-lang.c (opencl_language_data): Delete la_demangle initializer. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_language_data): Likewise. (rust_language::demangle): New member functi
2020-05-14 20:03:45 +02:00
char *demangle (const char *mangled, int options) const override
{
return gdb_demangle (mangled, options);
}
/* See language.h. */
gdb: Convert language la_print_type field to a method This commit changes the language_data::la_print_type function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete la_print_type initializer. (ada_language::print_type): New member function. * c-lang.c (c_language_data): Delete la_print_type initializer. (c_language::print_type): New member function. (cplus_language_data): Delete la_print_type initializer. (cplus_language::print_type): New member function. (asm_language_data): Delete la_print_type initializer. (asm_language::print_type): New member function. (minimal_language_data): Delete la_print_type initializer. (minimal_language::print_type): New member function. * d-lang.c (d_language_data): Delete la_print_type initializer. (d_language::print_type): New member function. * f-lang.c (f_language_data): Delete la_print_type initializer. (f_language::print_type): New member function. * go-lang.c (go_language_data): Delete la_print_type initializer. (go_language::print_type): New member function. * language.c (unk_lang_print_type): Delete. (unknown_language_data): Delete la_print_type initializer. (unknown_language::print_type): New member function. (auto_language_data): Delete la_print_type initializer. (auto_language::print_type): New member function. * language.h (language_data): Delete la_print_type field. (language_defn::print_type): New function. (LA_PRINT_TYPE): Update. * m2-lang.c (m2_language_data): Delete la_print_type initializer. (m2_language::print_type): New member function. * objc-lang.c (objc_language_data): Delete la_print_type initializer. (objc_language::print_type): New member function. * opencl-lang.c (opencl_print_type): Delete, implementation moved to opencl_language::print_type. (opencl_language_data): Delete la_print_type initializer. (opencl_language::print_type): New member function, implementation from opencl_print_type. * p-lang.c (pascal_language_data): Delete la_print_type initializer. (pascal_language::print_type): New member function. * rust-lang.c (rust_print_type): Delete, implementation moved to rust_language::print_type. (rust_language_data): Delete la_print_type initializer. (rust_language::print_type): New member function, implementation from rust_print_type.
2020-05-14 19:41:39 +02:00
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
{
print_offset_data podata;
rust_internal_print_type (type, varstring, stream, show, level,
flags, false, &podata);
}
gdb: Convert language la_watch_location_expression field to a method This commit changes the language_data::la_watch_location_expression function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_watch_location_expression): Rename to ada_language::watch_location_expression. (ada_language_data): Delete la_watch_location_expression initializer. (ada_language::watch_location_expression): New member function, implementation from ada_watch_location_expression. * breakpoint.c (watch_command_1): Update call to watch_location_expression. * c-lang.c (c_watch_location_expression): Rename to language_defn::watch_location_expression. (c_language_data): Delete la_watch_location_expression initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * c-lang.h (c_watch_location_expression): Delete declaration. * d-lang.c (d_language_data): Delete la_watch_location_expression initializer. * f-lang.c (f_language_data): Likewise. * go-lang.c (go_language_data): Likewise. * language.c (language_defn::watch_location_expression): Member function implementation from c_watch_location_expression. (unknown_language_data): Delete la_watch_location_expression initializer. (auto_language_data): Likewise. * language.h (language_data): Delete la_watch_location_expression field. (language_defn::watch_location_expression): Declare new member function. * m2-lang.c (m2_language_data): Delete la_watch_location_expression initializer. * objc-lang.c (objc_language_data): Likewise. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_watch_location_expression): Rename to rust_language::watch_location_expression. (rust_language_data): Delete la_watch_location_expression initializer. (rust_language::watch_location_expression): New member function, implementation from rust_watch_location_expression.
2020-06-01 16:06:43 +02:00
/* See language.h. */
gdb::unique_xmalloc_ptr<char> watch_location_expression
(struct type *type, CORE_ADDR addr) const override
{
type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
std::string name = type_to_string (type);
return gdb::unique_xmalloc_ptr<char>
(xstrprintf ("*(%s as *mut %s)", core_addr_to_string (addr),
name.c_str ()));
}
gdb: Convert language la_value_print_inner field to a method This commit changes the language_data::la_value_print_inner function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete la_value_print_inner initializer. (ada_language::value_print_inner): New member function. * c-lang.c (c_language_data): Delete la_value_print_inner initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. (d_language::value_print_inner): New member function. * f-lang.c (f_language_data): Delete la_value_print_inner initializer. (f_language::value_print_inner): New member function. * f-lang.h (f_value_print_innner): Rename to... (f_value_print_inner): ...this (note spelling of 'inner'). * f-valprint.c (f_value_print_innner): Rename to... (f_value_print_inner): ...this (note spelling of 'inner'). * go-lang.c (go_language_data): Delete la_value_print_inner initializer. (go_language::value_print_inner): New member function. * language.c (language_defn::value_print_inner): Define new member function. (unk_lang_value_print_inner): Delete. (unknown_language_data): Delete la_value_print_inner initializer. (unknown_language::value_print_inner): New member function. (auto_language_data): Delete la_value_print_inner initializer. (auto_language::value_print_inner): New member function. * language.h (language_data): Delete la_value_print_inner field. (language_defn::value_print_inner): Delcare new member function. * m2-lang.c (m2_language_data): Delete la_value_print_inner initializer. (m2_language::value_print_inner): New member function. * objc-lang.c (objc_language_data): Delete la_value_print_inner initializer. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. (pascal_language::value_print_inner): New member function. * rust-lang.c (rust_language_data): Delete la_value_print_inner initializer. (rust_language::value_print_inner): New member function. * valprint.c (do_val_print): Update call to value_print_inner.
2020-06-01 16:36:30 +02:00
/* See language.h. */
void value_print_inner
(struct value *val, struct ui_file *stream, int recurse,
const struct value_print_options *options) const override
{
return rust_value_print_inner (val, stream, recurse, options);
}
gdb: Represent all languages as sub-classes of language_defn This commit converts all languages to sub-classes of a language_defn base class. The motivation for this change is to make it easier to add new methods onto languages without having to update all of the individual language structures. In the future it might be possible to move more things, like expression parsing, into the language class(es) for better encapsulation, however I have no plans to tackle this in the short term. This commit sets up a strategy for transitioning from the current language system, where each language is an instance of the language_defn structure, to the class hierarchy system. The plan is to rename the existing language_defn into language_data, and make this a base class for the new language_defn class, something like this: struct language_data { ... old language_defn fields here ... }; struct language_defn : public language_data { language_defn (const language_data d) : language_data (d) { .... } }; Then each existing language, for example ada_language_defn can be converted into an instance of language_data, and passed into the constructor of a new language class, something like this: language_data ada_language_data = { ... old ada_language_defn values here ... }; struct ada_language : public language_defn { ada_language (ada_language_data) { .... } }; What this means is that immediately after the conversion nothing much changes. Every language is now its own class, but all the old language fields still exist and can be accessed in the same way. In later commits I will convert function pointers from the old language_defn structure into real class methods on language_defn, with overrides on sub-classes where needed. At this point I imagine that those fields of the old language_defn structure that contained only data will probably remain as data fields within the new language_data base structure, it is only the methods that I plan to change initially. I tweaked how we manage the list of languages a bit, each language is now registered as it is created, and this resulted in a small number of changes in language.c. Most of the changes in the *-lang.c files are identical. There should be no user visible changes after this commit. gdb/ChangeLog: * gdb/ada-lang.c (ada_language_defn): Convert to... (ada_language_data): ...this. (class ada_language): New class. (ada_language_defn): New static global. * gdb/c-lang.c (c_language_defn): Convert to... (c_language_data): ...this. (class c_language): New class. (c_language_defn): New static global. (cplus_language_defn): Convert to... (cplus_language_data): ...this. (class cplus_language): New class. (cplus_language_defn): New static global. (asm_language_defn): Convert to... (asm_language_data): ...this. (class asm_language): New class. (asm_language_defn): New static global. (minimal_language_defn): Convert to... (minimal_language_data): ...this. (class minimal_language): New class. (minimal_language_defn): New static global. * gdb/d-lang.c (d_language_defn): Convert to... (d_language_data): ...this. (class d_language): New class. (d_language_defn): New static global. * gdb/f-lang.c (f_language_defn): Convert to... (f_language_data): ...this. (class f_language): New class. (f_language_defn): New static global. * gdb/go-lang.c (go_language_defn): Convert to... (go_language_data): ...this. (class go_language): New class. (go_language_defn): New static global. * gdb/language.c (unknown_language_defn): Remove declaration. (current_language): Initialize to nullptr, real initialization is moved to _initialize_language. (languages): Delete global. (language_defn::languages): Define. (set_language_command): Use language_defn::languages. (set_language): Likewise. (range_error): Likewise. (language_enum): Likewise. (language_def): Likewise. (add_set_language_command): Use language_def::languages for the language list, and language_def to lookup language pointers. (skip_language_trampoline): Use language_defn::languages. (unknown_language_defn): Convert to... (unknown_language_data): ...this. (class unknown_language): New class. (unknown_language_defn): New static global. (auto_language_defn): Convert to... (auto_language_data): ...this. (class auto_language): New class. (auto_language_defn): New static global. (language_gdbarch_post_init): Use language_defn::languages. (_initialize_language): Initialize current_language. * gdb/language.h (struct language_defn): Rename to... (struct language_data): ...this. (struct language_defn): New. (auto_language_defn): Delete. (unknown_language_defn): Delete. (minimal_language_defn): Delete. (ada_language_defn): Delete. (asm_language_defn): Delete. (c_language_defn): Delete. (cplus_language_defn): Delete. (d_language_defn): Delete. (f_language_defn): Delete. (go_language_defn): Delete. (m2_language_defn): Delete. (objc_language_defn): Delete. (opencl_language_defn): Delete. (pascal_language_defn): Delete. (rust_language_defn): Delete. * gdb/m2-lang.c (m2_language_defn): Convert to... (m2_language_data): ...this. (class m2_language): New class. (m2_language_defn): New static global. * gdb/objc-lang.c (objc_language_defn): Convert to... (objc_language_data): ...this. (class objc_language): New class. (objc_language_defn): New static global. * gdb/opencl-lang.c (opencl_language_defn): Convert to... (opencl_language_data): ...this. (class opencl_language): New class. (opencl_language_defn): New static global. * gdb/p-lang.c (pascal_language_defn): Convert to... (pascal_language_data): ...this. (class pascal_language): New class. (pascal_language_defn): New static global. * gdb/rust-exp.y (rust_lex_tests): Use language_def to find language pointer, update comment format. * gdb/rust-lang.c (rust_language_defn): Convert to... (rust_language_data): ...this. (class rust_language): New class. (rust_language_defn): New static global.
2020-05-01 13:16:58 +02:00
};
/* Single instance of the Rust language class. */
static rust_language rust_language_defn;