H8/300: Fix pseudo registers reads/writes.
'info registers ccr' corrupts memory.
Debugging gdb under Valgrind, we see:
(gdb) info registers ccr
==23225== Invalid write of size 1
==23225== at 0x4A0A308: memcpy@@GLIBC_2.14 (mc_replace_strmem.c:881)
==23225== by 0x52D334: regcache_raw_read (regcache.c:625)
==23225== by 0x45E4D8: h8300_pseudo_register_read (h8300-tdep.c:1171)
==23225== by 0x5B694B: gdbarch_pseudo_register_read (gdbarch.c:1926)
==23225== by 0x52DADB: regcache_cooked_read (regcache.c:740)
==23225== by 0x52DC10: regcache_cooked_read_value (regcache.c:765)
==23225== by 0x68CA41: sentinel_frame_prev_register (sentinel-frame.c:52)
==23225== by 0x6B80CB: frame_unwind_register_value (frame.c:1105)
==23225== by 0x6B7C97: frame_register_unwind (frame.c:1010)
==23225== by 0x6B7F73: frame_unwind_register (frame.c:1064)
==23225== by 0x6B8359: frame_unwind_register_signed (frame.c:1162)
==23225== by 0x6B8396: get_frame_register_signed (frame.c:1169)
==23225== Address 0x4f7b031 is 0 bytes after a block of size 1 alloc'd
==23225== at 0x4A06B0F: calloc (vg_replace_malloc.c:593)
==23225== by 0x6EB754: xcalloc (common-utils.c:91)
==23225== by 0x6EB793: xzalloc (common-utils.c:101)
==23225== by 0x53A782: allocate_value_contents (value.c:854)
==23225== by 0x53A7B4: allocate_value (value.c:864)
==23225== by 0x52DBC8: regcache_cooked_read_value (regcache.c:757)
==23225== by 0x68CA41: sentinel_frame_prev_register (sentinel-frame.c:52)
==23225== by 0x6B80CB: frame_unwind_register_value (frame.c:1105)
==23225== by 0x6B7C97: frame_register_unwind (frame.c:1010)
==23225== by 0x6B7F73: frame_unwind_register (frame.c:1064)
==23225== by 0x6B8359: frame_unwind_register_signed (frame.c:1162)
==23225== by 0x6B8396: get_frame_register_signed (frame.c:1169)
==23225==
ccr 0x00 0 I-0 UI-0 H-0 U-0 N-0 Z-0 V-0 C-0 u> u>= != >= >
(gdb)
This bit:
==23225== Invalid write of size 1
==23225== at 0x4A0A308: memcpy@@GLIBC_2.14 (mc_replace_strmem.c:881)
==23225== by 0x52D334: regcache_raw_read (regcache.c:625)
==23225== by 0x45E4D8: h8300_pseudo_register_read (h8300-tdep.c:1171)
shows the problem. The CCR pseudo register has type length of 1,
while the corresponding CCR raw register has a length of 2 or 4
(depending on mode). In
sim/h8300/compile.c:sim_{fetch|store}_register we see that the sim
also treats those raw registers (CCR/EXR) as 2 or 4 bytes length.
gdb/
2014-02-12 Pedro Alves <palves@redhat.com>
* h8300-tdep.c (pseudo_from_raw_register)
(raw_from_pseudo_register): New functions.
(h8300_pseudo_register_read, h8300_pseudo_register_write): Use
them.