pcs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. *
  3. * debugger
  4. *
  5. */
  6. #include "defs.h"
  7. #include "fns.h"
  8. char NOPCS[] = "no process";
  9. /* sub process control */
  10. void
  11. subpcs(int modif)
  12. {
  13. int check;
  14. int runmode;
  15. int keepnote;
  16. int n, r;
  17. long line, curr;
  18. BKPT *bk;
  19. char *comptr;
  20. runmode=SINGLE;
  21. r = 0;
  22. keepnote=0;
  23. loopcnt=cntval;
  24. switch (modif) {
  25. /* delete breakpoint */
  26. case 'd':
  27. case 'D':
  28. if ((bk=scanbkpt(dot)) == 0)
  29. error("no breakpoint set");
  30. bk->flag=BKPTCLR;
  31. return;
  32. /* set breakpoint */
  33. case 'b':
  34. case 'B':
  35. if (bk=scanbkpt(dot))
  36. bk->flag=BKPTCLR;
  37. for (bk=bkpthead; bk; bk=bk->nxtbkpt)
  38. if (bk->flag == BKPTCLR)
  39. break;
  40. if (bk==0) {
  41. bk = (BKPT *)malloc(sizeof(*bk));
  42. if (bk == 0)
  43. error("too many breakpoints");
  44. bk->nxtbkpt=bkpthead;
  45. bkpthead=bk;
  46. }
  47. bk->loc = dot;
  48. bk->initcnt = bk->count = cntval;
  49. bk->flag = modif == 'b' ? BKPTSET : BKPTTMP;
  50. check=MAXCOM-1;
  51. comptr=bk->comm;
  52. rdc();
  53. reread();
  54. do {
  55. *comptr++ = readchar();
  56. } while (check-- && lastc!=EOR);
  57. *comptr=0;
  58. if(bk->comm[0] != EOR && cntflg == FALSE)
  59. bk->initcnt = bk->count = HUGEINT;
  60. reread();
  61. if (check)
  62. return;
  63. error("bkpt command too long");
  64. /* exit */
  65. case 'k' :
  66. case 'K':
  67. if (pid == 0)
  68. error(NOPCS);
  69. dprint("%d: killed", pid);
  70. pcsactive = 1; /* force 'kill' ctl */
  71. endpcs();
  72. return;
  73. /* run program */
  74. case 'r':
  75. case 'R':
  76. endpcs();
  77. setup();
  78. runmode = CONTIN;
  79. break;
  80. /* single step */
  81. case 's':
  82. if (pid == 0) {
  83. setup();
  84. loopcnt--;
  85. }
  86. runmode=SINGLE;
  87. keepnote=defval(1);
  88. break;
  89. case 'S':
  90. if (pid == 0) {
  91. setup();
  92. loopcnt--;
  93. }
  94. keepnote=defval(1);
  95. line = pc2line(rget(cormap, mach->pc));
  96. n = loopcnt;
  97. dprint("%s: running\n", symfil);
  98. flush();
  99. for (loopcnt = 1; n > 0; loopcnt = 1) {
  100. r = runpcs(SINGLE, keepnote);
  101. curr = pc2line(dot);
  102. if (line != curr) { /* on a new line of c */
  103. line = curr;
  104. n--;
  105. }
  106. }
  107. loopcnt = 0;
  108. break;
  109. /* continue with optional note */
  110. case 'c':
  111. case 'C':
  112. if (pid==0)
  113. error(NOPCS);
  114. runmode=CONTIN;
  115. keepnote=defval(1);
  116. break;
  117. case 'n': /* deal with notes */
  118. if (pid==0)
  119. error(NOPCS);
  120. n=defval(-1);
  121. if(n>=0 && n<nnote){
  122. nnote--;
  123. memmove(note[n], note[n+1], (nnote-n)*sizeof(note[0]));
  124. }
  125. notes();
  126. return;
  127. case 'h': /* halt the current process */
  128. if (adrflg && adrval == 0) {
  129. if (pid == 0)
  130. error(NOPCS);
  131. ungrab();
  132. }
  133. else {
  134. grab();
  135. dprint("stopped at%16t");
  136. goto Return;
  137. }
  138. return;
  139. case 'x': /* continue executing the current process */
  140. if (pid == 0)
  141. error(NOPCS);
  142. ungrab();
  143. return;
  144. default:
  145. error("bad `:' command");
  146. }
  147. if (loopcnt>0) {
  148. dprint("%s: running\n", symfil);
  149. flush();
  150. r = runpcs(runmode,keepnote);
  151. }
  152. if (r)
  153. dprint("breakpoint%16t");
  154. else
  155. dprint("stopped at%16t");
  156. Return:
  157. delbp();
  158. printpc();
  159. notes();
  160. }