diff options
author | Luis Machado <luis.machado@linaro.org> | 2020-12-02 11:29:30 -0300 |
---|---|---|
committer | Luis Machado <luis.machado@linaro.org> | 2020-12-04 11:17:00 -0300 |
commit | 5382f97180f5be551868449e411a4daaebf232fb (patch) | |
tree | 8cc4c6f8a8d23877ce212441c8946122c829c630 /gdb/arch/aarch64-insn.h | |
parent | 67748e0f666f0645d7f182e1365f4d9859e55f1d (diff) | |
download | fsf-binutils-gdb-5382f97180f5be551868449e411a4daaebf232fb.zip fsf-binutils-gdb-5382f97180f5be551868449e411a4daaebf232fb.tar.gz fsf-binutils-gdb-5382f97180f5be551868449e411a4daaebf232fb.tar.bz2 |
Fix shifting of negative value
When UBSan is enabled, I noticed runtime errors complaining of shifting
of negative numbers.
This patch fixes this by reusing existing macros from the ARM port.
It also removes unused macros from AArch64's port.
gdb/ChangeLog:
2020-12-04 Luis Machado <luis.machado@linaro.org>
* aarch64-tdep.c (submask, bit, bits): Remove.
* arch/aarch64-insn.c (extract_signed_bitfield): Remove.
(aarch64_decode_adr, aarch64_decode_b aarch64_decode_bcond)
(aarch64_decode_cb, aarch64_decode_tb)
(aarch64_decode_ldr_literal): Use sbits to extract a signed
immediate.
* arch/aarch64-insn.h (submask, bits, bit, sbits): New macros.
Diffstat (limited to 'gdb/arch/aarch64-insn.h')
-rw-r--r-- | gdb/arch/aarch64-insn.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gdb/arch/aarch64-insn.h b/gdb/arch/aarch64-insn.h index 6a63ce9..5ce46c1 100644 --- a/gdb/arch/aarch64-insn.h +++ b/gdb/arch/aarch64-insn.h @@ -21,6 +21,22 @@ extern bool aarch64_debug; +/* Support routines for instruction parsing. */ + +/* Create a mask of X bits. */ +#define submask(x) ((1L << ((x) + 1)) - 1) + +/* Extract the bitfield from OBJ starting at bit ST and ending at bit FN. */ +#define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st))) + +/* Extract bit ST from OBJ. */ +#define bit(obj,st) (((obj) >> (st)) & 1) + +/* Extract the signed bitfield from OBJ starting at bit ST and ending at + bit FN. The result is sign-extended. */ +#define sbits(obj,st,fn) \ + ((long) (bits(obj,st,fn) | ((long) bit(obj,fn) * ~ submask (fn - st)))) + /* List of opcodes that we need for building the jump pad and relocating an instruction. */ |