public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] [PC Target][Patch] Full Multi Thread debugging.
@ 2000-09-21 14:39 Fabrice Gautier
  0 siblings, 0 replies; only message in thread
From: Fabrice Gautier @ 2000-09-21 14:39 UTC (permalink / raw)
  To: Ecos-List (E-mail)

[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]

Hi,

Here is patch that's should provide full debugging multithread debug
capabilities to the PC target. 

In fact there are two things:

1/ New saved context:
Currently, the context saved during thread switch and the one saved on a
interrupt are different. The first thing this patch should do is to have the
same context saved. The context saved before a normal task switch(ie: not an
interrupt) will appears as if the thread were interrupted in
Cyg_Scheduler::unlock_inner.
I think this part of the patch is quite good. I didn't noticed any changes
while using eCos with this part of the patch.

2/ PC Stub modifications:
In the current PC stub, the context reported to gdb was always the context
of the interrupted task (ie: the current task)
In order to have the stub report all the context, I had to modify the stub.
This part of the patch is probably the less simple, so I enclosed my changes
in some #ifdef _FG_X. You will have to build eCos with this macro defined in
order to see the result.

The results looks quite good: You should be able to see the call stack of
each thread now. However, it is not perfect. For example, the position of
the idle task is often at 0xffffffff and I suspect it may be the cause of
some crashes. I ran some of the eCos tests with this patch and that seemed
fine, but I think more in-depth tests could reveal some problems. I think
that In most of my test the task switches are caused by the thread waiting
for some lock, and maybe there is some problems occuring in time-sliced task
switch.

I would be glad is someones have the time to try and look at this patch and
give some feedback. 

Thanks 

-- 
Fabrice Gautier
fabrice_gautier@sdesigns.com 


 


 <<pc_debug_thread.patch.fix>> 

