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.

123 lines
3.8 KiB

  1. //TracePDB - Extracts trace information from the PDB
  2. // This small tool is used to extract the same trace information that binplace does, but can be used 'after the fact'
  3. // that is if you have the full symbols PDB but no trace information, TracePDB can generate the trace
  4. // tmf and tmc files for you.
  5. #ifdef __cplusplus
  6. extern "C"{
  7. #endif
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <shellapi.h>
  15. #include <tchar.h>
  16. #include <dbghelp.h>
  17. #include "wppfmt.h"
  18. int _cdecl main(int argc, char** argv)
  19. {
  20. DWORD status;
  21. TCHAR lppath[MAX_PATH] ;
  22. TCHAR lppath_tmp[MAX_PATH];
  23. TCHAR pdbname[MAX_PATH] ;
  24. INT len, targv=0 ;
  25. BOOL Verbose = FALSE ;
  26. BOOL bPDBName = FALSE ;
  27. LPSTR szRSDSDllToLoad = NULL;
  28. TCHAR helptext[] = "Usage: TracePDB -f <pdbname> [-p <path>] [-v]\n"
  29. " Options:\n"
  30. // " -r recurse into subdirectories\n"
  31. " -f specifies the PDBName from which to extract tmf's\n"
  32. " -p specifies the path to create the tmf's,\n"
  33. " by default the current directory.\n"
  34. " -v verbose, displays actions taken \n" ;
  35. if (GetCurrentDirectory(MAX_PATH,lppath) == 0 ) {
  36. fputs("TracePDB: no current directory\n", stdout) ;
  37. exit(-1);
  38. }
  39. while (--argc > 0) {
  40. ++targv;
  41. if (argv[targv][0] == '-' || argv[targv][0] == '/') { // argument found
  42. if (argv[targv][1] == 'h' || argv[targv][1] == 'H'
  43. || argv[targv][1] == '?')
  44. {
  45. fputs(helptext, stdout);
  46. return 1;
  47. } else if (argv[targv][1] == 'f') {
  48. if (--argc >0 ) {
  49. ++targv ;
  50. if ((strlen(argv[targv])+1) > MAX_PATH) {
  51. fputs("TracePDB: PDBname toolarge\n", stdout);
  52. exit(-1);
  53. }
  54. strncpy(pdbname,argv[targv],strlen(argv[targv])+1);
  55. bPDBName = TRUE ;
  56. }
  57. } else if (argv[targv][1] == 'p') {
  58. if (--argc >0 ) {
  59. ++ targv ;
  60. if ((strlen(argv[targv])+1) > MAX_PATH) {
  61. fputs("TracePDB: Path larger than MAX_PATH\n", stdout);
  62. exit(-1);
  63. }
  64. strncpy(lppath,argv[targv],strlen(argv[targv])+1);
  65. }
  66. } else if (argv[targv][1] == 'v') {
  67. Verbose = TRUE ;
  68. } else {
  69. fputs(helptext, stdout);
  70. }
  71. }
  72. }
  73. if (!bPDBName) {
  74. printf("TracePDB: No PDB specified?\n\n%s",helptext);
  75. return (1);
  76. }
  77. if ((szRSDSDllToLoad = (LPSTR) malloc(MAX_PATH+1)) == NULL) {
  78. fputs("TracePDB: malloc failed\n", stdout);
  79. return FALSE ;
  80. }
  81. strcpy( szRSDSDllToLoad, "mspdb70.dll");
  82. //Append a '\' and check if the path name is a valid directory
  83. _sntprintf(lppath_tmp,MAX_PATH,_T("%s\\"),lppath);
  84. lppath_tmp[MAX_PATH-1] = _T('\0');
  85. if (!MakeSureDirectoryPathExists(lppath_tmp))
  86. {
  87. _tprintf ("TracePDB: Invalid Path Name %s\n", lppath);
  88. return 0;
  89. }
  90. status = BinplaceWppFmt(pdbname,
  91. lppath,
  92. szRSDSDllToLoad,
  93. TRUE // always verbose
  94. ) ;
  95. if (status != ERROR_SUCCESS) {
  96. printf("TracePDB: failed with error %d\n", status);
  97. }
  98. return 0;
  99. }
  100. #ifdef __cplusplus
  101. }
  102. #endif