From c14e512a032edf2504e17e279f89c902acc7bfc6 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Thu, 19 Nov 2015 13:06:14 -0800 Subject: [PATCH] wip --- src/corehost/inc/args.h | 1 - src/corehost/inc/trace.h | 12 ++---------- src/corehost/src/args.cpp | 10 +++++----- src/corehost/src/main.cpp | 4 ---- src/corehost/src/pal.windows.cpp | 2 +- src/corehost/src/trace.cpp | 28 +++++++++++++--------------- src/corehost/src/utils.cpp | 2 ++ 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/corehost/inc/args.h b/src/corehost/inc/args.h index 3d4328abc..66ff90f79 100644 --- a/src/corehost/inc/args.h +++ b/src/corehost/inc/args.h @@ -9,7 +9,6 @@ struct arguments_t { - trace::level_t trace_level; pal::string_t own_path; pal::string_t managed_application; pal::string_t clr_path; diff --git a/src/corehost/inc/trace.h b/src/corehost/inc/trace.h index 30a0282bb..1c717bb68 100644 --- a/src/corehost/inc/trace.h +++ b/src/corehost/inc/trace.h @@ -8,16 +8,8 @@ namespace trace { - enum class level_t - { - Error = 0, - Warning = 1, - Info = 2, - Verbose = 3 - }; - - void set_level(level_t level); - bool is_enabled(level_t level); + void enable(); + bool is_enabled(); void verbose(const pal::char_t* format, ...); void info(const pal::char_t* format, ...); void warning(const pal::char_t* format, ...); diff --git a/src/corehost/src/args.cpp b/src/corehost/src/args.cpp index 924b68af5..747a56ecc 100644 --- a/src/corehost/src/args.cpp +++ b/src/corehost/src/args.cpp @@ -5,7 +5,6 @@ #include "utils.h" arguments_t::arguments_t() : - trace_level(trace::level_t::Error), managed_application(_X("")), clr_path(_X("")), app_argc(0), @@ -20,7 +19,7 @@ void display_help() _X("Execute the specified managed assembly with the passed in arguments\n\n") _X("The Host's behavior can be altered using the following environment variables:\n") _X(" DOTNET_HOME Set the dotnet home directory. The CLR is expected to be in the runtime subdirectory of this directory. Overrides all other values for CLR search paths\n") - _X(" CLRHOST_TRACE Set to affect trace levels (0 = Errors only (default), 1 = Warnings, 2 = Info, 3 = Verbose)\n"); + _X(" COREHOST_TRACE Set to affect trace levels (0 = Errors only (default), 1 = Warnings, 2 = Info, 3 = Verbose)\n"); } bool parse_arguments(const int argc, const pal::char_t* argv[], arguments_t& args) @@ -61,12 +60,13 @@ bool parse_arguments(const int argc, const pal::char_t* argv[], arguments_t& arg // Read trace environment variable pal::string_t trace_str; - if (pal::getenv(_X("CLRHOST_TRACE"), trace_str)) + if (pal::getenv(_X("COREHOST_TRACE"), trace_str)) { auto trace_val = pal::xtoi(trace_str.c_str()); - if (trace_val >= (int)trace::level_t::Error && trace_val <= (int)trace::level_t::Verbose) + if (trace_val > 0) { - args.trace_level = (trace::level_t)trace_val; + trace::enable(); + trace::info(_X("tracing enabled")); } } diff --git a/src/corehost/src/main.cpp b/src/corehost/src/main.cpp index ae1ef51de..5c9667502 100644 --- a/src/corehost/src/main.cpp +++ b/src/corehost/src/main.cpp @@ -161,10 +161,6 @@ int main(const int argc, const pal::char_t* argv[]) return 1; } - // Configure tracing - trace::set_level(args.trace_level); - trace::info(_X("tracing enabled")); - // Resolve paths if (!pal::realpath(args.managed_application)) { diff --git a/src/corehost/src/pal.windows.cpp b/src/corehost/src/pal.windows.cpp index d56ed8051..6c05f2328 100644 --- a/src/corehost/src/pal.windows.cpp +++ b/src/corehost/src/pal.windows.cpp @@ -45,7 +45,7 @@ bool pal::load_library(const char_t* path, dll_t& dll) return false; } - if (trace::is_enabled(trace::level_t::Info)) + if (trace::is_enabled()) { pal::char_t buf[PATH_MAX]; ::GetModuleFileNameW(dll, buf, PATH_MAX); diff --git a/src/corehost/src/trace.cpp b/src/corehost/src/trace.cpp index f0eb85c83..5f67b8aa0 100644 --- a/src/corehost/src/trace.cpp +++ b/src/corehost/src/trace.cpp @@ -3,21 +3,21 @@ #include "trace.h" -static trace::level_t g_level = trace::level_t::Error; +static bool g_enabled = false; -void trace::set_level(trace::level_t new_level) +void trace::enable() { - g_level = new_level; + g_enabled = true; } -bool trace::is_enabled(trace::level_t level) +bool trace::is_enabled() { - return level <= g_level; + return g_enabled; } void trace::verbose(const pal::char_t* format, ...) { - if (trace::is_enabled(trace::level_t::Verbose)) + if (g_enabled) { va_list args; va_start(args, format); @@ -28,7 +28,7 @@ void trace::verbose(const pal::char_t* format, ...) void trace::info(const pal::char_t* format, ...) { - if (trace::is_enabled(trace::level_t::Info)) + if (g_enabled) { va_list args; va_start(args, format); @@ -39,18 +39,16 @@ void trace::info(const pal::char_t* format, ...) void trace::error(const pal::char_t* format, ...) { - if (trace::is_enabled(trace::level_t::Error)) - { - va_list args; - va_start(args, format); - pal::err_vprintf(format, args); - va_end(args); - } + // Always print errors + va_list args; + va_start(args, format); + pal::err_vprintf(format, args); + va_end(args); } void trace::warning(const pal::char_t* format, ...) { - if (trace::is_enabled(trace::level_t::Warning)) + if (g_enabled) { va_list args; va_start(args, format); diff --git a/src/corehost/src/utils.cpp b/src/corehost/src/utils.cpp index 742c2c893..4bfb66a79 100644 --- a/src/corehost/src/utils.cpp +++ b/src/corehost/src/utils.cpp @@ -2,12 +2,14 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include "utils.h" +#include "trace.h" bool coreclr_exists_in_dir(const pal::string_t& candidate) { pal::string_t test(candidate); append_path(test, _X("runtime")); append_path(test, LIBCORECLR_NAME); + trace::verbose(_X("checking for CoreCLR in default location: %s"), test.c_str()); return pal::file_exists(test); }