Abldbug.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. //***************************************************************************
  5. //
  6. // ABLDBUG.H
  7. //
  8. //***************************************************************************
  9. #ifndef ABLDBUG_H
  10. #define ABLDBUG_H
  11. #ifndef DABLDBUG_H
  12. #include "dabldbug.h"
  13. #endif
  14. #ifndef ABLENV_H
  15. #include "ablenv.h"
  16. #endif
  17. //***************************************************************************
  18. typedef enum {
  19. DEBUG_COMMAND_SET_MODULE,
  20. DEBUG_COMMAND_TRACE,
  21. DEBUG_COMMAND_STEP,
  22. DEBUG_COMMAND_BREAKPOINT_SET,
  23. DEBUG_COMMAND_BREAKPOINT_REMOVE,
  24. DEBUG_COMMAND_WATCH_SET,
  25. DEBUG_COMMAND_WATCH_REMOVE_ALL,
  26. DEBUG_COMMAND_PRINT,
  27. DEBUG_COMMAND_CONTINUE,
  28. DEBUG_COMMAND_HELP,
  29. DEBUG_COMMAND_INFO,
  30. NUM_DEBUG_COMMANDS
  31. } DebugCommandCode;
  32. //***************************************************************************
  33. typedef struct _Watch {
  34. SymTableNodePtr idPtr;
  35. bool store;
  36. bool breakOnStore;
  37. bool fetch;
  38. bool breakOnFetch;
  39. } Watch;
  40. typedef Watch* WatchPtr;
  41. class WatchManager {
  42. protected:
  43. long maxWatches;
  44. long numWatches;
  45. WatchPtr watches;
  46. public:
  47. void* operator new (size_t mySize);
  48. void operator delete (void* us);
  49. void init (void) {
  50. maxWatches = 0;
  51. maxWatches = 0;
  52. watches = NULL;
  53. }
  54. long init (long max);
  55. void destroy (void);
  56. WatchManager (void) {
  57. init();
  58. }
  59. ~WatchManager (void) {
  60. destroy();
  61. }
  62. WatchPtr add (SymTableNodePtr idPtr);
  63. long remove (SymTableNodePtr idPtr);
  64. long removeAll (void);
  65. long setStore (SymTableNodePtr idPtr, bool state, bool breakToDebug = false);
  66. long setFetch (SymTableNodePtr idPtr, bool state, bool breakToDebug = false);
  67. bool getStore (SymTableNodePtr idPtr);
  68. bool getFetch (SymTableNodePtr idPtr);
  69. void print (void);
  70. };
  71. //---------------------------------------------------------------------------
  72. class BreakPointManager {
  73. protected:
  74. long maxBreakPoints;
  75. long numBreakPoints;
  76. long* breakPoints;
  77. public:
  78. void* operator new (size_t mySize);
  79. void operator delete (void* us);
  80. void init (void) {
  81. maxBreakPoints = 0;
  82. numBreakPoints = 0;
  83. breakPoints = NULL;
  84. }
  85. long init (long max);
  86. void destroy (void);
  87. BreakPointManager (void) {
  88. init();
  89. }
  90. ~BreakPointManager (void) {
  91. destroy();
  92. }
  93. long add (long lineNumber);
  94. long remove (long lineNumber);
  95. long removeAll (void);
  96. bool isBreakPoint (long lineNumber);
  97. void print (void);
  98. };
  99. //---------------------------------------------------------------------------
  100. #define WATCH_STORE_OFF 1
  101. #define WATCH_STORE_ON 2
  102. #define WATCH_FETCH_OFF 4
  103. #define WATCH_FETCH_ON 8
  104. #define WATCH_BREAK 16
  105. class Debugger {
  106. protected:
  107. ABLModulePtr module; // Current executing module
  108. WatchManagerPtr watchManager; // Current executing watch manager
  109. BreakPointManagerPtr breakPointManager; // Current executing breakpt manager
  110. ABLModulePtr debugModule; // Current module being debugged
  111. bool enabled;
  112. bool debugCommand;
  113. bool halt;
  114. bool trace;
  115. bool step;
  116. bool traceEntry;
  117. bool traceExit;
  118. static char message[512];
  119. void (*printCallback)(char* s);
  120. public:
  121. void* operator new (size_t mySize);
  122. void operator delete (void* us);
  123. void init (void) {
  124. module = NULL;
  125. watchManager = NULL;
  126. breakPointManager = NULL;
  127. debugModule = module;
  128. enabled = false;
  129. debugCommand = false;
  130. halt = false;
  131. trace = false;
  132. step = false;
  133. traceEntry = false;
  134. traceExit = false;
  135. printCallback = NULL;
  136. }
  137. long init (void (*callback)(char* s), ABLModulePtr _module);
  138. void destroy (void);
  139. Debugger (void) {
  140. init();
  141. }
  142. ~Debugger (void) {
  143. destroy();
  144. }
  145. void enable (void) {
  146. enabled = true;
  147. }
  148. void disable (void) {
  149. enabled = false;
  150. }
  151. bool isEnabled (void) {
  152. return(enabled);
  153. }
  154. long print (char* s);
  155. void setModule (ABLModulePtr _module);
  156. long setWatch (long states);
  157. long addBreakPoint (void);
  158. long removeBreakPoint (void);
  159. void sprintStatement (char* dest);
  160. void sprintLineNumber (char* dest);
  161. void sprintDataValue (char* dest, StackItemPtr data, TypePtr dataType);
  162. long sprintSimpleValue (char* dest, SymTableNodePtr symbol);
  163. long sprintArrayValue (char* dest, SymTableNodePtr symbol, char* subscriptString);
  164. long sprintValue (char* dest, char* exprString);
  165. long traceStatementExecution (void);
  166. long traceRoutineEntry (SymTableNodePtr idPtr);
  167. long traceRoutineExit (SymTableNodePtr idPtr);
  168. long traceDataStore (SymTableNodePtr id, TypePtr idType, StackItemPtr target, TypePtr targetType);
  169. long traceDataFetch (SymTableNodePtr id, TypePtr idType, StackItemPtr data);
  170. void showValue (void);
  171. void assignVariable (void);
  172. void displayModuleInstanceRegistry (void);
  173. void processCommand (long commandId, char* strParam1, long numParam1, ABLModulePtr moduleParam1);
  174. void debugMode (void);
  175. ABLModulePtr getDebugModule (void) {
  176. return(debugModule);
  177. }
  178. };
  179. //***************************************************************************
  180. #endif