aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch.py
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-02-23 18:18:45 +0000
committerAndrew Burgess <aburgess@redhat.com>2023-03-13 21:51:03 +0000
commit74b1406e90bfa156aa324f9ecde424a5488cac51 (patch)
tree65f9d585cfdce73bfaadcdb31e72f2cc84935792 /gdb/gdbarch.py
parent0605df704d6f3c28c47bf6cd623bb237919e17a1 (diff)
downloadgdb-74b1406e90bfa156aa324f9ecde424a5488cac51.zip
gdb-74b1406e90bfa156aa324f9ecde424a5488cac51.tar.gz
gdb-74b1406e90bfa156aa324f9ecde424a5488cac51.tar.bz2
gdb/gdbarch: split postdefault setup from invalid check in gdbarch.py
Restructure how gdbarch.py generates the verify_gdbarch function. Previously the postdefault handling was bundled together with the validation. This means that a field can't have both a postdefault, and set its invalid attribute to a string. This doesn't seem reasonable to me, I see no reason why a field can't have both a postdefault (used when the tdep doesn't set the field), and an invalid expression, which can be used to validate the value that a tdep might set. In this commit I restructure the verify_gdbarch generation code to allow the above, there is no change in the actual generated code in this commit, that will come in later commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/gdbarch.py')
-rwxr-xr-xgdb/gdbarch.py42
1 files changed, 27 insertions, 15 deletions
diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
index 93b1e8b..5437c82 100755
--- a/gdb/gdbarch.py
+++ b/gdb/gdbarch.py
@@ -203,35 +203,47 @@ with open("gdbarch.c", "w") as f:
file=f,
)
for c in filter(not_info, components):
+ # An opportunity to write in the 'postdefault' value. We
+ # change field's value to the postdefault if its current value
+ # is not different to the initial value of the field.
+ if c.postdefault is not None:
+ init_value = c.predefault or "0"
+ print(f" if (gdbarch->{c.name} == {init_value})", file=f)
+ print(f" gdbarch->{c.name} = {c.postdefault};", file=f)
+
+ # Now validate the value.
if c.invalid is False:
print(f" /* Skip verify of {c.name}, invalid_p == 0 */", file=f)
elif c.predicate:
print(f" /* Skip verify of {c.name}, has predicate. */", file=f)
- elif isinstance(c.invalid, str) and c.postdefault is not None:
- print(f" if ({c.invalid})", file=f)
- print(f" gdbarch->{c.name} = {c.postdefault};", file=f)
- elif c.predefault is not None and c.postdefault is not None:
- print(f" if (gdbarch->{c.name} == {c.predefault})", file=f)
- print(f" gdbarch->{c.name} = {c.postdefault};", file=f)
- elif c.postdefault is not None:
- print(f" if (gdbarch->{c.name} == 0)", file=f)
- print(f" gdbarch->{c.name} = {c.postdefault};", file=f)
+ elif c.invalid is None:
+ # No validation has been requested for this component.
+ pass
elif isinstance(c.invalid, str):
print(f" if ({c.invalid})", file=f)
print(f""" log.puts ("\\n\\t{c.name}");""", file=f)
- elif c.predefault is not None:
- print(f" if (gdbarch->{c.name} == {c.predefault})", file=f)
- print(f""" log.puts ("\\n\\t{c.name}");""", file=f)
elif c.invalid is True:
- print(f" if (gdbarch->{c.name} == 0)", file=f)
- print(f""" log.puts ("\\n\\t{c.name}");""", file=f)
+ if c.postdefault is not None:
+ # This component has its 'invalid' field set to True, but
+ # also has a postdefault. This makes no sense, the
+ # postdefault will have been applied above, so this field
+ # will not have a zero value.
+ raise Exception(
+ f"component {c.name} has postdefault and invalid set to True"
+ )
+ else:
+ init_value = c.predefault or "0"
+ print(f" if (gdbarch->{c.name} == {init_value})", file=f)
+ print(f""" log.puts ("\\n\\t{c.name}");""", file=f)
else:
# We should not allow ourselves to simply do nothing here
# because no other case applies. If we end up here then
# either the input data needs adjusting so one of the
# above cases matches, or we need additional cases adding
# here.
- raise Exception("unhandled case when generating gdbarch validation")
+ raise Exception(
+ f"unhandled case when generating gdbarch validation: {c.name}"
+ )
print(" if (!log.empty ())", file=f)
print(
""" internal_error (_("verify_gdbarch: the following are invalid ...%s"),""",