This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH] bug in build_parse (parse.c)
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: [PATCH] bug in build_parse (parse.c)
- From: David Taylor <taylor at cygnus dot com>
- Date: Mon, 07 Aug 2000 10:25:57 -0400
In build_parse, you'll find the lines:
num_std_regs = 0;
#ifdef PC_REGNUM
if (PC_REGNUM >= 0)
num_std_regs++;
#endif
#ifdef FP_REGNUM
if (FP_REGNUM >= 0)
num_std_regs++;
#endif
#ifdef SP_REGNUM
if (SP_REGNUM >= 0)
num_std_regs++;
#endif
#ifdef PS_REGNUM
if (PS_REGNUM >= 0)
num_std_regs++;
#endif
Notice how num_std_regs only gets incremented if {PC_REGNUM,
FP_REGNUM, SP_REGNUM, PS_REGNUM} is *BOTH* defined and >= 0.
/* create an empty table */
std_regs = xmalloc ((num_std_regs + 1) * sizeof *std_regs);
But notice how it gets filled in if it's defined, regardless of
whether it is >= 0 or not:
i = 0;
/* fill it in */
#ifdef PC_REGNUM
std_regs[i].name = "pc";
std_regs[i].regnum = PC_REGNUM;
i++;
#endif
#ifdef FP_REGNUM
std_regs[i].name = "fp";
std_regs[i].regnum = FP_REGNUM;
i++;
#endif
#ifdef SP_REGNUM
std_regs[i].name = "sp";
std_regs[i].regnum = SP_REGNUM;
i++;
#endif
#ifdef PS_REGNUM
std_regs[i].name = "ps";
std_regs[i].regnum = PS_REGNUM;
i++;
#endif
Thus, if one of more of them is defined (possibly because other parts
of GDB won't compile if it's not defined), but is defined as -1
(because the processor doesn't support it of there is no ABI or...),
then build_parse will write off the end of the std_regs array.
Ooops. Here's a patch to fix it:
Index: parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.8
diff -c -r1.8 parse.c
*** parse.c 2000/07/30 01:48:26 1.8
--- parse.c 2000/08/07 14:20:31
***************
*** 1331,1354 ****
i = 0;
/* fill it in */
#ifdef PC_REGNUM
! std_regs[i].name = "pc";
! std_regs[i].regnum = PC_REGNUM;
! i++;
#endif
#ifdef FP_REGNUM
! std_regs[i].name = "fp";
! std_regs[i].regnum = FP_REGNUM;
! i++;
#endif
#ifdef SP_REGNUM
! std_regs[i].name = "sp";
! std_regs[i].regnum = SP_REGNUM;
! i++;
#endif
#ifdef PS_REGNUM
! std_regs[i].name = "ps";
! std_regs[i].regnum = PS_REGNUM;
! i++;
#endif
memset (&std_regs[i], 0, sizeof (std_regs[i]));
}
--- 1331,1366 ----
i = 0;
/* fill it in */
#ifdef PC_REGNUM
! if (PC_REGNUM >= 0)
! {
! std_regs[i].name = "pc";
! std_regs[i].regnum = PC_REGNUM;
! i++;
! }
#endif
#ifdef FP_REGNUM
! if (FP_REGNUM >= 0)
! {
! std_regs[i].name = "fp";
! std_regs[i].regnum = FP_REGNUM;
! i++;
! }
#endif
#ifdef SP_REGNUM
! if (SP_REGNUM >= 0)
! {
! std_regs[i].name = "sp";
! std_regs[i].regnum = SP_REGNUM;
! i++;
! }
#endif
#ifdef PS_REGNUM
! if (PS_REGNUM >= 0)
! {
! std_regs[i].name = "ps";
! std_regs[i].regnum = PS_REGNUM;
! i++;
! }
#endif
memset (&std_regs[i], 0, sizeof (std_regs[i]));
}