Changeset 45357 in vbox for trunk/src/VBox/Runtime/r0drv/nt/ntBldSymDb.cpp
- Timestamp:
- Apr 5, 2013 8:22:41 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/ntBldSymDb.cpp
r45350 r45357 34 34 #include <iprt/alloca.h> 35 35 #include <iprt/dir.h> 36 #include <iprt/file.h> 37 #include <iprt/getopt.h> 36 38 #include <iprt/initterm.h> 37 39 #include <iprt/list.h> … … 100 102 * Global Variables * 101 103 *******************************************************************************/ 102 /** Set if verbose operation.*/ 103 static bool g_fVerbose = false; 104 /** Set if verbose operation (-v, --verbose). */ 105 static bool g_fOptVerbose = false; 106 /** Set if we should force ahead despite errors. */ 107 static bool g_fOptForce = false; 104 108 105 109 /** The members of the KPRCB structure that we're interested in. */ … … 132 136 static void MyDbgPrintf(const char *pszFormat, ...) 133 137 { 134 if (g_f Verbose)138 if (g_fOptVerbose) 135 139 { 136 140 va_list va; … … 661 665 } 662 666 667 #if 0 668 /** Indicates that there is a filename. 669 * If not set, a directory was specified using a trailing slash or a volume 670 * was specified without any file/dir name following it. */ 671 #define RTPATHSPLIT_PROP_FILENAME UINT16_C(0x0001) 672 /** Indicates that this is an UNC path (Windows and OS/2 only). */ 673 #define RTPATHSPLIT_PROP_UNC UINT16_C(0x0002) 674 /** A root is specified. */ 675 #define RTPATHSPLIT_PROP_ROOT UINT16_C(0x0004) 676 /** A volume (drive) is specified. */ 677 #define RTPATHSPLIT_PROP_VOLSPEC UINT16_C(0x0008) 678 679 typedef struct RTPATHSPLIT 680 { 681 /** Number of path components. */ 682 uint32_t cComponents; 683 /** The first directory. */ 684 uint8_t iFirstDir; 685 uint8_t fReserved1; /**< Reserved */ 686 /** Path property flags, RTPATHSPLIT_PROP_XXX */ 687 uint16_t fProps; 688 /** Pointer to the dot in the filename suffix. If no suffix, this points to 689 * the terminator character. */ 690 const char *pszSuffix; 691 /** Array of pointers to components. 692 * @remarks This is variable sized and is followed by the strings it points to. 693 * It's set to 8 instead of the usual 1 as that's the minimum size of 694 * the RTPathSplit buffer. */ 695 const char *apszComponents[8]; 696 } RTPATHSPLIT; 697 /** Pointer to to a path split result. */ 698 typedef RTPATHSPLIT *PRTPATHSPLIT; 699 /** Pointer to to a const path split result. */ 700 typedef RTPATHSPLIT *PCRTPATHSPLIT; 701 702 703 int RTPathSplit(const char *pszPath, PRTPATHSPLIT pOutput, size_t cbOutput) 704 { 705 AssertReturn(cbOutput >= sizeof(*pOutput), VERR_BUFFER_UNDERFLOW); 706 AssertPtr(pszPath); 707 AsserPtr(pOutput); 708 709 /* 710 * Parse the path, we're using apszComponents to store offset + length of 711 * each component while parsing to avoid duplicating code and effort. 712 */ 713 struct TMPOFFSIZE 714 { 715 uint16_t off; 716 uint16_t cch; 717 } *paComponents = (struct TMPOFFSIZE *)&pOutput->apszComponents; 718 uint32_t cMaxComponents = (cbOutput - RT_OFFSETOF(RTPATHSPLIT, apszComponents)) / sizeof(paComponents[0]); 719 uint32_t iComponent = 0; 720 size_t cbStrings = 0; 721 uint16_t fFlags = 0; 722 size_t off = 0; 723 724 paComponents[0].off = 0; 725 726 /* The volume specifier bit first, it's special. */ 727 if (RTPATH_IS_SLASH(pszPath[0])) 728 { 729 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS) 730 if ( RTPATH_IS_SLASH(pszPath[1]) 731 && !RTPATH_IS_SLASH(pszPath[2]) 732 && pszPath[2]) 733 { 734 fFlags |= RTPATHSPLIT_PROP_UNC; 735 736 /* UNC server name */ 737 off = 2; 738 while (!RTPATH_IS_SLASH(pszPath[off]) && pszPath[off]) 739 off++; 740 paComponents[0].cch = off; 741 size_t cbStrings = 0; 742 743 744 while (RTPATH_IS_SLASH(pszPath[off])) 745 off++; 746 747 /* UNC share */ 748 while (!RTPATH_IS_SLASH(pszPath[off]) && pszPath[off]) 749 off++; 750 } 751 else 752 #endif 753 { 754 fFlags |= RTPATHSPLIT_PROP_ROOT; 755 cbString = sizeof("/"); 756 iComponent = 1; 757 off = 1; 758 } 759 while (RTPATH_IS_SLASH(pszPath[off])) 760 off++; 761 } 762 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS) 763 else if (RT_C_IS_ALPHA(pszPath[0]) && pszPath[1] == ':') 764 { 765 off = 2; 766 while (RTPATH_IS_SLASH(pszPath[off])) 767 off++; 768 } 769 #endif 770 Assert(!RTPATH_IS_SLASH(pszPath[off])); 771 772 773 } 774 #endif 663 775 664 776 /** … … 698 810 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Giving up on '%s'...\n", pszPdb); 699 811 812 700 813 return RTEXITCODE_SUCCESS; 701 814 } … … 708 821 * @param pszPdb The path to the PDB. 709 822 */ 710 static RTEXITCODE process OnePdb(const char *pszPdb)823 static RTEXITCODE processPdb(const char *pszPdb) 711 824 { 712 825 /* … … 844 957 */ 845 958 memcpy(&pszDir[cchDir], pDirEntry->szName, pDirEntry->cbName + 1); 846 RTEXITCODE rcExit2 = process OnePdb(pszDir);959 RTEXITCODE rcExit2 = processPdb(pszDir); 847 960 if (rcExit2 != RTEXITCODE_SUCCESS) 848 961 rcExit = rcExit2; … … 905 1018 * Parse options. 906 1019 */ 907 1020 static const RTGETOPTDEF s_aOptions[] = 1021 { 1022 { "--force", 'f', RTGETOPT_REQ_NOTHING }, 1023 { "--output", 'o', RTGETOPT_REQ_STRING }, 1024 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 1025 }; 1026 1027 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 1028 bool fFoundInput = false; 1029 const char *pszOutput = "-"; 1030 1031 int ch; 1032 RTGETOPTUNION ValueUnion; 1033 RTGETOPTSTATE GetState; 1034 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 1035 RTGETOPTINIT_FLAGS_OPTS_FIRST); 1036 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 1037 { 1038 switch (ch) 1039 { 1040 case 'f': 1041 g_fOptForce = true; 1042 break; 1043 1044 case 'v': 1045 g_fOptVerbose = true; 1046 break; 1047 1048 case 'o': 1049 pszOutput = ValueUnion.psz; 1050 break; 1051 1052 case 'V': 1053 RTPrintf("$Revision$"); 1054 break; 1055 1056 case 'h': 1057 RTPrintf("usage: %s [-v|--verbose] [-f|--force] [-o|--output <file.h>] <dir1|pdb1> [...]\n" 1058 " or: %s [-V|--version]\n" 1059 " or: %s [-h|--help]\n", 1060 argv[0], argv[0], argv[0]); 1061 return RTEXITCODE_SUCCESS; 1062 1063 case VINF_GETOPT_NOT_OPTION: 1064 { 1065 RTEXITCODE rcExit2; 1066 if (RTFileExists(ValueUnion.psz)) 1067 rcExit2 = processPdb(ValueUnion.psz); 1068 else 1069 rcExit2 = processDir(ValueUnion.psz); 1070 if (rcExit2 != RTEXITCODE_SUCCESS) 1071 { 1072 if (!g_fOptForce) 1073 return rcExit2; 1074 rcExit = rcExit2; 1075 } 1076 break; 1077 } 1078 1079 default: 1080 return RTGetOptPrintError(ch, &ValueUnion); 1081 } 1082 } 1083 if (!fFoundInput) 1084 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Not input files or directories specified.\n"); 908 1085 909 1086 /* 910 * Do job.1087 * Generate the output. 911 1088 */ 912 RTEXITCODE rcExit = processOnePdb(argv[argc - 1]); 913 914 if (rcExit == RTEXITCODE_SUCCESS) 915 { 916 generateHeader(g_pStdOut); 917 } 918 1089 PRTSTREAM pOut = g_pStdOut; 1090 if (strcmp(pszOutput, "-")) 1091 { 1092 rc = RTStrmOpen(pszOutput, "w", &pOut); 1093 if (RT_FAILURE(rc)) 1094 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening '%s' for writing: %Rrc\n", pszOutput, rc); 1095 } 1096 1097 generateHeader(pOut); 1098 1099 if (pOut != g_pStdOut) 1100 rc = RTStrmClose(pOut); 1101 else 1102 rc = RTStrmFlush(pOut); 1103 if (RT_FAILURE(rc)) 1104 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error %s '%s': %Rrc\n", pszOutput, 1105 pOut != g_pStdOut ? "closing" : "flushing", rc); 919 1106 return rcExit; 920 1107 }
Note:
See TracChangeset
for help on using the changeset viewer.