Hi folks,

- Use the debugger to understand why test_and_set_bit returns 0.  I
don't know what the 'tsbbl' instruction is, and haven't figured out how
to examine memory yet.

I finally muddled my way through gdb and newer kernel sources to understand this one.

The reason hal_init was seemingly unable to get the mutex lock under gdb is because the qualifiers in test_and_set_bit weren't quite right. The stuff in rtapi_bitops.h was copied from an old version of the kernel when gcc had no '+m' qualifier (operand is both input and output). If you look at a new arch/x86/include/asm/bitops.h, you'll see a cpp conditional that sets the qualifier to '+m' for newer gccs, '=m' (operand is output only) for older gccs.

I don't understand why the original code works running from the shell but not from gdb, but there are plenty of citations of other cases where programs behave differently in the two environments.

As for 'tsbbl', the code in newer kernels uses 'sbb'; not sure where the 't' comes from. 'sbb' is much easier to google. ;)

Probably someone more qualified than me needs to re-paste the kernel bitops.h code into rtapi_bitops.h (and/or just use the pthreads facilities for this when --with-realtime=linux). Of course the pasted kernel code needs to be fixed to use the longer DWORD instructions for rtapi.

With the attached patch, I can now use gdb to get through to the fork of rtapi_app and watch it segfault.

        John

PS: If anyone else wants to try, here's how I'm running gdb. Again, my apologies if everyone knows this already; it's all brand-new to me.

gdb [...]/halcmd
# I need the following since I run gdb as an inferior process from emacs
set environment EMC2VERSION=2.5.0~pre
# etc, for EMC2_EMCSH EMC2_HOME LD_LIBRARY_PATH and maybe PYTHONPATH
# replace [...] with your $EMC2_HOME
path [...]/bin:[...]/scripts:[...]/tcl
# run in the directory where your
# lat.hal, lat.xml, latexit.sh scripts live
cd /tmp/hal.lat
# follow children
set follow-fork-mode child
set detach-on-fork off
# break when forking
break fork
# whew, now we can run
start -f lat.hal
diff --git a/src/rtapi/rtapi_bitops.h b/src/rtapi/rtapi_bitops.h
index 2b2a9b5..81045c7 100644
--- a/src/rtapi/rtapi_bitops.h
+++ b/src/rtapi/rtapi_bitops.h
@@ -24,7 +24,7 @@ static __inline__ void set_bit(int nr, volatile void * addr)
 {
 	__asm__ __volatile__( 
 		"btsl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 
@@ -72,7 +72,7 @@ static __inline__ void clear_bit(int nr, volatile void * addr)
 {
 	__asm__ __volatile__( 
 		"btrl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 
@@ -90,7 +90,7 @@ static __inline__ int test_and_set_bit(int nr, volatile void * addr)
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr) : "memory");
 	return oldbit;
 }
@@ -110,7 +110,7 @@ static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
 
 	__asm__ __volatile__( 
 		"btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr) : "memory");
 	return oldbit;
 }
@@ -138,7 +138,7 @@ static __inline__ void set_bit(int nr, volatile void * addr)
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 }
 
@@ -157,7 +157,7 @@ static __inline__ void clear_bit(int nr, volatile void * addr)
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btrl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr));
 }
 
@@ -198,9 +198,10 @@ static __inline__ int test_and_set_bit(int nr, volatile void * addr)
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 	return oldbit;
+
 }
 
 /**
@@ -217,7 +218,7 @@ static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 	return oldbit;
 }
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to