1 /* Copyright (C) 2012-2017 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/>. */
23 init_target_desc (struct target_desc
*tdesc
)
29 for (i
= 0; VEC_iterate (tdesc_reg_p
, tdesc
->reg_defs
, i
, reg
); i
++)
35 tdesc
->registers_size
= offset
/ 8;
37 /* Make sure PBUFSIZ is large enough to hold a full register
39 gdb_assert (2 * tdesc
->registers_size
+ 32 <= PBUFSIZ
);
42 #ifndef IN_PROCESS_AGENT
44 static const struct target_desc default_description
{};
47 copy_target_description (struct target_desc
*dest
,
48 const struct target_desc
*src
)
50 dest
->reg_defs
= src
->reg_defs
;
51 dest
->expedite_regs
= src
->expedite_regs
;
52 dest
->registers_size
= src
->registers_size
;
53 dest
->xmltarget
= src
->xmltarget
;
56 const struct target_desc
*
57 current_target_desc (void)
59 if (current_thread
== NULL
)
60 return &default_description
;
62 return current_process ()->tdesc
;
66 set_tdesc_architecture (struct target_desc
*target_desc
,
69 target_desc
->arch
= xstrdup (name
);
73 set_tdesc_osabi (struct target_desc
*target_desc
, const char *name
)
75 target_desc
->osabi
= xstrdup (name
);
78 /* Return a string which is of XML format, including XML target
79 description to be sent to GDB. */
82 tdesc_get_features_xml (target_desc
*tdesc
)
84 /* Either .xmltarget or .features is not NULL. */
85 gdb_assert (tdesc
->xmltarget
!= NULL
86 || (tdesc
->features
!= NULL
87 && tdesc
->arch
!= NULL
88 && tdesc
->osabi
!= NULL
));
90 if (tdesc
->xmltarget
== NULL
)
92 std::string
buffer ("@<?xml version=\"1.0\"?>");
94 buffer
+= "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
96 buffer
+= "<architecture>";
97 buffer
+= tdesc
->arch
;
98 buffer
+= "</architecture>";
101 buffer
+= tdesc
->osabi
;
102 buffer
+= "</osabi>";
106 for (int i
= 0; VEC_iterate (char_ptr
, tdesc
->features
, i
, xml
); i
++)
108 buffer
+= "<xi:include href=\"";
113 buffer
+= "</target>";
115 tdesc
->xmltarget
= xstrdup (buffer
.c_str ());
118 return tdesc
->xmltarget
;
125 /* See arch/tdesc.h. */
127 struct tdesc_feature
*
128 tdesc_create_feature (struct target_desc
*tdesc
, const char *name
,
131 #ifndef IN_PROCESS_AGENT
132 VEC_safe_push (char_ptr
, tdesc
->features
, xstrdup (xml
));
137 /* See arch/tdesc.h. */
140 tdesc_create_flags (struct tdesc_feature
*feature
, const char *name
,
146 /* See arch/tdesc.h. */
149 tdesc_add_flag (struct tdesc_type
*type
, int start
,
150 const char *flag_name
)
153 /* See arch/tdesc.h. */
156 tdesc_named_type (const struct tdesc_feature
*feature
, const char *id
)
161 /* See arch/tdesc.h. */
164 tdesc_create_union (struct tdesc_feature
*feature
, const char *id
)
169 /* See arch/tdesc.h. */
172 tdesc_create_struct (struct tdesc_feature
*feature
, const char *id
)
177 /* See arch/tdesc.h. */
180 tdesc_create_reg (struct tdesc_feature
*feature
, const char *name
,
181 int regnum
, int save_restore
, const char *group
,
182 int bitsize
, const char *type
)
184 struct target_desc
*tdesc
= (struct target_desc
*) feature
;
186 while (VEC_length (tdesc_reg_p
, tdesc
->reg_defs
) < regnum
)
188 struct reg
*reg
= XCNEW (struct reg
);
192 VEC_safe_push (tdesc_reg_p
, tdesc
->reg_defs
, reg
);
195 gdb_assert (regnum
== 0
196 || regnum
== VEC_length (tdesc_reg_p
, tdesc
->reg_defs
));
198 struct reg
*reg
= XCNEW (struct reg
);
202 VEC_safe_push (tdesc_reg_p
, tdesc
->reg_defs
, reg
);
205 /* See arch/tdesc.h. */
208 tdesc_create_vector (struct tdesc_feature
*feature
, const char *name
,
209 struct tdesc_type
*field_type
, int count
)
215 tdesc_add_bitfield (struct tdesc_type
*type
, const char *field_name
,
219 /* See arch/tdesc.h. */
222 tdesc_add_field (struct tdesc_type
*type
, const char *field_name
,
223 struct tdesc_type
*field_type
)
226 /* See arch/tdesc.h. */
229 tdesc_set_struct_size (struct tdesc_type
*type
, int size
)