[PATCH] sim/rl78/gdb-if.c cleanup

Kevin Buettner kevinb@redhat.com
Thu Aug 8 00:34:00 GMT 2013


I've committed the patch below.

During early development of the rl78 port, it wasn't clear to us that
there was an instruction that could be used for a software breakpoint,
so I implemented a mechanism that utilized hardware breakpoints. 
Later on, when we learned of the instruction being used for software
breakpoints, I deleted most of the HW breakpoint machinery, but did
not delete all of it.  This patch gets rid of the rest of this unused
code.

I stumbled across this unused code while debugging a SIGSEGV in GDB
built for the rl78 target.  It turned out that the PC value was being
set incorrectly which in turn caused an out-of-bounds reference to the
array being deleted here.

While we still get a SIGSEGV elsewhere for some incorrect PC values, I
decided to add an assert which will ensure that PC will always have an
in range value.  I toyed with the idea of masking PC but, while this
is an easy fix, it's not really a correct fix because GDB should not
be trying to set PC to an out of range value.

I have another patch to GDB proper which fixes the SIGSEGV.

Kevin

	* gdb-if.c (hw_breakpoints): Remove.
	(sim_store_register): Add an assert() to make sure PC is in range.
	Delete code which referenced hw_breakpoints[].

Index: sim/rl78/gdb-if.c
===================================================================
RCS file: /cvs/src/src/sim/rl78/gdb-if.c,v
retrieving revision 1.4
diff -u -p -r1.4 gdb-if.c
--- sim/rl78/gdb-if.c	15 Mar 2013 17:53:44 -0000	1.4
+++ sim/rl78/gdb-if.c	8 Aug 2013 00:02:29 -0000
@@ -55,8 +55,6 @@ static struct sim_state the_minisim = {
 
 static int open;
 
-static unsigned char hw_breakpoints[MEM_SIZE/8];
-
 static struct host_callback_struct *host_callbacks;
 
 /* Open an instance of the sim.  For this sim, only one instance
@@ -341,7 +339,15 @@ sim_store_register (SIM_DESC sd, int reg
   val = get_le (buf, length);
 
   if (regno == sim_rl78_pc_regnum)
-    pc = val;
+    {
+      pc = val;
+
+      /* The rl78 program counter is 20 bits wide.  Ensure that GDB
+         hasn't picked up any stray bits.  This has occurred when performing
+	 a GDB "return" command in which the return address is obtained
+	 from a 32-bit container on the stack.  */
+      assert ((pc & ~0x0fffff) == 0);
+    }
   else
     memory[reg_addr (regno)] = val;
   return size;
@@ -456,13 +462,6 @@ sim_resume (SIM_DESC sd, int step, int s
 	  break;
 	}
 
-      if (hw_breakpoints[pc >> 3]
-          && (hw_breakpoints[pc >> 3] & (1 << (pc & 0x7))))
-	{
-	  reason = sim_stopped;
-	  siggnal = GDB_SIGNAL_TRAP;
-	  break;
-	}
       rc = setjmp (decode_jmp_buf);
       if (rc == 0)
 	rc = decode_opcode ();



More information about the Gdb-patches mailing list