[-- Attachment #2: pc_debug_thread.patch.fix --]
[-- Type: text/x-diff, Size: 12164 bytes --]

Index: hal/i386/arch/current/include/hal_arch.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/i386/arch/current/include/hal_arch.h,v
retrieving revision 1.7
diff -u -r1.7 hal_arch.h
--- hal/i386/arch/current/include/hal_arch.h	2000/06/16 16:44:07	1.7
+++ hal/i386/arch/current/include/hal_arch.h	2000/09/21 21:07:49
@@ -53,6 +53,7 @@
 // Processor saved states. This structure is also defined in i386.inc for
 // assembly code. Do not change this without changing that (or vice versa).
 
+#if 0
 typedef struct 
 {
     cyg_uint32  esp;
@@ -62,6 +63,24 @@
     cyg_uint32  esi;
     cyg_uint32  edi;
 } HAL_SavedRegisters;
+#endif
+// this one match interrupt context
+typedef struct 
+{
+    cyg_uint32  edi;
+    cyg_uint32  esi;
+    cyg_uint32  ebp;
+    cyg_uint32  esp;                  
+    cyg_uint32  ebx;
+    cyg_uint32  edx;
+    cyg_uint32  ecx;
+    cyg_uint32  eax;    
+    cyg_uint32  vector; // if saved on interrupt contains intr vector
+    cyg_uint32  eip;
+    cyg_uint32  arg1;   // cs or parameter
+    cyg_uint32  arg2;	// eflags or parameter
+} HAL_SavedRegisters;
+
 
 //-----------------------------------------------------------------------------
 // Exception handling function.
@@ -104,17 +123,22 @@
     *(--_sp_) = (CYG_WORD)(0);                                            \
     *(--_sp_) = (CYG_WORD)(0);                                            \
     *(--_sp_) = (CYG_WORD)(0);                                            \
-    *(--_sp_) = (CYG_WORD)(_thread_);                                     \
-    *(--_sp_) = (CYG_WORD)(0);                                            \
-    *(--_sp_) = (CYG_WORD)(_entry_);                                      \
                                                                           \
     _regs_ = (HAL_SavedRegisters *)                                       \
                ((unsigned long)_sp_ - sizeof(HAL_SavedRegisters));        \
+    _regs_->arg2   = (CYG_WORD)(_thread_);				  \
+    _regs_->arg1   = (CYG_WORD)(0);				  \
+    _regs_->eip	   = (CYG_WORD)(_entry_);				  \
+    _regs_->vector = (CYG_WORD)(_id_);					  \
+    _sp_-=4;								  \
     _regs_->esp    = (CYG_WORD) _sp_;                                     \
-    _regs_->ebx    = (CYG_WORD)(_id_);                                    \
     _regs_->ebp    = (CYG_WORD)(_id_);                                    \
     _regs_->esi    = (CYG_WORD)(_id_);                                    \
     _regs_->edi    = (CYG_WORD)(_id_);                                    \
+    _regs_->eax    = (CYG_WORD)(_id_);					  \
+    _regs_->ebx    = (CYG_WORD)(_id_);                                    \
+    _regs_->ecx    = (CYG_WORD)(_id_);					  \
+    _regs_->edx    = (CYG_WORD)(_id_);                                    \
     (_sparg_)      = (CYG_ADDRESS) _regs_;                                \
     CYG_MACRO_END
 
Index: hal/i386/arch/current/include/i386.inc
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/i386/arch/current/include/i386.inc,v
retrieving revision 1.3
diff -u -r1.3 i386.inc
--- hal/i386/arch/current/include/i386.inc	2000/02/02 19:57:08	1.3
+++ hal/i386/arch/current/include/i386.inc	2000/09/21 21:07:49
@@ -55,13 +55,20 @@
         # http://www.sco.com/products/layered/develop/devspecs/abi386-4.pdf
 
 	# Callee save registers (eax, ecx, and edx are scratch registers)
-	.equ	i386reg_esp,		0
-	.equ	i386reg_next_context,	4 # only used when dropping through...
-	.equ	i386reg_ebp,		8 # ...from switch_ to load_context.
-	.equ	i386reg_ebx,		12
-	.equ	i386reg_esi,		16
-	.equ	i386reg_edi,		20
-	.equ	i386reg_context_size, 	24
+
+	.equ	i386reg_edi,		0
+	.equ	i386reg_esi,		4
+	.equ	i386reg_ebp,		8
+	.equ	i386reg_esp,		12
+	.equ	i386reg_ebx,		16
+	.equ	i386reg_edx,		20
+	.equ	i386reg_ecx,		24
+	.equ	i386reg_eax,		28
+	.equ	i386reg_vector,		32
+	.equ	i386reg_eip,		36
+	.equ	i386reg_arg1,		40  # cs or parameter
+	.equ	i386reg_arg2,		44  # eflags or parameter
+	.equ	i386reg_context_size, 	48
 
 #------------------------------------------------------------------------------
 # end of i386.inc
Index: hal/i386/arch/current/src/context.S
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/i386/arch/current/src/context.S,v
retrieving revision 1.4
diff -u -r1.4 context.S
--- hal/i386/arch/current/src/context.S	2000/02/17 19:38:14	1.4
+++ hal/i386/arch/current/src/context.S	2000/09/21 21:07:50
@@ -67,35 +67,52 @@
 # %eax, %ecx, and %edx are ours to abuse.
         
 FUNC_START(hal_thread_switch_context)
-        movl    4(%esp),%eax            # next context ptr
-        movl    8(%esp),%edx            # this context ptr
+#        movl    4(%esp),%eax            # next context ptr
+#        movl    8(%esp),%edx            # this context ptr
 
+	popl %ecx  # save return eip
+	popl %eax  # get next context ptr
+	popl %edx  # get this context ptr
+
+	# Save context
+		
+	pushfl		# save eflags
+	pushw %cs	# save cs
+	pushw 0		# and pad to 32 bits
+	pushl %ecx	# save eip 
+	pushl $0xdeaddead # push vector
+	pusha		# push general registers
+	
         # Make room on the stack for the context
-        movl    %esp,%ecx               # keep original SP
-        sub	$i386reg_context_size,%esp
+#        movl    %esp,%ecx               # keep original SP
+#        sub	$i386reg_context_size,%esp
 
         # Save next context ptr in this context. Necessary because
         # hal_thread_load_context expects to find the ptr on the stack,
         # not in a register as on PPC.
-        movl    %eax,i386reg_next_context(%esp)
+#        movl    %eax,i386reg_next_context(%esp)
 
         # Save registers
-        movl    %ecx,i386reg_esp(%esp)  # original esp
-        movl    %ebp,i386reg_ebp(%esp)
-        movl    %ebx,i386reg_ebx(%esp)
-        movl    %esi,i386reg_esi(%esp)
-        movl    %edi,i386reg_edi(%esp)
+#        movl    %ecx,i386reg_esp(%esp)  # original esp
+#        movl    %ebp,i386reg_ebp(%esp)
+#        movl    %ebx,i386reg_ebx(%esp)
+#        movl    %esi,i386reg_esi(%esp)
+#        movl    %edi,i386reg_edi(%esp)
         
         # Store the context ptr
         movl    %esp,(%edx)
-
+        
+        #push next context ptr as an argument to load context
+	pushl 	%eax
+	pushl	$0xdeadbeef # return pointer, never used
+	
         # Now fall through to hal_thread_load_context
         
         
 #------------------------------------------------------------------------------
 # hal_thread_load_context
 # Load thread context
-# : 4(%esp) = i386reg_next_context(%esp) = address of sp of thread to execute
+# : 4(%esp) (!= i386reg_next_context(%esp)) = address of sp of thread to execute
 # Note that this function is also the second half of hal_thread_switch_context
 # and is simply dropped into from it.
 #
@@ -109,16 +126,20 @@
 	movl	%eax, %cr0
 #endif
 	
-        movl    i386reg_next_context(%esp),%eax # get new context ptr
-        movl    (%eax),%eax
+        movl    4(%esp),%eax # get new context ptr
+#       movl    (%eax),%eax
+	movl	(%eax),%esp
+	popal   # unstack general registers
+	popl %ecx # unstack vector (should be 0xdeaddead)
         
         # Restore registers
-        movl    i386reg_ebp(%eax),%ebp
-        movl    i386reg_ebx(%eax),%ebx
-        movl    i386reg_esi(%eax),%esi
-        movl    i386reg_edi(%eax),%edi
-        movl    i386reg_esp(%eax),%esp
+ #       movl    i386reg_ebp(%eax),%ebp
+ #       movl    i386reg_ebx(%eax),%ebx
+ #       movl    i386reg_esi(%eax),%esi
+ #       movl    i386reg_edi(%eax),%edi
+ #       movl    i386reg_esp(%eax),%esp
 
+	
         ret
 
 
@@ -181,6 +202,5 @@
         movl    %edx,0(%esp)
 
         ret
-
 #-----------------------------------------------------------------------------
 # End of context.S
Index: hal/i386/pc/current/src/plf_stub.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/i386/pc/current/src/plf_stub.c,v
retrieving revision 1.1
diff -u -r1.1 plf_stub.c
--- hal/i386/pc/current/src/plf_stub.c	2000/03/28 14:11:25	1.1
+++ hal/i386/pc/current/src/plf_stub.c	2000/09/21 21:07:51
@@ -340,11 +353,17 @@
 }
 
 
