pcs.c 3.2 KB

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