Create xml from target descriptions
[deliverable/binutils-gdb.git] / gdb / gdbserver / tdesc.c
CommitLineData
e2882c85 1/* Copyright (C) 2012-2018 Free Software Foundation, Inc.
3aee8918
PA
2
3 This file is part of GDB.
4
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.
9
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.
14
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/>. */
17
18#include "server.h"
19#include "tdesc.h"
20#include "regdef.h"
21
d80e5242
AH
22#ifndef IN_PROCESS_AGENT
23
24target_desc::~target_desc ()
25{
d80e5242
AH
26 xfree ((char *) arch);
27 xfree ((char *) osabi);
d80e5242
AH
28}
29
30bool target_desc::operator== (const target_desc &other) const
31{
5cd3e386 32 if (reg_defs != other.reg_defs)
d80e5242
AH
33 return false;
34
d80e5242
AH
35 /* Compare expedite_regs. */
36 int i = 0;
37 for (; expedite_regs[i] != NULL; i++)
38 {
39 if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
40 return false;
41 }
42 if (other.expedite_regs[i] != NULL)
43 return false;
44
45 return true;
46}
47
48#endif
49
e98577a9
AH
50void target_desc::accept (tdesc_element_visitor &v) const
51{
52#ifndef IN_PROCESS_AGENT
53 v.visit_pre (this);
54
55 for (const tdesc_feature_up &feature : features)
56 feature->accept (v);
57
58 v.visit_post (this);
59#endif
60}
61
3aee8918
PA
62void
63init_target_desc (struct target_desc *tdesc)
64{
c4dfafab 65 int offset = 0;
3aee8918 66
ea3e7d71 67 /* Go through all the features and populate reg_defs. */
82ec9bc7
AH
68 for (const tdesc_feature_up &feature : tdesc->features)
69 for (const tdesc_reg_up &treg : feature->registers)
70 {
71 int regnum = treg->target_regnum;
ea3e7d71 72
82ec9bc7
AH
73 /* Register number will increase (possibly with gaps) or be zero. */
74 gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
ea3e7d71 75
82ec9bc7
AH
76 if (regnum != 0)
77 tdesc->reg_defs.resize (regnum, reg (offset));
ea3e7d71 78
82ec9bc7
AH
79 tdesc->reg_defs.emplace_back (treg->name.c_str (), offset,
80 treg->bitsize);
81 offset += treg->bitsize;
82 }
3aee8918
PA
83
84 tdesc->registers_size = offset / 8;
85
86 /* Make sure PBUFSIZ is large enough to hold a full register
87 packet. */
38e08fca 88 gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
3aee8918
PA
89}
90
5f035c07
YQ
91struct target_desc *
92allocate_target_description (void)
93{
94 return new target_desc ();
95}
96
3aee8918
PA
97#ifndef IN_PROCESS_AGENT
98
f49ff000 99static const struct target_desc default_description {};
3aee8918
PA
100
101void
102copy_target_description (struct target_desc *dest,
103 const struct target_desc *src)
104{
105 dest->reg_defs = src->reg_defs;
3aee8918
PA
106 dest->expedite_regs = src->expedite_regs;
107 dest->registers_size = src->registers_size;
108 dest->xmltarget = src->xmltarget;
109}
110
111const struct target_desc *
112current_target_desc (void)
113{
0bfdf32f 114 if (current_thread == NULL)
3aee8918
PA
115 return &default_description;
116
117 return current_process ()->tdesc;
118}
0abe8a89 119
f46cd62a 120/* See common/tdesc.h. */
5f035c07 121
d278f585
AH
122const char *
123tdesc_architecture_name (const struct target_desc *target_desc)
124{
125 return target_desc->arch;
126}
127
128/* See common/tdesc.h. */
129
0abe8a89
YQ
130void
131set_tdesc_architecture (struct target_desc *target_desc,
132 const char *name)
133{
134 target_desc->arch = xstrdup (name);
135}
136
f46cd62a 137/* See common/tdesc.h. */
5f035c07 138
d278f585
AH
139const char *
140tdesc_osabi_name (const struct target_desc *target_desc)
141{
142 return target_desc->osabi;
143}
144
145/* See common/tdesc.h. */
146
0abe8a89
YQ
147void
148set_tdesc_osabi (struct target_desc *target_desc, const char *name)
149{
150 target_desc->osabi = xstrdup (name);
151}
152
e98577a9 153/* See common/tdesc.h. */
0abe8a89
YQ
154
155const char *
e98577a9 156tdesc_get_features_xml (const target_desc *tdesc)
0abe8a89
YQ
157{
158 /* Either .xmltarget or .features is not NULL. */
159 gdb_assert (tdesc->xmltarget != NULL
17d08cd4 160 || (!tdesc->features.empty ()
1d0aa65c 161 && tdesc->arch != NULL));
0abe8a89
YQ
162
163 if (tdesc->xmltarget == NULL)
164 {
e98577a9
AH
165 std::string buffer ("@");
166 print_xml_feature v (&buffer);
167 tdesc->accept (v);
0abe8a89
YQ
168 tdesc->xmltarget = xstrdup (buffer.c_str ());
169 }
170
171 return tdesc->xmltarget;
172}
3aee8918 173#endif
f49ff000 174
f46cd62a 175/* See common/tdesc.h. */
f49ff000
YQ
176
177struct tdesc_feature *
0abe8a89
YQ
178tdesc_create_feature (struct target_desc *tdesc, const char *name,
179 const char *xml)
f49ff000 180{
82ec9bc7
AH
181 struct tdesc_feature *new_feature = new tdesc_feature
182 (xml != nullptr ? xml : name);
183 tdesc->features.emplace_back (new_feature);
184 return new_feature;
f49ff000 185}
This page took 0.411361 seconds and 4 git commands to generate.