Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
3.3 KiB

  1. //
  2. // revtree.c
  3. //
  4. // two routines for printing out ascii reverse call tree's
  5. //
  6. #include <stdio.h>
  7. #include <string.h>
  8. #if defined(OS2)
  9. #define INCL_NOCOMMON
  10. #define INCL_DOSPROCESS
  11. #define INCL_DOSSEMAPHORES
  12. #define INCL_DOSFILEMGR
  13. #define INCL_DOSERRORS
  14. #define INCL_DOSMISC
  15. #include <os2.h>
  16. #else
  17. #include <windows.h>
  18. #endif
  19. #include <dos.h>
  20. #include "hungary.h"
  21. #include "bsc.h"
  22. #include "bscsup.h"
  23. // forward declarations
  24. static BOOL FUsedInst(IINST iinst);
  25. static VOID dRevTree(IINST iinst, WORD cuby);
  26. // static variables
  27. static BYTE *UbyBits = NULL;
  28. static WORD cNest = 0;
  29. VOID BSC_API
  30. RevTreeInst (IINST iinst)
  31. // emit the call tree starting from the given inst
  32. //
  33. {
  34. WORD iinstMac;
  35. int igrp;
  36. iinstMac = IinstMac();
  37. // allocate memory for bit array
  38. UbyBits = LpvAllocCb((WORD)(iinstMac/8 + 1));
  39. // no memory -- no call tree
  40. if (!UbyBits) return;
  41. igrp = iinstMac/8+1;
  42. while (--igrp>=0)
  43. UbyBits[igrp] = 0;
  44. cNest = 0;
  45. dRevTree(iinst, 1);
  46. FreeLpv(UbyBits);
  47. }
  48. static VOID
  49. dRevTree (IINST iinst, WORD cuby)
  50. // emit the call tree starting from the given inst
  51. //
  52. // there are many block variables to keep the stack to a minimum...
  53. {
  54. {
  55. ISYM isym;
  56. {
  57. ATR atr;
  58. TYP typ;
  59. InstInfo(iinst, &isym, &typ, &atr);
  60. if (typ > INST_TYP_LABEL)
  61. return;
  62. }
  63. {
  64. WORD i;
  65. cNest++;
  66. for (i = cNest; i; i--) BSCPrintf ("| ");
  67. }
  68. if (cuby > 1)
  69. BSCPrintf ("%s[%d]", LszNameFrSym (isym), cuby);
  70. else
  71. BSCPrintf ("%s", LszNameFrSym (isym));
  72. }
  73. if (FUsedInst(iinst)) {
  74. BSCPrintf ("...\n");
  75. cNest--;
  76. return;
  77. }
  78. BSCPrintf ("\n");
  79. {
  80. IUBY iuby, iubyMac;
  81. IINST iinstUby;
  82. UbyRangeOfInst(iinst, &iuby, &iubyMac);
  83. for (; iuby < iubyMac; iuby++) {
  84. UbyInfo(iuby, &iinstUby, &cuby);
  85. dRevTree (iinstUby, cuby);
  86. }
  87. }
  88. cNest--;
  89. }
  90. BOOL BSC_API
  91. FRevTreeLsz(LSZ lszName)
  92. // print out a call tree based on the given name
  93. //
  94. {
  95. IMOD imod;
  96. ISYM isym;
  97. cNest = 0;
  98. if (!lszName)
  99. return FALSE;
  100. {
  101. IINST iinstMac;
  102. int igrp;
  103. iinstMac = IinstMac();
  104. // allocate memory for bit array
  105. UbyBits = LpvAllocCb((WORD)(iinstMac/8 + 1));
  106. // no memory -- no call tree
  107. if (!UbyBits) return FALSE;
  108. igrp = iinstMac/8+1;
  109. while (--igrp >= 0)
  110. UbyBits[igrp] = 0;
  111. }
  112. if ((imod = ImodFrLsz (lszName)) != imodNil) {
  113. IMS ims, imsMac;
  114. MsRangeOfMod(imod, &ims, &imsMac);
  115. BSCPrintf ("%s\n", LszNameFrMod (imod));
  116. for ( ; ims < imsMac ; ims++)
  117. dRevTree (IinstOfIms(ims), 1);
  118. FreeLpv(UbyBits);
  119. return TRUE;
  120. }
  121. if ((isym = IsymFrLsz (lszName)) != isymNil) {
  122. IINST iinst, iinstMac;
  123. BSCPrintf ("%s\n", LszNameFrSym (isym));
  124. InstRangeOfSym(isym, &iinst, &iinstMac);
  125. for (; iinst < iinstMac; iinst++)
  126. dRevTree (iinst, 1);
  127. FreeLpv(UbyBits);
  128. return TRUE;
  129. }
  130. FreeLpv(UbyBits);
  131. return FALSE;
  132. }
  133. static BOOL
  134. FUsedInst(IINST iinst)
  135. // return the status bit for this iinst and set it true
  136. //
  137. {
  138. WORD igrp;
  139. BOOL fOut;
  140. WORD mask;
  141. igrp = iinst / 8;
  142. mask = (1 << (iinst % 8));
  143. fOut = !!(UbyBits[igrp] & mask);
  144. UbyBits[igrp] |= mask;
  145. return fOut;
  146. }