PERFORCE change 49859 for review

Marcel Moolenaar marcel at FreeBSD.org
Sun Mar 28 17:05:39 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=49859

Change 49859 by marcel at marcel_nfs on 2004/03/28 17:05:10

	Make sure we return a bspstore that's on the kernel stack.
	When the trapframe describes a kernel entry from userland,
	bspstore is on the user backingstore, while dirty registers
	end up on the kernel stack. So, return a bspstore in that
	case that points the base of the kernel stack. That way,
	bsp itself will also point to the kernel stack and all will
	be well.

Affected files ...

.. //depot/projects/gdb/sys/ia64/ia64/gdb_machdep.c#7 edit

Differences ...

==== //depot/projects/gdb/sys/ia64/ia64/gdb_machdep.c#7 (text+ko) ====

@@ -44,8 +44,8 @@
 void *
 gdb_cpu_getreg(int regnum, size_t *regsz)
 {
+	static uint64_t synth;
 	struct trapframe *tf = kdb_frame;
-	static uint64_t bsp;
 
 	*regsz = gdb_cpu_regsz(regnum);
 	switch (regnum) {
@@ -99,7 +99,6 @@
 	case 333: return (&tf->tf_special.cfm);
 	/* Registers 334-461: application registers. */
 	case 350: return (&tf->tf_special.rsc);
-	case 352: return (&tf->tf_special.bspstore);
 	case 353: return (&tf->tf_special.rnat);
 	case 359: return (&tf->tf_scratch.csd);
 	case 360: return (&tf->tf_scratch.ssd);
@@ -107,10 +106,28 @@
 	case 370: return (&tf->tf_special.unat);
 	case 374: return (&tf->tf_special.fpsr);
 	case 398: return (&tf->tf_special.pfs);
-	/* Synthesized registers. */
-	case 351:
-		bsp = tf->tf_special.bspstore + tf->tf_special.ndirty;
-		return (&bsp);
+	/* Synthesized registers. */	
+	case 351: /* bsp */
+		/*
+		 * If the trapframe belongs to a kernel entry from user
+		 * space, setup bspstore to point to the base of the
+		 * kernel stack.
+		 */
+		synth = (tf->tf_special.bspstore >= IA64_RR_BASE(5)) ?
+		    tf->tf_special.bspstore : (kdb_thread->td_kstack +
+			(tf->tf_special.bspstore & 0x1ffUL));
+		synth += tf->tf_special.ndirty;
+		return (&synth);
+	case 352: /* bspstore. */
+		/*
+		 * If the trapframe belongs to a kernel entry from user
+		 * space, setup bacpstore to point to the base of the
+		 * kernel stack.
+		 */
+		synth = (tf->tf_special.bspstore >= IA64_RR_BASE(5)) ?
+		    tf->tf_special.bspstore : (kdb_thread->td_kstack +
+			(tf->tf_special.bspstore & 0x1ffUL));
+		return (&synth);
 	}
 	return (NULL);
 }
@@ -127,22 +144,33 @@
 int
 gdb_cpu_query(void)
 {
-	if (gdb_rx_equal("Part:dirty:read::")) {
-		uint64_t *kstack;
-		uintmax_t slot;
-		if (gdb_rx_varhex(&slot) < 0) {
-			gdb_tx_err(EINVAL);
-			return (-1);
-		}
-		if (slot >= 0 && slot < (kdb_frame->tf_special.ndirty >> 3)) {
-			kstack = (uint64_t*)(kdb_thread->td_kstack +
-			    (kdb_frame->tf_special.bspstore & 0x1ffUL));
-			gdb_tx_begin('\0');
-			gdb_tx_mem((void*)(kstack + slot), 8);
-			gdb_tx_end();
-		}
-		return (1);
+	uint64_t bspstore, *kstack;
+	uintmax_t slot;
+
+	if (!gdb_rx_equal("Part:dirty:read::"))
+		return (0);
+
+	if (gdb_rx_varhex(&slot) < 0) {
+		gdb_tx_err(EINVAL);
+		return (-1);
+	}
+
+	/* slot is unsigned. No need to test for negative values. */
+	if (slot >= (kdb_frame->tf_special.ndirty >> 3)) {
+		gdb_tx_err(EINVAL);
+		return (-1);
 	}
 
-	return (0);
+	/*
+	 * If the trapframe describes a kernel entry, bspstore holds
+	 * the address of the user backing store. Calculate the right
+	 * kernel stack address. See also ptrace_machdep().
+	 */
+	bspstore = kdb_frame->tf_special.bspstore;
+	kstack = (bspstore >= IA64_RR_BASE(5)) ? (uint64_t*)bspstore :
+	    (uint64_t*)(kdb_thread->td_kstack + (bspstore & 0x1ffUL));
+	gdb_tx_begin('\0');
+	gdb_tx_mem((void*)(kstack + slot), 8);
+	gdb_tx_end();
+	return (1);
 }


More information about the p4-projects mailing list