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 ()
28 xfree ((char *) arch
);
29 xfree ((char *) osabi
);
32 bool target_desc::operator== (const target_desc
&other
) const
34 if (reg_defs
!= other
.reg_defs
)
37 /* Compare expedite_regs. */
39 for (; expedite_regs
[i
] != NULL
; i
++)
41 if (strcmp (expedite_regs
[i
], other
.expedite_regs
[i
]) != 0)
44 if (other
.expedite_regs
[i
] != NULL
)
53 init_target_desc (struct target_desc
*tdesc
)
57 for (reg
®
: tdesc
->reg_defs
)
63 tdesc
->registers_size
= offset
/ 8;
65 /* Make sure PBUFSIZ is large enough to hold a full register
67 gdb_assert (2 * tdesc
->registers_size
+ 32 <= PBUFSIZ
);
71 allocate_target_description (void)
73 return new target_desc ();
76 #ifndef IN_PROCESS_AGENT
78 static const struct target_desc default_description
{};
81 copy_target_description (struct target_desc
*dest
,
82 const struct target_desc
*src
)
84 dest
->reg_defs
= src
->reg_defs
;
85 dest
->expedite_regs
= src
->expedite_regs
;
86 dest
->registers_size
= src
->registers_size
;
87 dest
->xmltarget
= src
->xmltarget
;
90 const struct target_desc
*
91 current_target_desc (void)
93 if (current_thread
== NULL
)
94 return &default_description
;
96 return current_process ()->tdesc
;
99 /* See common/tdesc.h. */
102 set_tdesc_architecture (struct target_desc
*target_desc
,
105 target_desc
->arch
= xstrdup (name
);
108 /* See common/tdesc.h. */
111 set_tdesc_osabi (struct target_desc
*target_desc
, const char *name
)
113 target_desc
->osabi
= xstrdup (name
);
116 /* Return a string which is of XML format, including XML target
117 description to be sent to GDB. */
120 tdesc_get_features_xml (target_desc
*tdesc
)
122 /* Either .xmltarget or .features is not NULL. */
123 gdb_assert (tdesc
->xmltarget
!= NULL
124 || (!tdesc
->features
.empty ()
125 && tdesc
->arch
!= NULL
));
127 if (tdesc
->xmltarget
== NULL
)
129 std::string
buffer ("@<?xml version=\"1.0\"?>");
131 buffer
+= "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
132 buffer
+= "<target>";
133 buffer
+= "<architecture>";
134 buffer
+= tdesc
->arch
;
135 buffer
+= "</architecture>";
137 if (tdesc
->osabi
!= nullptr)
140 buffer
+= tdesc
->osabi
;
141 buffer
+= "</osabi>";
145 for (const std::string
&xml
: tdesc
->features
)
147 buffer
+= "<xi:include href=\"";
152 buffer
+= "</target>";
154 tdesc
->xmltarget
= xstrdup (buffer
.c_str ());
157 return tdesc
->xmltarget
;
164 /* See common/tdesc.h. */
166 struct tdesc_feature
*
167 tdesc_create_feature (struct target_desc
*tdesc
, const char *name
,
170 #ifndef IN_PROCESS_AGENT
171 tdesc
->features
.emplace_back (xml
);
176 /* See common/tdesc.h. */
178 tdesc_type_with_fields
*
179 tdesc_create_flags (struct tdesc_feature
*feature
, const char *name
,
185 /* See common/tdesc.h. */
188 tdesc_add_flag (tdesc_type_with_fields
*type
, int start
,
189 const char *flag_name
)
192 /* See common/tdesc.h. */
195 tdesc_named_type (const struct tdesc_feature
*feature
, const char *id
)
200 /* See common/tdesc.h. */
202 tdesc_type_with_fields
*
203 tdesc_create_union (struct tdesc_feature
*feature
, const char *id
)
208 /* See common/tdesc.h. */
210 tdesc_type_with_fields
*
211 tdesc_create_struct (struct tdesc_feature
*feature
, const char *id
)
216 /* See common/tdesc.h. */
219 tdesc_create_reg (struct tdesc_feature
*feature
, const char *name
,
220 int regnum
, int save_restore
, const char *group
,
221 int bitsize
, const char *type
)
223 struct target_desc
*tdesc
= (struct target_desc
*) feature
;
225 gdb_assert (regnum
== 0 || regnum
>= tdesc
->reg_defs
.size ());
228 tdesc
->reg_defs
.resize (regnum
);
230 tdesc
->reg_defs
.emplace_back (name
, bitsize
);
233 /* See common/tdesc.h. */
236 tdesc_create_vector (struct tdesc_feature
*feature
, const char *name
,
237 struct tdesc_type
*field_type
, int count
)
243 tdesc_add_bitfield (tdesc_type_with_fields
*type
, const char *field_name
,
247 /* See common/tdesc.h. */
250 tdesc_add_field (tdesc_type_with_fields
*type
, const char *field_name
,
251 struct tdesc_type
*field_type
)
254 /* See common/tdesc.h. */
257 tdesc_set_struct_size (tdesc_type_with_fields
*type
, int size
)