Source code of Windows XP (NT5)
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.

162 lines
4.1 KiB

  1. #if defined (use_CopyPdbX)
  2. #include "private.h"
  3. #include "splitsymx.h"
  4. typedef BOOL ( __cdecl *PPDBCOPYTO ) (
  5. PDB* ppdb,
  6. const char* szTargetPdb,
  7. DWORD dwCopyFilter,
  8. DWORD dwReserved
  9. );
  10. typedef BOOL ( __cdecl *PPDBOPEN )(
  11. LNGNM_CONST char *,
  12. LNGNM_CONST char *,
  13. SIG,
  14. EC *,
  15. char [cbErrMax],
  16. PDB **
  17. );
  18. typedef BOOL ( __cdecl *PPDBCLOSE ) (
  19. PDB* ppdb
  20. );
  21. static PPDBCOPYTO pPDBCopyTo = NULL;
  22. static PPDBOPEN pPDBOpen = NULL;
  23. static PPDBCLOSE pPDBClose = NULL;
  24. static BOOL RSDSLibLoaded = FALSE;
  25. // If you call CopyPdbX with a NB10, or NB* pdb, then
  26. // set szRSDSDllToLoad and it will use the statically
  27. // linked in PDBCopyTo in msdbi60l.lib
  28. BOOL
  29. CopyPdbX(
  30. CHAR const * szSrcPdb,
  31. CHAR const * szDestPdb,
  32. BOOL StripPrivate,
  33. CHAR const * szRSDSDllToLoad
  34. )
  35. #else
  36. BOOL
  37. CopyPdb(
  38. CHAR const * szSrcPdb,
  39. CHAR const * szDestPdb,
  40. BOOL StripPrivate
  41. )
  42. #endif
  43. {
  44. LONG ErrorCode;
  45. ULONG Sig = 0;
  46. char ErrorString[1024];
  47. BOOL rc;
  48. PDB * pSrcPdb;
  49. HINSTANCE hMsPdb;
  50. static BOOL RSDSLibLoaded = FALSE;
  51. // Add a short circut. PdbCopy fails miserably if the source and destination are the same.
  52. // If StripPrivate isn't set, check for this case and just return. If StripPrivate is set,
  53. // bummer.
  54. if (!StripPrivate) {
  55. if (!_stricmp(szSrcPdb, szDestPdb)) {
  56. rc = TRUE;
  57. } else {
  58. rc = CopyFile(szSrcPdb, szDestPdb, FALSE);
  59. }
  60. } else {
  61. #if defined ( use_CopyPdbX )
  62. if ( szRSDSDllToLoad != NULL ) {
  63. // Load the dll with PDBCopyTo
  64. HMODULE hDll;
  65. if ( !RSDSLibLoaded ) {
  66. hDll = LoadLibrary( szRSDSDllToLoad );
  67. if (hDll != NULL) {
  68. RSDSLibLoaded = TRUE;
  69. pPDBCopyTo = ( PPDBCOPYTO ) GetProcAddress( hDll, "PDBCopyTo" );
  70. if (pPDBCopyTo == NULL ) {
  71. return (FALSE);
  72. }
  73. pPDBOpen = ( PPDBOPEN ) GetProcAddress( hDll, "PDBOpen" );
  74. if (pPDBOpen == NULL ) {
  75. return (FALSE);
  76. }
  77. pPDBClose = ( PPDBCLOSE ) GetProcAddress( hDll, "PDBClose" );
  78. if (pPDBClose == NULL ) {
  79. return (FALSE);
  80. }
  81. } else {
  82. return (FALSE);
  83. }
  84. }
  85. __try
  86. {
  87. rc = pPDBOpen((char *)szSrcPdb, "r", Sig, &ErrorCode, ErrorString, &pSrcPdb);
  88. }
  89. __except (EXCEPTION_EXECUTE_HANDLER)
  90. {
  91. rc=FALSE;
  92. }
  93. } else {
  94. __try
  95. {
  96. rc = PDBOpen((char *)szSrcPdb, "r", Sig, &ErrorCode, ErrorString, &pSrcPdb);
  97. }
  98. __except (EXCEPTION_EXECUTE_HANDLER)
  99. {
  100. rc=FALSE;
  101. }
  102. }
  103. #else
  104. __try
  105. {
  106. rc = PDBOpen((char *)szSrcPdb, "r", Sig, &ErrorCode, ErrorString, &pSrcPdb);
  107. }
  108. __except (EXCEPTION_EXECUTE_HANDLER)
  109. {
  110. rc=FALSE;
  111. }
  112. #endif
  113. if (rc) {
  114. rc = DeleteFile(szDestPdb);
  115. if (rc || (GetLastError() == ERROR_FILE_NOT_FOUND)) {
  116. #if defined ( use_CopyPdbX )
  117. if ( szRSDSDllToLoad != NULL ) {
  118. rc = pPDBCopyTo(pSrcPdb, szDestPdb, StripPrivate ? 0x00000001 : 0x0000000, 0);
  119. } else {
  120. rc = PDBCopyTo(pSrcPdb, szDestPdb, StripPrivate ? 0x00000001 : 0x0000000, 0);
  121. }
  122. #else
  123. rc = PDBCopyTo(pSrcPdb, szDestPdb, StripPrivate ? 0x00000001 : 0x0000000, 0);
  124. #endif
  125. }
  126. if (!rc) {
  127. // PdbCopyTo doesn't cleanup on failure. Do it here.
  128. DeleteFile(szDestPdb);
  129. }
  130. #if defined ( use_CopyPdbX )
  131. if ( szRSDSDllToLoad != NULL ) {
  132. pPDBClose(pSrcPdb);
  133. } else {
  134. PDBClose(pSrcPdb);
  135. }
  136. #else
  137. PDBClose(pSrcPdb);
  138. #endif
  139. }
  140. }
  141. return(rc);
  142. }