jitd.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #include <precomp.h>
  2. #include "jitd.h"
  3. #include "jitdbreak.h"
  4. #include <api/service/svcs/svc_debuggerui.h>
  5. #include <api/service/svc_enum.h>
  6. #include <api/script/debugger/vcpudebug.h>
  7. #include <api/script/debugger/debuggerui.h>
  8. #include <api/script/debugger/sdebuggerui.h>
  9. #include <api/script/debugger/debugsymbols.h>
  10. MakiJITD::MakiJITD(VCPUDebugger *_debugger, int _vcpuid) {
  11. vip = vsp = vsd = vcc = -1;
  12. globalbreakpoint = 1; // fucko!!
  13. onhold = 0;
  14. debugger = _debugger;
  15. vcpuid = _vcpuid;
  16. uisvc = NULL;
  17. ui = NULL;
  18. simpleui = NULL;
  19. codeblock = _debugger->getCodeBlock(vcpuid);
  20. sysbp = new JITDBreakpoint(this, 0);
  21. breakpoints.addItem(sysbp);
  22. sysbp->setEnabled(0);
  23. symbols = new DebugSymbols(_vcpuid);
  24. }
  25. MakiJITD::~MakiJITD() {
  26. breakpoints.deleteAll();
  27. if (uisvc != NULL) {
  28. uisvc->destroyUI(ui);
  29. WASABI_API_SVC->service_release(uisvc);
  30. }
  31. delete simpleui;
  32. delete symbols;
  33. }
  34. int MakiJITD::getVIP() {
  35. return vip;
  36. }
  37. int MakiJITD::getVCC() {
  38. return vcc;
  39. }
  40. int MakiJITD::getVSD() {
  41. return vsd;
  42. }
  43. int MakiJITD::getVSP() {
  44. return vsp;
  45. }
  46. int MakiJITD::isGlobalBreakpointSet() {
  47. return globalbreakpoint;
  48. }
  49. void MakiJITD::setGlobalBreakpoint(int s) {
  50. globalbreakpoint = s;
  51. }
  52. int MakiJITD::getNumBreakpoints() {
  53. return breakpoints.getNumItems();
  54. }
  55. JITDBreakpoint *MakiJITD::enumBreakpoint(int n) {
  56. return breakpoints.enumItem(n);
  57. }
  58. JITDBreakpoint *MakiJITD::findBreakpoint(int pointer) {
  59. int i;
  60. for (i=0;i<breakpoints.getNumItems();i++) {
  61. JITDBreakpoint *bp = breakpoints.enumItem(i);
  62. if (bp->isEnabled() && bp->getPointer() == pointer)
  63. return bp;
  64. }
  65. return NULL;
  66. }
  67. void MakiJITD::addBreakpoint(int pointer) {
  68. breakpoints.addItem(new JITDBreakpoint(this, pointer));
  69. }
  70. void MakiJITD::removeBreakpoint(JITDBreakpoint *breakpoint) {
  71. breakpoints.removeItem(breakpoint);
  72. delete breakpoint;
  73. }
  74. void MakiJITD::clearAllBreakpoints() {
  75. breakpoints.deleteAll();
  76. }
  77. int MakiJITD::getVCPUId() {
  78. return vcpuid;
  79. }
  80. void MakiJITD::trace() {
  81. vip = debugger->getVIP();
  82. vsp = debugger->getVSP();
  83. vsd = debugger->getVSD();
  84. vcc = debugger->getVCC();
  85. if (globalbreakpoint || findBreakpoint(vip)) {
  86. enterUi();
  87. }
  88. }
  89. int MakiJITD::isActive() {
  90. return 1;
  91. }
  92. void MakiJITD::enterUi() {
  93. createUi();
  94. sysbp->setEnabled(0);
  95. globalbreakpoint = 0;
  96. onhold = 1;
  97. int next_command = ui->messageLoop();
  98. onhold = 0;
  99. switch (next_command) {
  100. case JITD_RETURN_STEPINTO:
  101. globalbreakpoint = 1;
  102. break;
  103. case JITD_RETURN_STEPOUT:
  104. // for now, continue
  105. break;
  106. case JITD_RETURN_TERMINATE:
  107. // for now, continue
  108. break;
  109. case JITD_RETURN_CONTINUE:
  110. // do nothing
  111. default:
  112. break;
  113. }
  114. }
  115. void MakiJITD::createUi() {
  116. if (ui != NULL) return;
  117. waServiceFactory *f = WASABI_API_SVC->service_getServiceByGuid(SERVICE_DEBUGGERUI);
  118. if (f != NULL) {
  119. uisvc = castService<svc_debuggerUI>(f);
  120. if (uisvc != NULL) {
  121. ui = uisvc->createUI();
  122. ui->setJITD(this);
  123. }
  124. } else {
  125. simpleui = new SimpleDebuggerUI();
  126. ui = simpleui;
  127. ui->setJITD(this);
  128. }
  129. }
  130. int MakiJITD::isOnHold() {
  131. return onhold;
  132. }
  133. const char *MakiJITD::getCodeBlock() {
  134. return codeblock;
  135. }
  136. void MakiJITD::setSysBreakpoint(int pointer) {
  137. sysbp->setPointer(pointer);
  138. sysbp->setEnabled(1);
  139. }
  140. int MakiJITD::getNumLines() {
  141. return symbols->getNumLines();
  142. }
  143. SourceCodeLine *MakiJITD::enumLine(int n) {
  144. return symbols->enumLine(n);
  145. }
  146. int MakiJITD::findLine(int pointer) {
  147. return symbols->findLine(pointer);
  148. }