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
)
51 init_target_desc (struct target_desc
*tdesc
)
55 /* Go through all the features and populate reg_defs. */
56 for (const tdesc_feature_up
&feature
: tdesc
->features
)
57 for (const tdesc_reg_up
&treg
: feature
->registers
)
59 int regnum
= treg
->target_regnum
;
61 /* Register number will increase (possibly with gaps) or be zero. */
62 gdb_assert (regnum
== 0 || regnum
>= tdesc
->reg_defs
.size ());
65 tdesc
->reg_defs
.resize (regnum
, reg (offset
));
67 tdesc
->reg_defs
.emplace_back (treg
->name
.c_str (), offset
,
69 offset
+= treg
->bitsize
;
72 tdesc
->registers_size
= offset
/ 8;
74 /* Make sure PBUFSIZ is large enough to hold a full register
76 gdb_assert (2 * tdesc
->registers_size
+ 32 <= PBUFSIZ
);
80 allocate_target_description (void)
82 return new target_desc ();
85 #ifndef IN_PROCESS_AGENT
87 static const struct target_desc default_description
{};
90 copy_target_description (struct target_desc
*dest
,
91 const struct target_desc
*src
)
93 dest
->reg_defs
= src
->reg_defs
;
94 dest
->expedite_regs
= src
->expedite_regs
;
95 dest
->registers_size
= src
->registers_size
;
96 dest
->xmltarget
= src
->xmltarget
;
99 const struct target_desc
*
100 current_target_desc (void)
102 if (current_thread
== NULL
)
103 return &default_description
;
105 return current_process ()->tdesc
;
108 /* See common/tdesc.h. */
111 set_tdesc_architecture (struct target_desc
*target_desc
,
114 target_desc
->arch
= xstrdup (name
);
117 /* See common/tdesc.h. */
120 set_tdesc_osabi (struct target_desc
*target_desc
, const char *name
)
122 target_desc
->osabi
= xstrdup (name
);
125 /* Return a string which is of XML format, including XML target
126 description to be sent to GDB. */
129 tdesc_get_features_xml (target_desc
*tdesc
)
131 /* Either .xmltarget or .features is not NULL. */
132 gdb_assert (tdesc
->xmltarget
!= NULL
133 || (!tdesc
->features
.empty ()
134 && tdesc
->arch
!= NULL
));
136 if (tdesc
->xmltarget
== NULL
)
138 std::string
buffer ("@<?xml version=\"1.0\"?>");
140 buffer
+= "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
141 buffer
+= "<target>";
142 buffer
+= "<architecture>";
143 buffer
+= tdesc
->arch
;
144 buffer
+= "</architecture>";
146 if (tdesc
->osabi
!= nullptr)
149 buffer
+= tdesc
->osabi
;
150 buffer
+= "</osabi>";
153 for (const tdesc_feature_up
&feature
: tdesc
->features
)
155 buffer
+= "<xi:include href=\"";
156 buffer
+= feature
->name
;
160 buffer
+= "</target>";
162 tdesc
->xmltarget
= xstrdup (buffer
.c_str ());
165 return tdesc
->xmltarget
;
169 /* See common/tdesc.h. */
171 struct tdesc_feature
*
172 tdesc_create_feature (struct target_desc
*tdesc
, const char *name
,
175 struct tdesc_feature
*new_feature
= new tdesc_feature
176 (xml
!= nullptr ? xml
: name
);
177 tdesc
->features
.emplace_back (new_feature
);
181 /* See common/tdesc.h. */
183 tdesc_type_with_fields
*
184 tdesc_create_flags (struct tdesc_feature
*feature
, const char *name
,
190 /* See common/tdesc.h. */
193 tdesc_add_flag (tdesc_type_with_fields
*type
, int start
,
194 const char *flag_name
)
197 /* See common/tdesc.h. */
200 tdesc_named_type (const struct tdesc_feature
*feature
, const char *id
)
205 /* See common/tdesc.h. */
207 tdesc_type_with_fields
*
208 tdesc_create_union (struct tdesc_feature
*feature
, const char *id
)
213 /* See common/tdesc.h. */
215 tdesc_type_with_fields
*
216 tdesc_create_struct (struct tdesc_feature
*feature
, const char *id
)
221 /* See common/tdesc.h. */
224 tdesc_create_vector (struct tdesc_feature
*feature
, const char *name
,
225 struct tdesc_type
*field_type
, int count
)
231 tdesc_add_bitfield (tdesc_type_with_fields
*type
, const char *field_name
,
235 /* See common/tdesc.h. */
238 tdesc_add_field (tdesc_type_with_fields
*type
, const char *field_name
,
239 struct tdesc_type
*field_type
)
242 /* See common/tdesc.h. */
245 tdesc_set_struct_size (tdesc_type_with_fields
*type
, int size
)