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.

176 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. upddbg.c
  5. Abstract:
  6. This tool updates debug files to match corresponding binary checksum,
  7. base address and timestamp
  8. Author:
  9. Matthew Hoehnen (matthoe) 08-Jun-1995
  10. Revision History:
  11. --*/
  12. #define _IMAGEHLP_SOURCE_
  13. #include <private.h>
  14. BOOL fUpdate;
  15. LPSTR CurrentImageName;
  16. LOADED_IMAGE CurrentImage;
  17. CHAR DebugFilePath[_MAX_PATH];
  18. CHAR SymbolPathBuffer[MAX_PATH*10];
  19. LPSTR SymbolPath;
  20. DWORD dw;
  21. LPSTR FilePart;
  22. CHAR Buffer[MAX_PATH];
  23. PIMAGE_LOAD_CONFIG_DIRECTORY ConfigInfo;
  24. CHAR c;
  25. LPSTR p;
  26. BOOL DbgHeaderModified;
  27. ULONG CheckSum;
  28. HANDLE hDbgFile;
  29. ULONG cb;
  30. IMAGE_SEPARATE_DEBUG_HEADER DbgHeader;
  31. VOID
  32. DisplayUsage(
  33. VOID
  34. )
  35. {
  36. fputs("usage: UPDDBG [switches] image-names... \n"
  37. " [-?] display this message\n"
  38. " [-u] update image\n"
  39. " [-s] path to symbol files\n", stderr
  40. );
  41. }
  42. int __cdecl
  43. main(
  44. int argc,
  45. char *argv[],
  46. char *envp[]
  47. )
  48. {
  49. if (argc <= 1) {
  50. DisplayUsage();
  51. return 1;
  52. }
  53. _tzset();
  54. while (--argc) {
  55. p = *++argv;
  56. if (*p == '/' || *p == '-') {
  57. while (c = *++p)
  58. switch (tolower( c )) {
  59. case '?':
  60. DisplayUsage();
  61. return 0;
  62. case 'u':
  63. fUpdate = TRUE;
  64. break;
  65. case 's':
  66. argc--, argv++;
  67. SymbolPath = *argv;
  68. break;
  69. default:
  70. fprintf( stderr, "UPDDBG: Invalid switch - /%c\n", c );
  71. DisplayUsage();
  72. return 1;
  73. }
  74. }
  75. }
  76. if (!SymbolPath) {
  77. if (GetEnvironmentVariable( "_nt_symbol_path", SymbolPathBuffer, sizeof(SymbolPathBuffer)-1 )) {
  78. SymbolPath = SymbolPathBuffer;
  79. }
  80. }
  81. if (!SymbolPath) {
  82. fprintf( stderr, "UPDDBG: uknown symbol file path\n" );
  83. return 1;
  84. }
  85. CurrentImageName = p;
  86. //
  87. // Map and load the current image
  88. //
  89. if (!MapAndLoad( CurrentImageName, NULL, &CurrentImage, FALSE, TRUE )) {
  90. fprintf( stderr, "UPDDBG: failure mapping and loading %s\n", CurrentImageName );
  91. return 1;
  92. }
  93. CurrentImageName = CurrentImage.ModuleName;
  94. FlushViewOfFile( CurrentImage.MappedAddress, 0 );
  95. if (!fUpdate) {
  96. hDbgFile = FindDebugInfoFile( CurrentImageName, SymbolPath, DebugFilePath );
  97. if (hDbgFile == INVALID_HANDLE_VALUE || hDbgFile == NULL) {
  98. fprintf( stderr, "UPDDBG: could not locate DBG file %s\n", CurrentImageName );
  99. return 1;
  100. }
  101. if (!ReadFile( hDbgFile, &DbgHeader, sizeof(IMAGE_SEPARATE_DEBUG_HEADER), &cb, NULL )) {
  102. fprintf( stderr, "UPDDBG: could not read DBG file %s\n", CurrentImageName );
  103. return 1;
  104. }
  105. printf( "*\n" );
  106. if (((PIMAGE_NT_HEADERS32)CurrentImage.FileHeader)->OptionalHeader.CheckSum != DbgHeader.CheckSum) {
  107. printf( "*************************************\n" );
  108. printf( "* WARNING: checksums do not match *\n" );
  109. printf( "*************************************\n" );
  110. printf( "*\n" );
  111. }
  112. _strlwr( CurrentImageName );
  113. _strlwr( DebugFilePath );
  114. printf( "Image 0x%08x %s\n", ((PIMAGE_NT_HEADERS32)CurrentImage.FileHeader)->OptionalHeader.CheckSum, CurrentImageName );
  115. printf( "DBG File 0x%08x %s\n", DbgHeader.CheckSum, DebugFilePath );
  116. return 0;
  117. }
  118. if (!((PIMAGE_NT_HEADERS32)CurrentImage.FileHeader)->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) {
  119. fprintf( stderr, "UPDDBG: symbols have not been split %s\n", CurrentImageName );
  120. return 1;
  121. }
  122. if ( UpdateDebugInfoFileEx( CurrentImageName,
  123. SymbolPath,
  124. DebugFilePath,
  125. (PIMAGE_NT_HEADERS32)(CurrentImage.FileHeader),
  126. ((PIMAGE_NT_HEADERS32)CurrentImage.FileHeader)->OptionalHeader.CheckSum
  127. ) ) {
  128. if (GetLastError() == ERROR_INVALID_DATA) {
  129. printf( "UPDDBG: Warning - Old checksum did not match for %s\n", DebugFilePath );
  130. }
  131. printf( "Updated symbols for %s\n", DebugFilePath );
  132. } else {
  133. printf( "Unable to update symbols: %s\n", DebugFilePath );
  134. }
  135. return 0;
  136. }
  137. #define _BUILDING_UPDDBG_
  138. #include "upddbgi.c"