Fix M68HC11_NUM_REGS
authorYao Qi <yao.qi@linaro.org>
Wed, 15 Nov 2017 09:36:51 +0000 (09:36 +0000)
committerYao Qi <yao.qi@linaro.org>
Wed, 15 Nov 2017 09:36:51 +0000 (09:36 +0000)
M68HC11_LAST_HARD_REG is 8, but m68hc11 register number is started from 0,
so there are 9 raw registers, but M68HC11_NUM_REGS is 8 by mistake.

My following unit test can find this issue (GDB is built with asan)

=================================================================
==15555==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000113150 at pc 0x51393f bp 0x7fffcec36f60 sp 0x7fffcec36f58
WRITE of size 2 at 0x602000113150 thread T0
    #0 0x51393e in m68hc11_pseudo_register_read gdb/m68hc11-tdep.c:320
    #1 0xc4b620 in gdbarch_pseudo_register_read(gdbarch*, regcache*, int, unsigned char*) gdb/gdbarch.c:1974
    #2 0xddad88 in regcache::cooked_read(int, unsigned char*) gdb/regcache.c:710
    #3 0xddff2b in cooked_read_test gdb/regcache.c:1850
    #4 0xdf8cfb in selftests::gdbarch_selftest::operator()() const gdb/selftest-arch.c:73

gdb:

2017-11-15  Yao Qi  <yao.qi@linaro.org>

* m68hc11-tdep.c (M68HC11_NUM_REGS): Change it to
M68HC11_LAST_HARD_REG + 1.

gdb/ChangeLog
gdb/m68hc11-tdep.c

index 6afec2800a05c82acb639f455dfbd59d0c7334b1..fe24318d204042a5a1488ffa3f6c40c4dda5a189 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-15  Yao Qi  <yao.qi@linaro.org>
+
+       * m68hc11-tdep.c (M68HC11_NUM_REGS): Change it to
+       M68HC11_LAST_HARD_REG + 1.
+
 2017-11-14  Paul Carroll  <pcarroll@codesourcery.com>
 
        PR gdb/22388
index b144d8b3542d7a1c99d0cd95512545bfad7b004e..9c2ecb031b8604ead4666814e8770a46ede7cf59 100644 (file)
@@ -112,7 +112,7 @@ enum insn_return_kind {
 #define SOFT_D32_REGNUM     (SOFT_D1_REGNUM+31)
 #define M68HC11_MAX_SOFT_REGS 32
 
-#define M68HC11_NUM_REGS        (8)
+#define M68HC11_NUM_REGS        (M68HC11_LAST_HARD_REG + 1)
 #define M68HC11_NUM_PSEUDO_REGS (M68HC11_MAX_SOFT_REGS+5)
 #define M68HC11_ALL_REGS        (M68HC11_NUM_REGS+M68HC11_NUM_PSEUDO_REGS)