Logging in the Shared Source CLI
Contents
There are several ways to turn on logging in the Shared Source CLI (SSCLI)
implementation. The two main categories of logging are:
- Platform Adaptation Layer (PAL) logging. This is logging at a low
level before calls are made to the operating system.
- Unified CLI logging. This log sequences in the SSCLI execution
engine. For example, garbage collection, just-in-time (JIT) compilation,
and so on.
PAL Logging
There are different SSCLI logging capabilities on the Microsoft® Windows®
operating system and the FreeBSD operating system.
Note: On both platforms, it's safe to use a checked or fastchecked build of
rotor_pal.dll in a retail build of everything else, so you can get API logging
while running retail binaries.
PAL Logging on Windows
| Environment Variable |
Value |
Description |
| PAL_API_TRACING |
debugger |
Send log output to the debugger via OutputDebugString
Note that from inside a debugger, if you modify the global variable
rotor_pal!LogFileHandle from the default value of 0 to 0xffffffff, then
logging will immediately begin to be output to the debugger. Setting it
back to 0 will disable it again. |
| filename |
Send log output to the specified filename. |
| stderr |
Send log output to the standard error handler. |
| stdout |
Send log output to the console. |
PAL Logging on FreeBSD
The logging infrastructure and options are fully documented in
%ROTOR_PAL%/pal/unix/include/pal/dbgmsg.h.
| Environment Variable |
Value |
Description |
| PAL_API_TRACING |
filename |
Send log output to the the specified filename. |
| PAL_DBG_CHANNELS |
[+|-] |
+ turns logging on. - turns logging off. |
| channel. |
Must be one of PAL, FILE, or others listed in
dbgmsg.h or the option "all" for all the channels. |
| level[: ...] |
Must be TRACE, ENTRY, WARN, ERROR or "all" Debug levels are described in dbgmsg.h |
| PAL_API_LEVELS |
1 |
Will cause the PAL to not log intra-PAL calls
When this environment variable is set to 1 and when the PAL's
implementation of an API like CreateFile calls PAL EnterCriticalSection,
you'll see just the call to CreateFile, but not the nested call to
EnterCriticalSection. Otherwise, the intra-PAL calls complicate the log
file considerably, usually without a lot of additional value. |
Example: Log all API entries and exits to the file entry.log:
set PAL_DBG_CHANNELS="+all.ENTRY"
set PAL_API_TRACING="entry.log"
Unified CLI Logging
The following environment variables can be set in order to enable detailed
execution
logging.
A unified logging system is used for garbage collection, JIT, and other execution logging and
the logging system is controlled by a set of variables. The implementation
of the logging system is in %ROTOR_DIR%/clr/src/utilcode/log.cpp and %ROTOR_DIR%/clr/src/inc/log.h. Logging is enabled
only in
checked and fastchecked builds. If you want to change this see the comment
in log.cpp.
Environment variables have the same name as code variables but must have "COMPlus_" prepended.
Every variable is read first from the environment then from the per-user
rotor.ini configuration file and finally from the per-installation rotor.ini configuration file.
Some additional environment variables are used by the specific subsystem.
| Environment Variable |
Value |
Description |
| COMPlus_LogEnable |
1 |
Enables logging. This value can be toggled on and
off without changing the other options to turn logging on and off. |
| COMPlus_LogToConsole |
1 One of these options must be set
to 1 to enable logging output |
Enables logging output to the console |
| COMPlus_LogToDebugger |
Enables logging to the debugger (cordbg.exe) |
| COMPlus_LogToFile |
Enables logging to a file |
| COMPlus_LogFile |
Name of log file |
Requires COMPlus_LogToFile=1 |
| COMPlus_LogFlushFile |
|
Flush file buffers everytime anything is logged. Applies
to both LogToConsole and LogToFile. Slow but very reliable logging. |
| COMPlus_LogFileAppend |
1 |
Append to log file instead of replacing it. |
| COMPlus_LogLevel |
n |
n ranges from 1 to 9. Where:
1 is the least detailed log
output
9 is the most detailed log output |
| COMPlus_LogFacility |
0xn |
Hex bitmask of facilities log. Each bit represents
one facility to log. The list of facilities is in
sscli/clr/src/inc/loglf.h
Some useful settings:
- 0x00000001 Log GC
- 0x00000008 Log JIT
- 0x12000003 Log GC, live pointers, app domains,
security
|
JIT-Specific Logging Environment Variables
By default these are only operational on checked or fastchecked builds.
| Environment Variable |
Value |
Description |
| COMPlus_JitName |
LibraryName |
Name of the JIT DLL library. If not defined we default
to the hardcoded names mscorejt.dll or libmscorejt.so on FreeBSD. |
| COMPlus_JitBreak |
FunctionName |
Break into the debugger before JIT compiling FunctionName.
Use * for to JIT all functions. |
| COMPlus_JitHalt |
FunctionName |
Emit a debugger break before the prolog of FunctionName.
The inserted break will occur just before execution of the function.
Use * for to JIT all functions. |
| COMPlus_JitTrace |
0 1 |
If 1, prints out the trace of functions that were
JIT compiled.
This trace output can also be obtained via the central logging system
but this is a more light weight mechanism that generates only JIT
information.
|
| COMPlus_JitDisasm |
FunctionName |
Emits the native code generated for FunctionName.
SSCLIChange:
This functionality is not supported in the SSCLI.
To obtain similar functionality, set COMPlus_JitBreak to the function
you are interested in disassembling and then view the disassembled code
in the debugger after it breaks in the function. |
Garbage
Collection-Specific Logging Environment Variables
By default these are only operational on checked or fastchecked builds.
| Environment Variable |
Value |
Description |
| COMPLUS_GCprnLvl |
detailnumber |
Sets the level of detail of the logging output to
detailnumber. The higher the number the more data will be
output. |
| COMPLUS_GCtraceStart |
startnumber |
The garbage collection generation at which to start
logging output. |
| COMPLUS_GCtraceEnd |
endnumber |
The garbage collection generation at which to stop
logging output. |
Additional Logging Options
By default these are only operational on checked or fastchecked builds.
These options require that Unified CLI Logging be enabled but do not affect
the other options set for Unified logging.
| Environment Variable |
Value |
Description |
| COMPlus_DumpOnClassLoad |
classname |
Dumps information about the classname class when
it is loaded. The information that is dumped contains:
- Method table summary.
- Number of class static fields.
- Number of class instance fields.
- Number of class static object reference fields.
- Number of declared fields.
- Number of declared methods.
- A vtable dump.
- A field layout dump.
- A garbage collection descriptor dump.
|
| COMPlus_JitCodeLog |
FunctionName |
Used only for JIT logging. Log JIT information for FunctionName.
You can
use FunctionName=* to log all functions |
Example Logging Sessions
Garbage Collection Example
Environment
- COMPlus_LogEnable=1
- COMPLUS_LogFacility=1
- COMPLUS_LogLevel=4 ( increase to get more detail )
- COMPLUS_LogToConsole=1
- COMPLUS_LogToFile=0
clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe
[For StringBuilder and threadsafety test.]
- TID c10: Executing program with command line 'Co8788StringBuilder.exe'
- TID 9a0: Finalizer thread
starting...C:\Data\Rotor2\tests\bcl\ThreadSafety\Types Co8788StringBuilder
- .cs , for StringBuilder - threadsafety test
- { =========== BEGINGC 0, (gen = 0, collect_classes = 0) ==========
- TID 1078: Promotion Phase, Stack
- TID 1078: Promotion Phase, Handles
- TID 1078: Relocation Phase, Stack
- TID 1078: Relocation Phase, Handles
- TID 1078: ========== ENDGC (gen = 0, collect_classes = 0) ===========}
- TID e1c: { =========== BEGINGC 1, (gen = 0, collect_classes = 0)
==========
- TID e1c: Promotion Phase, Stack
- TID e1c: Promotion Phase, Handles
- TID e1c: Relocation Phase, Stack
- TID e1c: Relocation Phase, Handles
- TID e1c: ========== ENDGC (gen = 0, collect_classes = 0) ===========}
- TID c6c: { =========== BEGINGC 2, (gen = 0, collect_classes = 0)
==========
- TID c6c: Promotion Phase, Stack
- TID c6c: Promotion Phase, Handles
- TID c6c: Relocation Phase, Stack
- TID c6c: Relocation Phase, Handles
Security Example
Environment
- COMPlus_LogEnable=1
- COMPLUS_LogFacility=0x10000000
- COMPLUS_LogLevel=6
- COMPLUS_LogToConsole=1
- COMPLUS_LogToFile=0
clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe
[For StringBuilder and threadsafety test.]
- TID 4bc: Executing program with command line 'Co8788StringBuilder.exe'
- TID 4bc: Code-access security check invoked.
- TID 4bc: Method: CodeAccessSecurityEngine.Check
- TID 4bc: Method: CodeAccessSecurityEngine.Check
- TID 4bc: Method: CodeAccessPermission.Demand
- TID 4bc: Method: Directory.GetCurrentDirectory
- TID 4bc: Method: Environment.get_CurrentDirectory
- TID 4bc: Method: Co8788StringBuilder..cctor
- TID 4bc: Method: Co8788StringBuilder.Main
- TID 4bc: Code-access stackwalk completed.
- TID 4bc: Code-access check passed.
Loader Example
Environment
- COMPlus_LogEnable=1
- COMPLUS_LogFacility=0x00000010
- COMPLUS_LogLevel=4
- COMPLUS_LogToConsole=1
- COMPLUS_LogToFile=0
clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe
[For StringBuilder and threadsafety test.]
- TID a00: Executing program with command line 'Co8788StringBuilder.exe'
- TID a00: Set: APPBASE: *C:\Data\Rotor2\tests\bcl\ThreadSafety\Types\*.
- TID a00: Set: APP_CONFIG_FILE: *Co8788StringBuilder.exe.config*.
- TID a00: Set: APP_NAME: *Co8788StringBuilder.exe*.
- TID a00: Set: MACHINE_CONFIG:
*C:\Data\Rotor2\build\v1.x86chk.rotor\config\machine.config*.
DumpOnClassLoad Example
Environment
- COMPlus_DumpOnClassLoad=MainApp
- COMPlus_LogEnable=1
- COMPLUS_LogLevel=1
- COMPLUS_LogToConsole=1
- COMPLUS_LogToFile=0
Hello World Sample Under Logging
clix hello.exe
- TID 9d8: Method table summary for 'MainApp':
- TID 9d8: Number of static fields: 0
- TID 9d8: Number of instance fields: 0
- TID 9d8: Number of static obj ref fields: 0
- TID 9d8: Number of declared fields: 0
- TID 9d8: Number of declared methods: 2
- TID 9d8: Vtable (with interface dupes) for 'MainApp':
- TID 9d8: Total duplicate slots = 201
- TID 9d8: slot 0: System.Object[mscorlib.dll]::ToString 0x3E2073 (slot = 0)
- TID 9d8: slot 1: System.Object[mscorlib.dll]::Equals 0x3E2223 (slot = 1)
- TID 9d8: slot 2: System.Object[mscorlib.dll]::GetHashCode 0x3E2253 (slot =
2)
- TID 9d8: slot 3: System.Object[mscorlib.dll]::Finalize 0x3E2113 (slot = 3)
- TID 9d8: <-- vtable ends here
- TID 9d8: slot 4: MainApp[hello.exe]::Main 0x7B50AB (slot = 4)
- TID 9d8: slot 5: MainApp[hello.exe]::.ctor 0x7B50D3 (slot = 5)
- TID 9d8:
- TID 9d8: GC description for 'MainApp':
Hello World!
JitCodeLog=Main Example:
LogLevel=4
Environment
Entry and exit logging code fragment are jitted in the prolog and epilog, and
in EH handlers
- COMPlus_JitCodeLog=Main
- COMPlus_LogEnable=1
- COMPLUS_LogFacility=0x00000008
- COMPLUS_LogLevel=4
- COMPLUS_LogToConsole=1
- COMPLUS_LogToFile=0
clix tests\bvt\short\CS_TryFinally.exe
- TID 98c: Executing program with command line
'tests\bvt\short\CS_TryFinally.exe'
- TID 98c: Fjitted 'CO_TryFinally::Main' at addr 0x2ca2d2c to 0x2ca3594
header 0
- TID 98c: { entering CO_TryFinally::Main
- 1: Abort( )
- TID 9f0: In DefaultCatchHandler
- 1: finally 1
- 1: finally 2
- 1: finally 3
- 1: finally 4
- 1: finally 5
- 1: finally 6
- 1: finally 7
- 1: finally 8
- 2: Abort( )
- TID 984: In DefaultCatchHandler
- 2: finally 8
- 2: finally 7
- 2: finally 6
- 2: finally 5
- 2: finally 4
- 2: finally 3
- 2: finally 2
- 2: finally 1
- 3: Abort( )
- TID 51c: In DefaultCatchHandler
- 3: finally 1
- TID 98c: } leaving System.String::Main
- TID 98c: Program exiting: return code = 0
JitCodeLog=Main Example:
LogLevel=5
Environment
COMPLUS_LogLevel=5
Garbage collection map information is printed describing the locals and the
arguments.
Logging code fragments describing the state of the processor are inserted
after code for each IL instruction
clix tests\bvt\short\CS_TryFinally.exe
- TID 8b0: Executing program with command line
'tests\bvt\short\CS_TryFinally.exe'
- TID 8b0: ********* GC map info *******
- TID 8b0: Locals: (Length = 0x5, Frame size = 0x18)
- TID 8b0: local 0: offset: -0x10 type: typeRef
- TID 8b0: local 1: offset: -0x14 type: typeRef
- TID 8b0: local 2: offset: -0x18 type: typeRef
- TID 8b0: local 3: offset: -0x1c type: typeRef
- TID 8b0: local 4: offset: -0x20 type: typeI4
- TID 8b0: Bitvectors printed low bit (low local), first
- TID 8b0: LocalsGCRef bit vector len=4 bits: 1 1 1 1
- TID 8b0: interiorGC bitvector len=0 bits:
- TID 8b0: Pinned LocalsGCRef bit vector: len=0 bits:
- TID 8b0: Pinned interiorGC bit vector len =0 bits:
- TID 8b0: Args: (Length = 0x1, Frame size = 0)
- TID 8b0: offset: -0xfffffff8 type: typeRef
- TID 8b0: Fjitted 'CO_TryFinally::Main' at addr 0x2ca2d2c to 0x2ca3594
header 0
- TID 8b0: { entering CO_TryFinally::Main
- TID 8b0: ESP: 6ee7c[ 0: 0: 0] EBP: 6ee9c IL: 0 newobj
- TID 8b0: ESP:+ 6ee78[ ad075c: 0: 0] EBP: 6ee9c IL: 5 stloc.0
- TID 8b0: ESP: 6ee7c[ 0: 0: 0] EBP: 6ee9c IL: 6 ldloc.0
- TID 8b0: ESP:+ 6ee78[ ad075c: 0: 0] EBP: 6ee9c IL: 7 ldftn
- TID 8b0: ESP:+ 6ee74[ 7b5153: ad075c: 0] EBP: 6ee9c IL: d newobj
- TID 8b0: ESP:+ 6ee78[ ad076c: 0: 0] EBP: 6ee9c IL: 12 newobj
- TID 8b0: ESP:+ 6ee78[ ad0788: 0: 0] EBP: 6ee9c IL: 17 stloc.1
- TID 8b0: ESP: 6ee7c[ 0: 0: 0] EBP: 6ee9c IL: 18 ldloc.0
- TID 8b0: ESP:+ 6ee78[ ad075c: 0: 0] EBP: 6ee9c IL: 19 ldftn
- TID 8b0: ESP:+ 6ee74[ 7b512b: ad075c: 0] EBP: 6ee9c IL: 1f newobj
- TID 8b0: ESP:+ 6ee78[ ad0bac: 0: 0] EBP: 6ee9c IL: 24 newobj
- TID 8b0: ESP:+ 6ee78[ ad0bc8: 0: 0] EBP: 6ee9c IL: 29 stloc.2
- TID 8b0: ESP: 6ee7c[ 0: 0: ad0bc8] EBP: 6ee9c IL: 2a ldloc.0
- TID 8b0: ESP:+ 6ee78[ ad075c: 0: 0] EBP: 6ee9c IL: 2b ldftn
- TID 8b0: ESP:+ 6ee74[ 7b5103: ad075c: 0] EBP: 6ee9c IL: 31 newobj
- TID 8b0: ESP:+ 6ee78[ ad0c08: 0: 0] EBP: 6ee9c IL: 36 newobj
- TID 8b0: ESP:+ 6ee78[ ad0c24: 0: 0] EBP: 6ee9c IL: 3b stloc.3
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 3c ldloc.1
- TID 8b0: ESP:+ 6ee78[ ad0788: 0: ad0c24] EBP: 6ee9c IL: 3d callvirt
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 42 ldloc.2
- TID 8b0: ESP:+ 6ee78[ ad0bc8: 0: ad0c24] EBP: 6ee9c IL: 43 callvirt
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 48 ldloc.3
- TID 8b0: ESP:+ 6ee78[ ad0c24: 0: ad0c24] EBP: 6ee9c IL: 49 callvirt
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 4e ldc.i4
- TID 8b0: ESP:+ 6ee78[ 7d0: 0: ad0c24] EBP: 6ee9c IL: 53 call
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 58 ldstr
- TID 8b0: ESP:+ 6ee78[ ad06e4: 0: ad0c24] EBP: 6ee9c IL: 5d call
- 1: Abort( )
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 62 ldloc.1
- TID 8b0: ESP:+ 6ee78[ ad0788: 0: ad0c24] EBP: 6ee9c IL: 63 callvirt
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 68 ldloc.1
- TID 8b0: ESP:+ 6ee78[ ad0788: 0: ad0c24] EBP: 6ee9c IL: 69 callvirt
- TID 588: In DefaultCatchHandler
- 1: finally 1
- 1: finally 2
- 1: finally 3
- 1: finally 4
- 1: finally 5
- 1: finally 6
- 1: finally 7
- 1: finally 8
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 6e ldstr
- TID 8b0: ESP:+ 6ee78[ ad070c: 0: ad0c24] EBP: 6ee9c IL: 73 call
- 2: Abort( )
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 78 ldloc.2
- TID 8b0: ESP:+ 6ee78[ ad0bc8: 0: ad0c24] EBP: 6ee9c IL: 79 callvirt
- TID 9ec: In DefaultCatchHandler
- 2: finally 8
- 2: finally 7
- 2: finally 6
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 7e ldloc.2
- TID 8b0: ESP:+ 6ee78[ ad0bc8: 0: ad0c24] EBP: 6ee9c IL: 7f callvirt
- 2: finally 5
- 2: finally 4
- 2: finally 3
- 2: finally 2
- 2: finally 1
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 84 ldstr
- TID 8b0: ESP:+ 6ee78[ ad0734: 0: ad0c24] EBP: 6ee9c IL: 89 call
- 3: Abort( )
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 8e ldloc.3
- TID 8b0: ESP:+ 6ee78[ ad0c24: 0: ad0c24] EBP: 6ee9c IL: 8f callvirt
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 94 ldloc.3
- TID 8b0: ESP:+ 6ee78[ ad0c24: 0: ad0c24] EBP: 6ee9c IL: 95 callvirt
- TID 9b0: In DefaultCatchHandler
- 3: finally 1
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 9a ldc.i4.0
- TID 8b0: ESP:+ 6ee78[ 0: 0: ad0c24] EBP: 6ee9c IL: 9b stloc.s
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 9d br.s
- TID 8b0: ESP: 6ee7c[ 0: ad0c24: ad0bc8] EBP: 6ee9c IL: 9f ldloc.s
- TID 8b0: ESP:+ 6ee78[ 0: 0: ad0c24] EBP: 6ee9c IL: a1 ret
- TID 8b0: } leaving ::Main
- TID 8b0: Program exiting: return code = 0
JitCodeLog=Main Example:
LogLevel=6
Environment
COMPLUS_LogLevel=6
Too much output to list.
With this setting the stack states encoded for GC are output.
Garbage Collection
Example: Detail Level=1
Environment
- COMPlus_GCprnLvl=1
- COMPlus_GCtraceStart=0
- COMPlus_GCtraceEnd=3
clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe
[For StringBuilder and threadsafety test.]
- ****Garbage Collection**** 1
- generation 0 condemned
- ****Garbage Collection**** 2
Garbage Collection
Example: Detail Level=2
Environment
- COMPlus_GCprnLvl=2
- COMPlus_GCtraceStart=0
- COMPlus_GCtraceEnd=2
clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe
[For StringBuilder and threadsafety test.]
- ****Garbage Collection**** 1
- Generation 1: [00A0002C 00ACF898[, gap size: 12
- Generation 0: [00ACF898 00B16888[, gap size: 12
- generation 0 condemned
- ---- Copy Phase condemning 0 ----
- ---- Scavenge Phase ---- Condemned generation 0
- ---- Scavenge Phase ---- Condemned generation 0
- ---- Scavenge Phase ---- Condemned generation 0
- ---- End of Copy phase ----
- Generation 1: [00A0002C 00ADDCD4[, gap size: 12
- Generation 0: [00ADDCD4 00ADDCE0[, gap size: 12
Garbage Collection
Example: Detail Level=3
Environment
- COMPlus_GCprnLvl=3
- COMPlus_GCtraceStart=0
- COMPlus_GCtraceEnd=2
clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe
[For StringBuilder and threadsafety test.]
Too much output to list. Detailed per memory location log of operations
performed during the first GC
Copyright (c) 2002 Microsoft Corporation