Hi
before pasting the code let me Clarify NON-signaled would mean a thread executing WaitForSingleObject is suspended
I am still running into problems where other threads are executing the overlayed code
here is the code Initiallly the event is created signaled
sysblk.single_thread = CreateEvent(NULL,TRUE,FALSE,"WaitThread");
/* this block of code checks if the address where the code is executing is within the address looking to be traced and is the address space correct the GET_WU function checks the the task or thread within the address space so GET_WU returns a 64 bit value 32 bits for a address space 32 for the task this is UNIQUE */
if(sysblk.debug_init == 0)
{
if (sysblk.asid != 0)
{
if((shouldstep == 1) && (regs->CR_LHL(4) == sysblk.asid))
{
sysblk.debug_init = 1;
regs->should_step = 1;
sysblk.hercgui_break = 1;
sysblk.hercgui_initbreak = 0; sysblk.debug_wu.D = ARCH_DEP(GET_WU)(regs);
if(IsDebuggerPresent())
{
sprintf(buf,"CPU%4.4X: WU Being Debugged ASCB=%4X,TCB/SRB=%4X \n",regs->cpuad,sysblk.debug_wu.F.H.F,sysblk.debug_wu.F.L.F);
OutputDebugString(buf);
}
}
else
shouldstep = 0;
}
/* the next piece of code checks after the user has examined the code and I have restored the correct instruction I want to let it execute and not over lay stop ia is the instruction address */
// Hercmd is a from end Windows MFC/C++ I have written to display the information
if(regs->psw.ia.D == sysblk.debug_ia.D)
{
wu_ptr.D = ARCH_DEP(GET_WU)(regs);
if(wu_ptr.D == sysblk.debug_wu.D)
{
sysblk.debug_ia.D =0;
if(IsDebuggerPresent())
{
ARCH_DEP(vfetchc)(buf1,5,regs->psw.ia.D,0X00,regs);
sprintf(buf,"CPU%4.4X: inst being executed=%s At address %8X\n",buf1,regs->psw.ia.D);
OutputDebugString(buf);
}
return;
}
}
/* this is the code where I check if other threads are execting the same code and the address or instruction has been overlayed to genarate a pause so I WaitForSingleObject */
if(regs->psw.ia.D == sysblk.debug_ia.D)
{
wu_ptr.D = ARCH_DEP(GET_WU)(regs);
if (wu_ptr.D != sysblk.debug_wu.D)
{
regs->cpustate = CPUSTATE_STOPPED;
dwWaitResult = WaitForSingleObject(sysblk.single_thread,INFINITE);
if(dwWaitResult == -1)
errcd = GetLastError();
if(IsDebuggerPresent())
{
ARCH_DEP(vfetchc)(buf1,4,regs->psw.ia.D,0X00,regs);
FETCH_FW(INST,buf1);
sprintf(buf,"CPU%4.4X: WU Was Held ASCB=%4X TCB/SRB=%4X, AT instruction address %8X inst=%04X\n",regs->cpuad,wu_ptr.F.H.F,wu_ptr.F.L.F,regs->psw.ia.D,INST);
OutputDebugString(buf);
}
return;
}
else
return;
}
// this where I overlay the insruction to stop the CORRECT task
if ((wu_ptr.D = ARCH_DEP(GET_WU)(regs)) == sysblk.debug_wu.D && shouldstep == 1)
{
ResetEvent(sysblk.single_thread); ip = regs->ip < regs->aip ? regs->inst : regs->ip;
ARCH_DEP(display_inst) (regs, ip);
sysblk.debug_inst_count++;
sysblk.stop_ip = regs->ip < regs->aip ? regs->inst : regs->ip;
if(sysblk.debug_overlay[0] == 0x00)
{
ip = regs->ip < regs->aip ? regs->inst : regs->ip;
sysblk.debug_ip = ip;
memcpy((void *)&sysblk.debug_overlay[0],(void *)ip,2);
memcpy((char *)&sysblk.savereg15,(char *)®s->gr[15],8);
memcpy((char *)&sysblk.savereg14,(char *)®s->gr[14],8);
sysblk.debug_ia.D = regs->psw.ia.D;
memcpy((void *)®s->gr[15].F.L.F,(void *)&sysblk.pause_rtn,4);
memcpy((void *)ip,(void *)&BASSM,2);
sysblk.hercgui_debug = 1;
}
regs->is_debugging = 1;
if(IsDebuggerPresent())
{
sprintf(buf,"CPU%4.4X: Inst Modified For ASCB=%4X TCB/SRB=%4X \n",regs->cpuad,wu_ptr.F.H.F,wu_ptr.F.L.F);
OutputDebugString(buf);
}
}
// This the code after the emulated instruction that I overlayed has executed I put back the 1st two bytes of the instruction and do a SetEvent as now other threads can proceed
if((regs->gr[15].F.L.F == sysblk.pause_rtn) && ((void *)sysblk.pause_rtn != NULL))
{
memcpy(sysblk.stop_ip,&sysblk.debug_overlay[0],2);
memcpy((char *)®s->gr[15],(char *)&sysblk.savereg15,8);
memcpy((char *)®s->gr[14],(char *)&sysblk.savereg14,8);
sysblk.debug_overlay[0] = 0x00;
sysblk.debug_overlay[1] = 0x00;
sysblk.hercgui_is_debugging = 0;
regs->bypass_debug = 1;
regs->is_debugging = 0;
regs->should_step = 0;
SetEvent(sysblk.single_thread);
wu_ptr.D = ARCH_DEP(GET_WU)(regs);
if(IsDebuggerPresent())
{
sprintf(buf,"CPU%4.4X: SetEvent for ASCB=%4X TBC/SRB=%4X\n",regs->cpuad,wu_ptr.F.H.F,wu_ptr.F.L.F);
OutputDebugString(buf);
}
}
|