GNU Binutils with patches for OS216
Révision | 21f6f5ffc652e116e518fee29ebdc8fbfeeaa734 (tree) |
---|---|
l'heure | 2018-01-23 21:37:41 |
Auteur | Philipp Rudo <prudo@linu...> |
Commiter | Andreas Arnez |
s390: Allocate gdbarch & tdep at start of gdbarch_init
Moving the allocation of gdbarch_tdep to the start of s390_gdbarch_init
allows us to use its fields for tracking the different features instead of
using separate variables. To make the code a little nicer move the actual
allocation and initialization to a separate function. Also move the
allocation of gdbarch to keep the two together.
gdb/ChangeLog:
* s390-linux-tdep (s390_abi_kind) <ABI_NONE>: New default field.
(gdbarch_tdep) <have_upper, have_vx>: New fields.
(s390_gdbarch_tdep_alloc): New function.
(s390_gdbarch_init): Allocate tdep at start and use its fields
instead of separate variables.
@@ -1,5 +1,13 @@ | ||
1 | 1 | 2018-01-23 Philipp Rudo <prudo@linux.vnet.ibm.com> |
2 | 2 | |
3 | + * s390-linux-tdep (s390_abi_kind) <ABI_NONE>: New default field. | |
4 | + (gdbarch_tdep) <have_upper, have_vx>: New fields. | |
5 | + (s390_gdbarch_tdep_alloc): New function. | |
6 | + (s390_gdbarch_init): Allocate tdep at start and use its fields | |
7 | + instead of separate variables. | |
8 | + | |
9 | +2018-01-23 Philipp Rudo <prudo@linux.vnet.ibm.com> | |
10 | + | |
3 | 11 | * s390-linux-tdep.c (s390_gdbarch_init): Remove duplicate checks |
4 | 12 | when looking for cached gdbarch and add comment for remaining. |
5 | 13 |
@@ -85,6 +85,7 @@ static char *s390_disassembler_options; | ||
85 | 85 | |
86 | 86 | enum s390_abi_kind |
87 | 87 | { |
88 | + ABI_NONE, | |
88 | 89 | ABI_LINUX_S390, |
89 | 90 | ABI_LINUX_ZSERIES |
90 | 91 | }; |
@@ -111,9 +112,11 @@ struct gdbarch_tdep | ||
111 | 112 | int cc_regnum; |
112 | 113 | int v0_full_regnum; |
113 | 114 | |
115 | + bool have_upper; | |
114 | 116 | int have_linux_v1; |
115 | 117 | int have_linux_v2; |
116 | 118 | int have_tdb; |
119 | + bool have_vx; | |
117 | 120 | bool have_gs; |
118 | 121 | }; |
119 | 122 |
@@ -7804,6 +7807,32 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep, | ||
7804 | 7807 | record_tdep->ioctl_FIOQSIZE = 0x545e; |
7805 | 7808 | } |
7806 | 7809 | |
7810 | +/* Allocate and initialize new gdbarch_tdep. Caller is responsible to free | |
7811 | + memory after use. */ | |
7812 | + | |
7813 | +static struct gdbarch_tdep * | |
7814 | +s390_gdbarch_tdep_alloc () | |
7815 | +{ | |
7816 | + struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep); | |
7817 | + | |
7818 | + tdep->abi = ABI_NONE; | |
7819 | + tdep->vector_abi = S390_VECTOR_ABI_NONE; | |
7820 | + | |
7821 | + tdep->gpr_full_regnum = -1; | |
7822 | + tdep->v0_full_regnum = -1; | |
7823 | + tdep->pc_regnum = -1; | |
7824 | + tdep->cc_regnum = -1; | |
7825 | + | |
7826 | + tdep->have_upper = false; | |
7827 | + tdep->have_linux_v1 = 0; | |
7828 | + tdep->have_linux_v2 = 0; | |
7829 | + tdep->have_tdb = 0; | |
7830 | + tdep->have_vx = false; | |
7831 | + tdep->have_gs = false; | |
7832 | + | |
7833 | + return tdep; | |
7834 | +} | |
7835 | + | |
7807 | 7836 | /* Set up gdbarch struct. */ |
7808 | 7837 | |
7809 | 7838 | static struct gdbarch * |
@@ -7811,16 +7840,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7811 | 7840 | { |
7812 | 7841 | const struct target_desc *tdesc = info.target_desc; |
7813 | 7842 | struct tdesc_arch_data *tdesc_data = NULL; |
7814 | - struct gdbarch *gdbarch; | |
7815 | - struct gdbarch_tdep *tdep; | |
7816 | - enum s390_abi_kind tdep_abi; | |
7817 | - enum s390_vector_abi_kind vector_abi; | |
7818 | - int have_upper = 0; | |
7819 | - int have_linux_v1 = 0; | |
7820 | - int have_linux_v2 = 0; | |
7821 | - int have_tdb = 0; | |
7822 | - int have_vx = 0; | |
7823 | - int have_gs = 0; | |
7824 | 7843 | int first_pseudo_reg, last_pseudo_reg; |
7825 | 7844 | static const char *const stap_register_prefixes[] = { "%", NULL }; |
7826 | 7845 | static const char *const stap_register_indirection_prefixes[] = { "(", |
@@ -7828,25 +7847,30 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7828 | 7847 | static const char *const stap_register_indirection_suffixes[] = { ")", |
7829 | 7848 | NULL }; |
7830 | 7849 | |
7850 | + struct gdbarch_tdep *tdep = s390_gdbarch_tdep_alloc (); | |
7851 | + struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep); | |
7852 | + | |
7831 | 7853 | /* Default ABI and register size. */ |
7832 | 7854 | switch (info.bfd_arch_info->mach) |
7833 | 7855 | { |
7834 | 7856 | case bfd_mach_s390_31: |
7835 | - tdep_abi = ABI_LINUX_S390; | |
7857 | + tdep->abi = ABI_LINUX_S390; | |
7836 | 7858 | break; |
7837 | 7859 | |
7838 | 7860 | case bfd_mach_s390_64: |
7839 | - tdep_abi = ABI_LINUX_ZSERIES; | |
7861 | + tdep->abi = ABI_LINUX_ZSERIES; | |
7840 | 7862 | break; |
7841 | 7863 | |
7842 | 7864 | default: |
7865 | + xfree (tdep); | |
7866 | + gdbarch_free (gdbarch); | |
7843 | 7867 | return NULL; |
7844 | 7868 | } |
7845 | 7869 | |
7846 | 7870 | /* Use default target description if none provided by the target. */ |
7847 | 7871 | if (!tdesc_has_registers (tdesc)) |
7848 | 7872 | { |
7849 | - if (tdep_abi == ABI_LINUX_S390) | |
7873 | + if (tdep->abi == ABI_LINUX_S390) | |
7850 | 7874 | tdesc = tdesc_s390_linux32; |
7851 | 7875 | else |
7852 | 7876 | tdesc = tdesc_s390x_linux64; |
@@ -7899,7 +7923,11 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7899 | 7923 | |
7900 | 7924 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.core"); |
7901 | 7925 | if (feature == NULL) |
7902 | - return NULL; | |
7926 | + { | |
7927 | + xfree (tdep); | |
7928 | + gdbarch_free (gdbarch); | |
7929 | + return NULL; | |
7930 | + } | |
7903 | 7931 | |
7904 | 7932 | tdesc_data = tdesc_data_alloc (); |
7905 | 7933 |
@@ -7916,7 +7944,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7916 | 7944 | } |
7917 | 7945 | else |
7918 | 7946 | { |
7919 | - have_upper = 1; | |
7947 | + tdep->have_upper = true; | |
7920 | 7948 | |
7921 | 7949 | for (i = 0; i < 16; i++) |
7922 | 7950 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
@@ -7932,6 +7960,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7932 | 7960 | if (feature == NULL) |
7933 | 7961 | { |
7934 | 7962 | tdesc_data_cleanup (tdesc_data); |
7963 | + xfree (tdep); | |
7964 | + gdbarch_free (gdbarch); | |
7935 | 7965 | return NULL; |
7936 | 7966 | } |
7937 | 7967 |
@@ -7945,6 +7975,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7945 | 7975 | if (feature == NULL) |
7946 | 7976 | { |
7947 | 7977 | tdesc_data_cleanup (tdesc_data); |
7978 | + xfree (tdep); | |
7979 | + gdbarch_free (gdbarch); | |
7948 | 7980 | return NULL; |
7949 | 7981 | } |
7950 | 7982 |
@@ -7961,13 +7993,13 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7961 | 7993 | |
7962 | 7994 | if (tdesc_numbered_register (feature, tdesc_data, |
7963 | 7995 | S390_LAST_BREAK_REGNUM, "last_break")) |
7964 | - have_linux_v1 = 1; | |
7996 | + tdep->have_linux_v1 = 1; | |
7965 | 7997 | |
7966 | 7998 | if (tdesc_numbered_register (feature, tdesc_data, |
7967 | 7999 | S390_SYSTEM_CALL_REGNUM, "system_call")) |
7968 | - have_linux_v2 = 1; | |
8000 | + tdep->have_linux_v2 = 1; | |
7969 | 8001 | |
7970 | - if (have_linux_v2 > have_linux_v1) | |
8002 | + if (tdep->have_linux_v2 > tdep->have_linux_v1) | |
7971 | 8003 | valid_p = 0; |
7972 | 8004 | } |
7973 | 8005 |
@@ -7979,7 +8011,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7979 | 8011 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
7980 | 8012 | S390_TDB_DWORD0_REGNUM + i, |
7981 | 8013 | tdb_regs[i]); |
7982 | - have_tdb = 1; | |
8014 | + tdep->have_tdb = 1; | |
7983 | 8015 | } |
7984 | 8016 | |
7985 | 8017 | /* Vector registers. */ |
@@ -7994,7 +8026,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
7994 | 8026 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
7995 | 8027 | S390_V16_REGNUM + i, |
7996 | 8028 | vxrs_high[i]); |
7997 | - have_vx = 1; | |
8029 | + tdep->have_vx = true; | |
7998 | 8030 | } |
7999 | 8031 | |
8000 | 8032 | /* Guarded-storage registers. */ |
@@ -8005,14 +8037,14 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
8005 | 8037 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
8006 | 8038 | S390_GSD_REGNUM + i, |
8007 | 8039 | gs_cb[i]); |
8008 | - have_gs = 1; | |
8040 | + tdep->have_gs = true; | |
8009 | 8041 | } |
8010 | 8042 | |
8011 | 8043 | /* Guarded-storage broadcast control. */ |
8012 | 8044 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gsbc"); |
8013 | 8045 | if (feature) |
8014 | 8046 | { |
8015 | - valid_p &= have_gs; | |
8047 | + valid_p &= tdep->have_gs; | |
8016 | 8048 | |
8017 | 8049 | for (i = 0; i < 3; i++) |
8018 | 8050 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
@@ -8023,20 +8055,21 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
8023 | 8055 | if (!valid_p) |
8024 | 8056 | { |
8025 | 8057 | tdesc_data_cleanup (tdesc_data); |
8058 | + xfree (tdep); | |
8059 | + gdbarch_free (gdbarch); | |
8026 | 8060 | return NULL; |
8027 | 8061 | } |
8028 | 8062 | } |
8029 | 8063 | |
8030 | 8064 | /* Determine vector ABI. */ |
8031 | - vector_abi = S390_VECTOR_ABI_NONE; | |
8032 | 8065 | #ifdef HAVE_ELF |
8033 | - if (have_vx | |
8066 | + if (tdep->have_vx | |
8034 | 8067 | && info.abfd != NULL |
8035 | 8068 | && info.abfd->format == bfd_object |
8036 | 8069 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
8037 | 8070 | && bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, |
8038 | 8071 | Tag_GNU_S390_ABI_Vector) == 2) |
8039 | - vector_abi = S390_VECTOR_ABI_128; | |
8072 | + tdep->vector_abi = S390_VECTOR_ABI_128; | |
8040 | 8073 | #endif |
8041 | 8074 | |
8042 | 8075 | /* Find a candidate among extant architectures. */ |
@@ -8044,29 +8077,21 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
8044 | 8077 | arches != NULL; |
8045 | 8078 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) |
8046 | 8079 | { |
8047 | - tdep = gdbarch_tdep (arches->gdbarch); | |
8048 | - if (!tdep) | |
8080 | + struct gdbarch_tdep *tmp = gdbarch_tdep (arches->gdbarch); | |
8081 | + if (!tmp) | |
8049 | 8082 | continue; |
8050 | 8083 | /* A program can 'choose' not to use the vector registers when they |
8051 | 8084 | are present. Leading to the same tdesc but different tdep and |
8052 | 8085 | thereby a different gdbarch. */ |
8053 | - if (tdep->vector_abi != vector_abi) | |
8086 | + if (tmp->vector_abi != tdep->vector_abi) | |
8054 | 8087 | continue; |
8055 | 8088 | if (tdesc_data != NULL) |
8056 | 8089 | tdesc_data_cleanup (tdesc_data); |
8090 | + xfree (tdep); | |
8091 | + gdbarch_free (gdbarch); | |
8057 | 8092 | return arches->gdbarch; |
8058 | 8093 | } |
8059 | 8094 | |
8060 | - /* Otherwise create a new gdbarch for the specified machine type. */ | |
8061 | - tdep = XCNEW (struct gdbarch_tdep); | |
8062 | - tdep->abi = tdep_abi; | |
8063 | - tdep->vector_abi = vector_abi; | |
8064 | - tdep->have_linux_v1 = have_linux_v1; | |
8065 | - tdep->have_linux_v2 = have_linux_v2; | |
8066 | - tdep->have_tdb = have_tdb; | |
8067 | - tdep->have_gs = have_gs; | |
8068 | - gdbarch = gdbarch_alloc (&info, tdep); | |
8069 | - | |
8070 | 8095 | set_gdbarch_believe_pcc_promotion (gdbarch, 0); |
8071 | 8096 | set_gdbarch_char_signed (gdbarch, 0); |
8072 | 8097 |
@@ -8118,14 +8143,12 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | ||
8118 | 8143 | /* Assign pseudo register numbers. */ |
8119 | 8144 | first_pseudo_reg = gdbarch_num_regs (gdbarch); |
8120 | 8145 | last_pseudo_reg = first_pseudo_reg; |
8121 | - tdep->gpr_full_regnum = -1; | |
8122 | - if (have_upper) | |
8146 | + if (tdep->have_upper) | |
8123 | 8147 | { |
8124 | 8148 | tdep->gpr_full_regnum = last_pseudo_reg; |
8125 | 8149 | last_pseudo_reg += 16; |
8126 | 8150 | } |
8127 | - tdep->v0_full_regnum = -1; | |
8128 | - if (have_vx) | |
8151 | + if (tdep->have_vx) | |
8129 | 8152 | { |
8130 | 8153 | tdep->v0_full_regnum = last_pseudo_reg; |
8131 | 8154 | last_pseudo_reg += 16; |