From: Luis Machado Date: Wed, 6 May 2020 16:41:48 +0000 (-0300) Subject: [Morello] Capability address_class support and testcase X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=efb06fe149c75d41f09201026c774943b5c7e871;p=thirdparty%2Fbinutils-gdb.git [Morello] Capability address_class support and testcase Handle the new address class type for Morello, which modifies regular pointers and makes them 16 bytes in size. gdb/ChangeLog: 2020-10-20 Luis Machado * aarch64-tdep.c (aarch64_address_class_type_flags) (aarch64_address_class_type_flags_to_name) (aarch64_address_class_name_to_type_flags): New functions. (aarch64_gdbarch_init): Register address class hooks. gdb/testsuite/ChangeLog: 2020-10-20 Luis Machado * gdb.dwarf2/dw2-capability.exp: New test. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8c634d9fa9d..e44d615fe3f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2020-10-20 Luis Machado + + * aarch64-tdep.c (aarch64_address_class_type_flags) + (aarch64_address_class_type_flags_to_name) + (aarch64_address_class_name_to_type_flags): New functions. + (aarch64_gdbarch_init): Register address class hooks. + 2020-10-20 Luis Machado * aarch64-linux-nat.c: Include arch/aarch64-cap-linux.h. diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index c9c9e262dd4..d9b55fdbdd0 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3370,6 +3370,54 @@ aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum) return 0; } +/* Implementation of `address_class_type_flags' gdbarch method. + + This method maps DW_AT_address_class attributes to a + type_instance_flag_value. */ + +static type_instance_flags +aarch64_address_class_type_flags (int byte_size, int dwarf2_addr_class) +{ + /* The value 1 of the DW_AT_address_class attribute corresponds to the + __capability qualifier, meaning a capability for Morello. */ + + if (dwarf2_addr_class == 1) + return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; + return 0; +} + +/* Implementation of `address_class_type_flags_to_name' gdbarch method. + + Convert a type_instance_flag_value to an address space qualifier. */ + +static const char* +aarch64_address_class_type_flags_to_name (struct gdbarch *gdbarch, + type_instance_flags type_flags) +{ + if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1) + return "__capability"; + else + return NULL; +} + +/* Implementation of `address_class_name_to_type_flags' gdbarch method. + + Convert an address space qualifier to a type_instance_flag_value. */ + +static bool +aarch64_address_class_name_to_type_flags (struct gdbarch *gdbarch, + const char* name, + type_instance_flags *type_flags_ptr) +{ + if (strcmp (name, "__capability") == 0) + { + *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; + return true; + } + else + return false; +} + /* Initialize the current architecture based on INFO. If possible, re-use an architecture from ARCHES, which is a list of architectures already created during this debugging session. @@ -3640,6 +3688,17 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) register_aarch64_ravenscar_ops (gdbarch); + /* Set address class hooks for capabilities. */ + if (feature_capability) + { + set_gdbarch_address_class_type_flags + (gdbarch, aarch64_address_class_type_flags); + set_gdbarch_address_class_name_to_type_flags + (gdbarch, aarch64_address_class_name_to_type_flags); + set_gdbarch_address_class_type_flags_to_name + (gdbarch, aarch64_address_class_type_flags_to_name); + } + return gdbarch; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 8cc9fdaa471..82afea8d82c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-10-20 Luis Machado + + * gdb.dwarf2/dw2-capability.exp: New test. + 2020-10-20 Luis Machado * gdb.arch/aarch64-morello-captypes.c: New file. diff --git a/gdb/testsuite/gdb.dwarf2/dw2-capability.exp b/gdb/testsuite/gdb.dwarf2/dw2-capability.exp new file mode 100644 index 00000000000..5d60bd5ec0c --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-capability.exp @@ -0,0 +1,152 @@ +# Copyright 2018-2020 Free Software Foundation, Inc. + +# 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 . +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile main.c capability-dw.S + +# Make some DWARF for the test. + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile + + cu {} { + DW_TAG_compile_unit { + {DW_AT_language @DW_LANG_C_plus_plus} + {DW_AT_name dw2-capability.c} + {DW_AT_comp_dir /tmp} + } { + declare_labels itype cap_type ptr_type \ + intcap_type intcap_ptr_type uintcap_type uintcap_ptr_type \ + var_a_label var_b_label var_c_label \ + var_d_label var_e_label var_f_label var_g_label + + intcap_type: DW_TAG_base_type { + {DW_AT_byte_size 16 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_CHERI_signed_intcap} + {DW_AT_name __intcap_t} + {DW_AT_alignment 16 DW_FORM_sdata} + } + + uintcap_type: DW_TAG_base_type { + {DW_AT_byte_size 16 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_CHERI_unsigned_intcap} + {DW_AT_name __uintcap_t} + {DW_AT_alignment 16 DW_FORM_sdata} + } + + itype: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name int} + {DW_AT_alignment 4 DW_FORM_sdata} + } + + cap_type: DW_TAG_pointer_type { + {DW_AT_byte_size 16 DW_FORM_sdata} + {DW_AT_type :$itype} + {DW_AT_alignment 16 DW_FORM_sdata} + {DW_AT_address_class 1 DW_FORM_sdata} + } + + intcap_ptr_type: DW_TAG_pointer_type { + {DW_AT_byte_size 16 DW_FORM_sdata} + {DW_AT_type :$intcap_type} + {DW_AT_alignment 16 DW_FORM_sdata} + {DW_AT_address_class 1 DW_FORM_sdata} + } + + uintcap_ptr_type: DW_TAG_pointer_type { + {DW_AT_byte_size 16 DW_FORM_sdata} + {DW_AT_type :$uintcap_type} + {DW_AT_alignment 16 DW_FORM_sdata} + {DW_AT_address_class 1 DW_FORM_sdata} + } + + ptr_type: DW_TAG_pointer_type { + {DW_AT_byte_size 8 DW_FORM_sdata} + {DW_AT_type :$itype} + {DW_AT_alignment 8 DW_FORM_sdata} + {DW_AT_address_class 0 DW_FORM_sdata} + } + + var_a_label: DW_TAG_variable { + {DW_AT_name "var_a"} + {DW_AT_type :${cap_type}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 0xdeadbeef DW_FORM_sdata} + } + + var_b_label: DW_TAG_variable { + {DW_AT_name "var_b"} + {DW_AT_type :${ptr_type}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 0xdeadbeef DW_FORM_sdata} + } + + var_c_label: DW_TAG_variable { + {DW_AT_name "var_c"} + {DW_AT_type :${itype}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 0xdeadbeef DW_FORM_sdata} + } + + var_d_label: DW_TAG_variable { + {DW_AT_name "var_d"} + {DW_AT_type :${intcap_type}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 0xdeadbeef DW_FORM_sdata} + } + + var_e_label: DW_TAG_variable { + {DW_AT_name "var_e"} + {DW_AT_type :${uintcap_type}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 0xdeadbeef DW_FORM_sdata} + } + + var_f_label: DW_TAG_variable { + {DW_AT_name "var_f"} + {DW_AT_type :${intcap_ptr_type}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 0xdeadbeef DW_FORM_sdata} + } + + var_g_label: DW_TAG_variable { + {DW_AT_name "var_g"} + {DW_AT_type :${uintcap_ptr_type}} + {DW_AT_external 1 DW_FORM_flag} + {DW_AT_const_value 0xdeadbeef DW_FORM_sdata} + } + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_test_no_output "set lang c++" +gdb_interact