Click here to Skip to main content
15,895,656 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Multithreading question Pin
Richard MacCutchan7-Jan-17 20:51
mveRichard MacCutchan7-Jan-17 20:51 
AnswerRe: Multithreading question Pin
leon de boer8-Jan-17 20:03
leon de boer8-Jan-17 20:03 
GeneralRe: Multithreading question Pin
Jon McKee8-Jan-17 20:58
professionalJon McKee8-Jan-17 20:58 
GeneralRe: Multithreading question Pin
ForNow8-Jan-17 22:30
ForNow8-Jan-17 22:30 
GeneralRe: Multithreading question Pin
leon de boer9-Jan-17 18:23
leon de boer9-Jan-17 18:23 
GeneralRe: Multithreading question Pin
ForNow9-Jan-17 18:57
ForNow9-Jan-17 18:57 
GeneralRe: Multithreading question Pin
leon de boer10-Jan-17 23:23
leon de boer10-Jan-17 23:23 
GeneralRe: Multithreading question The Code Pin
ForNow11-Jan-17 12:29
ForNow11-Jan-17 12:29 
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

C++
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 */

C++
 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;  // TEMPORARY
     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

C++
// this should oly happens if hercmd hit <enter>
  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 */


C++
    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();
           // regs->cpustate = CPUSTATE_STARTED;
            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

C++
  if ((wu_ptr.D = ARCH_DEP(GET_WU)(regs)) == sysblk.debug_wu.D &&  shouldstep == 1)
	   
  
    {
 ResetEvent(sysblk.single_thread);   // Turn to NON-signal any thread executing the WaitForSingleObject will stop   
        ip = regs->ip < regs->aip ? regs->inst : regs->ip;
        ARCH_DEP(display_inst) (regs, ip);
  
   sysblk.debug_inst_count++;

	
// debug2:
	 
	
	  

  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);  /* point IEAVPSE2 */
			   
			 memcpy((void *)ip,(void *)&BASSM,2);  // Overlay the istruction 
			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;
  //  SetEvent(sysblk.single_thread2);
      regs->bypass_debug = 1;
      regs->is_debugging = 0;
      regs->should_step = 0;
      SetEvent(sysblk.single_thread);  // let other threads go
      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);
       }
  }

GeneralRe: Multithreading question The Code Pin
leon de boer12-Jan-17 14:38
leon de boer12-Jan-17 14:38 
GeneralRe: Multithreading question The Code Pin
ForNow13-Jan-17 3:28
ForNow13-Jan-17 3:28 
GeneralRe: Multithreading question The Code Pin
leon de boer14-Jan-17 22:47
leon de boer14-Jan-17 22:47 
GeneralRe: Multithreading question Pin
ForNow8-Jan-17 22:56
ForNow8-Jan-17 22:56 
GeneralRe: Multithreading question Pin
Munchies_Matt23-Jan-17 6:32
Munchies_Matt23-Jan-17 6:32 
QuestionMFC ribbon designer (gallery button) Pin
Maximilien6-Jan-17 9:43
Maximilien6-Jan-17 9:43 
AnswerRe: MFC ribbon designer (gallery button) Pin
DeeEllEll30-Mar-17 4:55
DeeEllEll30-Mar-17 4:55 
QuestionIs function prototyping dead? Pin
Vaclav_6-Jan-17 5:43
Vaclav_6-Jan-17 5:43 
AnswerRe: Is function prototyping dead? Pin
Richard MacCutchan6-Jan-17 5:49
mveRichard MacCutchan6-Jan-17 5:49 
GeneralRe: Is function prototyping dead? Pin
Vaclav_6-Jan-17 16:19
Vaclav_6-Jan-17 16:19 
GeneralRe: Is function prototyping dead? Pin
Richard MacCutchan6-Jan-17 21:55
mveRichard MacCutchan6-Jan-17 21:55 
AnswerRe: Is function prototyping dead? Pin
Jochen Arndt6-Jan-17 22:17
professionalJochen Arndt6-Jan-17 22:17 
GeneralRe: Is function prototyping dead? Pin
Vaclav_7-Jan-17 4:29
Vaclav_7-Jan-17 4:29 
GeneralRe: Is function prototyping dead? Pin
Jochen Arndt8-Jan-17 20:58
professionalJochen Arndt8-Jan-17 20:58 
AnswerRe: Is function prototyping dead? Pin
Jochen Arndt6-Jan-17 6:49
professionalJochen Arndt6-Jan-17 6:49 
QuestionMulti Core question Pin
ForNow4-Jan-17 4:11
ForNow4-Jan-17 4:11 
AnswerRe: Multi Core question Pin
Jochen Arndt4-Jan-17 4:39
professionalJochen Arndt4-Jan-17 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.