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:

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

clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe

[For StringBuilder and threadsafety test.]

Security Example

Environment

clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe

[For StringBuilder and threadsafety test.]

Loader Example

Environment

clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe

[For StringBuilder and threadsafety test.]

DumpOnClassLoad Example

Environment

Hello World Sample Under Logging

clix hello.exe

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

clix tests\bvt\short\CS_TryFinally.exe

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
 

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


clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe

[For StringBuilder and threadsafety test.]

Garbage Collection Example: Detail Level=2

Environment

clix tests\bcl\ThreadSafety\Types Co8788StringBuilder.exe

[For StringBuilder and threadsafety test.]

Garbage Collection Example: Detail Level=3

Environment

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