]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/target-descriptions.c
1 /* Target description support for GDB.
3 Copyright (C) 2006, 2007 Free Software Foundation, Inc.
5 Contributed by CodeSourcery.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
25 #include "arch-utils.h"
27 #include "target-descriptions.h"
30 #include "gdb_assert.h"
34 typedef struct property
39 DEF_VEC_O(property_s
);
43 /* Any architecture-specific properties specified by the target. */
44 VEC(property_s
) *properties
;
47 /* Global state. These variables are associated with the current
48 target; if GDB adds support for multiple simultaneous targets, then
49 these variables should become target-specific data. */
51 /* A flag indicating that a description has already been fetched from
52 the current target, so it should not be queried again. */
54 static int target_desc_fetched
;
56 /* The description fetched from the current target, or NULL if the
57 current target did not supply any description. Only valid when
58 target_desc_fetched is set. Only the description initialization
59 code should access this; normally, the description should be
60 accessed through the gdbarch object. */
62 static const struct target_desc
*current_target_desc
;
64 /* Fetch the current target's description, and switch the current
65 architecture to one which incorporates that description. */
68 target_find_description (void)
70 /* If we've already fetched a description from the target, don't do
71 it again. This allows a target to fetch the description early,
72 during its to_open or to_create_inferior, if it needs extra
73 information about the target to initialize. */
74 if (target_desc_fetched
)
77 /* The current architecture should not have any target description
78 specified. It should have been cleared, e.g. when we
79 disconnected from the previous target. */
80 gdb_assert (gdbarch_target_desc (current_gdbarch
) == NULL
);
82 current_target_desc
= target_read_description (¤t_target
);
84 /* If a non-NULL description was returned, then update the current
86 if (current_target_desc
)
88 struct gdbarch_info info
;
90 gdbarch_info_init (&info
);
91 info
.target_desc
= current_target_desc
;
92 if (!gdbarch_update_p (info
))
93 warning (_("Could not use target-supplied description"));
96 /* Now that we know this description is usable, record that we
98 target_desc_fetched
= 1;
101 /* Discard any description fetched from the current target, and switch
102 the current architecture to one with no target description. */
105 target_clear_description (void)
107 struct gdbarch_info info
;
109 if (!target_desc_fetched
)
112 target_desc_fetched
= 0;
113 current_target_desc
= NULL
;
115 gdbarch_info_init (&info
);
116 if (!gdbarch_update_p (info
))
117 internal_error (__FILE__
, __LINE__
,
118 _("Could not remove target-supplied description"));
121 /* Return the global current target description. This should only be
122 used by gdbarch initialization code; most access should be through
123 an existing gdbarch. */
125 const struct target_desc
*
126 target_current_description (void)
128 if (target_desc_fetched
)
129 return current_target_desc
;
134 /* Return the string value of a property named KEY, or NULL if the
135 property was not specified. */
138 tdesc_property (const struct target_desc
*target_desc
, const char *key
)
140 struct property
*prop
;
143 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
145 if (strcmp (prop
->key
, key
) == 0)
151 /* Methods for constructing a target description. */
154 allocate_target_description (void)
156 return XZALLOC (struct target_desc
);
160 set_tdesc_property (struct target_desc
*target_desc
,
161 const char *key
, const char *value
)
163 struct property
*prop
, new_prop
;
166 gdb_assert (key
!= NULL
&& value
!= NULL
);
168 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
170 if (strcmp (prop
->key
, key
) == 0)
171 internal_error (__FILE__
, __LINE__
,
172 _("Attempted to add duplicate property \"%s\""), key
);
175 new_prop
.value
= value
;
176 VEC_safe_push (property_s
, target_desc
->properties
, &new_prop
);