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.

143 lines
3.3 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. pchfh.h
  5. Abstract:
  6. Unit test for symbol resolver
  7. Revision History:
  8. Brijesh Krishnaswami (brijeshk) - 04/01/99 - Created
  9. ********************************************************************/
  10. #include <stdafx.h>
  11. #include <symres.h>
  12. // for trace output to include filename
  13. #ifdef THIS_FILE
  14. #undef THIS_FILE
  15. #endif
  16. static char __szTraceSourceFile[]=__FILE__;
  17. #define THIS_FILE __szTraceSourceFile
  18. #define TRACE_ID 1
  19. typedef struct _CallStack {
  20. WCHAR szFilename[MAX_PATH];
  21. WCHAR szVersion[MAX_PATH];
  22. DWORD dwCheckSum;
  23. DWORD dwSection;
  24. UINT_PTR Offset;
  25. WCHAR szFuncName[MAX_PATH];
  26. } CALLSTACK;
  27. // reads callstack list from file
  28. void
  29. MakeList(
  30. LPTSTR szCSFile,
  31. std::list<CALLSTACK *>& CallStackList
  32. )
  33. {
  34. FILE* fCS = NULL;
  35. CALLSTACK* pCallStack = NULL;
  36. TCHAR szVersion[MAX_PATH];
  37. TCHAR szFilename[MAX_PATH];
  38. TraceFunctEnter("MakeList");
  39. fCS = (FILE *) fopen(szCSFile, "r");
  40. if (!fCS)
  41. {
  42. ErrorTrace(TRACE_ID, "Error opening file");
  43. goto exit;
  44. }
  45. pCallStack = (CALLSTACK *) malloc(sizeof(CALLSTACK));
  46. if (!pCallStack)
  47. {
  48. ErrorTrace(TRACE_ID, "malloc failed");
  49. goto exit;
  50. }
  51. // read from file
  52. while (fscanf(fCS,
  53. "%s %s %X %X",
  54. szFilename,
  55. szVersion,
  56. &(pCallStack->dwSection),
  57. &(pCallStack->Offset)) == 4)
  58. {
  59. MultiByteToWideChar(CP_ACP,0,szFilename,-1,pCallStack->szFilename,MAX_PATH);
  60. if (!lstrcmp(szVersion,TEXT("-")))
  61. {
  62. lstrcpyW(pCallStack->szVersion,L"");
  63. }
  64. else
  65. {
  66. MultiByteToWideChar(CP_ACP,0,szVersion,-1,pCallStack->szVersion,MAX_PATH);
  67. }
  68. CallStackList.push_back(pCallStack);
  69. pCallStack = (CALLSTACK *) malloc(sizeof(CALLSTACK));
  70. if (!pCallStack)
  71. {
  72. ErrorTrace(TRACE_ID, "malloc failed");
  73. goto exit;
  74. }
  75. }
  76. // free unused node
  77. if (pCallStack)
  78. {
  79. free(pCallStack);
  80. }
  81. exit:
  82. if (fCS)
  83. {
  84. fclose(fCS);
  85. }
  86. TraceFunctLeave();
  87. return;
  88. }
  89. void _cdecl
  90. main(int argc, char *argv[])
  91. {
  92. HMODULE hSym = NULL;
  93. std::list<CALLSTACK *> CallStackList;
  94. std::list<CALLSTACK *>::iterator it;
  95. TraceFunctEnter("main");
  96. #ifndef NOTRACE
  97. InitAsyncTrace();
  98. #endif
  99. MakeList(argv[1], CallStackList);
  100. for (it = CallStackList.begin(); it != CallStackList.end(); it++)
  101. {
  102. ResolveSymbols((*it)->szFilename,
  103. (*it)->szVersion,
  104. (*it)->dwSection,
  105. (*it)->Offset,
  106. (*it)->szFuncName);
  107. printf("\n%S %S %04X:%08X %S",
  108. (*it)->szFilename,
  109. (*it)->szVersion,
  110. (*it)->dwSection,
  111. (*it)->Offset,
  112. (*it)->szFuncName);
  113. }
  114. TraceFunctLeave();
  115. TermAsyncTrace();
  116. }