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"
30 #include "gdb_assert.h"
38 /* Global state. These variables are associated with the current
39 target; if GDB adds support for multiple simultaneous targets, then
40 these variables should become target-specific data. */
42 /* A flag indicating that a description has already been fetched from
43 the current target, so it should not be queried again. */
45 static int target_desc_fetched
;
47 /* The description fetched from the current target, or NULL if the
48 current target did not supply any description. Only valid when
49 target_desc_fetched is set. Only the description initialization
50 code should access this; normally, the description should be
51 accessed through the gdbarch object. */
53 static const struct target_desc
*current_target_desc
;
55 /* Fetch the current target's description, and switch the current
56 architecture to one which incorporates that description. */
59 target_find_description (void)
61 /* If we've already fetched a description from the target, don't do
62 it again. This allows a target to fetch the description early,
63 during its to_open or to_create_inferior, if it needs extra
64 information about the target to initialize. */
65 if (target_desc_fetched
)
68 /* The current architecture should not have any target description
69 specified. It should have been cleared, e.g. when we
70 disconnected from the previous target. */
71 gdb_assert (gdbarch_target_desc (current_gdbarch
) == NULL
);
73 current_target_desc
= target_read_description (¤t_target
);
75 /* If a non-NULL description was returned, then update the current
77 if (current_target_desc
)
79 struct gdbarch_info info
;
81 gdbarch_info_init (&info
);
82 info
.target_desc
= current_target_desc
;
83 if (!gdbarch_update_p (info
))
84 warning (_("Could not use target-supplied description"));
87 /* Now that we know this description is usable, record that we
89 target_desc_fetched
= 1;
92 /* Discard any description fetched from the current target, and switch
93 the current architecture to one with no target description. */
96 target_clear_description (void)
98 struct gdbarch_info info
;
100 if (!target_desc_fetched
)
103 target_desc_fetched
= 0;
104 current_target_desc
= NULL
;
106 gdbarch_info_init (&info
);
107 if (!gdbarch_update_p (info
))
108 internal_error (__FILE__
, __LINE__
,
109 _("Could not remove target-supplied description"));
112 /* Return the global current target description. This should only be
113 used by gdbarch initialization code; most access should be through
114 an existing gdbarch. */
116 const struct target_desc
*
117 target_current_description (void)
119 if (target_desc_fetched
)
120 return current_target_desc
;
125 /* Methods for constructing a target description. */
128 allocate_target_description (void)
130 return XZALLOC (struct target_desc
);
This page took 0.049611 seconds and 4 git commands to generate.