Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Enhance hax logger on Windows, and some cleanup. #215

Merged
merged 1 commit into from
Aug 5, 2019
Merged

Enhance hax logger on Windows, and some cleanup. #215

merged 1 commit into from
Aug 5, 2019

Conversation

coxuintel
Copy link
Contributor

  • Use hax logger instead of direct call to DbgPrint, so that platform
    specific APIs are not called directly.
  • Specify DPFLTR_IHVDRIVER_ID to vDbgPrintExWithPrefix(), and assign
    log level accordingly. DPFLTR_xxx level to HAX log level mapping:
    HAX_LOGD >> DPFLTR_TRACE_LEVEL
    HAX_LOGI >> DPFLTR_INFO_LEVEL
    HAX_LOGW >> DPFLTR_WARNING_LEVEL
    HAX_LOGE >> DPFLTR_ERROR_LEVEL
    According to MSDN, non-OS component should use DPFLTR_IHVDRIVER_ID.
    With proper level set, on-the-fly log level can be controlled by
    component filter mask without recompiling the driver.
    Check MSDN for details:
    https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/reading-and-filtering-debugging-messages
  • Replace reduntant default_hax_log_level with HAX_LOG_DEFAULT in hax.h,
    and prevent using instant value directly in logger.
  • Some spelling mistake and cleanup.

Signed-off-by: Colin Xu colin.xu@intel.com


if (level >= HAX_LOG_DEFAULT)
vDbgPrintExWithPrefix("haxm: ", DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, fmt, arglist);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

va_end() missed. Even if it is dummy on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, it's better pair va_start() with va_end() even it's dummy. Thanks for point it out.

@HaxmCI HaxmCI added CI:Build Pass CI:Build Pass CI:Mac Test Pass CI:Mac Test Pass labels Jun 24, 2019
@coxuintel coxuintel requested review from wcwang and hyuan3 July 4, 2019 05:38
Copy link
Contributor

@wcwang wcwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to unify the log functions invocation approach on Windows.

  1. All log functions are the wrappers of hax_log_level().
  2. hax_log_level() is no longer called individually, instead of calling the wrapper functions.
  3. Replace the remaining places that call hax_log_level() with the corresponding wrapper functions.
    ./platforms/windows/hax_entry.c
    Line 696 and 707: hax_error

if (HAX_LOGE >= default_hax_log_level)
vDbgPrintExWithPrefix("haxm_error:", -1, 0, fmt, arglist);

if (HAX_LOGE >= HAX_LOG_DEFAULT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hax_log_level(HAX_LOGE, fmt, arglist);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got your point. Let me revise and update.

}

void hax_warning(char *fmt, ...)
{
va_list arglist;
va_start(arglist, fmt);

if (HAX_LOGW >= default_hax_log_level)
vDbgPrintExWithPrefix("haxm_warning:", -1, 0, fmt, arglist);
if (HAX_LOGW >= HAX_LOG_DEFAULT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hax_log_level(HAX_LOGW, fmt, arglist);

}

void hax_info(char *fmt, ...)
{
va_list arglist;
va_start(arglist, fmt);

if (HAX_LOGI >= default_hax_log_level)
vDbgPrintExWithPrefix("haxm_info:", -1, 0, fmt, arglist);
if (HAX_LOGI >= HAX_LOG_DEFAULT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hax_log_level(HAX_LOGI, fmt, arglist);

}

void hax_debug(char *fmt, ...)
{
va_list arglist;
va_start(arglist, fmt);

if (HAX_LOGD >= default_hax_log_level)
vDbgPrintExWithPrefix("haxm_debug:", -1, 0, fmt, arglist);
if (HAX_LOGD >= HAX_LOG_DEFAULT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hax_log_level(HAX_LOGD, fmt, arglist);

@@ -237,47 +226,70 @@ void hax_disable_irq(void)
asm_disable_irq();
}

void hax_error(char *fmt, ...)
int hax_log_level(int level, const char *fmt, ...)
Copy link
Contributor

@wcwang wcwang Jul 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int hax_log_level(int level, const char *fmt, va_list arglist)
{
const char *prefix[] = {
"",
"haxm_debug: ", // HAX_LOGD
"haxm_info: ", // HAX_LOGI
"haxm_warning: ", // HAX_LOGW
"haxm_error: " // HAX_LOGE
};
if (level >= HAX_LOG_DEFAULT)
vDbgPrintExWithPrefix(prefix[level], DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, fmt, arglist);
return 0;
}

Copy link
Contributor

@wcwang wcwang Jul 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering to define prefix as below to prevent this array from being created and destroyed over and over again, and add a space after colons:
static const char *prefix[] = {
"",
"haxm_debug: ", // HAX_LOGD
"haxm_info: ", // HAX_LOGI
"haxm_warning: ", // HAX_LOGW
"haxm_error: " // HAX_LOGE
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refine the log accordingly.

KERN_INFO,
KERN_WARNING,
KERN_ERR,
KERN_ERR,
Copy link
Contributor

@wcwang wcwang Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to remove the comma after KERN_ERR?
It is recommended to add comment for each level, such as '// HAX_LOGE'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

DPFLTR_INFO_LEVEL,
DPFLTR_WARNING_LEVEL,
DPFLTR_ERROR_LEVEL,
DPFLTR_ERROR_LEVEL,
Copy link
Contributor

@wcwang wcwang Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to remove the comma as it is the last item?
It is recommended to add comments for each level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Enhance hax logger on Windows:
- Use hax logger instead of direct call to DbgPrint, so that platform
  specific APIs are not called directly.
- Specify DPFLTR_IHVDRIVER_ID to vDbgPrintExWithPrefix(), and assign
  log level accordingly. DPFLTR_xxx level to HAX log level mapping:
  HAX_LOGD >> DPFLTR_TRACE_LEVEL
  HAX_LOGI >> DPFLTR_INFO_LEVEL
  HAX_LOGW >> DPFLTR_WARNING_LEVEL
  HAX_LOGE >> DPFLTR_ERROR_LEVEL
  According to MSDN, non-OS component should use DPFLTR_IHVDRIVER_ID.
  With proper level set, on-the-fly log level can be controlled by
  component filter mask without recompiling the driver.
  Check MSDN for details:
  https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/reading-and-filtering-debugging-messages
- Replace reduntant default_hax_log_level with HAX_LOG_DEFAULT in hax.h,
  and prevent using instant value directly in logger.
Retire other log interface except hax_log() with level input.
  Now all log will call hax_log() with expect log level defined in hax.h.
Some spelling mistakes and cleanup.

Signed-off-by: Colin Xu <colin.xu@intel.com>
@wcwang wcwang merged commit 25b1856 into intel:master Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CI:Build Pass CI:Build Pass CI:Mac Test Pass CI:Mac Test Pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants