XCNEW gdbarch_tdep in rl78 and rx
authorYao Qi <yao.qi@linaro.org>
Thu, 13 Apr 2017 07:29:43 +0000 (08:29 +0100)
committerYao Qi <yao.qi@linaro.org>
Thu, 13 Apr 2017 07:29:43 +0000 (08:29 +0100)
"struct gdbarch_tdep" is XNEW'ed in rl78 and rx, so the memory is not
cleared.  As the result, tdep->rl78_psw_type is never initialized
properly.

  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  if (tdep->rl78_psw_type == NULL)
    {
      tdep->rl78_psw_type = arch_flags_type (gdbarch,
     "builtin_type_rl78_psw", 1);

The bug is found by my unit test in the following patch.

gdb:

2017-04-13  Yao Qi  <yao.qi@linaro.org>

* rl78-tdep.c (rl78_gdbarch_init): Use XCNEW instead of XNEW.
* rx-tdep.c (rx_gdbarch_init): Likewise.

gdb/ChangeLog
gdb/rl78-tdep.c
gdb/rx-tdep.c

index 315932eb322b4d88a7cf8356ad691539f356b3d4..58c4b5e74cb59a629fce2fdccbfe7374584bee06 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-13  Yao Qi  <yao.qi@linaro.org>
+
+       * rl78-tdep.c (rl78_gdbarch_init): Use XCNEW instead of XNEW.
+       * rx-tdep.c (rx_gdbarch_init): Likewise.
+
 2017-04-13  Pedro Alves  <palves@redhat.com>
 
        * breakpoint.h (struct breakpoint): Reindent.
index 9f2193e56153cacb22198491954090be41556c29..307a7607e6b437b0debc7bc2e075fc062c2b1f7f 100644 (file)
@@ -1412,7 +1412,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* None found, create a new architecture from the information
      provided.  */
-  tdep = XNEW (struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
   tdep->elf_flags = elf_flags;
 
index 7b66d6da1980fd2ded7c7c6c0bad2ba42a0cbcce..1a3d103faaef397aa28a397dc858bc4ffb3ecfb9 100644 (file)
@@ -1101,7 +1101,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* None found, create a new architecture from the information
      provided.  */
-  tdep = XNEW (struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
   tdep->elf_flags = elf_flags;