1 /* Copyright (C) 2012-2018 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #ifndef IN_PROCESS_AGENT
24 target_desc::~target_desc ()
26 xfree ((char *) arch);
27 xfree ((char *) osabi);
30 bool target_desc::operator== (const target_desc &other) const
32 if (reg_defs != other.reg_defs)
35 /* Compare expedite_regs. */
37 for (; expedite_regs[i] != NULL; i++)
39 if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
42 if (other.expedite_regs[i] != NULL)
50 void target_desc::accept (tdesc_element_visitor &v) const
52 #ifndef IN_PROCESS_AGENT
55 for (const tdesc_feature_up &feature : features)
63 init_target_desc (struct target_desc *tdesc)
67 /* Go through all the features and populate reg_defs. */
68 for (const tdesc_feature_up &feature : tdesc->features)
69 for (const tdesc_reg_up &treg : feature->registers)
71 int regnum = treg->target_regnum;
73 /* Register number will increase (possibly with gaps) or be zero. */
74 gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
77 tdesc->reg_defs.resize (regnum, reg (offset));
79 tdesc->reg_defs.emplace_back (treg->name.c_str (), offset,
81 offset += treg->bitsize;
84 tdesc->registers_size = offset / 8;
86 /* Make sure PBUFSIZ is large enough to hold a full register
88 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
92 allocate_target_description (void)
94 return new target_desc ();
97 #ifndef IN_PROCESS_AGENT
99 static const struct target_desc default_description {};
102 copy_target_description (struct target_desc *dest,
103 const struct target_desc *src)
105 dest->reg_defs = src->reg_defs;
106 dest->expedite_regs = src->expedite_regs;
107 dest->registers_size = src->registers_size;
108 dest->xmltarget = src->xmltarget;
111 const struct target_desc *
112 current_target_desc (void)
114 if (current_thread == NULL)
115 return &default_description;
117 return current_process ()->tdesc;
120 /* See common/tdesc.h. */
123 tdesc_architecture_name (const struct target_desc *target_desc)
125 return target_desc->arch;
128 /* See common/tdesc.h. */
131 set_tdesc_architecture (struct target_desc *target_desc,
134 target_desc->arch = xstrdup (name);
137 /* See common/tdesc.h. */
140 tdesc_osabi_name (const struct target_desc *target_desc)
142 return target_desc->osabi;
145 /* See common/tdesc.h. */
148 set_tdesc_osabi (struct target_desc *target_desc, const char *name)
150 target_desc->osabi = xstrdup (name);
153 /* See common/tdesc.h. */
156 tdesc_get_features_xml (const target_desc *tdesc)
158 /* Either .xmltarget or .features is not NULL. */
159 gdb_assert (tdesc->xmltarget != NULL
160 || (!tdesc->features.empty ()
161 && tdesc->arch != NULL));
163 if (tdesc->xmltarget == NULL)
165 std::string buffer ("@");
166 print_xml_feature v (&buffer);
168 tdesc->xmltarget = xstrdup (buffer.c_str ());
171 return tdesc->xmltarget;
175 /* See common/tdesc.h. */
177 struct tdesc_feature *
178 tdesc_create_feature (struct target_desc *tdesc, const char *name)
180 struct tdesc_feature *new_feature = new tdesc_feature (name);
181 tdesc->features.emplace_back (new_feature);