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.

267 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. splitsym.c
  5. Abstract:
  6. This is the main source file for the SPLITSYM utility program. This
  7. program can be used to split the debugging information contained in
  8. an executable image file into a separate .DBG file and strip it from
  9. the image file. Allow stripped image files to be distributed which
  10. significantly reduces disk space requirements, but allows full
  11. debugging by accesing the associated .DBG files over the network
  12. when needed.
  13. Author:
  14. Steve Wood (stevewo) 03-May-1993
  15. Revision History:
  16. --*/
  17. #include <private.h>
  18. #include <splitsymx.h>
  19. BOOL fVerbose;
  20. BOOL fRecurse;
  21. ULONG SplitFlags = 0;
  22. UCHAR RecurseDirectory[ MAX_PATH ];
  23. UCHAR CurrentImageName[ MAX_PATH ];
  24. UCHAR SymbolPath[ MAX_PATH ];
  25. UCHAR RSDSDllPath[ MAX_PATH ];
  26. UCHAR DbgFileName[ MAX_PATH ];
  27. VOID
  28. SplitSymbolsInTree(
  29. LPSTR RootPath
  30. );
  31. void
  32. Usage( void )
  33. {
  34. fputs ( "usage: SPLITSYM [-?] [-v] [-p] [-a] [-s symbol directory] [-r directory] image-names...\n"
  35. " [-?] display this message\n"
  36. " [-v] verbose output\n"
  37. " [-p] remove private debug info when creating .dbg file\n"
  38. " [-a] extract all debug info into .dbg file\n"
  39. " [-m] RSDS dll to load, default is mspdb70.dll\n"
  40. " [-r directory] - recursively process all image files.\n"
  41. " [-s symbol directory] - where to put .DBG files.\n"
  42. " Default is same place as image file.\n",
  43. stderr );
  44. exit( 1 );
  45. }
  46. int __cdecl
  47. main(
  48. int argc,
  49. char *argv[],
  50. char *envp[]
  51. )
  52. {
  53. char c, *s;
  54. LPSTR FilePart;
  55. if (argc <= 1) {
  56. Usage();
  57. }
  58. strcpy(RSDSDllPath, "mspdb70.dll");
  59. SymbolPath[ 0 ] = '\0';
  60. while (--argc) {
  61. s = *++argv;
  62. if (*s == '/' || *s == '-') {
  63. while (c = *++s)
  64. switch (toupper( c )) {
  65. case '?':
  66. Usage();
  67. break;
  68. case 'M':
  69. if (--argc) {
  70. strcpy( (PCHAR) RSDSDllPath, *++argv );
  71. }
  72. else {
  73. fprintf( stderr, "SPLITSYM: Argument to /%c switch missing\n", c );
  74. Usage();
  75. }
  76. break;
  77. case 'V':
  78. fVerbose = TRUE;
  79. break;
  80. case 'R':
  81. if (--argc) {
  82. fRecurse = TRUE;
  83. strcpy( (PCHAR) RecurseDirectory, *++argv );
  84. }
  85. else {
  86. fprintf( stderr, "SPLITSYM: Argument to /%c switch missing\n", c );
  87. Usage();
  88. }
  89. break;
  90. case 'S':
  91. if (--argc) {
  92. strcpy( (PCHAR) SymbolPath, *++argv );
  93. }
  94. else {
  95. fprintf( stderr, "SPLITSYM: Argument to /%c switch missing\n", c );
  96. Usage();
  97. }
  98. break;
  99. case 'P':
  100. SplitFlags |= SPLITSYM_REMOVE_PRIVATE;
  101. break;
  102. case 'A':
  103. SplitFlags |= SPLITSYM_EXTRACT_ALL;
  104. break;
  105. default:
  106. fprintf( stderr, "SPLITSYM: Invalid switch - /%c\n", c );
  107. Usage();
  108. break;
  109. }
  110. }
  111. else {
  112. if (fRecurse) {
  113. fprintf( stderr, "SPLITSYM: May not specify specific file names with /R switch.\n" );
  114. Usage();
  115. }
  116. else
  117. if (!GetFullPathNameA( s, sizeof( CurrentImageName ), (PCHAR) CurrentImageName, &FilePart )) {
  118. fprintf( stderr, "SPLITSYM: invalid file name - %s (%u)\n", s, GetLastError() );
  119. }
  120. else {
  121. if (SplitSymbolsX( (PCHAR) CurrentImageName, (PCHAR) SymbolPath, (PCHAR) DbgFileName,
  122. SplitFlags, RSDSDllPath, NULL, 0L )) {
  123. if (fVerbose) {
  124. fprintf( stdout,
  125. "SPLITSYM: %16s symbols split into %s\n",
  126. FilePart,
  127. DbgFileName
  128. );
  129. }
  130. }
  131. else
  132. if (GetLastError() != ERROR_BAD_EXE_FORMAT &&
  133. GetLastError() != ERROR_ALREADY_ASSIGNED
  134. ) {
  135. fprintf( stderr, "SPLITSYM: Unable to split symbols from '%s' into '%s' (%u)\n",
  136. CurrentImageName,
  137. DbgFileName,
  138. GetLastError()
  139. );
  140. }
  141. }
  142. }
  143. }
  144. if (fRecurse) {
  145. SplitSymbolsInTree( (PCHAR) RecurseDirectory );
  146. }
  147. exit( 0 );
  148. return 0;
  149. }
  150. #define MAX_DEPTH 32
  151. VOID
  152. SplitSymbolsInTree(
  153. LPSTR RootPath
  154. )
  155. {
  156. LPSTR FilePart;
  157. PUCHAR Prefix = (PUCHAR) "";
  158. CHAR PathBuffer[ MAX_PATH ];
  159. ULONG Depth;
  160. PCHAR PathTail[ MAX_DEPTH ];
  161. PCHAR FindHandle[ MAX_DEPTH ];
  162. LPWIN32_FIND_DATA FindFileData;
  163. UCHAR FindFileBuffer[ MAX_PATH + sizeof( WIN32_FIND_DATA ) ];
  164. strcpy( PathBuffer, RootPath );
  165. FindFileData = (LPWIN32_FIND_DATA)FindFileBuffer;
  166. Depth = 0;
  167. while (TRUE) {
  168. startDirectorySearch:
  169. PathTail[ Depth ] = strchr( PathBuffer, '\0' );
  170. if (PathTail[ Depth ] > PathBuffer && PathTail[ Depth ][ -1 ] != '\\') {
  171. *(PathTail[ Depth ])++ = '\\';
  172. }
  173. strcpy( PathTail[ Depth ], "*.*" );
  174. FindHandle[ Depth ] = (PCHAR) FindFirstFile( PathBuffer, FindFileData );
  175. if (FindHandle[ Depth ] != INVALID_HANDLE_VALUE) {
  176. do {
  177. if (FindFileData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  178. if (strcmp( FindFileData->cFileName, "." ) &&
  179. strcmp( FindFileData->cFileName, ".." ) &&
  180. Depth < MAX_DEPTH
  181. ) {
  182. sprintf( PathTail[ Depth ], "%s\\", FindFileData->cFileName );
  183. Depth++;
  184. goto startDirectorySearch;
  185. }
  186. }
  187. else
  188. if (!(FindFileData->dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
  189. strcpy( PathTail[ Depth ], FindFileData->cFileName );
  190. if (!GetFullPathNameA( PathBuffer, sizeof( CurrentImageName ), (PCHAR) CurrentImageName, &FilePart )) {
  191. fprintf( stderr, "SPLITSYM: invalid file name - %s (%u)\n", PathBuffer, GetLastError() );
  192. }
  193. else {
  194. if (SplitSymbolsX( (PCHAR) CurrentImageName, (PCHAR) SymbolPath, (PCHAR) DbgFileName,
  195. SplitFlags, RSDSDllPath, NULL, 0L )) {
  196. if (fVerbose) {
  197. fprintf( stdout,
  198. "SPLITSYM: %16s symbols split into %s\n",
  199. FilePart,
  200. DbgFileName
  201. );
  202. }
  203. }
  204. else
  205. if (GetLastError() != ERROR_BAD_EXE_FORMAT ) {
  206. fprintf( stderr, "SPLITSYM: Unable to split symbols from '%s' into '%s' (%u)\n",
  207. CurrentImageName,
  208. DbgFileName,
  209. GetLastError()
  210. );
  211. }
  212. }
  213. }
  214. restartDirectorySearch:
  215. ;
  216. }
  217. while (FindNextFile( FindHandle[ Depth ], FindFileData ));
  218. FindClose( FindHandle[ Depth ] );
  219. if (Depth == 0) {
  220. break;
  221. }
  222. Depth--;
  223. goto restartDirectorySearch;
  224. }
  225. }
  226. return;
  227. }