1 # Architecture commands for GDB, the GNU debugger.
3 # Copyright (C) 1998-2024 Free Software Foundation, Inc.
5 # This file is part of GDB.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from typing
import List
, Optional
, Tuple
, Union
23 def join_type_and_name(t
: str, n
: str):
24 "Combine the type T and the name N into a C declaration."
25 if t
.endswith("*") or t
.endswith("&"):
31 def join_params(params
: List
[Tuple
[str, str]]):
32 """Given a sequence of (TYPE, NAME) pairs, generate a comma-separated
33 list of declarations."""
34 return ", ".join([join_type_and_name(p
[0], p
[1]) for p
in params
])
38 "Base class for all components."
44 printer
: Optional
[str] = None,
45 comment
: Optional
[str] = None,
46 predicate
: bool = False,
47 predefault
: Optional
[str] = None,
48 postdefault
: Optional
[str] = None,
49 invalid
: Union
[bool, str] = True,
50 params
: Optional
[List
[Tuple
[str, str]]] = None,
51 param_checks
: Optional
[List
[str]] = None,
52 result_checks
: Optional
[List
[str]] = None,
53 implement
: bool = True,
57 self
.printer
= printer
58 self
.comment
= comment
59 self
.predicate
= predicate
60 self
.predefault
= predefault
61 self
.postdefault
= postdefault
62 self
.invalid
= invalid
63 self
.params
= params
or []
64 self
.param_checks
= param_checks
65 self
.result_checks
= result_checks
66 self
.implement
= implement
68 components
.append(self
)
70 # It doesn't make sense to have a check of the result value
71 # for a function or method with void return type.
72 if self
.type == "void" and self
.result_checks
:
73 raise Exception("can't have result checks with a void return type")
75 def get_predicate(self
):
76 "Return the expression used for validity checking."
78 predicate
= f
"gdbarch->{self.name} != {self.predefault}"
80 predicate
= f
"gdbarch->{self.name} != NULL"
84 class Info(Component
):
85 "An Info component is copied from the gdbarch_info."
88 class Value(Component
):
89 "A Value component is just a data member."
96 comment
: Optional
[str] = None,
97 predicate
: bool = False,
98 predefault
: Optional
[str] = None,
99 postdefault
: Optional
[str] = None,
100 invalid
: Union
[bool, str] = True,
101 printer
: Optional
[str] = None,
108 predefault
=predefault
,
109 postdefault
=postdefault
,
115 class Function(Component
):
116 "A Function component is a function pointer member."
123 params
: List
[Tuple
[str, str]],
124 comment
: Optional
[str] = None,
125 predicate
: bool = False,
126 predefault
: Optional
[str] = None,
127 postdefault
: Optional
[str] = None,
128 invalid
: Union
[bool, str] = True,
129 printer
: Optional
[str] = None,
130 param_checks
: Optional
[List
[str]] = None,
131 result_checks
: Optional
[List
[str]] = None,
132 implement
: bool = True,
139 predefault
=predefault
,
140 postdefault
=postdefault
,
144 param_checks
=param_checks
,
145 result_checks
=result_checks
,
150 "Return the name of the function typedef to use."
151 return f
"gdbarch_{self.name}_ftype"
153 def param_list(self
):
154 "Return the formal parameter list as a string."
155 return join_params(self
.params
)
158 """Return the formal parameter list of the caller function,
159 as a string. This list includes the gdbarch."""
160 arch_arg
= ("struct gdbarch *", "gdbarch")
161 arch_tuple
= [arch_arg
]
162 return join_params(arch_tuple
+ list(self
.params
))
165 "Return the actual parameters to forward, as a string."
166 return ", ".join([p
[1] for p
in self
.params
])
169 class Method(Function
):
170 "A Method is like a Function but passes the gdbarch through."
172 def param_list(self
):
174 return self
.set_list()
178 result
= ["gdbarch"] + [p
[1] for p
in self
.params
]
179 return ", ".join(result
)
182 # All the components created in gdbarch-components.py.
183 components
: List
[Component
] = []