runpcs.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. BKPT *bkpthead;
  17. BOOL bpin;
  18. int pid;
  19. int nnote;
  20. int ending;
  21. char note[NNOTE][ERRMAX];
  22. /* service routines for sub process control */
  23. runpcs(int runmode, int keepnote)
  24. {
  25. int rc;
  26. BKPT *bkpt;
  27. rc = 0;
  28. if (adrflg)
  29. rput(cormap, mach->pc, dot);
  30. dot = rget(cormap, mach->pc);
  31. flush();
  32. while (loopcnt-- > 0) {
  33. if(loopcnt != 0)
  34. printpc();
  35. if (runmode == SINGLE) {
  36. bkpt = scanbkpt(dot);
  37. if (bkpt) {
  38. switch(bkpt->flag){
  39. case BKPTTMP:
  40. bkpt->flag = BKPTCLR;
  41. break;
  42. case BKPTSKIP:
  43. bkpt->flag = BKPTSET;
  44. break;
  45. }
  46. }
  47. runstep(dot, keepnote);
  48. } else {
  49. if ((bkpt = scanbkpt(rget(cormap, mach->pc))) != 0) {
  50. execbkpt(bkpt, keepnote);
  51. keepnote = 0;
  52. }
  53. setbp();
  54. runrun(keepnote);
  55. }
  56. keepnote = 0;
  57. delbp();
  58. dot = rget(cormap, mach->pc);
  59. /* real note? */
  60. if (nnote > 0) {
  61. keepnote = 1;
  62. rc = 0;
  63. continue;
  64. }
  65. bkpt = scanbkpt(dot);
  66. if(bkpt == 0){
  67. keepnote = 0;
  68. rc = 0;
  69. continue;
  70. }
  71. /* breakpoint */
  72. if (bkpt->flag == BKPTTMP)
  73. bkpt->flag = BKPTCLR;
  74. else if (bkpt->flag == BKPTSKIP) {
  75. execbkpt(bkpt, keepnote);
  76. keepnote = 0;
  77. loopcnt++; /* we didn't really stop */
  78. continue;
  79. }
  80. else {
  81. bkpt->flag = BKPTSKIP;
  82. --bkpt->count;
  83. if ((bkpt->comm[0] == EOR || command(bkpt->comm, ':') != 0)
  84. && bkpt->count != 0) {
  85. execbkpt(bkpt, keepnote);
  86. keepnote = 0;
  87. loopcnt++;
  88. continue;
  89. }
  90. bkpt->count = bkpt->initcnt;
  91. }
  92. rc = 1;
  93. }
  94. return(rc);
  95. }
  96. /*
  97. * finish the process off;
  98. * kill if still running
  99. */
  100. void
  101. endpcs(void)
  102. {
  103. BKPT *bk;
  104. if(ending)
  105. return;
  106. ending = 1;
  107. if (pid) {
  108. if(pcsactive){
  109. killpcs();
  110. pcsactive = 0;
  111. }
  112. pid=0;
  113. nnote=0;
  114. for (bk=bkpthead; bk; bk = bk->nxtbkpt)
  115. if (bk->flag == BKPTTMP)
  116. bk->flag = BKPTCLR;
  117. else if (bk->flag != BKPTCLR)
  118. bk->flag = BKPTSET;
  119. }
  120. bpin = FALSE;
  121. ending = 0;
  122. }
  123. /*
  124. * start up the program to be debugged in a child
  125. */
  126. void
  127. setup(void)
  128. {
  129. nnote = 0;
  130. startpcs();
  131. bpin = FALSE;
  132. pcsactive = 1;
  133. }
  134. /*
  135. * skip over a breakpoint:
  136. * remove breakpoints, then single step
  137. * so we can put it back
  138. */
  139. void
  140. execbkpt(BKPT *bk, int keepnote)
  141. {
  142. runstep(bk->loc, keepnote);
  143. bk->flag = BKPTSET;
  144. }
  145. /*
  146. * find the breakpoint at adr, if any
  147. */
  148. BKPT *
  149. scanbkpt(ADDR adr)
  150. {
  151. BKPT *bk;
  152. for (bk = bkpthead; bk; bk = bk->nxtbkpt)
  153. if (bk->flag != BKPTCLR && bk->loc == adr)
  154. break;
  155. return(bk);
  156. }
  157. /*
  158. * remove all breakpoints from the process' address space
  159. */
  160. void
  161. delbp(void)
  162. {
  163. BKPT *bk;
  164. if (bpin == FALSE || pid == 0)
  165. return;
  166. for (bk = bkpthead; bk; bk = bk->nxtbkpt)
  167. if (bk->flag != BKPTCLR)
  168. bkput(bk, 0);
  169. bpin = FALSE;
  170. }
  171. /*
  172. * install all the breakpoints
  173. */
  174. void
  175. setbp(void)
  176. {
  177. BKPT *bk;
  178. if (bpin == TRUE || pid == 0)
  179. return;
  180. for (bk = bkpthead; bk; bk = bk->nxtbkpt)
  181. if (bk->flag != BKPTCLR)
  182. bkput(bk, 1);
  183. bpin = TRUE;
  184. }