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.

213 lines
3.5 KiB

  1. //
  2. // calltree.c
  3. //
  4. // two routines for printing out ascii 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 dCallTree(IINST iinst, WORD cuse);
  26. // static variables
  27. static BYTE *UseBits = NULL;
  28. static WORD cNest = 0;
  29. VOID BSC_API
  30. CallTreeInst (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. UseBits = LpvAllocCb((WORD)(iinstMac/8 + 1));
  39. // no memory -- no call tree
  40. if (!UseBits) return;
  41. igrp = iinstMac/8+1;
  42. while (--igrp>=0)
  43. UseBits[igrp] = 0;
  44. cNest = 0;
  45. dCallTree(iinst, 1);
  46. FreeLpv(UseBits);
  47. }
  48. static VOID
  49. dCallTree (IINST iinst, WORD cuse)
  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. TYP typ;
  58. ATR atr;
  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 (cuse > 1)
  69. BSCPrintf ("%s[%d]", LszNameFrSym (isym), cuse);
  70. else
  71. BSCPrintf ("%s", LszNameFrSym (isym));
  72. }
  73. {
  74. IDEF idef, idefMac;
  75. LSZ lsz;
  76. WORD w;
  77. DefRangeOfInst(iinst, &idef, &idefMac);
  78. DefInfo(idef, &lsz, &w);
  79. if (strcmp("<Unknown>", lsz) == 0) {
  80. BSCPrintf ("?\n");
  81. cNest--;
  82. return;
  83. }
  84. }
  85. if (FUsedInst(iinst)) {
  86. BSCPrintf ("...\n");
  87. cNest--;
  88. return;
  89. }
  90. BSCPrintf ("\n");
  91. {
  92. IUSE iuse, iuseMac;
  93. IINST iinstUse;
  94. UseRangeOfInst(iinst, &iuse, &iuseMac);
  95. for (; iuse < iuseMac; iuse++) {
  96. UseInfo(iuse, &iinstUse, &cuse);
  97. dCallTree (iinstUse, cuse);
  98. }
  99. }
  100. cNest--;
  101. }
  102. BOOL BSC_API
  103. FCallTreeLsz(LSZ lszName)
  104. // print out a call tree based on the given name
  105. //
  106. {
  107. IMOD imod;
  108. ISYM isym;
  109. cNest = 0;
  110. if (!lszName)
  111. return FALSE;
  112. {
  113. IINST iinstMac;
  114. int igrp;
  115. iinstMac = IinstMac();
  116. // allocate memory for bit array
  117. UseBits = LpvAllocCb((WORD)(iinstMac/8 + 1));
  118. // no memory -- no call tree
  119. if (!UseBits) return FALSE;
  120. igrp = iinstMac/8+1;
  121. while (--igrp >= 0)
  122. UseBits[igrp] = 0;
  123. }
  124. if ((imod = ImodFrLsz (lszName)) != imodNil) {
  125. IMS ims, imsMac;
  126. MsRangeOfMod(imod, &ims, &imsMac);
  127. BSCPrintf ("%s\n", LszNameFrMod (imod));
  128. for ( ; ims < imsMac ; ims++)
  129. dCallTree (IinstOfIms(ims), 1);
  130. FreeLpv(UseBits);
  131. return TRUE;
  132. }
  133. if ((isym = IsymFrLsz (lszName)) != isymNil) {
  134. IINST iinst, iinstMac;
  135. BSCPrintf ("%s\n", LszNameFrSym (isym));
  136. InstRangeOfSym(isym, &iinst, &iinstMac);
  137. for (; iinst < iinstMac; iinst++)
  138. dCallTree (iinst, 1);
  139. FreeLpv(UseBits);
  140. return TRUE;
  141. }
  142. FreeLpv(UseBits);
  143. return FALSE;
  144. }
  145. static BOOL
  146. FUsedInst(IINST iinst)
  147. // return the status bit for this iinst and set it true
  148. //
  149. {
  150. WORD igrp;
  151. BOOL fOut;
  152. WORD mask;
  153. igrp = iinst / 8;
  154. mask = (1 << (iinst % 8));
  155. fOut = !!(UseBits[igrp] & mask);
  156. UseBits[igrp] |= mask;
  157. return fOut;
  158. }