1 /* Target description support for GDB.
4 Free Software Foundation, Inc.
6 Contributed by CodeSourcery.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
26 #include "arch-utils.h"
28 #include "target-descriptions.h"
31 #include "gdb_assert.h"
35 typedef struct property
40 DEF_VEC_O(property_s
);
44 /* Any architecture-specific properties specified by the target. */
45 VEC(property_s
) *properties
;
48 /* Global state. These variables are associated with the current
49 target; if GDB adds support for multiple simultaneous targets, then
50 these variables should become target-specific data. */
52 /* A flag indicating that a description has already been fetched from
53 the current target, so it should not be queried again. */
55 static int target_desc_fetched
;
57 /* The description fetched from the current target, or NULL if the
58 current target did not supply any description. Only valid when
59 target_desc_fetched is set. Only the description initialization
60 code should access this; normally, the description should be
61 accessed through the gdbarch object. */
63 static const struct target_desc
*current_target_desc
;
65 /* Fetch the current target's description, and switch the current
66 architecture to one which incorporates that description. */
69 target_find_description (void)
71 /* If we've already fetched a description from the target, don't do
72 it again. This allows a target to fetch the description early,
73 during its to_open or to_create_inferior, if it needs extra
74 information about the target to initialize. */
75 if (target_desc_fetched
)
78 /* The current architecture should not have any target description
79 specified. It should have been cleared, e.g. when we
80 disconnected from the previous target. */
81 gdb_assert (gdbarch_target_desc (current_gdbarch
) == NULL
);
83 current_target_desc
= target_read_description (¤t_target
);
85 /* If a non-NULL description was returned, then update the current
87 if (current_target_desc
)
89 struct gdbarch_info info
;
91 gdbarch_info_init (&info
);
92 info
.target_desc
= current_target_desc
;
93 if (!gdbarch_update_p (info
))
94 warning (_("Could not use target-supplied description"));
97 /* Now that we know this description is usable, record that we
99 target_desc_fetched
= 1;
102 /* Discard any description fetched from the current target, and switch
103 the current architecture to one with no target description. */
106 target_clear_description (void)
108 struct gdbarch_info info
;
110 if (!target_desc_fetched
)
113 target_desc_fetched
= 0;
114 current_target_desc
= NULL
;
116 gdbarch_info_init (&info
);
117 if (!gdbarch_update_p (info
))
118 internal_error (__FILE__
, __LINE__
,
119 _("Could not remove target-supplied description"));
122 /* Return the global current target description. This should only be
123 used by gdbarch initialization code; most access should be through
124 an existing gdbarch. */
126 const struct target_desc
*
127 target_current_description (void)
129 if (target_desc_fetched
)
130 return current_target_desc
;
135 /* Return the string value of a property named KEY, or NULL if the
136 property was not specified. */
139 tdesc_property (const struct target_desc
*target_desc
, const char *key
)
141 struct property
*prop
;
144 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
146 if (strcmp (prop
->key
, key
) == 0)
152 /* Methods for constructing a target description. */
155 allocate_target_description (void)
157 return XZALLOC (struct target_desc
);
161 set_tdesc_property (struct target_desc
*target_desc
,
162 const char *key
, const char *value
)
164 struct property
*prop
, new_prop
;
167 gdb_assert (key
!= NULL
&& value
!= NULL
);
169 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
171 if (strcmp (prop
->key
, key
) == 0)
172 internal_error (__FILE__
, __LINE__
,
173 _("Attempted to add duplicate property \"%s\""), key
);
176 new_prop
.value
= value
;
177 VEC_safe_push (property_s
, target_desc
->properties
, &new_prop
);
This page took 0.037428 seconds and 4 git commands to generate.