-
 int hal_pc_trap_registers[NUMREGS] ;
+#ifdef _FG_X
+HAL_SavedRegisters hal_pc_saved_trap_registers;
+#endif
+
 int hal_pc_trap_number ;
 int gdb_i386errcode;
 
+
+
+
 /* GDB stores segment registers in 32-bit words (that's just the way
    m-i386v.h is written).  So zero the appropriate areas in registers.  */
 #define SAVE_REGISTERS1()                       \
@@ -364,12 +383,11 @@
   asm ("movw %ax, hal_pc_trap_registers+58");   \
   asm ("movw %gs, hal_pc_trap_registers+60");   \
   asm ("movw %ax, hal_pc_trap_registers+62");
-
+ 
 #define SAVE_ERRCODE() \
   asm ("popl %ebx"); \
   asm ("movl %ebx, gdb_i386errcode");
 
-
 #define SAVE_REGISTERS2() \
   asm ("popl %ebx"); /* old eip */			  		                 \
   asm ("movl %ebx, hal_pc_trap_registers+32");			  		     \
@@ -383,15 +401,42 @@
   asm ("movw %ax, hal_pc_trap_registers+46");     	       	         \
   asm ("movl %esp, hal_pc_trap_registers+16");
 
+#ifndef _FG_X
+#define CALL_HOOK() \
+	asm("popl %eax; movl %eax, hal_pc_trap_number; call __handle_exception; jmp hal_pc_trap_exit")
+#else
 
