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.

341 lines
11 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. dbgdump.c
  5. Abstract:
  6. This is the main source file for the DBGDUMP utility program. This
  7. program can be used to dump out symbolic debugging information for an
  8. image.
  9. Author:
  10. Steve Wood (stevewo) 03-May-1993
  11. Revision History:
  12. --*/
  13. #include <private.h>
  14. BOOL fVerbose;
  15. BOOL fRemote;
  16. UCHAR CurrentImageName[ MAX_PATH ];
  17. UCHAR SymbolPath[ MAX_PATH ];
  18. void
  19. Usage( void )
  20. {
  21. fputs("usage: DBGDUMP [-?] [-v] [-r] image-names...\n"
  22. " [-?] display this message\n"
  23. " [-v] verbose output\n"
  24. " [-r symbol path] assume image names are from remote system.\n",
  25. stderr);
  26. exit( 1 );
  27. }
  28. void
  29. ShowDebugInfo(
  30. PIMAGE_DEBUG_INFORMATION64 DebugInfo
  31. );
  32. VOID
  33. DumpSectionHeader(
  34. IN ULONG i,
  35. IN PIMAGE_SECTION_HEADER Sh
  36. );
  37. int __cdecl
  38. main(
  39. int argc,
  40. char *argv[],
  41. char *envp[]
  42. )
  43. {
  44. char c, *s;
  45. LPSTR FilePart;
  46. HANDLE FileHandle;
  47. PIMAGE_DEBUG_INFORMATION64 DebugInfo;
  48. if (argc <= 1) {
  49. Usage();
  50. }
  51. while (--argc) {
  52. s = *++argv;
  53. if (*s == '/' || *s == '-') {
  54. while (c = *++s)
  55. switch (toupper( c )) {
  56. case '?':
  57. Usage();
  58. break;
  59. case 'V':
  60. fVerbose = TRUE;
  61. break;
  62. case 'R':
  63. if (--argc) {
  64. strcpy( (PCHAR) SymbolPath, *++argv );
  65. fRemote = TRUE;
  66. }
  67. else {
  68. fprintf( stderr, "DBGDUMP: Argument to /%c switch missing\n", c );
  69. Usage();
  70. }
  71. break;
  72. default:
  73. fprintf( stderr, "DBGDUMP: Invalid switch - /%c\n", c );
  74. Usage();
  75. break;
  76. }
  77. }
  78. else {
  79. DebugInfo = NULL;
  80. if (!fRemote) {
  81. if (!GetFullPathNameA( s, sizeof( CurrentImageName ), (PCHAR) CurrentImageName, &FilePart )) {
  82. fprintf( stderr, "DBGDUMP: invalid file name - %s (%u)\n", s, GetLastError() );
  83. }
  84. else {
  85. FileHandle = CreateFileA( (PCHAR)CurrentImageName,
  86. GENERIC_READ,
  87. FILE_SHARE_READ | FILE_SHARE_WRITE,
  88. NULL,
  89. OPEN_EXISTING,
  90. 0,
  91. NULL
  92. );
  93. if (FileHandle == INVALID_HANDLE_VALUE) {
  94. fprintf( stderr, "DBGDUMP: unable to open - %s (%u)\n", CurrentImageName, GetLastError() );
  95. }
  96. else {
  97. DebugInfo = MapDebugInformation64( FileHandle, NULL, NULL, 0 );
  98. }
  99. }
  100. }
  101. else {
  102. strcpy( (PCHAR) CurrentImageName, s );
  103. DebugInfo = MapDebugInformation64( NULL, (PCHAR) CurrentImageName, (PCHAR) SymbolPath, 0 );
  104. }
  105. if (DebugInfo != NULL) {
  106. ShowDebugInfo( DebugInfo );
  107. UnmapDebugInformation64( DebugInfo );
  108. }
  109. }
  110. }
  111. exit( 0 );
  112. return 0;
  113. }
  114. VOID
  115. DumpSectionHeader(
  116. IN ULONG i,
  117. IN PIMAGE_SECTION_HEADER Sh
  118. )
  119. {
  120. PCHAR name;
  121. ULONG li, lj;
  122. USHORT memFlags, alignFlags;
  123. printf( "\nSECTION HEADER #%hX\n% 8.8s name\n", i, Sh->Name );
  124. printf( "% 8lX physical address\n% 8lX virtual address\n% 8lX size of raw data\n% 8lX file pointer to raw data\n% 8lX file pointer to relocation table\n",
  125. Sh->Misc.PhysicalAddress,
  126. Sh->VirtualAddress,
  127. Sh->SizeOfRawData,
  128. Sh->PointerToRawData,
  129. Sh->PointerToRelocations );
  130. printf( "% 8lX file pointer to line numbers\n% 8hX number of relocations\n% 8hX number of line numbers\n% 8lX flags\n",
  131. Sh->PointerToLinenumbers,
  132. Sh->NumberOfRelocations,
  133. Sh->NumberOfLinenumbers,
  134. Sh->Characteristics );
  135. memFlags = alignFlags = 0;
  136. for (li=Sh->Characteristics, lj=0L; li; li=li>>1, lj++) {
  137. if (li & 1) {
  138. switch((li & 1) << lj) {
  139. case IMAGE_SCN_TYPE_NO_PAD : name = (PCHAR) "No Pad"; break;
  140. case IMAGE_SCN_CNT_CODE : name = (PCHAR) "Code"; break;
  141. case IMAGE_SCN_CNT_INITIALIZED_DATA : name = (PCHAR) "Initialized Data"; break;
  142. case IMAGE_SCN_CNT_UNINITIALIZED_DATA : name = (PCHAR) "Uninitialized Data"; break;
  143. case IMAGE_SCN_LNK_OTHER : name = (PCHAR) "Other"; break;
  144. case IMAGE_SCN_LNK_INFO : name = (PCHAR) "Info"; break;
  145. case IMAGE_SCN_LNK_REMOVE : name = (PCHAR) "Remove"; break;
  146. case IMAGE_SCN_LNK_COMDAT : name = (PCHAR) "Communal"; break;
  147. case IMAGE_SCN_ALIGN_1BYTES :
  148. case IMAGE_SCN_ALIGN_2BYTES :
  149. case IMAGE_SCN_ALIGN_4BYTES :
  150. case IMAGE_SCN_ALIGN_8BYTES :
  151. case IMAGE_SCN_ALIGN_16BYTES :
  152. case IMAGE_SCN_ALIGN_32BYTES :
  153. case IMAGE_SCN_ALIGN_64BYTES : name = (PCHAR) ""; break;
  154. case IMAGE_SCN_MEM_DISCARDABLE: name = (PCHAR) "Discardable"; break;
  155. case IMAGE_SCN_MEM_NOT_CACHED : name = (PCHAR) "Not Cached"; break;
  156. case IMAGE_SCN_MEM_NOT_PAGED : name = (PCHAR) "Not Paged"; break;
  157. case IMAGE_SCN_MEM_SHARED : name = (PCHAR) "Shared"; break;
  158. case IMAGE_SCN_MEM_EXECUTE : name = (PCHAR) ""; memFlags |= 1; break;
  159. case IMAGE_SCN_MEM_READ : name = (PCHAR) ""; memFlags |= 2; break;
  160. case IMAGE_SCN_MEM_WRITE : name = (PCHAR) ""; memFlags |= 4; break;
  161. default : name = (PCHAR) "RESERVED - UNKNOWN";
  162. }
  163. if (*name) {
  164. printf( " %s\n", name );
  165. }
  166. }
  167. }
  168. if (Sh->Characteristics & IMAGE_SCN_ALIGN_64BYTES) {
  169. switch(Sh->Characteristics & IMAGE_SCN_ALIGN_64BYTES) {
  170. case IMAGE_SCN_ALIGN_1BYTES : name = (PCHAR) "Align1"; break;
  171. case IMAGE_SCN_ALIGN_2BYTES : name = (PCHAR) "Align2"; break;
  172. case IMAGE_SCN_ALIGN_4BYTES : name = (PCHAR) "Align4"; break;
  173. case IMAGE_SCN_ALIGN_8BYTES : name = (PCHAR) "Align8"; break;
  174. case IMAGE_SCN_ALIGN_16BYTES : name = (PCHAR) "Align16"; break;
  175. case IMAGE_SCN_ALIGN_32BYTES : name = (PCHAR) "Align32"; break;
  176. case IMAGE_SCN_ALIGN_64BYTES : name = (PCHAR) "Align64"; break;
  177. }
  178. printf( " %s\n", name );
  179. }
  180. if (memFlags) {
  181. switch(memFlags) {
  182. case 1 : name = (PCHAR) "Execute Only"; break;
  183. case 2 : name = (PCHAR) "Read Only"; break;
  184. case 3 : name = (PCHAR) "Execute Read"; break;
  185. case 4 : name = (PCHAR) "Write Only"; break;
  186. case 5 : name = (PCHAR) "Execute Write"; break;
  187. case 6 : name = (PCHAR) "Read Write"; break;
  188. case 7 : name = (PCHAR) "Execute Read Write"; break;
  189. default : name = (PCHAR) "Unknown Memory Flags"; break;
  190. }
  191. printf( " %s\n", name );
  192. }
  193. }
  194. char *FrameType[] = {
  195. "FRAME_FPO",
  196. "FRAME_TRAP",
  197. "FRAME_TSS",
  198. "FRAME_NONFPO",
  199. "FRAME_UNKNOWN"
  200. };
  201. void
  202. ShowDebugInfo(
  203. PIMAGE_DEBUG_INFORMATION64 DebugInfo
  204. )
  205. {
  206. ULONG i;
  207. PIMAGE_SECTION_HEADER Section;
  208. PIMAGE_FUNCTION_ENTRY FunctionEntry;
  209. PFPO_DATA FpoEntry;
  210. LPSTR s;
  211. printf( "Debug information at % p\n", DebugInfo );
  212. printf( " Size % 8lx\n", DebugInfo->Size );
  213. printf( " Mapped at % p\n", DebugInfo->MappedBase );
  214. printf( " Machine % 8hx\n", DebugInfo->Machine );
  215. printf( " Characteristics % 8hx\n", DebugInfo->Characteristics );
  216. printf( " Time/Date stamp % 8lx", DebugInfo->TimeDateStamp );
  217. if (DebugInfo->TimeDateStamp && (s = ctime( (time_t *)&DebugInfo->TimeDateStamp ))) {
  218. printf( " %s", s );
  219. }
  220. else {
  221. putchar( '\n' );
  222. }
  223. printf( " CheckSum % 8lx\n", DebugInfo->CheckSum );
  224. printf( " ImageBase % 8lx\n", DebugInfo->ImageBase );
  225. printf( " SizeOfImage % 8lx\n", DebugInfo->SizeOfImage );
  226. printf( " NumberOfSections % 8lx\n", DebugInfo->NumberOfSections );
  227. printf( " ExportedNamesSize% 8lx\n", DebugInfo->ExportedNamesSize );
  228. printf( " #Function Entries% 8lx\n", DebugInfo->NumberOfFunctionTableEntries );
  229. printf( " #FPO Entries % 8lx\n", DebugInfo->NumberOfFpoTableEntries );
  230. printf( " Coff Symbol Size % 8lx\n", DebugInfo->SizeOfCoffSymbols );
  231. printf( " CV Symbol Size % 8lx\n", DebugInfo->SizeOfCodeViewSymbols );
  232. printf( " Image Path %s\n", DebugInfo->ImageFilePath );
  233. printf( " Image Name %s\n", DebugInfo->ImageFileName );
  234. printf( " Debug Path %s\n", DebugInfo->DebugFilePath );
  235. printf( "\n" );
  236. if (DebugInfo->NumberOfSections != 0) {
  237. printf( "Section Headers:\n" );
  238. Section = DebugInfo->Sections;
  239. for (i=0; i<DebugInfo->NumberOfSections; i++) {
  240. DumpSectionHeader( i, Section++ );
  241. }
  242. printf( "\n" );
  243. }
  244. if (DebugInfo->ExportedNamesSize != 0) {
  245. printf( "Exported Names:\n" );
  246. s = DebugInfo->ExportedNames;
  247. while (*s) {
  248. printf( " %s\n", s );
  249. while (*s++) {
  250. }
  251. }
  252. printf( "\n" );
  253. }
  254. if (DebugInfo->NumberOfFunctionTableEntries != 0) {
  255. printf( "Function Table:\n" );
  256. FunctionEntry = DebugInfo->FunctionTableEntries;
  257. for (i=0; i<DebugInfo->NumberOfFunctionTableEntries; i++) {
  258. printf( " % 4x: % 8x % 8x % 8x\n",
  259. i,
  260. FunctionEntry->StartingAddress,
  261. FunctionEntry->EndingAddress,
  262. FunctionEntry->EndOfPrologue
  263. );
  264. FunctionEntry += 1;
  265. }
  266. printf( "\n" );
  267. }
  268. if (DebugInfo->NumberOfFpoTableEntries != 0) {
  269. printf( "FPO Table:\n" );
  270. FpoEntry = DebugInfo->FpoTableEntries;
  271. for (i=0; i<DebugInfo->NumberOfFpoTableEntries; i++) {
  272. printf( " % 4x: % 8x % 8x % 8x [%02x %1x%s%s %s]\n",
  273. i,
  274. FpoEntry->ulOffStart,
  275. FpoEntry->cbProcSize,
  276. FpoEntry->cdwParams,
  277. FpoEntry->cbProlog,
  278. FpoEntry->cbRegs,
  279. FpoEntry->fHasSEH ? " SEH" : "",
  280. FpoEntry->fUseBP ? " EBP" : "",
  281. FrameType[ FpoEntry->cbFrame ]
  282. );
  283. FpoEntry += 1;
  284. }
  285. printf( "\n" );
  286. }
  287. return;
  288. }