Changeset 96811 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Sep 21, 2022 1:23:31 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/log/log.cpp
r96810 r96811 281 281 /** The group. (used for prefixing.) */ 282 282 unsigned iGroup; 283 /** Used by RTLogBulkNestedWrite. */ 284 const char *pszInfix; 283 285 } RTLOGOUTPUTPREFIXEDARGS, *PRTLOGOUTPUTPREFIXEDARGS; 284 286 … … 297 299 static FNRTLOGPHASEMSG rtlogPhaseMsgNormal; 298 300 #endif 301 static DECLCALLBACK(size_t) rtLogOutputPrefixed(void *pv, const char *pachChars, size_t cbChars); 299 302 static void rtlogLoggerExFLocked(PRTLOGGERINTERNAL pLoggerInt, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...); 300 303 … … 405 408 { RT_STR_TUPLE("com"), RTLOGDEST_COM }, 406 409 { RT_STR_TUPLE("nodeny"), RTLOGDEST_F_NO_DENY }, 410 { RT_STR_TUPLE("vmmrel"), RTLOGDEST_VMM_REL }, /* before vmm */ 411 { RT_STR_TUPLE("vmm"), RTLOGDEST_VMM }, 407 412 { RT_STR_TUPLE("user"), RTLOGDEST_USER }, 408 413 /* The RTLOGDEST_FIXED_XXX flags are omitted on purpose. */ … … 544 549 uint16_t const iGroup = RT_HI_U16(fFlagsAndGroup); 545 550 if ( iGroup != UINT16_MAX 546 547 551 && ( (pLoggerInt->afGroups[iGroup < pLoggerInt->cGroups ? iGroup : 0] & (fFlags | RTLOGGRPFLAGS_ENABLED)) 552 != (fFlags | RTLOGGRPFLAGS_ENABLED))) 548 553 pLoggerInt = NULL; 549 554 } … … 1085 1090 RTLogWriteUser(pszSecond, cchSecond); 1086 1091 } 1092 1093 # if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) 1094 if (pLoggerInt->fDestFlags & RTLOGDEST_VMM) 1095 { 1096 if (cchPreamble) 1097 RTLogWriteVmm(pszPreamble, cchPreamble, false /*fReleaseLog*/); 1098 if (cchFirst) 1099 RTLogWriteVmm(pszFirst, cchFirst, false /*fReleaseLog*/); 1100 if (cchSecond) 1101 RTLogWriteVmm(pszSecond, cchSecond, false /*fReleaseLog*/); 1102 } 1103 1104 if (pLoggerInt->fDestFlags & RTLOGDEST_VMM_REL) 1105 { 1106 if (cchPreamble) 1107 RTLogWriteVmm(pszPreamble, cchPreamble, true /*fReleaseLog*/); 1108 if (cchFirst) 1109 RTLogWriteVmm(pszFirst, cchFirst, true /*fReleaseLog*/); 1110 if (cchSecond) 1111 RTLogWriteVmm(pszSecond, cchSecond, true /*fReleaseLog*/); 1112 } 1113 # endif 1087 1114 1088 1115 if (pLoggerInt->fDestFlags & RTLOGDEST_DEBUGGER) … … 2436 2463 for (i = 0; i < RT_ELEMENTS(g_aLogDst); i++) 2437 2464 { 2438 size_t cchInstr = strlen(g_aLogDst[i].pszInstr); 2439 if (!strncmp(pszValue, g_aLogDst[i].pszInstr, cchInstr)) 2465 if (!strncmp(pszValue, g_aLogDst[i].pszInstr, g_aLogDst[i].cchInstr)) 2440 2466 { 2441 2467 if (!fNo) … … 2443 2469 else 2444 2470 pLoggerInt->fDestFlags &= ~g_aLogDst[i].fFlag; 2445 pszValue += cchInstr;2471 pszValue += g_aLogDst[i].cchInstr; 2446 2472 2447 2473 /* check for value. */ … … 3216 3242 3217 3243 3244 /** 3245 * Write/copy bulk log data from a nested VM logger. 3246 * 3247 * This is used for 3248 * 3249 * @returns IRPT status code. 3250 * @param pLogger The logger instance (NULL for default logger). 3251 * @param pch Pointer to the block of bulk log text to write. 3252 * @param cch Size of the block of bulk log text to write. 3253 * @param pszInfix String to put after the line prefixes and the 3254 * line content. 3255 */ 3256 RTDECL(int) RTLogBulkNestedWrite(PRTLOGGER pLogger, const char *pch, size_t cch, const char *pszInfix) 3257 { 3258 if (cch > 0) 3259 { 3260 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pLogger; 3261 RTLOG_RESOLVE_DEFAULT_RET(pLoggerInt, VINF_LOG_NO_LOGGER); 3262 3263 /* 3264 * Lock and validate it. 3265 */ 3266 int rc = rtlogLock(pLoggerInt); 3267 if (RT_SUCCESS(rc)) 3268 { 3269 /* 3270 * If we've got an auxilary descriptor, check if the buffer was flushed. 3271 */ 3272 PRTLOGBUFFERDESC pBufDesc = pLoggerInt->pBufDesc; 3273 PRTLOGBUFFERAUXDESC pAuxDesc = pBufDesc->pAux; 3274 if (!pAuxDesc || !pAuxDesc->fFlushedIndicator) 3275 { /* likely, except maybe for ring-0 */ } 3276 else 3277 { 3278 pAuxDesc->fFlushedIndicator = false; 3279 pBufDesc->offBuf = 0; 3280 } 3281 3282 /* 3283 * Write the stuff. 3284 */ 3285 RTLOGOUTPUTPREFIXEDARGS Args; 3286 Args.pLoggerInt = pLoggerInt; 3287 Args.fFlags = 0; 3288 Args.iGroup = ~0U; 3289 Args.pszInfix = pszInfix; 3290 rtLogOutputPrefixed(&Args, pch, cch); 3291 rtLogOutputPrefixed(&Args, pch, 0); /* termination call */ 3292 3293 /* 3294 * Maybe flush the buffer and update the auxiliary descriptor if there is one. 3295 */ 3296 pBufDesc = pLoggerInt->pBufDesc; /* (the descriptor may have changed) */ 3297 if ( !(pLoggerInt->fFlags & RTLOGFLAGS_BUFFERED) 3298 && pBufDesc->offBuf) 3299 rtlogFlush(pLoggerInt, false /*fNeedSpace*/); 3300 else 3301 { 3302 pAuxDesc = pBufDesc->pAux; 3303 if (pAuxDesc) 3304 pAuxDesc->offBuf = pBufDesc->offBuf; 3305 } 3306 3307 rtlogUnlock(pLoggerInt); 3308 } 3309 return rc; 3310 } 3311 return VINF_SUCCESS; 3312 } 3313 RT_EXPORT_SYMBOL(RTLogBulkNestedWrite); 3314 3315 3218 3316 /********************************************************************************************************************************* 3219 3317 * Flushing * … … 3326 3424 if (pLoggerInt->fDestFlags & RTLOGDEST_USER) 3327 3425 RTLogWriteUser(pchToFlush, cchToFlush); 3426 3427 #if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) 3428 if (pLoggerInt->fDestFlags & RTLOGDEST_VMM) 3429 RTLogWriteVmm(pchToFlush, cchToFlush, false /*fReleaseLog*/); 3430 3431 if (pLoggerInt->fDestFlags & RTLOGDEST_VMM_REL) 3432 RTLogWriteVmm(pchToFlush, cchToFlush, true /*fReleaseLog*/); 3433 #endif 3328 3434 3329 3435 if (pLoggerInt->fDestFlags & RTLOGDEST_DEBUGGER) … … 3471 3577 RTLogWriteUser(pThis->achScratch, pThis->offScratch); 3472 3578 3579 # if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) 3580 if (pThis->fDestFlags & RTLOGDEST_VMM) 3581 RTLogWriteVmm(pThis->achScratch, pThis->offScratch, false /*fReleaseLog*/); 3582 3583 if (pThis->fDestFlags & RTLOGDEST_VMM_REL) 3584 RTLogWriteVmm(pThis->achScratch, pThis->offScratch, true /*fReleaseLog*/); 3585 # endif 3586 3473 3587 if (pThis->fDestFlags & RTLOGDEST_DEBUGGER) 3474 3588 RTLogWriteDebugger(pThis->achScratch, pThis->offScratch); … … 3758 3872 if (cbChars) 3759 3873 { 3760 size_t cbRet = 0; 3874 uint64_t const fFlags = pLoggerInt->fFlags; 3875 size_t cbRet = 0; 3761 3876 for (;;) 3762 3877 { … … 3791 3906 /* 3792 3907 * Flush the buffer if there isn't enough room for the maximum prefix config. 3793 * Max is 2 56, add a couple of extra bytes. See CCH_PREFIX check way below.3908 * Max is 265, add a couple of extra bytes. See CCH_PREFIX check way below. 3794 3909 */ 3795 if (cb >= 2 56+ 16)3910 if (cb >= 265 + 16) 3796 3911 pLoggerInt->fPendingPrefix = false; 3797 3912 else … … 3806 3921 */ 3807 3922 psz = &pchBuf[offBuf]; 3808 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_TS)3923 if (fFlags & RTLOGFLAGS_PREFIX_TS) 3809 3924 { 3810 uint64_t u64 = RTTimeNanoTS();3811 int iBase = 16;3812 unsigned int f Flags = RTSTR_F_ZEROPAD;3813 if ( pLoggerInt->fFlags & RTLOGFLAGS_DECIMAL_TS)3925 uint64_t u64 = RTTimeNanoTS(); 3926 int iBase = 16; 3927 unsigned int fStrFlags = RTSTR_F_ZEROPAD; 3928 if (fFlags & RTLOGFLAGS_DECIMAL_TS) 3814 3929 { 3815 iBase = 10;3816 f Flags = 0;3930 iBase = 10; 3931 fStrFlags = 0; 3817 3932 } 3818 if ( pLoggerInt->fFlags & RTLOGFLAGS_REL_TS)3933 if (fFlags & RTLOGFLAGS_REL_TS) 3819 3934 { 3820 3935 static volatile uint64_t s_u64LastTs; … … 3827 3942 } 3828 3943 /* 1E15 nanoseconds = 11 days */ 3829 psz += RTStrFormatNumber(psz, u64, iBase, 16, 0, f Flags);3944 psz += RTStrFormatNumber(psz, u64, iBase, 16, 0, fStrFlags); 3830 3945 *psz++ = ' '; 3831 3946 } 3832 3947 #define CCH_PREFIX_01 0 + 17 3833 3948 3834 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_TSC)3949 if (fFlags & RTLOGFLAGS_PREFIX_TSC) 3835 3950 { 3836 3951 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) 3837 uint64_t u64 = ASMReadTSC();3952 uint64_t u64 = ASMReadTSC(); 3838 3953 #else 3839 uint64_t u64 = RTTimeNanoTS();3954 uint64_t u64 = RTTimeNanoTS(); 3840 3955 #endif 3841 int iBase = 16;3842 unsigned int f Flags = RTSTR_F_ZEROPAD;3843 if ( pLoggerInt->fFlags & RTLOGFLAGS_DECIMAL_TS)3956 int iBase = 16; 3957 unsigned int fStrFlags = RTSTR_F_ZEROPAD; 3958 if (fFlags & RTLOGFLAGS_DECIMAL_TS) 3844 3959 { 3845 iBase = 10;3846 f Flags = 0;3960 iBase = 10; 3961 fStrFlags = 0; 3847 3962 } 3848 if ( pLoggerInt->fFlags & RTLOGFLAGS_REL_TS)3963 if (fFlags & RTLOGFLAGS_REL_TS) 3849 3964 { 3850 3965 static volatile uint64_t s_u64LastTsc; … … 3857 3972 } 3858 3973 /* 1E15 ticks at 4GHz = 69 hours */ 3859 psz += RTStrFormatNumber(psz, u64, iBase, 16, 0, f Flags);3974 psz += RTStrFormatNumber(psz, u64, iBase, 16, 0, fStrFlags); 3860 3975 *psz++ = ' '; 3861 3976 } 3862 3977 #define CCH_PREFIX_02 CCH_PREFIX_01 + 17 3863 3978 3864 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_MS_PROG)3979 if (fFlags & RTLOGFLAGS_PREFIX_MS_PROG) 3865 3980 { 3866 3981 #ifndef IN_RING0 … … 3875 3990 #define CCH_PREFIX_03 CCH_PREFIX_02 + 21 3876 3991 3877 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_TIME)3992 if (fFlags & RTLOGFLAGS_PREFIX_TIME) 3878 3993 { 3879 3994 #if defined(IN_RING3) || defined(IN_RING0) … … 3896 4011 #define CCH_PREFIX_04 CCH_PREFIX_03 + (3+1+3+1+3+1+7+1) 3897 4012 3898 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_TIME_PROG)4013 if (fFlags & RTLOGFLAGS_PREFIX_TIME_PROG) 3899 4014 { 3900 4015 … … 3920 4035 3921 4036 # if 0 3922 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_DATETIME)4037 if (fFlags & RTLOGFLAGS_PREFIX_DATETIME) 3923 4038 { 3924 4039 char szDate[32]; … … 3935 4050 # endif 3936 4051 3937 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_PID)4052 if (fFlags & RTLOGFLAGS_PREFIX_PID) 3938 4053 { 3939 4054 RTPROCESS Process = RTProcSelf(); … … 3943 4058 #define CCH_PREFIX_07 CCH_PREFIX_06 + 9 3944 4059 3945 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_TID)4060 if (fFlags & RTLOGFLAGS_PREFIX_TID) 3946 4061 { 3947 4062 RTNATIVETHREAD Thread = RTThreadNativeSelf(); … … 3951 4066 #define CCH_PREFIX_08 CCH_PREFIX_07 + 17 3952 4067 3953 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_THREAD)4068 if (fFlags & RTLOGFLAGS_PREFIX_THREAD) 3954 4069 { 3955 4070 #ifdef IN_RING3 … … 3964 4079 #define CCH_PREFIX_09 CCH_PREFIX_08 + 17 3965 4080 3966 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_CPUID)4081 if (fFlags & RTLOGFLAGS_PREFIX_CPUID) 3967 4082 { 3968 4083 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) … … 3976 4091 #define CCH_PREFIX_10 CCH_PREFIX_09 + 17 3977 4092 3978 if ( ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_CUSTOM)4093 if ( (fFlags & RTLOGFLAGS_PREFIX_CUSTOM) 3979 4094 && pLoggerInt->pfnPrefix) 3980 4095 { … … 3984 4099 #define CCH_PREFIX_11 CCH_PREFIX_10 + 32 3985 4100 3986 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_LOCK_COUNTS)4101 if (fFlags & RTLOGFLAGS_PREFIX_LOCK_COUNTS) 3987 4102 { 3988 4103 #ifdef IN_RING3 /** @todo implement these counters in ring-0 too? */ … … 4009 4124 #define CCH_PREFIX_12 CCH_PREFIX_11 + 8 4010 4125 4011 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_FLAG_NO)4126 if (fFlags & RTLOGFLAGS_PREFIX_FLAG_NO) 4012 4127 { 4013 4128 psz += RTStrFormatNumber(psz, pArgs->fFlags, 16, 8, 0, RTSTR_F_ZEROPAD); … … 4016 4131 #define CCH_PREFIX_13 CCH_PREFIX_12 + 9 4017 4132 4018 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_FLAG)4133 if (fFlags & RTLOGFLAGS_PREFIX_FLAG) 4019 4134 { 4020 4135 #ifdef IN_RING3 … … 4027 4142 #define CCH_PREFIX_14 CCH_PREFIX_13 + 17 4028 4143 4029 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_GROUP_NO)4144 if (fFlags & RTLOGFLAGS_PREFIX_GROUP_NO) 4030 4145 { 4031 4146 if (pArgs->iGroup != ~0U) … … 4042 4157 #define CCH_PREFIX_15 CCH_PREFIX_14 + 9 4043 4158 4044 if ( pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_GROUP)4159 if (fFlags & RTLOGFLAGS_PREFIX_GROUP) 4045 4160 { 4046 4161 const unsigned fGrp = pLoggerInt->afGroups[pArgs->iGroup != ~0U ? pArgs->iGroup : 0]; … … 4071 4186 #define CCH_PREFIX_16 CCH_PREFIX_15 + 17 4072 4187 4073 #define CCH_PREFIX ( CCH_PREFIX_16 ) 4074 { AssertCompile(CCH_PREFIX < 256); } 4188 if (pArgs->pszInfix) 4189 { 4190 size_t cchInfix = strlen(pArgs->pszInfix); 4191 psz = rtLogStPNCpyPad2(psz, pArgs->pszInfix, RT_MIN(cchInfix, 8), 1); 4192 } 4193 #define CCH_PREFIX_17 CCH_PREFIX_16 + 9 4194 4195 4196 #define CCH_PREFIX ( CCH_PREFIX_17 ) 4197 { AssertCompile(CCH_PREFIX < 265); } 4075 4198 4076 4199 /* … … 4078 4201 */ 4079 4202 AssertMsg(psz - &pchBuf[offBuf] <= 223, 4080 ("%#zx (%zd) - fFlags=%#x\n", psz - &pchBuf[offBuf], psz - &pchBuf[offBuf], pLoggerInt->fFlags));4203 ("%#zx (%zd) - fFlags=%#x\n", psz - &pchBuf[offBuf], psz - &pchBuf[offBuf], fFlags)); 4081 4204 pBufDesc->offBuf = offBuf = (uint32_t)(psz - pchBuf); 4082 4205 cb = cbBuf - offBuf - 1; … … 4101 4224 { 4102 4225 cb = pszNewLine - pachChars; 4103 if (!( pLoggerInt->fFlags & RTLOGFLAGS_USECRLF))4226 if (!(fFlags & RTLOGFLAGS_USECRLF)) 4104 4227 { 4105 4228 cb += 1; … … 4191 4314 OutputArgs.iGroup = iGroup; 4192 4315 OutputArgs.fFlags = fFlags; 4316 OutputArgs.pszInfix = NULL; 4193 4317 RTLogFormatV(rtLogOutputPrefixed, &OutputArgs, pszFormat, args); 4194 4318 }
Note:
See TracChangeset
for help on using the changeset viewer.