+/* common exception handling code
+   This one is called by the trap number specific handlers written is asm
+   We just pass to the stub handler, a HAL_SavedRegister structure. not 
+   all the gdb registers.
+*/  
+void hal_pc_handle_exception(void)
+{
+	hal_pc_saved_trap_registers.eax=hal_pc_trap_registers[EAX];
+	hal_pc_saved_trap_registers.ebx=hal_pc_trap_registers[EBX];
+	hal_pc_saved_trap_registers.ecx=hal_pc_trap_registers[ECX];
+	hal_pc_saved_trap_registers.edx=hal_pc_trap_registers[EDX];
+	hal_pc_saved_trap_registers.esi=hal_pc_trap_registers[ESI];
+	hal_pc_saved_trap_registers.edi=hal_pc_trap_registers[EDI];
+	hal_pc_saved_trap_registers.ebp=hal_pc_trap_registers[EBP];
+	hal_pc_saved_trap_registers.esp=hal_pc_trap_registers[ESP];
+	hal_pc_saved_trap_registers.eip=hal_pc_trap_registers[EIP];
+	hal_pc_saved_trap_registers.arg1=hal_pc_trap_registers[CS];
+	hal_pc_saved_trap_registers.arg2=hal_pc_trap_registers[PS];
+	hal_pc_saved_trap_registers.vector=hal_pc_trap_number;
+	cyg_hal_exception_handler(&hal_pc_saved_trap_registers);
+}
 
 #define CALL_HOOK() \
-	asm("popl %eax; movl %eax, hal_pc_trap_number; call __handle_exception; jmp hal_pc_trap_exit")
+	asm("popl %eax; movl %eax, hal_pc_trap_number; call hal_pc_handle_exception; jmp hal_pc_trap_exit")
+#endif
 
+
 asm(".text");
 asm(".globl return_to_prog");
 asm("hal_pc_trap_exit:");
-asm("        movw registers+44, %ss");
+asm("        movw hal_pc_trap_registers+44, %ss");
 asm("        movl registers+16, %esp");
 asm("        movl registers+4, %ecx");
 asm("        movl registers+8, %edx");
@@ -399,10 +444,10 @@
 asm("        movl registers+20, %ebp");
 asm("        movl registers+24, %esi");
 asm("        movl registers+28, %edi");
-asm("        movw registers+48, %ds");
-asm("        movw registers+52, %es");
-asm("        movw registers+56, %fs");
-asm("        movw registers+60, %gs");
+asm("        movw hal_pc_trap_registers+48, %ds");
+asm("        movw hal_pc_trap_registers+52, %es");
+asm("        movw hal_pc_trap_registers+56, %fs");
+asm("        movw hal_pc_trap_registers+60, %gs");
 asm("        movl registers+36, %eax");
 asm("        pushl %eax");  /* saved eflags */
 asm("        movl registers+40, %eax");
@@ -561,6 +606,7 @@
  *   old eip
  *
  */
+
 externC void hal_pc_exception_3(void);
 asm(".text");
 asm(".globl hal_pc_exception_3");
@@ -760,8 +806,8 @@
   hal_pc_exception_handler(14, hal_pc_exception_14);
   hal_pc_exception_handler(16, hal_pc_exception_16);
 }
-
 
+#ifndef _FG_X
 void hal_get_gdb_registers(target_register_t * d, HAL_SavedRegisters * s)
 {
 	int i ;
@@ -777,7 +823,7 @@
 	for (i = 0; i < NUMREGS; i++)
 		hal_pc_trap_registers[i] = s[i] ;
 }
-
+#endif
 
 #endif // ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
 //-----------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-09-21 14:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-21 14:39 [ECOS] [PC Target][Patch] Full Multi Thread debugging Fabrice Gautier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).