bpt.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #include <u.h>
  10. #include <libc.h>
  11. #include <ctype.h>
  12. #include <bio.h>
  13. #include <mach.h>
  14. #define Extern extern
  15. #include "power.h"
  16. void
  17. dobplist(void)
  18. {
  19. Breakpoint *b;
  20. char buf[512];
  21. for(b = bplist; b; b = b->next) {
  22. switch(b->type) {
  23. case Instruction:
  24. Bprint(bioout, "0x%lux,%d:b %d done, at ", b->addr, b->count, b->done);
  25. symoff(buf, sizeof(buf), b->addr, CTEXT);
  26. Bprint(bioout, "%s", buf);
  27. break;
  28. case Access:
  29. Bprint(bioout, "0x%lux,%d:ba %d done, at ", b->addr, b->count, b->done);
  30. symoff(buf, sizeof(buf), b->addr, CDATA);
  31. Bprint(bioout, "%s", buf);
  32. break;
  33. case Read:
  34. Bprint(bioout, "0x%lux,%d:br %d done, at ", b->addr, b->count, b->done);
  35. symoff(buf, sizeof(buf), b->addr, CDATA);
  36. Bprint(bioout, "%s", buf);
  37. break;
  38. case Write:
  39. Bprint(bioout, "0x%lux,%d:bw %d done, at ", b->addr, b->count, b->done);
  40. symoff(buf, sizeof(buf), b->addr, CDATA);
  41. Bprint(bioout, "%s", buf);
  42. break;
  43. case Equal:
  44. Bprint(bioout, "0x%lux,%d:be at ", b->addr, b->count);
  45. symoff(buf, sizeof(buf), b->addr, CDATA);
  46. Bprint(bioout, "%s", buf);
  47. break;
  48. }
  49. Bprint(bioout, "\n");
  50. }
  51. }
  52. void
  53. breakpoint(char *addr, char *cp)
  54. {
  55. Breakpoint *b;
  56. int type;
  57. cp = nextc(cp);
  58. type = Instruction;
  59. switch(*cp) {
  60. case 'r':
  61. membpt++;
  62. type = Read;
  63. break;
  64. case 'a':
  65. membpt++;
  66. type = Access;
  67. break;
  68. case 'w':
  69. membpt++;
  70. type = Write;
  71. break;
  72. case 'e':
  73. membpt++;
  74. type = Equal;
  75. break;
  76. }
  77. b = emalloc(sizeof(Breakpoint));
  78. b->addr = expr(addr);
  79. b->type = type;
  80. b->count = cmdcount;
  81. b->done = cmdcount;
  82. b->next = bplist;
  83. bplist = b;
  84. }
  85. void
  86. delbpt(char *addr)
  87. {
  88. Breakpoint *b, **l;
  89. uint32_t baddr;
  90. baddr = expr(addr);
  91. l = &bplist;
  92. for(b = *l; b; b = b->next) {
  93. if(b->addr == baddr) {
  94. if(b->type != Instruction)
  95. membpt++;
  96. *l = b->next;
  97. free(b);
  98. return;
  99. }
  100. l = &b->next;
  101. }
  102. Bprint(bioout, "no breakpoint\n");
  103. }
  104. void
  105. brkchk(uint32_t addr, int type)
  106. {
  107. Breakpoint *b;
  108. for(b = bplist; b; b = b->next) {
  109. if(b->addr == addr && (b->type&type)) {
  110. if(b->type == Equal && getmem_4(addr) == b->count) {
  111. count = 1;
  112. atbpt = 1;
  113. return;
  114. }
  115. if(--b->done == 0) {
  116. b->done = b->count;
  117. count = 1;
  118. atbpt = 1;
  119. return;
  120. }
  121. }
  122. }
  123. }