diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-05-05 11:00:04 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-05-10 14:21:21 +0100 |
commit | a4f76c0765a0b9c643dc91d5a398a1cd9519572b (patch) | |
tree | 863f44e6daf20cb51d996417849512ea34f3d0fe /gdb/gdbarch.h | |
parent | 2b34e06765779335cef45a579e7a5698e198472b (diff) | |
download | gdb-a4f76c0765a0b9c643dc91d5a398a1cd9519572b.zip gdb-a4f76c0765a0b9c643dc91d5a398a1cd9519572b.tar.gz gdb-a4f76c0765a0b9c643dc91d5a398a1cd9519572b.tar.bz2 |
gdb: add gdbarch_stack_grows_down function
In another patch I'm working on I needed to ask: does the stack grow
down, or grow up?
Looking around I found in infcall.c some code where we needed to ask
the same question, what we do there is ask:
gdbarch_inner_than (gdbarch, 1, 2)
which should do the job. However, I don't particularly like copying
this, it feels like we're asking something slightly different that
just happens to align with the question we're actually asking.
I propose adding a new function `gdbarch_stack_grows_down`. This is
not going to be a gdbarch method that can be overridden, instead, this
will just call the gdbarch_inner_than function. We already have some
gdbarch methods like this, checkout arch-utils.c for examples.
I think it's now clearer what we're actually doing.
A new self-test ensures that all architectures have a stack that
either grows down, or grows up.
There should be no user visible changes after this commit.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/gdbarch.h')
-rw-r--r-- | gdb/gdbarch.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 77d3406..d4c6795 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -370,4 +370,12 @@ gdbarch_num_cooked_regs (gdbarch *arch) return gdbarch_num_regs (arch) + gdbarch_num_pseudo_regs (arch); } +/* Return true if stacks for ARCH grow down, otherwise return true. */ + +static inline bool +gdbarch_stack_grows_down (gdbarch *arch) +{ + return gdbarch_inner_than (arch, 1, 2) != 0; +} + #endif |