home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / CUATHDS.C < prev    next >
Text File  |  1996-03-18  |  18KB  |  379 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   cuathds.c                                                               */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Cua threads dialog functions.                                           */
  8. /*                                                                           */
  9. /*...Release 1.01 (04/03/92)                                                 */
  10. /*...                                                                        */
  11. /*... 05/08/92  701   Srinivas  Cua Interface.                               */
  12. /*****************************************************************************/
  13. #include "all.h"
  14. #include "diaThds.h"                    /* threads dialog data            701*/
  15.  
  16. #define TIDLEN      4                   /* thread id field length            */
  17. #define DBGLEN      4                   /* debug state field length          */
  18. #define THDLEN      4                   /* thread state field length         */
  19. #define FNLEN      18                   /* file name field length            */
  20. #define LINELEN    11                   /* line number field length          */
  21. #define FUNCLEN    21                   /* function name field length        */
  22.  
  23. extern uchar   VideoAtr;                /* logical screen attribute          */
  24. extern uchar   ScrollShade1[];          /* scroll bar attributes          701*/
  25. extern uchar   ScrollShade2[];          /* scroll bar attributes          701*/
  26. extern uchar   hilite[];                /* high light field attributes    701*/
  27. extern uchar   normal[];                /* normal field attributes        701*/
  28. extern uchar   ClearField[];            /* clear field attributes         701*/
  29.  
  30. extern TSTATE   *thead;                 /* thread list head pointer          */
  31. extern AFILE    *fp_focus;              /* a holder for an afile node.       */
  32. extern CmdParms cmd;
  33.  
  34. static uchar Header[] = "Tid Dbg Thd FileName          Line       Function";
  35. static char *Tvals[4] =                 /* thread state values               */
  36. {                                       /*                                   */
  37.  "Run",                                 /* Runnable                          */
  38.  "Sus",                                 /* Suspended                         */
  39.  "Blk",                                 /* Blocked                           */
  40.  "Cri"                                  /* Critical section                  */
  41. };                                      /*                                   */
  42.                                         /*                                   */
  43. static char *Dvals[3] =                 /* debug state values                */
  44. {                                       /*                                   */
  45.  "Thw",                                 /* thawed                            */
  46.  "Frz",                                 /* frozen                            */
  47.  "Trm"                                  /* terminating (DBG_N_ThreadTerm)    */
  48. };                                      /* from DosDebug                     */
  49.                                         /*                                   */
  50. static TSTATE  *nplast;                 /* last display node                 */
  51. static uchar    allinfo;                /* toggle to display all threads info*/
  52.  
  53. AFILE *showthds( uint *Dummy )
  54. {
  55.   return( Cua_showthds() );
  56. }
  57.  
  58. /*****************************************************************************/
  59. /* Cua_showthds()                                                         701*/
  60. /*                                                                           */
  61. /* Description:                                                              */
  62. /*                                                                           */
  63. /*     Calls functions to display, process key & mouse events & remove the   */
  64. /*  threads dialog.                                                          */
  65. /*                                                                           */
  66. /* Parameters:                                                               */
  67. /*                                                                           */
  68. /* Return:                                                                   */
  69. /*   none                                                                    */
  70. /*****************************************************************************/
  71. AFILE  *Cua_showthds()
  72. {
  73.   GetScrAccess();
  74.  
  75.   DisplayDialog( &Dia_Thds, TRUE );
  76.   ProcessDialog( &Dia_Thds, &Dia_Thds_Choices, TRUE, NULL );
  77.   RemoveDialog( &Dia_Thds );
  78.   SetScrAccess();
  79.   return( fp_focus );
  80. }
  81.  
  82. /*****************************************************************************/
  83. /* DisplayThdsChoice()                                                    701*/
  84. /*                                                                           */
  85. /* Description:                                                              */
  86. /*                                                                           */
  87. /*   Displays the Thread names and other related information in the dialog   */
  88. /* window.                                                                   */
  89. /*                                                                           */
  90. /* Parameters:                                                               */
  91. /*                                                                           */
  92. /*   shell   ->  pointer to a dialog shell structure.                        */
  93. /*   ptr     ->  pointer to a dialog choice structure.                       */
  94. /*                                                                           */
  95. /* Return:                                                                   */
  96. /*   none                                                                    */
  97. /*****************************************************************************/
  98. void  DisplayThdsChoice( DIALOGSHELL *shell, DIALOGCHOICE *ptr )
  99. {
  100.   UINT    i,j;
  101.   UINT    StartIndex;
  102.   UCHAR  *buf,*fn;
  103.   UCHAR  *pbuf;
  104.   ULONG   bufsize;
  105.  
  106.   /***************************************************************************/
  107.   /* set pointer to head of the threads linked list & allocate memory requi- */
  108.   /* red display a sinle row.                                                */
  109.   /***************************************************************************/
  110.   nplast  = thead;
  111.   bufsize = shell->width - 1 - SCROLLBARCOLOFFSET;
  112.   buf     = Talloc( bufsize );
  113.  
  114.   /***************************************************************************/
  115.   /* Put the header text and init variables.                                 */
  116.   /***************************************************************************/
  117.   putrc( shell->row + 2, shell->col + 2, Header );
  118.   StartIndex = 1;
  119.  
  120.   /***************************************************************************/
  121.   /* Advance the startindex and -> to thread node depending on the skip rows */
  122.   /***************************************************************************/
  123.   for( i = 0; i < ptr->SkipRows; i++ )
  124.   {
  125.     nplast = nplast->next;
  126.     StartIndex++;
  127.   }
  128.  
  129.   /***************************************************************************/
  130.   /* Display the rows that can fit in the window.                            */
  131.   /***************************************************************************/
  132.   for( i = 0; i < ptr->MaxRows; i++, StartIndex++ )
  133.   {
  134.     pbuf = buf + 1;
  135.     /*************************************************************************/
  136.     /* Clear the display buffer.                                             */
  137.     /*************************************************************************/
  138.     memset( buf, ' ', shell->width - 2 - SCROLLBARCOLOFFSET );
  139.     if( StartIndex <= ptr->entries )
  140.     {
  141.       /**********************************************************************/
  142.       /*  - Put the TID (thread id) and DBG (debug state ) into the buffer  */
  143.       /*  - advance the pointer.                                            */
  144.       /**********************************************************************/
  145.       j = sprintf( pbuf, "%-3d %s ", nplast->tid,
  146.                    Dvals[nplast->ts.DebugState] );
  147.       *(pbuf +j) = ' ';
  148.       pbuf += TIDLEN + DBGLEN;
  149.  
  150.       /**********************************************************************/
  151.       /*  If the thread is not terminated and all info flag is set build    */
  152.       /* all the info ie filename , line no and function name.              */
  153.       /**********************************************************************/
  154.       if( allinfo )                                                     /*906*/
  155.       {
  156.         memcpy( pbuf, Tvals[nplast->ts.ThreadState], THDLEN - 1 );
  157.         pbuf += THDLEN;
  158.  
  159.         /*********************************************************************/
  160.         /* If not fake get the moudle or file name                           */
  161.         /*********************************************************************/
  162.         if( nplast->mid != FAKEMID )
  163.         {
  164.           int junk;
  165.  
  166.           fn = DBModName( nplast->mid, nplast->sfi, nplast->pdf, &junk );
  167.           if( fn )
  168.            strncpy( pbuf, fn + 1, min( *fn, FNLEN ) );
  169.         }
  170.         else
  171.         {
  172.           uchar buffer[CCHMAXPATH];
  173.  
  174.           strcpy(buffer,nplast->pdf->DebFilePtr->fn);
  175.  
  176.           memcpy( pbuf, buffer, min( FNLEN, strlen(buffer) ) );
  177.         }
  178.         pbuf += FNLEN;
  179.  
  180.         /*********************************************************************/
  181.         /* put the lno stopped info into the buffer                          */
  182.         /*********************************************************************/
  183.         sprintf( pbuf - 1, " line %-5u ", nplast->lno );
  184.         pbuf += LINELEN;
  185.  
  186.         /*********************************************************************/
  187.         /* put the function name into the buffer.                            */
  188.         /*********************************************************************/
  189.         fn = DBFindProcName( nplast->ip, nplast->pdf );
  190.         if( fn )
  191.           strncpy( pbuf, fn+2, min( *(ushort *)fn, FUNCLEN ) );
  192.       }
  193.       /***********************************************************************/
  194.       /* if this is the current execthd put in the arrow mark in front       */
  195.       /***********************************************************************/
  196.       if( nplast == GetExecThread() )
  197.         buf[0] = '>';
  198.       /***********************************************************************/
  199.       /* bump to the next thread.                                            */
  200.       /***********************************************************************/
  201.       nplast = nplast->next;
  202.     }
  203.     buf[bufsize-1] = 0; /* terminate the string */
  204.     putrc( shell->row + i + shell->SkipLines, shell->col + 1, buf );
  205.   }
  206.   Tfree( buf );
  207. }
  208.  
  209. /*****************************************************************************/
  210. /*                                                                           */
  211. /* ThreadsDialogFunction()                                                   */
  212. /*                                                                           */
  213. /* Description:                                                              */
  214. /*                                                                           */
  215. /* This is the function called by ProcessDialog (in pulldown.c) whenever an  */
  216. /* event occurs in the dialog. This fuction handles the events in a way      */
  217. /* specific to this dialog.                                                  */
  218. /*                                                                           */
  219. /* Parameters:                                                               */
  220. /*                                                                           */
  221. /*   shell         input  - Pointer to DIALOGSHELL structure.                */
  222. /*   ptr           input  - Pointer to DIALOGCHOICE structure.               */
  223. /*   nEvent        input  - Pointer to EVENT structure.                      */
  224. /*                                                                           */
  225. /* Return:                                                                   */
  226. /*        = 0     - The caller has to continue processing the dialog.        */
  227. /*       != 0     - The caller can terminate processing the dialog.          */
  228. /*****************************************************************************/
  229. uint  ThreadsDialogFunction( DIALOGSHELL *shell, DIALOGCHOICE *ptr,
  230.                              EVENT *nEvent, void *ParamBlock )
  231. {
  232.   int     SelectIndex;
  233.   uint    Counter;
  234.   TSTATE *np;
  235.   UINT    tid;
  236.  
  237.   SelectIndex = shell->CurrentField + ptr->SkipRows;
  238.   ptr->entries = 0;
  239.   nplast = thead;
  240.   Counter = 1;
  241.   while( nplast != 0 )
  242.   {
  243.     ptr->entries++;
  244.     if( nEvent->Value == INIT_DIALOG )
  245.     {
  246.       if( nplast == GetExecThread() )
  247.         SelectIndex = Counter;
  248.     }
  249.     else
  250.     {
  251.       if( Counter == SelectIndex )
  252.         np = nplast;
  253.     }
  254.     nplast = nplast->next;
  255.     Counter++;
  256.   }
  257.  
  258.   switch( nEvent->Value )
  259.   {
  260.     case INIT_DIALOG:
  261.     {
  262.       /*********************************************************************/
  263.       /* This message is sent before displaying elements in display area.  */
  264.       /* It is to initialise the locals in the dialog function.            */
  265.       /*  - Set the field cursor and variables to the first field.         */
  266.       /*  - Set the length of the field highlite bar in normal and hilite  */
  267.       /*    arrays (used in the call to putrc).                            */
  268.       /*  - Return zero to denote continue dialog processing.              */
  269.       /*********************************************************************/
  270.       hilite[1] = normal[1] = (UCHAR)shell->width - SCROLLBARCOLOFFSET - 2;
  271.       putrc( shell->row + 2, shell->col + 2, Header );
  272.       return( 0 );
  273.     }
  274.  
  275.     case key_H:
  276.     case key_h:
  277.     {
  278.       xThawThread( 0 );                                                 /*827*/
  279.       BuildThreadList();
  280.       DisplayThdsChoice( shell, ptr );
  281.       return( 0 );
  282.     }
  283.  
  284.     case key_R:
  285.     case key_r:
  286.     {
  287.       xFreezeThread( 0 );                                               /*827*/
  288.       BuildThreadList();
  289.       DisplayThdsChoice( shell, ptr );
  290.       return( 0 );
  291.     }
  292.  
  293.     case key_F:
  294.     case key_f:
  295.     {
  296.       tid = np->tid;
  297.       xFreezeThread( tid );                                             /*827*/
  298.       BuildThreadList();
  299.       /***********************************************************************/
  300.       /* - BuildThreadList wipes out the thread list so we have to update.   */
  301.       /***********************************************************************/
  302.       np = GetThreadTSTATE( tid );
  303.       putrc( shell->row + shell->SkipLines + shell->CurrentField - 1,
  304.              shell->col + 2 + TIDLEN,
  305.             Dvals[np->ts.DebugState] );
  306.       return( 0 );
  307.     }
  308.  
  309.     case key_T:
  310.     case key_t:
  311.     {
  312.       tid = np->tid;
  313.       xThawThread( tid );                                               /*827*/
  314.       BuildThreadList();
  315.       /***********************************************************************/
  316.       /* - BuildThreadList wipes out the thread list so we have to update.   */
  317.       /***********************************************************************/
  318.       np = GetThreadTSTATE( tid );
  319.       putrc( shell->row + shell->SkipLines + shell->CurrentField - 1,
  320.              shell->col + 2 + TIDLEN,
  321.             Dvals[np->ts.DebugState] );
  322.       return( 0 );
  323.     }
  324.  
  325.     case key_A:
  326.     case key_a:
  327.     {
  328.       allinfo ^= 0x1;
  329.       DisplayThdsChoice( shell, ptr );
  330.       return( 0 );
  331.     }
  332.  
  333.     case ENTER:
  334.     {
  335.       /*********************************************************************/
  336.       /* This message is sent if the user clicks on the ENTER button or    */
  337.       /* presses the ENTER key.                                            */
  338.       /*  - Return non zero value to denote the end of dialog processing.  */
  339.       /*********************************************************************/
  340.       ptr->SkipRows = 0;
  341.       return( ENTER );
  342.     }
  343.  
  344.     case F1:
  345.     {
  346.       uchar  *HelpMsg;
  347.  
  348.       HelpMsg = GetHelpMsg( HELP_DLG_THREADS, NULL,0 );
  349.       CuaShowHelpBox( HelpMsg );
  350.       return( 0 );
  351.     }
  352.  
  353.     case ESC:
  354.     case F10:
  355.     {
  356.       /*********************************************************************/
  357.       /* This message is sent if the user clicks on the CANCEL button or   */
  358.       /* presses the ESC/F10 keys.                                         */
  359.       /*  - Return non zero value to denote the end of dialog processing.  */
  360.       /*********************************************************************/
  361.       ptr->SkipRows = 0;
  362.       return( nEvent->Value );
  363.     }
  364.  
  365.     case SPACEBAR:
  366.     {
  367.       /* 906 removed a check for thread in terminating state.*/
  368.       {
  369.         RunThread( np->tid );
  370.         DisplayThdsChoice( shell, ptr );
  371.       }
  372.       return( 0 );
  373.     }
  374.  
  375.     default:
  376.       return( 0 );
  377.   }
  378. }
  379.