041d72be15cb92ad8558200d1cbbcfac9811a73f
[deliverable/binutils-gdb.git] / gdb / target-descriptions.c
1 /* Target description support for GDB.
2
3 Copyright (C) 2006
4 Free Software Foundation, Inc.
5
6 Contributed by CodeSourcery.
7
8 This file is part of GDB.
9
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.
14
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.
19
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. */
24
25 #include "defs.h"
26 #include "arch-utils.h"
27 #include "target.h"
28 #include "target-descriptions.h"
29
30 #include "gdb_assert.h"
31
32 /* Types. */
33
34 struct target_desc
35 {
36 };
37
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. */
41
42 /* A flag indicating that a description has already been fetched from
43 the current target, so it should not be queried again. */
44
45 static int target_desc_fetched;
46
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. */
52
53 static const struct target_desc *current_target_desc;
54
55 /* Fetch the current target's description, and switch the current
56 architecture to one which incorporates that description. */
57
58 void
59 target_find_description (void)
60 {
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)
66 return;
67
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);
72
73 current_target_desc = target_read_description (&current_target);
74
75 /* If a non-NULL description was returned, then update the current
76 architecture. */
77 if (current_target_desc)
78 {
79 struct gdbarch_info info;
80
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"));
85 }
86
87 /* Now that we know this description is usable, record that we
88 fetched it. */
89 target_desc_fetched = 1;
90 }
91
92 /* Discard any description fetched from the current target, and switch
93 the current architecture to one with no target description. */
94
95 void
96 target_clear_description (void)
97 {
98 struct gdbarch_info info;
99
100 if (!target_desc_fetched)
101 return;
102
103 target_desc_fetched = 0;
104 current_target_desc = NULL;
105
106 gdbarch_info_init (&info);
107 if (!gdbarch_update_p (info))
108 internal_error (__FILE__, __LINE__,
109 _("Could not remove target-supplied description"));
110 }
111
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. */
115
116 const struct target_desc *
117 target_current_description (void)
118 {
119 if (target_desc_fetched)
120 return current_target_desc;
121
122 return NULL;
123 }
124
125 /* Methods for constructing a target description. */
126
127 struct target_desc *
128 allocate_target_description (void)
129 {
130 return XZALLOC (struct target_desc);
131 }
This page took 0.031442 seconds and 3 git commands to generate.